Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / extensions / api / sync_file_system / extension_sync_event_observer.h
blob7d2847aded74e2731c7e12cd96d3e4dbf605de07
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SYNC_FILE_SYSTEM_EXTENSION_SYNC_EVENT_OBSERVER_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_SYNC_FILE_SYSTEM_EXTENSION_SYNC_EVENT_OBSERVER_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/values.h"
12 #include "chrome/browser/sync_file_system/sync_event_observer.h"
13 #include "extensions/browser/browser_context_keyed_api_factory.h"
14 #include "extensions/browser/extension_event_histogram_value.h"
16 namespace content {
17 class BrowserContext;
20 namespace sync_file_system {
21 class SyncFileSystemService;
24 namespace extensions {
26 // Observes changes in SyncFileSystem and relays events to JS Extension API.
27 class ExtensionSyncEventObserver : public sync_file_system::SyncEventObserver,
28 public BrowserContextKeyedAPI {
29 public:
30 static BrowserContextKeyedAPIFactory<ExtensionSyncEventObserver>*
31 GetFactoryInstance();
33 explicit ExtensionSyncEventObserver(content::BrowserContext* context);
34 ~ExtensionSyncEventObserver() override;
36 void InitializeForService(
37 sync_file_system::SyncFileSystemService* sync_service);
39 // KeyedService override.
40 void Shutdown() override;
42 // sync_file_system::SyncEventObserver interface implementation.
43 void OnSyncStateUpdated(const GURL& app_origin,
44 sync_file_system::SyncServiceState state,
45 const std::string& description) override;
47 void OnFileSynced(const storage::FileSystemURL& url,
48 sync_file_system::SyncFileType file_type,
49 sync_file_system::SyncFileStatus status,
50 sync_file_system::SyncAction action,
51 sync_file_system::SyncDirection direction) override;
53 private:
54 friend class BrowserContextKeyedAPIFactory<ExtensionSyncEventObserver>;
56 // Returns an empty string if the extension |app_origin| cannot be found
57 // in the installed extension list.
58 std::string GetExtensionId(const GURL& app_origin);
60 // BrowserContextKeyedAPI implementation.
61 static const char* service_name() { return "ExtensionSyncEventObserver"; }
62 static const bool kServiceIsCreatedWithBrowserContext = false;
64 content::BrowserContext* browser_context_;
66 // Not owned. If not null, then this is registered to SyncFileSystemService.
67 sync_file_system::SyncFileSystemService* sync_service_;
69 void BroadcastOrDispatchEvent(const GURL& app_origin,
70 events::HistogramValue histogram_value,
71 const std::string& event_name,
72 scoped_ptr<base::ListValue> value);
74 DISALLOW_COPY_AND_ASSIGN(ExtensionSyncEventObserver);
77 template <>
78 void BrowserContextKeyedAPIFactory<
79 ExtensionSyncEventObserver>::DeclareFactoryDependencies();
81 } // namespace extensions
83 #endif // CHROME_BROWSER_EXTENSIONS_API_SYNC_FILE_SYSTEM_EXTENSION_SYNC_EVENT_OBSERVER_H_