Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / app_list / app_list_syncable_service_factory.cc
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/browser_context_keyed_service/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 namespace app_list {
17
18 // static
19 AppListSyncableService* AppListSyncableServiceFactory::GetForProfile(
20     Profile* profile) {
21   return static_cast<AppListSyncableService*>(
22       GetInstance()->GetServiceForBrowserContext(profile, true));
23 }
24
25 // static
26 AppListSyncableServiceFactory* AppListSyncableServiceFactory::GetInstance() {
27   return Singleton<AppListSyncableServiceFactory>::get();
28 }
29
30 AppListSyncableServiceFactory::AppListSyncableServiceFactory()
31     : BrowserContextKeyedServiceFactory(
32         "AppListSyncableService",
33         BrowserContextDependencyManager::GetInstance()) {
34   DependsOn(
35       extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
36 }
37
38 AppListSyncableServiceFactory::~AppListSyncableServiceFactory() {
39 }
40
41 BrowserContextKeyedService*
42 AppListSyncableServiceFactory::BuildServiceInstanceFor(
43     content::BrowserContext* browser_context) const {
44   Profile* profile = static_cast<Profile*>(browser_context);
45   return new AppListSyncableService(profile,
46                                     extensions::ExtensionSystem::Get(profile));
47 }
48
49 void AppListSyncableServiceFactory::RegisterProfilePrefs(
50     user_prefs::PrefRegistrySyncable* registry) {
51 }
52
53 content::BrowserContext* AppListSyncableServiceFactory::GetBrowserContextToUse(
54     content::BrowserContext* context) const {
55   // In Guest session, off the record profile should not be redirected to the
56   // original one.
57   Profile* profile = static_cast<Profile*>(context);
58   if (profile->IsGuestSession())
59     return chrome::GetBrowserContextOwnInstanceInIncognito(context);
60   return chrome::GetBrowserContextRedirectedInIncognito(context);
61 }
62
63 }  // namespace app_list