Chromium Code Reviews| 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/profiles/profile.h" | |
| 12 #include "chrome/browser/profiles/profile_dependency_manager.h" | |
| 13 #include "chrome/browser/search_engines/template_url_service_factory.h" | |
| 14 #include "chrome/browser/sessions/tab_restore_service_factory.h" | |
| 15 #include "chrome/browser/signin/signin_manager.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/themes/theme_service_factory.h" | |
| 19 #include "chrome/browser/ui/global_error_service_factory.h" | |
| 20 | |
| 21 // static | |
| 22 ProfileSyncServiceFactory* ProfileSyncServiceFactory::GetInstance() { | |
| 23 return Singleton<ProfileSyncServiceFactory>::get(); | |
| 24 } | |
| 25 | |
| 26 // static | |
| 27 ProfileSyncService* ProfileSyncServiceFactory::GetForProfile( | |
| 28 Profile* profile) { | |
| 29 if (!ProfileSyncService::IsSyncEnabled()) | |
| 30 return NULL; | |
| 31 | |
| 32 ProfileSyncService* service = static_cast<ProfileSyncService*>( | |
| 33 GetInstance()->GetServiceForProfile(profile, false)); | |
| 34 | |
| 35 // TODO(tim): This ugliness is necessary because part of ProfileSyncService | |
| 36 // initialization is registering enabled data types with the | |
| 37 // ProfileSyncComponentsFactory, which creates DataTypeControllers. | |
| 38 // The NewNonFrontendDataTypeController class doesn't have the sync service | |
| 39 // injected (oddly, since FrontendDTC does), and tries to get it from the | |
| 40 // profile / this factory. This means we need to separate the act of creating | |
| 41 // the ProfileSyncService (and making GetForProfile return non-NULL) from | |
| 42 // initializing it, hence this code. We'll make the DTC take the service by | |
| 43 // injection to resolve this in a separate CL. (Or decide to move | |
| 44 // initialization elsewhere). Bug 93922. | |
| 45 if (!service) { | |
| 46 service = static_cast<ProfileSyncService*>( | |
| 47 GetInstance()->GetServiceForProfile(profile, true)); | |
| 48 service->factory()->RegisterDataTypes(service); | |
|
Andrew T Wilson (Slow)
2012/01/17 20:25:41
Why does this live here and not down in BuildServi
Elliot Glaysher
2012/01/17 20:56:07
If I understand this correctly, Tim is using GetSe
tim (not reviewing)
2012/01/17 21:17:26
I tried to explain this in the TODO, but the reaso
| |
| 49 service->Initialize(); | |
| 50 } | |
| 51 | |
| 52 DCHECK(service); | |
| 53 return service; | |
| 54 } | |
| 55 | |
| 56 ProfileSyncServiceFactory::ProfileSyncServiceFactory() | |
| 57 : ProfileKeyedServiceFactory(ProfileDependencyManager::GetInstance()) { | |
| 58 | |
| 59 // The ProfileSyncService depends on various SyncableServices being around | |
| 60 // when it is shut down. Specify those dependencies here to build the proper | |
| 61 // destruction order. | |
| 62 DependsOn(TemplateURLServiceFactory::GetInstance()); | |
| 63 DependsOn(PersonalDataManagerFactory::GetInstance()); | |
| 64 DependsOn(ThemeServiceFactory::GetInstance()); | |
| 65 DependsOn(TabRestoreServiceFactory::GetInstance()); | |
| 66 DependsOn(GlobalErrorServiceFactory::GetInstance()); | |
| 67 | |
| 68 // The following have not been converted to ProfileKeyedServices yet, and for | |
| 69 // now they are explicitly destroyed after the ProfileDependencyManager is | |
| 70 // told to DestroyProfileServices, so they will be around when the | |
| 71 // ProfileSyncService is destroyed. | |
| 72 | |
| 73 // DependsOn(SigninManagerFactory::GetInstance()); | |
|
Andrew T Wilson (Slow)
2012/01/17 20:25:41
Don't forget to uncomment this when my change re-l
| |
| 74 // DependsOn(WebDataServiceFactory::GetInstance()); | |
| 75 // DependsOn(HistoryServiceFactory::GetInstance()); | |
| 76 // DependsOn(BookmarkBarModelFactory::GetInstance()); | |
| 77 // DependsOn(FaviconServiceFactory::GetInstance()); | |
| 78 // DependsOn(PasswordStoreService::GetInstance()); | |
| 79 // DependsOn(ExtensionServiceFactory::GetInstance()); | |
| 80 } | |
| 81 | |
| 82 ProfileSyncServiceFactory::~ProfileSyncServiceFactory() { | |
| 83 } | |
| 84 | |
| 85 ProfileKeyedService* ProfileSyncServiceFactory::BuildServiceInstanceFor( | |
| 86 Profile* profile) const { | |
| 87 ProfileSyncService::StartBehavior behavior = | |
| 88 browser_defaults::kSyncAutoStarts ? ProfileSyncService::AUTO_START | |
| 89 : ProfileSyncService::MANUAL_START; | |
| 90 | |
| 91 SigninManager* signin = profile->GetSigninManager(); | |
| 92 | |
| 93 // TODO(tim): Currently, AUTO/MANUAL settings refer to the *first* time sync | |
| 94 // is set up and *not* a browser restart for a manual-start platform (where | |
| 95 // sync has already been set up, and should be able to start without user | |
| 96 // intervention). We can get rid of the browser_default eventually, but | |
| 97 // need to take care that ProfileSyncService doesn't get tripped up between | |
| 98 // those two cases. Bug 88109. | |
| 99 ProfileSyncService* pss = new ProfileSyncService( | |
| 100 new ProfileSyncComponentsFactoryImpl(profile, | |
| 101 CommandLine::ForCurrentProcess()), | |
| 102 profile, | |
| 103 signin, | |
| 104 behavior); | |
| 105 return pss; | |
| 106 } | |
| 107 | |
| 108 // static | |
| 109 bool ProfileSyncServiceFactory::HasProfileSyncService(Profile* profile) { | |
| 110 return GetInstance()->GetServiceForProfile(profile, false) != NULL; | |
| 111 } | |
| OLD | NEW |