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

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

Issue 8832006: Reverts a commit that caused ASAN failures, and 2 dependent commits. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years 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.h » ('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 22 matching lines...) Expand all
33 } 33 }
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_(base::Bind(&DiskCacheBasedSSLHostInfo::OnIOComplete, 43 callback_(new CallbackImpl(weak_ptr_factory_.GetWeakPtr(),
44 weak_ptr_factory_.GetWeakPtr())), 44 &DiskCacheBasedSSLHostInfo::OnIOComplete)),
45 state_(GET_BACKEND), 45 state_(GET_BACKEND),
46 ready_(false), 46 ready_(false),
47 found_entry_(false), 47 found_entry_(false),
48 hostname_(hostname), 48 hostname_(hostname),
49 http_cache_(http_cache), 49 http_cache_(http_cache),
50 backend_(NULL), 50 backend_(NULL),
51 entry_(NULL) { 51 entry_(NULL) {
52 } 52 }
53 53
54 void DiskCacheBasedSSLHostInfo::Start() { 54 void DiskCacheBasedSSLHostInfo::Start() {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 return; 86 return;
87 87
88 state_ = CREATE_OR_OPEN; 88 state_ = CREATE_OR_OPEN;
89 DoLoop(OK); 89 DoLoop(OK);
90 } 90 }
91 91
92 DiskCacheBasedSSLHostInfo::~DiskCacheBasedSSLHostInfo() { 92 DiskCacheBasedSSLHostInfo::~DiskCacheBasedSSLHostInfo() {
93 DCHECK(user_callback_.is_null()); 93 DCHECK(user_callback_.is_null());
94 if (entry_) 94 if (entry_)
95 entry_->Close(); 95 entry_->Close();
96 if (!IsCallbackPending())
97 delete callback_;
96 } 98 }
97 99
98 std::string DiskCacheBasedSSLHostInfo::key() const { 100 std::string DiskCacheBasedSSLHostInfo::key() const {
99 return "sslhostinfo:" + hostname_; 101 return "sslhostinfo:" + hostname_;
100 } 102 }
101 103
102 void DiskCacheBasedSSLHostInfo::OnIOComplete(int rv) { 104 void DiskCacheBasedSSLHostInfo::OnIOComplete(int rv) {
103 rv = DoLoop(rv); 105 rv = DoLoop(rv);
104 if (rv != ERR_IO_PENDING && !user_callback_.is_null()) { 106 if (rv != ERR_IO_PENDING && !user_callback_.is_null()) {
105 CompletionCallback callback = user_callback_; 107 CompletionCallback callback = user_callback_;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 rv = OK; 153 rv = OK;
152 NOTREACHED(); 154 NOTREACHED();
153 } 155 }
154 } while (rv != ERR_IO_PENDING && state_ != NONE); 156 } while (rv != ERR_IO_PENDING && state_ != NONE);
155 157
156 return rv; 158 return rv;
157 } 159 }
158 160
159 int DiskCacheBasedSSLHostInfo::DoGetBackendComplete(int rv) { 161 int DiskCacheBasedSSLHostInfo::DoGetBackendComplete(int rv) {
160 if (rv == OK) { 162 if (rv == OK) {
163 backend_ = callback_->backend();
161 state_ = OPEN; 164 state_ = OPEN;
162 } else { 165 } else {
163 state_ = WAIT_FOR_DATA_READY_DONE; 166 state_ = WAIT_FOR_DATA_READY_DONE;
164 } 167 }
165 return OK; 168 return OK;
166 } 169 }
167 170
168 int DiskCacheBasedSSLHostInfo::DoOpenComplete(int rv) { 171 int DiskCacheBasedSSLHostInfo::DoOpenComplete(int rv) {
169 if (rv == OK) { 172 if (rv == OK) {
173 entry_ = callback_->entry();
170 state_ = READ; 174 state_ = READ;
171 found_entry_ = true; 175 found_entry_ = true;
172 } else { 176 } else {
173 state_ = WAIT_FOR_DATA_READY_DONE; 177 state_ = WAIT_FOR_DATA_READY_DONE;
174 } 178 }
175 179
176 return OK; 180 return OK;
177 } 181 }
178 182
179 int DiskCacheBasedSSLHostInfo::DoReadComplete(int rv) { 183 int DiskCacheBasedSSLHostInfo::DoReadComplete(int rv) {
180 if (rv > 0) 184 if (rv > 0)
181 data_.assign(read_buffer_->data(), rv); 185 data_.assign(read_buffer_->data(), rv);
182 186
183 state_ = WAIT_FOR_DATA_READY_DONE; 187 state_ = WAIT_FOR_DATA_READY_DONE;
184 return OK; 188 return OK;
185 } 189 }
186 190
187 int DiskCacheBasedSSLHostInfo::DoWriteComplete(int rv) { 191 int DiskCacheBasedSSLHostInfo::DoWriteComplete(int rv) {
188 state_ = SET_DONE; 192 state_ = SET_DONE;
189 return OK; 193 return OK;
190 } 194 }
191 195
192 int DiskCacheBasedSSLHostInfo::DoCreateOrOpenComplete(int rv) { 196 int DiskCacheBasedSSLHostInfo::DoCreateOrOpenComplete(int rv) {
193 if (rv != OK) 197 if (rv != OK) {
194 state_ = SET_DONE; 198 state_ = SET_DONE;
195 else 199 } else {
200 entry_ = callback_->entry();
196 state_ = WRITE; 201 state_ = WRITE;
197 202 }
198 return OK; 203 return OK;
199 } 204 }
200 205
201 int DiskCacheBasedSSLHostInfo::DoGetBackend() { 206 int DiskCacheBasedSSLHostInfo::DoGetBackend() {
202 state_ = GET_BACKEND_COMPLETE; 207 state_ = GET_BACKEND_COMPLETE;
203 return http_cache_->GetBackend(&backend_, callback_); 208 return http_cache_->GetBackend(callback_->backend_pointer(), callback_);
204 } 209 }
205 210
206 int DiskCacheBasedSSLHostInfo::DoOpen() { 211 int DiskCacheBasedSSLHostInfo::DoOpen() {
207 state_ = OPEN_COMPLETE; 212 state_ = OPEN_COMPLETE;
208 return backend_->OpenEntry(key(), &entry_, callback_); 213 return backend_->OpenEntry(key(), callback_->entry_pointer(), callback_);
209 } 214 }
210 215
211 int DiskCacheBasedSSLHostInfo::DoRead() { 216 int DiskCacheBasedSSLHostInfo::DoRead() {
212 const int32 size = entry_->GetDataSize(0 /* index */); 217 const int32 size = entry_->GetDataSize(0 /* index */);
213 if (!size) { 218 if (!size) {
214 state_ = WAIT_FOR_DATA_READY_DONE; 219 state_ = WAIT_FOR_DATA_READY_DONE;
215 return OK; 220 return OK;
216 } 221 }
217 222
218 read_buffer_ = new IOBuffer(size); 223 read_buffer_ = new IOBuffer(size);
219 state_ = READ_COMPLETE; 224 state_ = READ_COMPLETE;
220 return entry_->ReadData(0 /* index */, 0 /* offset */, read_buffer_, 225 return entry_->ReadData(0 /* index */, 0 /* offset */, read_buffer_,
221 size, callback_); 226 size, callback_);
222 } 227 }
223 228
224 int DiskCacheBasedSSLHostInfo::DoWrite() { 229 int DiskCacheBasedSSLHostInfo::DoWrite() {
225 write_buffer_ = new IOBuffer(new_data_.size()); 230 write_buffer_ = new IOBuffer(new_data_.size());
226 memcpy(write_buffer_->data(), new_data_.data(), new_data_.size()); 231 memcpy(write_buffer_->data(), new_data_.data(), new_data_.size());
227 state_ = WRITE_COMPLETE; 232 state_ = WRITE_COMPLETE;
228 233
229 return entry_->WriteData(0 /* index */, 0 /* offset */, write_buffer_, 234 return entry_->WriteData(0 /* index */, 0 /* offset */, write_buffer_,
230 new_data_.size(), callback_, 235 new_data_.size(), callback_, true /* truncate */);
231 true /* truncate */);
232 } 236 }
233 237
234 int DiskCacheBasedSSLHostInfo::DoCreateOrOpen() { 238 int DiskCacheBasedSSLHostInfo::DoCreateOrOpen() {
235 DCHECK(entry_ == NULL); 239 DCHECK(entry_ == NULL);
236 state_ = CREATE_OR_OPEN_COMPLETE; 240 state_ = CREATE_OR_OPEN_COMPLETE;
237 if (found_entry_) 241 if (found_entry_)
238 return backend_->OpenEntry(key(), &entry_, callback_); 242 return backend_->OpenEntry(key(), callback_->entry_pointer(), callback_);
239 243
240 return backend_->CreateEntry(key(), &entry_, callback_); 244 return backend_->CreateEntry(key(), callback_->entry_pointer(), callback_);
241 } 245 }
242 246
243 int DiskCacheBasedSSLHostInfo::DoWaitForDataReadyDone() { 247 int DiskCacheBasedSSLHostInfo::DoWaitForDataReadyDone() {
244 DCHECK(!ready_); 248 DCHECK(!ready_);
245 state_ = NONE; 249 state_ = NONE;
246 ready_ = true; 250 ready_ = true;
247 // We close the entry because, if we shutdown before ::Persist is called, 251 // We close the entry because, if we shutdown before ::Persist is called,
248 // then we might leak a cache reference, which causes a DCHECK on shutdown. 252 // then we might leak a cache reference, which causes a DCHECK on shutdown.
249 if (entry_) 253 if (entry_)
250 entry_->Close(); 254 entry_->Close();
(...skipping 17 matching lines...) Expand all
268 case READ_COMPLETE: 272 case READ_COMPLETE:
269 case CREATE_OR_OPEN_COMPLETE: 273 case CREATE_OR_OPEN_COMPLETE:
270 case WRITE_COMPLETE: 274 case WRITE_COMPLETE:
271 return true; 275 return true;
272 default: 276 default:
273 return false; 277 return false;
274 } 278 }
275 } 279 }
276 280
277 } // namespace net 281 } // namespace net
OLDNEW
« no previous file with comments | « net/http/disk_cache_based_ssl_host_info.h ('k') | net/http/http_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698