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

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: Fixed another bug for OTRProfile. 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..de213aa6835135f7ccfdb2ba9b4d8cd3e349fff7
--- /dev/null
+++ b/chrome/browser/chromeos/policy/network_policy_service_factory.cc
@@ -0,0 +1,90 @@
+// 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/browser_process.h"
+#include "chrome/browser/chromeos/login/user.h"
+#include "chrome/browser/chromeos/login/user_manager.h"
+#include "chrome/browser/chromeos/policy/network_policy_service.h"
+#include "chrome/browser/policy/browser_policy_connector.h"
+#include "chrome/browser/policy/cloud/cloud_policy_constants.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 "chrome/common/pref_names.h"
+#include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
+#include "components/user_prefs/pref_registry_syncable.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 (profile->IsLoginProfile())
+ return NULL;
+
+ chromeos::UserManager* user_manager = chromeos::UserManager::Get();
+ chromeos::User* user = user_manager->GetUserByProfile(profile);
+ DCHECK(user);
+ if (user != user_manager->GetPrimaryUser())
+ return NULL;
+
+ BrowserPolicyConnector* browser_connector =
+ g_browser_process->browser_policy_connector();
+
+ // Allow trusted certs from policy only for accounts with managed user
+ // affiliation, i.e users that are managed by the same domain as the device.
+ bool allow_trusted_certs_from_policy =
+ browser_connector->GetUserAffiliation(user->email()) ==
+ USER_AFFILIATION_MANAGED &&
+ user->GetType() == chromeos::User::USER_TYPE_REGULAR;
+
+ ProfilePolicyConnector* profile_connector =
+ ProfilePolicyConnectorFactory::GetForProfile(profile);
+
+ return new NetworkPolicyService(allow_trusted_certs_from_policy,
+ *user,
+ profile->GetPrefs(),
+ profile_connector->policy_service());
+}
+
+void NetworkPolicyServiceFactory::RegisterProfilePrefs(
+ user_prefs::PrefRegistrySyncable* registry) {
+ registry->RegisterBooleanPref(
+ prefs::kUsedPolicyCertificatesOnce,
+ false,
+ user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
+}
+
+} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698