1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ios/chrome/browser/sync/sync_setup_service_factory.h"
7 #include "base/memory/singleton.h"
8 #include "components/keyed_service/ios/browser_state_dependency_manager.h"
9 #include "ios/chrome/browser/sync/sync_setup_service.h"
10 #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h"
11 #include "ios/public/provider/chrome/browser/keyed_service_provider.h"
14 SyncSetupService
* SyncSetupServiceFactory::GetForBrowserState(
15 ios::ChromeBrowserState
* browser_state
) {
16 return static_cast<SyncSetupService
*>(
17 GetInstance()->GetServiceForBrowserState(browser_state
, true));
21 SyncSetupService
* SyncSetupServiceFactory::GetForBrowserStateIfExists(
22 ios::ChromeBrowserState
* browser_state
) {
23 return static_cast<SyncSetupService
*>(
24 GetInstance()->GetServiceForBrowserState(browser_state
, false));
28 SyncSetupServiceFactory
* SyncSetupServiceFactory::GetInstance() {
29 return Singleton
<SyncSetupServiceFactory
>::get();
32 SyncSetupServiceFactory::SyncSetupServiceFactory()
33 : BrowserStateKeyedServiceFactory(
35 BrowserStateDependencyManager::GetInstance()) {
36 DependsOn(ios::GetKeyedServiceProvider()->GetSyncServiceFactory());
39 SyncSetupServiceFactory::~SyncSetupServiceFactory() {
42 scoped_ptr
<KeyedService
> SyncSetupServiceFactory::BuildServiceInstanceFor(
43 web::BrowserState
* context
) const {
44 ios::ChromeBrowserState
* browser_state
=
45 ios::ChromeBrowserState::FromBrowserState(context
);
46 return make_scoped_ptr(new SyncSetupService(
47 ios::GetKeyedServiceProvider()->GetSyncServiceForBrowserState(
49 browser_state
->GetPrefs()));