blob: 64fed097f24ea0cea85ded76619edcd06a19cc83 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/bookmarks/managed_bookmark_service_factory.h"
#include <string>
#include "base/bind.h"
#include "base/memory/singleton.h"
#include "chrome/browser/policy/profile_policy_connector.h"
#include "chrome/browser/policy/profile_policy_connector_factory.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "components/bookmarks/managed/managed_bookmark_service.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "policy/policy_constants.h"
namespace {
std::string GetManagedBookmarksDomain(Profile* profile) {
policy::ProfilePolicyConnector* connector =
policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile);
if (connector->IsPolicyFromCloudPolicy(policy::key::kManagedBookmarks))
return connector->GetManagementDomain();
return std::string();
}
scoped_ptr<KeyedService> BuildManagedBookmarkService(
content::BrowserContext* context) {
Profile* profile = Profile::FromBrowserContext(context);
return make_scoped_ptr(new bookmarks::ManagedBookmarkService(
profile->GetPrefs(),
base::Bind(&GetManagedBookmarksDomain, base::Unretained(profile))));
}
} // namespace
// static
bookmarks::ManagedBookmarkService* ManagedBookmarkServiceFactory::GetForProfile(
Profile* profile) {
return static_cast<bookmarks::ManagedBookmarkService*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
// static
ManagedBookmarkServiceFactory* ManagedBookmarkServiceFactory::GetInstance() {
return base::Singleton<ManagedBookmarkServiceFactory>::get();
}
// static
BrowserContextKeyedServiceFactory::TestingFactoryFunction
ManagedBookmarkServiceFactory::GetDefaultFactory() {
return &BuildManagedBookmarkService;
}
ManagedBookmarkServiceFactory::ManagedBookmarkServiceFactory()
: BrowserContextKeyedServiceFactory(
"ManagedBookmarkService",
BrowserContextDependencyManager::GetInstance()) {
DependsOn(policy::ProfilePolicyConnectorFactory::GetInstance());
}
ManagedBookmarkServiceFactory::~ManagedBookmarkServiceFactory() {}
KeyedService* ManagedBookmarkServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
return BuildManagedBookmarkService(context).release();
}
content::BrowserContext* ManagedBookmarkServiceFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextRedirectedInIncognito(context);
}
bool ManagedBookmarkServiceFactory::ServiceIsNULLWhileTesting() const {
return true;
}
|