| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 6 |
| 7 #include "base/command_line.h" |
| 8 #include "base/memory/singleton.h" |
| 9 #include "chrome/browser/defaults.h" |
| 10 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 11 #include "chrome/browser/prefs/pref_service.h" |
| 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/profiles/profile_dependency_manager.h" |
| 14 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 15 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
| 16 #include "chrome/browser/sync/profile_sync_components_factory_impl.h" |
| 17 #include "chrome/browser/sync/profile_sync_service.h" |
| 18 #include "chrome/browser/sync/signin_manager.h" |
| 19 #include "chrome/browser/themes/theme_service_factory.h" |
| 20 #include "chrome/browser/ui/global_error_service_factory.h" |
| 21 #include "chrome/common/pref_names.h" |
| 22 |
| 23 // static |
| 24 ProfileSyncServiceFactory* ProfileSyncServiceFactory::GetInstance() { |
| 25 return Singleton<ProfileSyncServiceFactory>::get(); |
| 26 } |
| 27 |
| 28 // static |
| 29 ProfileSyncService* ProfileSyncServiceFactory::GetForProfile( |
| 30 Profile* profile) { |
| 31 if (!ProfileSyncService::IsSyncEnabled()) |
| 32 return NULL; |
| 33 |
| 34 return static_cast<ProfileSyncService*>( |
| 35 GetInstance()->GetServiceForProfile(profile, true)); |
| 36 } |
| 37 |
| 38 ProfileSyncServiceFactory::ProfileSyncServiceFactory() |
| 39 : ProfileKeyedServiceFactory(ProfileDependencyManager::GetInstance()) { |
| 40 |
| 41 // The ProfileSyncService depends on various SyncableServices being around |
| 42 // when it is shut down. Specify those dependencies here to build the proper |
| 43 // destruction order. |
| 44 DependsOn(TemplateURLServiceFactory::GetInstance()); |
| 45 DependsOn(PersonalDataManagerFactory::GetInstance()); |
| 46 DependsOn(ThemeServiceFactory::GetInstance()); |
| 47 DependsOn(TabRestoreServiceFactory::GetInstance()); |
| 48 DependsOn(GlobalErrorServiceFactory::GetInstance()); |
| 49 |
| 50 // The following have not been converted to ProfileKeyedServices yet, and for |
| 51 // now they are explicitly destroyed after the ProfileDependencyManager is |
| 52 // told to DestroyProfileServices, so they will be around when the |
| 53 // ProfileSyncService is destroyed. |
| 54 |
| 55 // DependsOn(SigninManagerFactory::GetInstance()); |
| 56 // DependsOn(WebDataServiceFactory::GetInstance()); |
| 57 // DependsOn(HistoryServiceFactory::GetInstance()); |
| 58 // DependsOn(BookmarkBarModelFactory::GetInstance()); |
| 59 // DependsOn(FaviconServiceFactory::GetInstance()); |
| 60 // DependsOn(PasswordStoreService::GetInstance()); |
| 61 // DependsOn(ExtensionServiceFactory::GetInstance()); |
| 62 } |
| 63 |
| 64 ProfileSyncServiceFactory::~ProfileSyncServiceFactory() { |
| 65 } |
| 66 |
| 67 ProfileKeyedService* ProfileSyncServiceFactory::BuildServiceInstanceFor( |
| 68 Profile* profile) const { |
| 69 ProfileSyncService::StartBehavior behavior = |
| 70 browser_defaults::kSyncAutoStarts ? ProfileSyncService::AUTO_START |
| 71 : ProfileSyncService::MANUAL_START; |
| 72 |
| 73 PrefService* prefs = profile->GetPrefs(); |
| 74 SigninManager* signin = new SigninManager(); |
| 75 signin->SetAuthenticatedUsername(prefs->GetString( |
| 76 prefs::kGoogleServicesUsername)); |
| 77 |
| 78 // TODO(tim): Currently, AUTO/MANUAL settings refer to the *first* time sync |
| 79 // is set up and *not* a browser restart for a manual-start platform (where |
| 80 // sync has already been set up, and should be able to start without user |
| 81 // intervention). We can get rid of the browser_default eventually, but |
| 82 // need to take care that ProfileSyncService doesn't get tripped up between |
| 83 // those two cases. Bug 88109. |
| 84 ProfileSyncService* pss = new ProfileSyncService( |
| 85 new ProfileSyncComponentsFactoryImpl(profile, |
| 86 CommandLine::ForCurrentProcess()), |
| 87 profile, |
| 88 signin, |
| 89 behavior); |
| 90 |
| 91 pss->factory()->RegisterDataTypes(pss); |
| 92 pss->Initialize(); |
| 93 return pss; |
| 94 } |
| 95 |
| 96 // static |
| 97 bool ProfileSyncServiceFactory::HasProfileSyncService(Profile* profile) { |
| 98 return GetInstance()->GetServiceForProfile(profile, false) != NULL; |
| 99 } |
| OLD | NEW |