app_list_syncable_service_factory.cc revision c5cede9ae108bb15f6b7a8aea21c7e1fefa2834c
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 16namespace app_list { 17 18// static 19AppListSyncableService* AppListSyncableServiceFactory::GetForProfile( 20 Profile* profile) { 21 return static_cast<AppListSyncableService*>( 22 GetInstance()->GetServiceForBrowserContext(profile, true)); 23} 24 25// static 26AppListSyncableServiceFactory* AppListSyncableServiceFactory::GetInstance() { 27 return Singleton<AppListSyncableServiceFactory>::get(); 28} 29 30// static 31KeyedService* AppListSyncableServiceFactory::BuildInstanceFor( 32 content::BrowserContext* browser_context) { 33 Profile* profile = static_cast<Profile*>(browser_context); 34 VLOG(1) << "BuildServiceInstanceFor: " << profile->GetDebugName(); 35 return new AppListSyncableService(profile, 36 extensions::ExtensionSystem::Get(profile)); 37} 38 39AppListSyncableServiceFactory::AppListSyncableServiceFactory() 40 : BrowserContextKeyedServiceFactory( 41 "AppListSyncableService", 42 BrowserContextDependencyManager::GetInstance()) { 43 VLOG(1) << "AppListSyncableServiceFactory()"; 44 DependsOn( 45 extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory()); 46} 47 48AppListSyncableServiceFactory::~AppListSyncableServiceFactory() { 49} 50 51KeyedService* AppListSyncableServiceFactory::BuildServiceInstanceFor( 52 content::BrowserContext* browser_context) const { 53 return BuildInstanceFor(static_cast<Profile*>(browser_context)); 54} 55 56void AppListSyncableServiceFactory::RegisterProfilePrefs( 57 user_prefs::PrefRegistrySyncable* registry) { 58} 59 60content::BrowserContext* AppListSyncableServiceFactory::GetBrowserContextToUse( 61 content::BrowserContext* context) const { 62 // In Guest session, off the record profile should not be redirected to the 63 // original one. 64 Profile* profile = static_cast<Profile*>(context); 65 if (profile->IsGuestSession()) 66 return chrome::GetBrowserContextOwnInstanceInIncognito(context); 67 return chrome::GetBrowserContextRedirectedInIncognito(context); 68} 69 70bool AppListSyncableServiceFactory::ServiceIsCreatedWithBrowserContext() const { 71 // Start AppListSyncableService early so that the app list positions are 72 // available before the app list is opened. 73 return true; 74} 75 76bool AppListSyncableServiceFactory::ServiceIsNULLWhileTesting() const { 77 return true; 78} 79 80} // namespace app_list 81