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_CHROMEOS_DRIVE_DRIVE_INTEGRATION_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_INTEGRATION_SERVICE_H_ |
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_INTEGRATION_SERVICE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_INTEGRATION_SERVICE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 | 62 |
63 // DriveIntegrationService is used to integrate Drive to Chrome. This class | 63 // DriveIntegrationService is used to integrate Drive to Chrome. This class |
64 // exposes the file system representation built on top of Drive and some | 64 // exposes the file system representation built on top of Drive and some |
65 // other Drive related objects to the file manager, and some other sub | 65 // other Drive related objects to the file manager, and some other sub |
66 // systems. | 66 // systems. |
67 // | 67 // |
68 // The class is essentially a container that manages lifetime of the objects | 68 // The class is essentially a container that manages lifetime of the objects |
69 // that are used to integrate Drive to Chrome. The object of this class is | 69 // that are used to integrate Drive to Chrome. The object of this class is |
70 // created per-profile. | 70 // created per-profile. |
71 class DriveIntegrationService | 71 class DriveIntegrationService |
72 : public ProfileKeyedService, | 72 : public BrowserContextKeyedService, |
73 public google_apis::DriveNotificationObserver { | 73 public google_apis::DriveNotificationObserver { |
74 public: | 74 public: |
75 // test_drive_service, test_cache_root and test_file_system are used by tests | 75 // test_drive_service, test_cache_root and test_file_system are used by tests |
76 // to inject customized instances. | 76 // to inject customized instances. |
77 // Pass NULL or the empty value when not interested. | 77 // Pass NULL or the empty value when not interested. |
78 DriveIntegrationService( | 78 DriveIntegrationService( |
79 Profile* profile, | 79 Profile* profile, |
80 google_apis::DriveServiceInterface* test_drive_service, | 80 google_apis::DriveServiceInterface* test_drive_service, |
81 const base::FilePath& test_cache_root, | 81 const base::FilePath& test_cache_root, |
82 FileSystemInterface* test_file_system); | 82 FileSystemInterface* test_file_system); |
83 virtual ~DriveIntegrationService(); | 83 virtual ~DriveIntegrationService(); |
84 | 84 |
85 // Initializes the object. This function should be called before any | 85 // Initializes the object. This function should be called before any |
86 // other functions. | 86 // other functions. |
87 void Initialize(); | 87 void Initialize(); |
88 | 88 |
89 // ProfileKeyedService override: | 89 // BrowserContextKeyedService override: |
90 virtual void Shutdown() OVERRIDE; | 90 virtual void Shutdown() OVERRIDE; |
91 | 91 |
92 // Adds and removes the observer. | 92 // Adds and removes the observer. |
93 void AddObserver(DriveIntegrationServiceObserver* observer); | 93 void AddObserver(DriveIntegrationServiceObserver* observer); |
94 void RemoveObserver(DriveIntegrationServiceObserver* observer); | 94 void RemoveObserver(DriveIntegrationServiceObserver* observer); |
95 | 95 |
96 // google_apis::DriveNotificationObserver implementation. | 96 // google_apis::DriveNotificationObserver implementation. |
97 virtual void OnNotificationReceived() OVERRIDE; | 97 virtual void OnNotificationReceived() OVERRIDE; |
98 virtual void OnPushNotificationEnabled(bool enabled) OVERRIDE; | 98 virtual void OnPushNotificationEnabled(bool enabled) OVERRIDE; |
99 | 99 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 ObserverList<DriveIntegrationServiceObserver> observers_; | 171 ObserverList<DriveIntegrationServiceObserver> observers_; |
172 | 172 |
173 // Note: This should remain the last member so it'll be destroyed and | 173 // Note: This should remain the last member so it'll be destroyed and |
174 // invalidate its weak pointers before any other members are destroyed. | 174 // invalidate its weak pointers before any other members are destroyed. |
175 base::WeakPtrFactory<DriveIntegrationService> weak_ptr_factory_; | 175 base::WeakPtrFactory<DriveIntegrationService> weak_ptr_factory_; |
176 DISALLOW_COPY_AND_ASSIGN(DriveIntegrationService); | 176 DISALLOW_COPY_AND_ASSIGN(DriveIntegrationService); |
177 }; | 177 }; |
178 | 178 |
179 // Singleton that owns all instances of DriveIntegrationService and | 179 // Singleton that owns all instances of DriveIntegrationService and |
180 // associates them with Profiles. | 180 // associates them with Profiles. |
181 class DriveIntegrationServiceFactory : public ProfileKeyedServiceFactory { | 181 class DriveIntegrationServiceFactory |
| 182 : public BrowserContextKeyedServiceFactory { |
182 public: | 183 public: |
183 // Factory function used by tests. | 184 // Factory function used by tests. |
184 typedef base::Callback<DriveIntegrationService*(Profile* profile)> | 185 typedef base::Callback<DriveIntegrationService*(Profile* profile)> |
185 FactoryCallback; | 186 FactoryCallback; |
186 | 187 |
187 // Returns the DriveIntegrationService for |profile|, creating it if it is | 188 // Returns the DriveIntegrationService for |profile|, creating it if it is |
188 // not yet created. | 189 // not yet created. |
189 // | 190 // |
190 // This function starts returning NULL if Drive is disabled, even if this | 191 // This function starts returning NULL if Drive is disabled, even if this |
191 // function previously returns a non-NULL object. In other words, clients | 192 // function previously returns a non-NULL object. In other words, clients |
(...skipping 23 matching lines...) Expand all Loading... |
215 | 216 |
216 // Sets a factory function for tests. | 217 // Sets a factory function for tests. |
217 static void SetFactoryForTest(const FactoryCallback& factory_for_test); | 218 static void SetFactoryForTest(const FactoryCallback& factory_for_test); |
218 | 219 |
219 private: | 220 private: |
220 friend struct DefaultSingletonTraits<DriveIntegrationServiceFactory>; | 221 friend struct DefaultSingletonTraits<DriveIntegrationServiceFactory>; |
221 | 222 |
222 DriveIntegrationServiceFactory(); | 223 DriveIntegrationServiceFactory(); |
223 virtual ~DriveIntegrationServiceFactory(); | 224 virtual ~DriveIntegrationServiceFactory(); |
224 | 225 |
225 // ProfileKeyedServiceFactory: | 226 // BrowserContextKeyedServiceFactory: |
226 virtual ProfileKeyedService* BuildServiceInstanceFor( | 227 virtual BrowserContextKeyedService* BuildServiceInstanceFor( |
227 content::BrowserContext* context) const OVERRIDE; | 228 content::BrowserContext* context) const OVERRIDE; |
228 | 229 |
229 FactoryCallback factory_for_test_; | 230 FactoryCallback factory_for_test_; |
230 }; | 231 }; |
231 | 232 |
232 } // namespace drive | 233 } // namespace drive |
233 | 234 |
234 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_INTEGRATION_SERVICE_H_ | 235 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_INTEGRATION_SERVICE_H_ |
OLD | NEW |