1 // Copyright 2013 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/ui/app_list/app_list_syncable_service_factory.h" 6 7 #include <set> 8 9 #include "base/prefs/pref_service.h" 10 #include "chrome/browser/apps/drive/drive_app_provider.h" 11 #include "chrome/browser/profiles/incognito_helpers.h" 12 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/ui/app_list/app_list_syncable_service.h" 14 #include "components/keyed_service/content/browser_context_dependency_manager.h" 15 #include "extensions/browser/extension_system.h" 16 #include "extensions/browser/extension_system_provider.h" 17 #include "extensions/browser/extensions_browser_client.h" 18 19 #if defined(OS_CHROMEOS) 20 #include "chrome/browser/chromeos/profiles/profile_helper.h" 21 #endif 22 23 namespace app_list { 24 25 // static GetForProfile(Profile * profile)26AppListSyncableService* AppListSyncableServiceFactory::GetForProfile( 27 Profile* profile) { 28 return static_cast<AppListSyncableService*>( 29 GetInstance()->GetServiceForBrowserContext(profile, true)); 30 } 31 32 // static GetInstance()33AppListSyncableServiceFactory* AppListSyncableServiceFactory::GetInstance() { 34 return Singleton<AppListSyncableServiceFactory>::get(); 35 } 36 37 // static BuildInstanceFor(content::BrowserContext * browser_context)38KeyedService* AppListSyncableServiceFactory::BuildInstanceFor( 39 content::BrowserContext* browser_context) { 40 Profile* profile = static_cast<Profile*>(browser_context); 41 #if defined(OS_CHROMEOS) 42 if (chromeos::ProfileHelper::IsSigninProfile(profile)) 43 return NULL; 44 #endif 45 VLOG(1) << "BuildInstanceFor: " << profile->GetDebugName() 46 << " (" << profile << ")"; 47 return new AppListSyncableService(profile, 48 extensions::ExtensionSystem::Get(profile)); 49 } 50 AppListSyncableServiceFactory()51AppListSyncableServiceFactory::AppListSyncableServiceFactory() 52 : BrowserContextKeyedServiceFactory( 53 "AppListSyncableService", 54 BrowserContextDependencyManager::GetInstance()) { 55 VLOG(1) << "AppListSyncableServiceFactory()"; 56 typedef std::set<BrowserContextKeyedServiceFactory*> FactorySet; 57 FactorySet dependent_factories; 58 dependent_factories.insert( 59 extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); 60 DriveAppProvider::AppendDependsOnFactories(&dependent_factories); 61 for (FactorySet::iterator it = dependent_factories.begin(); 62 it != dependent_factories.end(); 63 ++it) { 64 DependsOn(*it); 65 } 66 } 67 ~AppListSyncableServiceFactory()68AppListSyncableServiceFactory::~AppListSyncableServiceFactory() { 69 } 70 BuildServiceInstanceFor(content::BrowserContext * browser_context) const71KeyedService* AppListSyncableServiceFactory::BuildServiceInstanceFor( 72 content::BrowserContext* browser_context) const { 73 return BuildInstanceFor(static_cast<Profile*>(browser_context)); 74 } 75 RegisterProfilePrefs(user_prefs::PrefRegistrySyncable * registry)76void AppListSyncableServiceFactory::RegisterProfilePrefs( 77 user_prefs::PrefRegistrySyncable* registry) { 78 } 79 GetBrowserContextToUse(content::BrowserContext * context) const80content::BrowserContext* AppListSyncableServiceFactory::GetBrowserContextToUse( 81 content::BrowserContext* context) const { 82 // This matches the logic in ExtensionSyncServiceFactory, which uses the 83 // orginal browser context. 84 return chrome::GetBrowserContextRedirectedInIncognito(context); 85 } 86 ServiceIsCreatedWithBrowserContext() const87bool AppListSyncableServiceFactory::ServiceIsCreatedWithBrowserContext() const { 88 // Start AppListSyncableService early so that the app list positions are 89 // available before the app list is opened. 90 return true; 91 } 92 ServiceIsNULLWhileTesting() const93bool AppListSyncableServiceFactory::ServiceIsNULLWhileTesting() const { 94 return true; 95 } 96 97 } // namespace app_list 98