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

Side by Side Diff: chrome/browser/chromeos/policy/policy_cert_verifier.h

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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_POLICY_CERT_VERIFIER_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_POLICY_CERT_VERIFIER_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_POLICY_CERT_VERIFIER_H_ 6 #define CHROME_BROWSER_CHROMEOS_POLICY_POLICY_CERT_VERIFIER_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/callback.h" 11 #include "base/callback_list.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "net/base/completion_callback.h"
15 #include "net/cert/cert_trust_anchor_provider.h" 17 #include "net/cert/cert_trust_anchor_provider.h"
16 #include "net/cert/cert_verifier.h" 18 #include "net/cert/cert_verifier.h"
17 19
18 namespace net { 20 namespace net {
21 class CertVerifyResult;
19 class X509Certificate; 22 class X509Certificate;
20 typedef std::vector<scoped_refptr<X509Certificate> > CertificateList; 23 typedef std::vector<scoped_refptr<X509Certificate> > CertificateList;
21 } 24 }
22 25
23 namespace policy { 26 namespace policy {
24 27
25 // Wraps a MultiThreadedCertVerifier to make it use the additional trust anchors 28 // Wraps a MultiThreadedCertVerifier to make it use the additional trust anchors
26 // configured by the ONC user policy. 29 // configured by the ONC user policy.
27 class PolicyCertVerifier : public net::CertVerifier, 30 class PolicyCertVerifier : public net::CertVerifier,
28 public net::CertTrustAnchorProvider { 31 public net::CertTrustAnchorProvider {
29 public: 32 public:
30 // This object must be created on the UI thread. It's member functions and 33 // This object must be created on the UI thread. It's member functions and
31 // destructor must be called on the IO thread. |anchor_used_callback| is 34 // destructor must be called on the IO thread. |anchor_used_callback| is
32 // called on the IO thread everytime a certificate from the additional trust 35 // called on the IO thread everytime a certificate from the additional trust
33 // anchors (set with SetTrustAnchors) is used. 36 // anchors (set with SetTrustAnchors) is used.
34 explicit PolicyCertVerifier(const base::Closure& anchor_used_callback); 37 PolicyCertVerifier();
35 virtual ~PolicyCertVerifier(); 38 virtual ~PolicyCertVerifier();
36 39
37 void InitializeOnIOThread(); 40 void InitializeOnIOThread();
41 void ShutdownOnUIThread();
42
43 scoped_ptr<base::CallbackList<void()>::Subscription>
44 RegisterAnchorUsedCallback(const base::Closure& cb);
38 45
39 void SetTrustAnchors(const net::CertificateList& trust_anchors); 46 void SetTrustAnchors(const net::CertificateList& trust_anchors);
40 47
41 // CertVerifier: 48 // CertVerifier:
42 // Note: |callback| can be null. 49 // Note: |callback| can be null.
43 virtual int Verify(net::X509Certificate* cert, 50 virtual int Verify(net::X509Certificate* cert,
44 const std::string& hostname, 51 const std::string& hostname,
45 int flags, 52 int flags,
46 net::CRLSet* crl_set, 53 net::CRLSet* crl_set,
47 net::CertVerifyResult* verify_result, 54 net::CertVerifyResult* verify_result,
48 const net::CompletionCallback& callback, 55 const net::CompletionCallback& callback,
49 RequestHandle* out_req, 56 RequestHandle* out_req,
50 const net::BoundNetLog& net_log) OVERRIDE; 57 const net::BoundNetLog& net_log) OVERRIDE;
51 58
52 virtual void CancelRequest(RequestHandle req) OVERRIDE; 59 virtual void CancelRequest(RequestHandle req) OVERRIDE;
53 60
54 // CertTrustAnchorProvider: 61 // CertTrustAnchorProvider:
55 virtual const net::CertificateList& GetAdditionalTrustAnchors() OVERRIDE; 62 virtual const net::CertificateList& GetAdditionalTrustAnchors() OVERRIDE;
56 63
57 private: 64 private:
65 void RunCallback();
66
67 static void MaybeSignalAnchorUse(
68 int error,
69 const net::CertVerifyResult& verify_result,
70 const base::WeakPtr<PolicyCertVerifier>& weak_ptr);
71
72 static void CompleteAndSignalAnchorUse(
73 const net::CompletionCallback& completion_callback,
74 const net::CertVerifyResult* verify_result,
75 const base::WeakPtr<PolicyCertVerifier>& weak_ptr,
76 int error);
77
58 net::CertificateList trust_anchors_; 78 net::CertificateList trust_anchors_;
59 base::Closure anchor_used_callback_;
60 scoped_ptr<CertVerifier> delegate_; 79 scoped_ptr<CertVerifier> delegate_;
61 80
81 // Must be constructed, modified, and destructed on the UI thread.
82 scoped_ptr<base::CallbackList<void()> > anchor_used_callback_list_;
83
84 // Must be constructed, modified, and invalidated on the UI thread.
85 base::WeakPtrFactory<PolicyCertVerifier> weak_ptr_factory_;
86
87 // Must be constructed and dereferenced on the UI thread. This WeakPtr has to
88 // be used for callbacks from the IO thread to the UI thread.
89 base::WeakPtr<PolicyCertVerifier> weak_ptr_;
90
62 DISALLOW_COPY_AND_ASSIGN(PolicyCertVerifier); 91 DISALLOW_COPY_AND_ASSIGN(PolicyCertVerifier);
63 }; 92 };
64 93
65 } // namespace policy 94 } // namespace policy
66 95
67 #endif // CHROME_BROWSER_CHROMEOS_POLICY_POLICY_CERT_VERIFIER_H_ 96 #endif // CHROME_BROWSER_CHROMEOS_POLICY_POLICY_CERT_VERIFIER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698