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