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