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

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: Fix/Extend NetworkConfigurationUpdater unit test. Created 7 years, 1 month 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..fc0624510d511ac5663476997dee30e01482a872
--- /dev/null
+++ b/chrome/browser/chromeos/policy/network_policy_service_factory.cc
@@ -0,0 +1,73 @@
+// 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/policy/policy_cert_verifier.h"
+#include "chrome/browser/chromeos/policy/user_network_configuration_updater_factory.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, false));
+}
+
+// static
+scoped_ptr<PolicyCertVerifier> NetworkPolicyServiceFactory::CreateForProfile(
+ Profile* profile) {
+ DCHECK(!GetInstance()->GetServiceForBrowserContext(profile, false));
+ NetworkPolicyService* service = static_cast<NetworkPolicyService*>(
+ GetInstance()->GetServiceForBrowserContext(profile, true));
+ if (!service)
+ return scoped_ptr<PolicyCertVerifier>();
+ return service->CreatePolicyCertVerifier();
+}
+
+// static
+NetworkPolicyServiceFactory* NetworkPolicyServiceFactory::GetInstance() {
+ return Singleton<NetworkPolicyServiceFactory>::get();
+}
+
+NetworkPolicyServiceFactory::NetworkPolicyServiceFactory()
+ : BrowserContextKeyedServiceFactory(
+ "NetworkPolicyService",
+ BrowserContextDependencyManager::GetInstance()) {
+ DependsOn(UserNetworkConfigurationUpdaterFactory::GetInstance());
+}
+
+NetworkPolicyServiceFactory::~NetworkPolicyServiceFactory() {}
+
+BrowserContextKeyedService*
+NetworkPolicyServiceFactory::BuildServiceInstanceFor(
+ content::BrowserContext* context) const {
+ Profile* profile = static_cast<Profile*>(context);
+ UserNetworkConfigurationUpdater* net_conf_updater =
+ UserNetworkConfigurationUpdaterFactory::GetForProfile(profile);
+ if (!net_conf_updater)
+ return NULL;
+
+ // In case of usage of additional trust anchors from an incognito profile, the
+ // prefs of the original profile have to be marked.
+ return new NetworkPolicyService(net_conf_updater,
+ profile->GetOriginalProfile()->GetPrefs());
Joao da Silva 2013/11/11 12:38:19 This factory must override GetBrowserContextToUse(
pneubeck (no reviews) 2013/11/12 10:07:53 ops. Done.
+}
+
+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