| 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 #include "chrome/browser/sync/profile_sync_service_factory.h" | 5 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 } // anonymous namespace | 96 } // anonymous namespace |
| 97 | 97 |
| 98 // static | 98 // static |
| 99 ProfileSyncServiceFactory* ProfileSyncServiceFactory::GetInstance() { | 99 ProfileSyncServiceFactory* ProfileSyncServiceFactory::GetInstance() { |
| 100 return base::Singleton<ProfileSyncServiceFactory>::get(); | 100 return base::Singleton<ProfileSyncServiceFactory>::get(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 // static | 103 // static |
| 104 ProfileSyncService* ProfileSyncServiceFactory::GetForProfile( | 104 ProfileSyncService* ProfileSyncServiceFactory::GetForProfile( |
| 105 Profile* profile) { | 105 Profile* profile) { |
| 106 if (!ProfileSyncService::IsSyncAllowedByFlag()) | |
| 107 return nullptr; | |
| 108 | |
| 109 return static_cast<ProfileSyncService*>( | 106 return static_cast<ProfileSyncService*>( |
| 110 GetInstance()->GetServiceForBrowserContext(profile, true)); | 107 GetSyncServiceForBrowserContext(profile)); |
| 111 } | 108 } |
| 112 | 109 |
| 113 // static | 110 // static |
| 114 syncer::SyncService* ProfileSyncServiceFactory::GetSyncServiceForBrowserContext( | 111 syncer::SyncService* ProfileSyncServiceFactory::GetSyncServiceForBrowserContext( |
| 115 content::BrowserContext* context) { | 112 content::BrowserContext* context) { |
| 116 return GetForProfile(Profile::FromBrowserContext(context)); | 113 if (!ProfileSyncService::IsSyncAllowedByFlag()) { |
| 114 return nullptr; |
| 115 } |
| 116 |
| 117 return static_cast<syncer::SyncService*>( |
| 118 GetInstance()->GetServiceForBrowserContext(context, true)); |
| 117 } | 119 } |
| 118 | 120 |
| 119 ProfileSyncServiceFactory::ProfileSyncServiceFactory() | 121 ProfileSyncServiceFactory::ProfileSyncServiceFactory() |
| 120 : BrowserContextKeyedServiceFactory( | 122 : BrowserContextKeyedServiceFactory( |
| 121 "ProfileSyncService", | 123 "ProfileSyncService", |
| 122 BrowserContextDependencyManager::GetInstance()) { | 124 BrowserContextDependencyManager::GetInstance()) { |
| 123 // The ProfileSyncService depends on various SyncableServices being around | 125 // The ProfileSyncService depends on various SyncableServices being around |
| 124 // when it is shut down. Specify those dependencies here to build the proper | 126 // when it is shut down. Specify those dependencies here to build the proper |
| 125 // destruction order. | 127 // destruction order. |
| 126 DependsOn(AboutSigninInternalsFactory::GetInstance()); | 128 DependsOn(AboutSigninInternalsFactory::GetInstance()); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 | 260 |
| 259 // static | 261 // static |
| 260 void ProfileSyncServiceFactory::SetSyncClientFactoryForTest( | 262 void ProfileSyncServiceFactory::SetSyncClientFactoryForTest( |
| 261 SyncClientFactory* client_factory) { | 263 SyncClientFactory* client_factory) { |
| 262 client_factory_ = client_factory; | 264 client_factory_ = client_factory; |
| 263 } | 265 } |
| 264 | 266 |
| 265 // static | 267 // static |
| 266 ProfileSyncServiceFactory::SyncClientFactory* | 268 ProfileSyncServiceFactory::SyncClientFactory* |
| 267 ProfileSyncServiceFactory::client_factory_ = nullptr; | 269 ProfileSyncServiceFactory::client_factory_ = nullptr; |
| OLD | NEW |