| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SYNC_FILE_SYSTEM_EXTENSION_SYNC_EVENT_OBSE
RVER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SYNC_FILE_SYSTEM_EXTENSION_SYNC_EVENT_OBSE
RVER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_SYNC_FILE_SYSTEM_EXTENSION_SYNC_EVENT_OBSE
RVER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_SYNC_FILE_SYSTEM_EXTENSION_SYNC_EVENT_OBSE
RVER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/extensions/api/profile_keyed_api_factory.h" |
| 12 #include "chrome/browser/sync_file_system/sync_event_observer.h" | 13 #include "chrome/browser/sync_file_system/sync_event_observer.h" |
| 13 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" | |
| 14 | 14 |
| 15 class Profile; | 15 class Profile; |
| 16 | 16 |
| 17 namespace sync_file_system { | 17 namespace sync_file_system { |
| 18 class SyncFileSystemService; | 18 class SyncFileSystemService; |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace extensions { | 21 namespace extensions { |
| 22 | 22 |
| 23 // Observes changes in SyncFileSystem and relays events to JS Extension API. | 23 // Observes changes in SyncFileSystem and relays events to JS Extension API. |
| 24 class ExtensionSyncEventObserver | 24 class ExtensionSyncEventObserver : public sync_file_system::SyncEventObserver, |
| 25 : public sync_file_system::SyncEventObserver, | 25 public ProfileKeyedAPI { |
| 26 public BrowserContextKeyedService { | |
| 27 public: | 26 public: |
| 27 static ProfileKeyedAPIFactory<ExtensionSyncEventObserver>* |
| 28 GetFactoryInstance(); |
| 29 |
| 28 explicit ExtensionSyncEventObserver(Profile* profile); | 30 explicit ExtensionSyncEventObserver(Profile* profile); |
| 29 virtual ~ExtensionSyncEventObserver(); | 31 virtual ~ExtensionSyncEventObserver(); |
| 30 | 32 |
| 31 void InitializeForService( | 33 void InitializeForService( |
| 32 sync_file_system::SyncFileSystemService* sync_service); | 34 sync_file_system::SyncFileSystemService* sync_service); |
| 33 | 35 |
| 34 // BrowserContextKeyedService override. | 36 // BrowserContextKeyedService override. |
| 35 virtual void Shutdown() OVERRIDE; | 37 virtual void Shutdown() OVERRIDE; |
| 36 | 38 |
| 37 // sync_file_system::SyncEventObserver interface implementation. | 39 // sync_file_system::SyncEventObserver interface implementation. |
| 38 virtual void OnSyncStateUpdated( | 40 virtual void OnSyncStateUpdated( |
| 39 const GURL& app_origin, | 41 const GURL& app_origin, |
| 40 sync_file_system::SyncServiceState state, | 42 sync_file_system::SyncServiceState state, |
| 41 const std::string& description) OVERRIDE; | 43 const std::string& description) OVERRIDE; |
| 42 | 44 |
| 43 virtual void OnFileSynced( | 45 virtual void OnFileSynced( |
| 44 const fileapi::FileSystemURL& url, | 46 const fileapi::FileSystemURL& url, |
| 45 sync_file_system::SyncFileStatus status, | 47 sync_file_system::SyncFileStatus status, |
| 46 sync_file_system::SyncAction action, | 48 sync_file_system::SyncAction action, |
| 47 sync_file_system::SyncDirection direction) OVERRIDE; | 49 sync_file_system::SyncDirection direction) OVERRIDE; |
| 48 | 50 |
| 49 private: | 51 private: |
| 52 friend class ProfileKeyedAPIFactory<ExtensionSyncEventObserver>; |
| 53 |
| 50 // Returns an empty string if the extension |app_origin| cannot be found | 54 // Returns an empty string if the extension |app_origin| cannot be found |
| 51 // in the installed extension list. | 55 // in the installed extension list. |
| 52 std::string GetExtensionId(const GURL& app_origin); | 56 std::string GetExtensionId(const GURL& app_origin); |
| 53 | 57 |
| 58 // ProfileKeyedAPI implementation. |
| 59 static const char* service_name() { return "ExtensionSyncEventObserver"; } |
| 60 static const bool kServiceIsCreatedWithBrowserContext = false; |
| 61 |
| 54 Profile* profile_; | 62 Profile* profile_; |
| 55 | 63 |
| 56 // Not owned. If not null, then this is registered to SyncFileSystemService. | 64 // Not owned. If not null, then this is registered to SyncFileSystemService. |
| 57 sync_file_system::SyncFileSystemService* sync_service_; | 65 sync_file_system::SyncFileSystemService* sync_service_; |
| 58 | 66 |
| 59 void BroadcastOrDispatchEvent(const GURL& app_origin, | 67 void BroadcastOrDispatchEvent(const GURL& app_origin, |
| 60 const std::string& event_name, | 68 const std::string& event_name, |
| 61 scoped_ptr<base::ListValue> value); | 69 scoped_ptr<base::ListValue> value); |
| 62 | 70 |
| 63 DISALLOW_COPY_AND_ASSIGN(ExtensionSyncEventObserver); | 71 DISALLOW_COPY_AND_ASSIGN(ExtensionSyncEventObserver); |
| 64 }; | 72 }; |
| 65 | 73 |
| 74 template <> |
| 75 void ProfileKeyedAPIFactory< |
| 76 ExtensionSyncEventObserver>::DeclareFactoryDependencies(); |
| 77 |
| 66 } // namespace extensions | 78 } // namespace extensions |
| 67 | 79 |
| 68 #endif // CHROME_BROWSER_EXTENSIONS_API_SYNC_FILE_SYSTEM_EXTENSION_SYNC_EVENT_O
BSERVER_H_ | 80 #endif // CHROME_BROWSER_EXTENSIONS_API_SYNC_FILE_SYSTEM_EXTENSION_SYNC_EVENT_O
BSERVER_H_ |
| OLD | NEW |