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

Side by Side Diff: net/base/cert_verifier.cc

Issue 4669003: Revert 65349 - Update CertVerifier to watch for the origin loop's destruction... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2008 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 #include "net/base/cert_verifier.h" 5 #include "net/base/cert_verifier.h"
6 6
7 #if defined(USE_NSS) 7 #if defined(USE_NSS)
8 #include <private/pprthred.h> // PR_DetatchThread 8 #include <private/pprthred.h> // PR_DetatchThread
9 #endif 9 #endif
10 10
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/worker_pool.h" 12 #include "base/worker_pool.h"
13 #include "net/base/cert_verify_result.h" 13 #include "net/base/cert_verify_result.h"
14 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
15 #include "net/base/x509_certificate.h" 15 #include "net/base/x509_certificate.h"
16 16
17 namespace net { 17 namespace net {
18 18
19 class CertVerifier::Request : 19 class CertVerifier::Request :
20 public base::RefCountedThreadSafe<CertVerifier::Request>, 20 public base::RefCountedThreadSafe<CertVerifier::Request> {
21 public MessageLoop::DestructionObserver {
22 public: 21 public:
23 Request(CertVerifier* verifier, 22 Request(CertVerifier* verifier,
24 X509Certificate* cert, 23 X509Certificate* cert,
25 const std::string& hostname, 24 const std::string& hostname,
26 int flags, 25 int flags,
27 CertVerifyResult* verify_result, 26 CertVerifyResult* verify_result,
28 CompletionCallback* callback) 27 CompletionCallback* callback)
29 : cert_(cert), 28 : cert_(cert),
30 hostname_(hostname), 29 hostname_(hostname),
31 flags_(flags), 30 flags_(flags),
32 verifier_(verifier), 31 verifier_(verifier),
33 verify_result_(verify_result), 32 verify_result_(verify_result),
34 callback_(callback), 33 callback_(callback),
35 origin_loop_(MessageLoop::current()), 34 origin_loop_(MessageLoop::current()),
36 error_(OK) { 35 error_(OK) {
37 if (origin_loop_)
38 origin_loop_->AddDestructionObserver(this);
39 } 36 }
40 37
41 void DoVerify() { 38 void DoVerify() {
42 // Running on the worker thread 39 // Running on the worker thread
43 error_ = cert_->Verify(hostname_, flags_, &result_); 40 error_ = cert_->Verify(hostname_, flags_, &result_);
44 #if defined(USE_NSS) 41 #if defined(USE_NSS)
45 // Detach the thread from NSPR. 42 // Detach the thread from NSPR.
46 // Calling NSS functions attaches the thread to NSPR, which stores 43 // Calling NSS functions attaches the thread to NSPR, which stores
47 // the NSPR thread ID in thread-specific data. 44 // the NSPR thread ID in thread-specific data.
48 // The threads in our thread pool terminate after we have called 45 // The threads in our thread pool terminate after we have called
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 // destroyed. 79 // destroyed.
83 verifier_->request_ = NULL; 80 verifier_->request_ = NULL;
84 81
85 callback_->Run(error_); 82 callback_->Run(error_);
86 } 83 }
87 84
88 void Cancel() { 85 void Cancel() {
89 verifier_ = NULL; 86 verifier_ = NULL;
90 87
91 AutoLock locked(origin_loop_lock_); 88 AutoLock locked(origin_loop_lock_);
92 if (origin_loop_) {
93 origin_loop_->RemoveDestructionObserver(this);
94 origin_loop_ = NULL;
95 }
96 }
97
98 // MessageLoop::DestructionObserver override.
99 virtual void WillDestroyCurrentMessageLoop() {
100 LOG(ERROR) << "CertVerifier wasn't deleted before the thread was deleted.";
101 AutoLock locked(origin_loop_lock_);
102 origin_loop_ = NULL; 89 origin_loop_ = NULL;
103 } 90 }
104 91
105 private: 92 private:
106 friend class base::RefCountedThreadSafe<CertVerifier::Request>; 93 friend class base::RefCountedThreadSafe<CertVerifier::Request>;
107 94
108 ~Request() { 95 ~Request() {}
109 Cancel();
110 }
111 96
112 // Set on the origin thread, read on the worker thread. 97 // Set on the origin thread, read on the worker thread.
113 scoped_refptr<X509Certificate> cert_; 98 scoped_refptr<X509Certificate> cert_;
114 std::string hostname_; 99 std::string hostname_;
115 // bitwise OR'd of X509Certificate::VerifyFlags. 100 // bitwise OR'd of X509Certificate::VerifyFlags.
116 int flags_; 101 int flags_;
117 102
118 // Only used on the origin thread (where Verify was called). 103 // Only used on the origin thread (where Verify was called).
119 CertVerifier* verifier_; 104 CertVerifier* verifier_;
120 CertVerifyResult* verify_result_; 105 CertVerifyResult* verify_result_;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 NewRunnableMethod(request_.get(), &Request::DoVerify), true)) { 146 NewRunnableMethod(request_.get(), &Request::DoVerify), true)) {
162 NOTREACHED(); 147 NOTREACHED();
163 request_ = NULL; 148 request_ = NULL;
164 return ERR_FAILED; 149 return ERR_FAILED;
165 } 150 }
166 151
167 return ERR_IO_PENDING; 152 return ERR_IO_PENDING;
168 } 153 }
169 154
170 } // namespace net 155 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698