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

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

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

Powered by Google App Engine
This is Rietveld 408576698