Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: chrome/browser/bookmarks/managed_bookmark_service_factory.cc

Issue 1233673002: Fix componentization of chrome/browser/bookmarks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix "gn check" and compilation on Mac Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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/bookmarks/managed_bookmark_service_factory.h"
6
7 #include <string>
8
9 #include "base/bind.h"
10 #include "base/memory/singleton.h"
11 #include "chrome/browser/policy/profile_policy_connector.h"
12 #include "chrome/browser/policy/profile_policy_connector_factory.h"
13 #include "chrome/browser/profiles/incognito_helpers.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "components/bookmarks/managed/managed_bookmark_service.h"
16 #include "components/keyed_service/content/browser_context_dependency_manager.h"
17 #include "policy/policy_constants.h"
18
19 namespace {
20
21 std::string GetManagedBookmarksDomain(Profile* profile) {
22 policy::ProfilePolicyConnector* connector =
23 policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile);
24 if (connector->IsPolicyFromCloudPolicy(policy::key::kManagedBookmarks))
25 return connector->GetManagementDomain();
26 return std::string();
27 }
28
29 scoped_ptr<KeyedService> BuildManagedBookmarkService(
30 content::BrowserContext* context) {
31 Profile* profile = Profile::FromBrowserContext(context);
32 return make_scoped_ptr(new bookmarks::ManagedBookmarkService(
33 profile->GetPrefs(),
34 base::Bind(&GetManagedBookmarksDomain, base::Unretained(profile))));
35 }
36
37 } // namespace
38
39 // static
40 bookmarks::ManagedBookmarkService* ManagedBookmarkServiceFactory::GetForProfile(
41 Profile* profile) {
42 return static_cast<bookmarks::ManagedBookmarkService*>(
43 GetInstance()->GetServiceForBrowserContext(profile, true));
44 }
45
46 // static
47 ManagedBookmarkServiceFactory* ManagedBookmarkServiceFactory::GetInstance() {
48 return Singleton<ManagedBookmarkServiceFactory>::get();
49 }
50
51 // static
52 BrowserContextKeyedServiceFactory::TestingFactoryFunction
53 ManagedBookmarkServiceFactory::GetDefaultFactory() {
54 return &BuildManagedBookmarkService;
55 }
56
57 ManagedBookmarkServiceFactory::ManagedBookmarkServiceFactory()
58 : BrowserContextKeyedServiceFactory(
59 "ManagedBookmarkService",
60 BrowserContextDependencyManager::GetInstance()) {
61 DependsOn(policy::ProfilePolicyConnectorFactory::GetInstance());
62 }
63
64 ManagedBookmarkServiceFactory::~ManagedBookmarkServiceFactory() {}
65
66 KeyedService* ManagedBookmarkServiceFactory::BuildServiceInstanceFor(
67 content::BrowserContext* context) const {
68 return BuildManagedBookmarkService(context).release();
69 }
70
71 content::BrowserContext* ManagedBookmarkServiceFactory::GetBrowserContextToUse(
72 content::BrowserContext* context) const {
73 return chrome::GetBrowserContextRedirectedInIncognito(context);
74 }
75
76 bool ManagedBookmarkServiceFactory::ServiceIsNULLWhileTesting() const {
77 return true;
78 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698