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

Unified Diff: chrome/browser/chromeos/policy/network_policy_service_factory.cc

Issue 24153012: Fix cyclic dependency between ProfilePolicyConnector and PrefService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use callback_list in PolicyCertVerifier. Created 7 years, 2 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/chromeos/policy/network_policy_service_factory.cc
diff --git a/chrome/browser/chromeos/policy/network_policy_service_factory.cc b/chrome/browser/chromeos/policy/network_policy_service_factory.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d4dea91781c4d379a20d13292c9fbd817ca38a5e
--- /dev/null
+++ b/chrome/browser/chromeos/policy/network_policy_service_factory.cc
@@ -0,0 +1,62 @@
+// Copyright 2013 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/chromeos/policy/network_policy_service_factory.h"
+
+#include "base/memory/singleton.h"
+#include "chrome/browser/chromeos/policy/network_policy_service.h"
+#include "chrome/browser/chromeos/profiles/profile_helper.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/browser_context_keyed_service/browser_context_dependency_manager.h"
+
+namespace policy {
+
+// static
+NetworkPolicyService* NetworkPolicyServiceFactory::GetForProfile(
+ Profile* profile) {
+ return static_cast<NetworkPolicyService*>(
+ GetInstance()->GetServiceForBrowserContext(profile, true));
+}
+
+// static
+NetworkPolicyServiceFactory* NetworkPolicyServiceFactory::GetInstance() {
+ return Singleton<NetworkPolicyServiceFactory>::get();
+}
+
+NetworkPolicyServiceFactory::NetworkPolicyServiceFactory()
+ : BrowserContextKeyedServiceFactory(
+ "NetworkPolicyService",
+ BrowserContextDependencyManager::GetInstance()) {
+ DependsOn(ProfilePolicyConnectorFactory::GetInstance());
+}
+
+NetworkPolicyServiceFactory::~NetworkPolicyServiceFactory() {}
+
+content::BrowserContext* NetworkPolicyServiceFactory::GetBrowserContextToUse(
+ content::BrowserContext* context) const {
+ return chrome::GetBrowserContextRedirectedInIncognito(context);
+}
+
+BrowserContextKeyedService*
+NetworkPolicyServiceFactory::BuildServiceInstanceFor(
+ content::BrowserContext* context) const {
+ Profile* profile = static_cast<Profile*>(context);
+ if (chromeos::ProfileHelper::IsSigninProfile(profile))
+ return NULL;
+
+ bool is_primary_user =
+ chromeos::UserManager::Get()->GetLoggedInUsers().size() == 1;
+ if (!is_primary_user)
+ return NULL;
Joao da Silva 2013/10/16 12:44:58 Check instead UserManager::GetUserByProfile(profil
pneubeck (no reviews) 2013/10/22 18:47:41 Done.
+
+ ProfilePolicyConnector* connector =
+ ProfilePolicyConnectorFactory::GetForProfile(profile);
+ return new NetworkPolicyService(profile->GetPrefs(),
+ connector->policy_service());
+}
+
+} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698