| 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_SYNC_PROFILE_SYNC_SERVICE_FACTORY_H_ | 5 #ifndef CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_FACTORY_H_ |
| 6 #define CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_FACTORY_H_ | 6 #define CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_FACTORY_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "components/keyed_service/content/browser_context_keyed_service_factory
.h" | 9 #include "components/keyed_service/content/browser_context_keyed_service_factory
.h" |
| 10 | 10 |
| 11 namespace base { | 11 namespace base { |
| 12 template <typename T> | 12 template <typename T> |
| 13 struct DefaultSingletonTraits; | 13 struct DefaultSingletonTraits; |
| 14 } | 14 } |
| 15 | 15 |
| 16 namespace sync_driver { | 16 namespace sync_driver { |
| 17 class SyncClient; |
| 17 class SyncService; | 18 class SyncService; |
| 18 } | 19 } |
| 19 | 20 |
| 20 class Profile; | 21 class Profile; |
| 21 class ProfileSyncService; | 22 class ProfileSyncService; |
| 22 | 23 |
| 23 class ProfileSyncServiceFactory : public BrowserContextKeyedServiceFactory { | 24 class ProfileSyncServiceFactory : public BrowserContextKeyedServiceFactory { |
| 24 public: | 25 public: |
| 26 typedef base::Callback<std::unique_ptr<sync_driver::SyncClient>(Profile*)> |
| 27 SyncClientFactory; |
| 28 |
| 25 static ProfileSyncService* GetForProfile(Profile* profile); | 29 static ProfileSyncService* GetForProfile(Profile* profile); |
| 26 static bool HasProfileSyncService(Profile* profile); | 30 static bool HasProfileSyncService(Profile* profile); |
| 27 | 31 |
| 28 // Convenience method that returns the ProfileSyncService as a | 32 // Convenience method that returns the ProfileSyncService as a |
| 29 // sync_driver::SyncService. | 33 // sync_driver::SyncService. |
| 30 static sync_driver::SyncService* GetSyncServiceForBrowserContext( | 34 static sync_driver::SyncService* GetSyncServiceForBrowserContext( |
| 31 content::BrowserContext* context); | 35 content::BrowserContext* context); |
| 32 | 36 |
| 33 static ProfileSyncServiceFactory* GetInstance(); | 37 static ProfileSyncServiceFactory* GetInstance(); |
| 34 | 38 |
| 39 // Overrides how the SyncClient is created for testing purposes. |
| 40 static void SetSyncClientFactoryForTest(SyncClientFactory* client_factory); |
| 41 |
| 35 private: | 42 private: |
| 36 friend struct base::DefaultSingletonTraits<ProfileSyncServiceFactory>; | 43 friend struct base::DefaultSingletonTraits<ProfileSyncServiceFactory>; |
| 37 | 44 |
| 38 ProfileSyncServiceFactory(); | 45 ProfileSyncServiceFactory(); |
| 39 ~ProfileSyncServiceFactory() override; | 46 ~ProfileSyncServiceFactory() override; |
| 40 | 47 |
| 41 // BrowserContextKeyedServiceFactory: | 48 // BrowserContextKeyedServiceFactory: |
| 42 KeyedService* BuildServiceInstanceFor( | 49 KeyedService* BuildServiceInstanceFor( |
| 43 content::BrowserContext* context) const override; | 50 content::BrowserContext* context) const override; |
| 44 | 51 |
| 52 // A factory function for overriding the way the SyncClient is created. |
| 53 // This is a raw pointer so it can be statically initialized. |
| 54 static SyncClientFactory* client_factory_; |
| 55 |
| 45 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceFactory); | 56 DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceFactory); |
| 46 }; | 57 }; |
| 47 | 58 |
| 48 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_FACTORY_H_ | 59 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_SERVICE_FACTORY_H_ |
| OLD | NEW |