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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/bookmarks/managed_bookmark_service_factory.cc
diff --git a/chrome/browser/bookmarks/managed_bookmark_service_factory.cc b/chrome/browser/bookmarks/managed_bookmark_service_factory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ffeafb30512ea6babd51a4a2e48eafdc93c43316
--- /dev/null
+++ b/chrome/browser/bookmarks/managed_bookmark_service_factory.cc
@@ -0,0 +1,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 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;
+}

Powered by Google App Engine
This is Rietveld 408576698