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

Side by Side Diff: net/http/disk_cache_based_ssl_host_info.cc

Issue 7715007: Do not call callback->Run() until we are about to return from this (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Add ssl_host_info.h to the CL. Created 9 years, 4 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
« no previous file with comments | « net/http/disk_cache_based_ssl_host_info.h ('k') | net/http/http_cache_unittest.cc » ('j') | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/http/disk_cache_based_ssl_host_info.h" 5 #include "net/http/disk_cache_based_ssl_host_info.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "net/base/io_buffer.h" 9 #include "net/base/io_buffer.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
(...skipping 23 matching lines...) Expand all
34 } 34 }
35 35
36 DiskCacheBasedSSLHostInfo::DiskCacheBasedSSLHostInfo( 36 DiskCacheBasedSSLHostInfo::DiskCacheBasedSSLHostInfo(
37 const std::string& hostname, 37 const std::string& hostname,
38 const SSLConfig& ssl_config, 38 const SSLConfig& ssl_config,
39 CertVerifier* cert_verifier, 39 CertVerifier* cert_verifier,
40 HttpCache* http_cache) 40 HttpCache* http_cache)
41 : SSLHostInfo(hostname, ssl_config, cert_verifier), 41 : SSLHostInfo(hostname, ssl_config, cert_verifier),
42 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 42 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
43 callback_(new CallbackImpl(weak_ptr_factory_.GetWeakPtr(), 43 callback_(new CallbackImpl(weak_ptr_factory_.GetWeakPtr(),
44 &DiskCacheBasedSSLHostInfo::DoLoop)), 44 &DiskCacheBasedSSLHostInfo::OnIOComplete)),
45 state_(GET_BACKEND), 45 state_(GET_BACKEND),
46 ready_(false), 46 ready_(false),
47 hostname_(hostname), 47 hostname_(hostname),
48 http_cache_(http_cache), 48 http_cache_(http_cache),
49 backend_(NULL), 49 backend_(NULL),
50 entry_(NULL), 50 entry_(NULL),
51 user_callback_(NULL) { 51 user_callback_(NULL) {
52 } 52 }
53 53
54 void DiskCacheBasedSSLHostInfo::Start() { 54 void DiskCacheBasedSSLHostInfo::Start() {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 if (entry_) 91 if (entry_)
92 entry_->Close(); 92 entry_->Close();
93 if (!IsCallbackPending()) 93 if (!IsCallbackPending())
94 delete callback_; 94 delete callback_;
95 } 95 }
96 96
97 std::string DiskCacheBasedSSLHostInfo::key() const { 97 std::string DiskCacheBasedSSLHostInfo::key() const {
98 return "sslhostinfo:" + hostname_; 98 return "sslhostinfo:" + hostname_;
99 } 99 }
100 100
101 void DiskCacheBasedSSLHostInfo::DoLoop(int rv) { 101 void DiskCacheBasedSSLHostInfo::OnIOComplete(int rv) {
102 rv = DoLoop(rv);
103 if (rv != ERR_IO_PENDING) {
104 CompletionCallback* callback = user_callback_;
105 user_callback_ = NULL;
106 if (callback)
107 callback->Run(rv);
108 }
109 }
110
111 int DiskCacheBasedSSLHostInfo::DoLoop(int rv) {
102 do { 112 do {
103 switch (state_) { 113 switch (state_) {
104 case GET_BACKEND: 114 case GET_BACKEND:
105 rv = DoGetBackend(); 115 rv = DoGetBackend();
106 break; 116 break;
107 case GET_BACKEND_COMPLETE: 117 case GET_BACKEND_COMPLETE:
108 rv = DoGetBackendComplete(rv); 118 rv = DoGetBackendComplete(rv);
109 break; 119 break;
110 case OPEN: 120 case OPEN:
111 rv = DoOpen(); 121 rv = DoOpen();
(...skipping 23 matching lines...) Expand all
135 rv = DoWriteComplete(rv); 145 rv = DoWriteComplete(rv);
136 break; 146 break;
137 case SET_DONE: 147 case SET_DONE:
138 rv = DoSetDone(); 148 rv = DoSetDone();
139 break; 149 break;
140 default: 150 default:
141 rv = OK; 151 rv = OK;
142 NOTREACHED(); 152 NOTREACHED();
143 } 153 }
144 } while (rv != ERR_IO_PENDING && state_ != NONE); 154 } while (rv != ERR_IO_PENDING && state_ != NONE);
155
156 return rv;
145 } 157 }
146 158
147 int DiskCacheBasedSSLHostInfo::DoGetBackendComplete(int rv) { 159 int DiskCacheBasedSSLHostInfo::DoGetBackendComplete(int rv) {
148 if (rv == OK) { 160 if (rv == OK) {
149 backend_ = callback_->backend(); 161 backend_ = callback_->backend();
150 state_ = OPEN; 162 state_ = OPEN;
151 } else { 163 } else {
152 state_ = WAIT_FOR_DATA_READY_DONE; 164 state_ = WAIT_FOR_DATA_READY_DONE;
153 } 165 }
154 return OK; 166 return OK;
155 } 167 }
156 168
157 int DiskCacheBasedSSLHostInfo::DoOpenComplete(int rv) { 169 int DiskCacheBasedSSLHostInfo::DoOpenComplete(int rv) {
158 if (rv == OK) { 170 if (rv == OK) {
159 entry_ = callback_->entry(); 171 entry_ = callback_->entry();
160 state_ = READ; 172 state_ = READ;
161 } else { 173 } else {
162 state_ = WAIT_FOR_DATA_READY_DONE; 174 state_ = WAIT_FOR_DATA_READY_DONE;
163 } 175 }
164 176
165 return OK; 177 return OK;
166 } 178 }
167 179
168 int DiskCacheBasedSSLHostInfo::DoReadComplete(int rv) { 180 int DiskCacheBasedSSLHostInfo::DoReadComplete(int rv) {
169 if (rv > 0) 181 if (rv > 0)
170 data_ = std::string(read_buffer_->data(), rv); 182 data_.assign(read_buffer_->data(), rv);
171 183
172 state_ = WAIT_FOR_DATA_READY_DONE; 184 state_ = WAIT_FOR_DATA_READY_DONE;
173 return OK; 185 return OK;
174 } 186 }
175 187
176 int DiskCacheBasedSSLHostInfo::DoWriteComplete(int rv) { 188 int DiskCacheBasedSSLHostInfo::DoWriteComplete(int rv) {
177 state_ = SET_DONE; 189 state_ = SET_DONE;
178 return OK; 190 return OK;
179 } 191 }
180 192
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 new_data_.size(), callback_, true /* truncate */); 232 new_data_.size(), callback_, true /* truncate */);
221 } 233 }
222 234
223 int DiskCacheBasedSSLHostInfo::DoCreate() { 235 int DiskCacheBasedSSLHostInfo::DoCreate() {
224 DCHECK(entry_ == NULL); 236 DCHECK(entry_ == NULL);
225 state_ = CREATE_COMPLETE; 237 state_ = CREATE_COMPLETE;
226 return backend_->CreateEntry(key(), callback_->entry_pointer(), callback_); 238 return backend_->CreateEntry(key(), callback_->entry_pointer(), callback_);
227 } 239 }
228 240
229 int DiskCacheBasedSSLHostInfo::DoWaitForDataReadyDone() { 241 int DiskCacheBasedSSLHostInfo::DoWaitForDataReadyDone() {
230 CompletionCallback* callback;
231
232 DCHECK(!ready_); 242 DCHECK(!ready_);
233 state_ = NONE; 243 state_ = NONE;
234 ready_ = true; 244 ready_ = true;
235 callback = user_callback_;
236 user_callback_ = NULL;
237 // We close the entry because, if we shutdown before ::Persist is called, 245 // We close the entry because, if we shutdown before ::Persist is called,
238 // then we might leak a cache reference, which causes a DCHECK on shutdown. 246 // then we might leak a cache reference, which causes a DCHECK on shutdown.
239 if (entry_) 247 if (entry_)
240 entry_->Close(); 248 entry_->Close();
241 entry_ = NULL; 249 entry_ = NULL;
242 Parse(data_); 250 Parse(data_);
243
244 if (callback)
245 callback->Run(OK);
246
247 return OK; 251 return OK;
248 } 252 }
249 253
250 int DiskCacheBasedSSLHostInfo::DoSetDone() { 254 int DiskCacheBasedSSLHostInfo::DoSetDone() {
251 if (entry_) 255 if (entry_)
252 entry_->Close(); 256 entry_->Close();
253 entry_ = NULL; 257 entry_ = NULL;
254 state_ = NONE; 258 state_ = NONE;
255 return OK; 259 return OK;
256 } 260 }
257 261
258 bool DiskCacheBasedSSLHostInfo::IsCallbackPending() const { 262 bool DiskCacheBasedSSLHostInfo::IsCallbackPending() const {
259 switch (state_) { 263 switch (state_) {
260 case GET_BACKEND_COMPLETE: 264 case GET_BACKEND_COMPLETE:
261 case OPEN_COMPLETE: 265 case OPEN_COMPLETE:
262 case READ_COMPLETE: 266 case READ_COMPLETE:
263 case CREATE_COMPLETE: 267 case CREATE_COMPLETE:
264 case WRITE_COMPLETE: 268 case WRITE_COMPLETE:
265 return true; 269 return true;
266 default: 270 default:
267 return false; 271 return false;
268 } 272 }
269 } 273 }
270 274
271 } // namespace net 275 } // namespace net
OLDNEW
« no previous file with comments | « net/http/disk_cache_based_ssl_host_info.h ('k') | net/http/http_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698