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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/policy/network_policy_service.h"
6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
9 #include "base/logging.h"
10 #include "base/prefs/pref_service.h"
11 #include "chrome/browser/chromeos/policy/policy_cert_verifier.h"
12 #include "chrome/common/pref_names.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "net/cert/x509_certificate.h"
15
16 namespace policy {
17
18 NetworkPolicyService::~NetworkPolicyService() {
19 DCHECK(cert_verifier_)
20 << "CreatePolicyCertVerifier() must be called after construction.";
21 }
22
23 NetworkPolicyService::NetworkPolicyService(
24 UserNetworkConfigurationUpdater* net_conf_updater,
25 PrefService* user_prefs)
26 : cert_verifier_(NULL),
27 net_conf_updater_(net_conf_updater),
28 user_prefs_(user_prefs),
29 weak_ptr_factory_(this) {
30 DCHECK(net_conf_updater_);
31 DCHECK(user_prefs_);
32 }
33
34 scoped_ptr<PolicyCertVerifier>
35 NetworkPolicyService::CreatePolicyCertVerifier() {
36 base::Closure callback =
37 base::Bind(&NetworkPolicyService::SetUsedPolicyCertificatesOnce,
38 weak_ptr_factory_.GetWeakPtr());
39 cert_verifier_ = new PolicyCertVerifier(
40 base::Bind(base::IgnoreResult(&content::BrowserThread::PostTask),
41 content::BrowserThread::UI,
42 FROM_HERE,
43 callback));
44 // Certs are forwarded to |cert_verifier_|, thus register here after
45 // |cert_verifier_| is created.
46 net_conf_updater_->AddTrustedCertsObserver(this);
47
48 // Set the current list of trust anchors.
49 net::CertificateList trust_anchors;
50 net_conf_updater_->GetWebTrustedCertificates(&trust_anchors);
51 OnTrustAnchorsChanged(trust_anchors);
52
53 return make_scoped_ptr(cert_verifier_);
54 }
55
56 void NetworkPolicyService::OnTrustAnchorsChanged(
57 const net::CertificateList& trust_anchors) {
58 DCHECK(cert_verifier_);
59 // It's safe to use base::Unretained here, because it's guaranteed that
60 // |cert_verifier_| outlives this object (see description of
61 // CreatePolicyCertVerifier).
62 // Note: ProfileIOData, which owns the CertVerifier is deleted by a
63 // DeleteSoon on IO, i.e. after all pending tasks on IO are finished.
64 content::BrowserThread::PostTask(
65 content::BrowserThread::IO,
66 FROM_HERE,
67 base::Bind(&PolicyCertVerifier::SetTrustAnchors,
68 base::Unretained(cert_verifier_),
69 trust_anchors));
70 }
71
72 bool NetworkPolicyService::UsedPolicyCertificates() const {
73 return user_prefs_->GetBoolean(prefs::kUsedPolicyCertificatesOnce);
74 }
75
76 void NetworkPolicyService::Shutdown() {
77 weak_ptr_factory_.InvalidateWeakPtrs();
78 net_conf_updater_->RemoveTrustedCertsObserver(this);
79 OnTrustAnchorsChanged(net::CertificateList());
80 net_conf_updater_ = NULL;
81 user_prefs_ = NULL;
82 }
83
84 void NetworkPolicyService::SetUsedPolicyCertificatesOnce() {
85 user_prefs_->SetBoolean(prefs::kUsedPolicyCertificatesOnce, true);
86 }
87
88 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698