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.
5 #include "chrome/browser/ui/app_list/app_list_syncable_service_factory.h"
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"
19 #if defined(OS_CHROMEOS)
20 #include "chrome/browser/chromeos/profiles/profile_helper.h"
26 AppListSyncableService* AppListSyncableServiceFactory::GetForProfile(
28 return static_cast<AppListSyncableService*>(
29 GetInstance()->GetServiceForBrowserContext(profile, true));
33 AppListSyncableServiceFactory* AppListSyncableServiceFactory::GetInstance() {
34 return Singleton<AppListSyncableServiceFactory>::get();
38 KeyedService* 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))
45 VLOG(1) << "BuildInstanceFor: " << profile->GetDebugName()
46 << " (" << profile << ")";
47 return new AppListSyncableService(profile,
48 extensions::ExtensionSystem::Get(profile));
51 AppListSyncableServiceFactory::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();
68 AppListSyncableServiceFactory::~AppListSyncableServiceFactory() {
71 KeyedService* AppListSyncableServiceFactory::BuildServiceInstanceFor(
72 content::BrowserContext* browser_context) const {
73 return BuildInstanceFor(static_cast<Profile*>(browser_context));
76 void AppListSyncableServiceFactory::RegisterProfilePrefs(
77 user_prefs::PrefRegistrySyncable* registry) {
80 content::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);
87 bool AppListSyncableServiceFactory::ServiceIsCreatedWithBrowserContext() const {
88 // Start AppListSyncableService early so that the app list positions are
89 // available before the app list is opened.
93 bool AppListSyncableServiceFactory::ServiceIsNULLWhileTesting() const {
97 } // namespace app_list