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 namespace content { |
| 16 class BrowserContext; |
| 17 } |
16 | 18 |
17 namespace sync_file_system { | 19 namespace sync_file_system { |
18 class SyncFileSystemService; | 20 class SyncFileSystemService; |
19 } | 21 } |
20 | 22 |
21 namespace extensions { | 23 namespace extensions { |
22 | 24 |
23 // Observes changes in SyncFileSystem and relays events to JS Extension API. | 25 // Observes changes in SyncFileSystem and relays events to JS Extension API. |
24 class ExtensionSyncEventObserver | 26 class ExtensionSyncEventObserver : public sync_file_system::SyncEventObserver, |
25 : public sync_file_system::SyncEventObserver, | 27 public ProfileKeyedAPI { |
26 public BrowserContextKeyedService { | |
27 public: | 28 public: |
28 explicit ExtensionSyncEventObserver(Profile* profile); | 29 static ProfileKeyedAPIFactory<ExtensionSyncEventObserver>* |
| 30 GetFactoryInstance(); |
| 31 |
| 32 explicit ExtensionSyncEventObserver(content::BrowserContext* context); |
29 virtual ~ExtensionSyncEventObserver(); | 33 virtual ~ExtensionSyncEventObserver(); |
30 | 34 |
31 void InitializeForService( | 35 void InitializeForService( |
32 sync_file_system::SyncFileSystemService* sync_service); | 36 sync_file_system::SyncFileSystemService* sync_service); |
33 | 37 |
34 // BrowserContextKeyedService override. | 38 // BrowserContextKeyedService override. |
35 virtual void Shutdown() OVERRIDE; | 39 virtual void Shutdown() OVERRIDE; |
36 | 40 |
37 // sync_file_system::SyncEventObserver interface implementation. | 41 // sync_file_system::SyncEventObserver interface implementation. |
38 virtual void OnSyncStateUpdated( | 42 virtual void OnSyncStateUpdated( |
39 const GURL& app_origin, | 43 const GURL& app_origin, |
40 sync_file_system::SyncServiceState state, | 44 sync_file_system::SyncServiceState state, |
41 const std::string& description) OVERRIDE; | 45 const std::string& description) OVERRIDE; |
42 | 46 |
43 virtual void OnFileSynced( | 47 virtual void OnFileSynced( |
44 const fileapi::FileSystemURL& url, | 48 const fileapi::FileSystemURL& url, |
45 sync_file_system::SyncFileStatus status, | 49 sync_file_system::SyncFileStatus status, |
46 sync_file_system::SyncAction action, | 50 sync_file_system::SyncAction action, |
47 sync_file_system::SyncDirection direction) OVERRIDE; | 51 sync_file_system::SyncDirection direction) OVERRIDE; |
48 | 52 |
49 private: | 53 private: |
| 54 friend class ProfileKeyedAPIFactory<ExtensionSyncEventObserver>; |
| 55 |
50 // Returns an empty string if the extension |app_origin| cannot be found | 56 // Returns an empty string if the extension |app_origin| cannot be found |
51 // in the installed extension list. | 57 // in the installed extension list. |
52 std::string GetExtensionId(const GURL& app_origin); | 58 std::string GetExtensionId(const GURL& app_origin); |
53 | 59 |
54 Profile* profile_; | 60 // ProfileKeyedAPI implementation. |
| 61 static const char* service_name() { return "ExtensionSyncEventObserver"; } |
| 62 static const bool kServiceIsCreatedWithBrowserContext = false; |
| 63 |
| 64 content::BrowserContext* browser_context_; |
55 | 65 |
56 // Not owned. If not null, then this is registered to SyncFileSystemService. | 66 // Not owned. If not null, then this is registered to SyncFileSystemService. |
57 sync_file_system::SyncFileSystemService* sync_service_; | 67 sync_file_system::SyncFileSystemService* sync_service_; |
58 | 68 |
59 void BroadcastOrDispatchEvent(const GURL& app_origin, | 69 void BroadcastOrDispatchEvent(const GURL& app_origin, |
60 const std::string& event_name, | 70 const std::string& event_name, |
61 scoped_ptr<base::ListValue> value); | 71 scoped_ptr<base::ListValue> value); |
62 | 72 |
63 DISALLOW_COPY_AND_ASSIGN(ExtensionSyncEventObserver); | 73 DISALLOW_COPY_AND_ASSIGN(ExtensionSyncEventObserver); |
64 }; | 74 }; |
65 | 75 |
| 76 template <> |
| 77 void ProfileKeyedAPIFactory< |
| 78 ExtensionSyncEventObserver>::DeclareFactoryDependencies(); |
| 79 |
66 } // namespace extensions | 80 } // namespace extensions |
67 | 81 |
68 #endif // CHROME_BROWSER_EXTENSIONS_API_SYNC_FILE_SYSTEM_EXTENSION_SYNC_EVENT_O
BSERVER_H_ | 82 #endif // CHROME_BROWSER_EXTENSIONS_API_SYNC_FILE_SYSTEM_EXTENSION_SYNC_EVENT_O
BSERVER_H_ |
OLD | NEW |