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

Unified Diff: chrome/browser/chromeos/policy/network_policy_service.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.cc
diff --git a/chrome/browser/chromeos/policy/network_policy_service.cc b/chrome/browser/chromeos/policy/network_policy_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..36399548925150aa430e1e3826d387df0c194bc4
--- /dev/null
+++ b/chrome/browser/chromeos/policy/network_policy_service.cc
@@ -0,0 +1,88 @@
+// 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.h"
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/logging.h"
+#include "base/prefs/pref_service.h"
+#include "chrome/browser/chromeos/policy/policy_cert_verifier.h"
+#include "chrome/common/pref_names.h"
+#include "content/public/browser/browser_thread.h"
+#include "net/cert/x509_certificate.h"
+
+namespace policy {
+
+NetworkPolicyService::~NetworkPolicyService() {
+ DCHECK(cert_verifier_)
+ << "CreatePolicyCertVerifier() must be called after construction.";
+}
+
+NetworkPolicyService::NetworkPolicyService(
+ UserNetworkConfigurationUpdater* net_conf_updater,
+ PrefService* user_prefs)
+ : cert_verifier_(NULL),
+ net_conf_updater_(net_conf_updater),
+ user_prefs_(user_prefs),
+ weak_ptr_factory_(this) {
+ DCHECK(net_conf_updater_);
+ DCHECK(user_prefs_);
+}
+
+scoped_ptr<PolicyCertVerifier>
+NetworkPolicyService::CreatePolicyCertVerifier() {
+ base::Closure callback =
+ base::Bind(&NetworkPolicyService::SetUsedPolicyCertificatesOnce,
+ weak_ptr_factory_.GetWeakPtr());
+ cert_verifier_ = new PolicyCertVerifier(
+ base::Bind(base::IgnoreResult(&content::BrowserThread::PostTask),
+ content::BrowserThread::UI,
+ FROM_HERE,
+ callback));
+ // Certs are forwarded to |cert_verifier_|, thus register here after
+ // |cert_verifier_| is created.
+ net_conf_updater_->AddTrustedCertsObserver(this);
+
+ // Set the current list of trust anchors.
+ net::CertificateList trust_anchors;
+ net_conf_updater_->GetWebTrustedCertificates(&trust_anchors);
+ OnTrustAnchorsChanged(trust_anchors);
+
+ return make_scoped_ptr(cert_verifier_);
+}
+
+void NetworkPolicyService::OnTrustAnchorsChanged(
+ const net::CertificateList& trust_anchors) {
+ DCHECK(cert_verifier_);
+ // It's safe to use base::Unretained here, because it's guaranteed that
+ // |cert_verifier_| outlives this object (see description of
+ // CreatePolicyCertVerifier).
+ // Note: ProfileIOData, which owns the CertVerifier is deleted by a
+ // DeleteSoon on IO, i.e. after all pending tasks on IO are finished.
+ content::BrowserThread::PostTask(
+ content::BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(&PolicyCertVerifier::SetTrustAnchors,
+ base::Unretained(cert_verifier_),
+ trust_anchors));
+}
+
+bool NetworkPolicyService::UsedPolicyCertificates() const {
+ return user_prefs_->GetBoolean(prefs::kUsedPolicyCertificatesOnce);
+}
+
+void NetworkPolicyService::Shutdown() {
+ weak_ptr_factory_.InvalidateWeakPtrs();
+ net_conf_updater_->RemoveTrustedCertsObserver(this);
+ OnTrustAnchorsChanged(net::CertificateList());
+ net_conf_updater_ = NULL;
+ user_prefs_ = NULL;
+}
+
+void NetworkPolicyService::SetUsedPolicyCertificatesOnce() {
+ user_prefs_->SetBoolean(prefs::kUsedPolicyCertificatesOnce, true);
+}
+
+} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698