Chromium Code Reviews| Index: net/http/disk_cache_based_ssl_host_info.cc |
| diff --git a/net/http/disk_cache_based_ssl_host_info.cc b/net/http/disk_cache_based_ssl_host_info.cc |
| index cd1cac8ca07479c14decc839ceaa86bdc43e63a4..551384acaf72fc1103383c47186f1f11303ce61d 100644 |
| --- a/net/http/disk_cache_based_ssl_host_info.cc |
| +++ b/net/http/disk_cache_based_ssl_host_info.cc |
| @@ -17,9 +17,9 @@ DiskCacheBasedSSLHostInfo::DiskCacheBasedSSLHostInfo( |
| const SSLConfig& ssl_config, |
| HttpCache* http_cache) |
| : SSLHostInfo(hostname, ssl_config), |
| - callback_(new CancelableCompletionCallback<DiskCacheBasedSSLHostInfo>( |
| - ALLOW_THIS_IN_INITIALIZER_LIST(this), |
| - &DiskCacheBasedSSLHostInfo::DoLoop)), |
| + weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| + callback_(new CallbackImpl(weak_ptr_factory_.GetWeakPtr(), |
| + &DiskCacheBasedSSLHostInfo::DoLoop)), |
| state_(GET_BACKEND), |
| ready_(false), |
| hostname_(hostname), |
| @@ -39,7 +39,8 @@ DiskCacheBasedSSLHostInfo::~DiskCacheBasedSSLHostInfo() { |
| DCHECK(!user_callback_); |
| if (entry_) |
| entry_->Close(); |
| - callback_->Cancel(); |
| + if (!IsCallbackPending()) |
| + delete callback_; |
| } |
| std::string DiskCacheBasedSSLHostInfo::key() const { |
| @@ -92,13 +93,28 @@ void DiskCacheBasedSSLHostInfo::DoLoop(int rv) { |
| } while (rv != ERR_IO_PENDING && state_ != NONE); |
| } |
| +bool DiskCacheBasedSSLHostInfo::IsCallbackPending() const { |
| + switch (state_) { |
|
willchan no longer on Chromium
2010/12/15 00:03:14
indentation is off for these cases.
http://google-
agl
2010/12/15 16:28:08
Done.
|
| + case GET_BACKEND_COMPLETE: |
| + case OPEN_COMPLETE: |
| + case READ_COMPLETE: |
| + case CREATE_COMPLETE: |
| + case WRITE_COMPLETE: |
| + return true; |
| + default: |
| + return false; |
| + } |
| +} |
| + |
| int DiskCacheBasedSSLHostInfo::DoGetBackend() { |
| state_ = GET_BACKEND_COMPLETE; |
| - return http_cache_->GetBackend(&backend_, callback_.get()); |
| + return http_cache_->GetBackend((disk_cache::Backend**) &callback_->user_data, |
| + callback_); |
| } |
| int DiskCacheBasedSSLHostInfo::DoGetBackendComplete(int rv) { |
| if (rv == OK) { |
| + backend_ = (disk_cache::Backend*) callback_->user_data; |
| state_ = OPEN; |
| } else { |
| state_ = WAIT_FOR_DATA_READY_DONE; |
| @@ -108,11 +124,13 @@ int DiskCacheBasedSSLHostInfo::DoGetBackendComplete(int rv) { |
| int DiskCacheBasedSSLHostInfo::DoOpen() { |
| state_ = OPEN_COMPLETE; |
| - return backend_->OpenEntry(key(), &entry_, callback_.get()); |
| + return backend_->OpenEntry(key(), (disk_cache::Entry**) &callback_->user_data, |
| + callback_); |
| } |
| int DiskCacheBasedSSLHostInfo::DoOpenComplete(int rv) { |
| if (rv == OK) { |
| + entry_ = (disk_cache::Entry*) callback_->user_data; |
| state_ = READ; |
| } else { |
| state_ = WAIT_FOR_DATA_READY_DONE; |
| @@ -131,7 +149,7 @@ int DiskCacheBasedSSLHostInfo::DoRead() { |
| read_buffer_ = new IOBuffer(size); |
| state_ = READ_COMPLETE; |
| return entry_->ReadData(0 /* index */, 0 /* offset */, read_buffer_, |
| - size, callback_.get()); |
| + size, callback_); |
| } |
| int DiskCacheBasedSSLHostInfo::DoReadComplete(int rv) { |
| @@ -195,13 +213,15 @@ void DiskCacheBasedSSLHostInfo::Persist() { |
| int DiskCacheBasedSSLHostInfo::DoCreate() { |
| DCHECK(entry_ == NULL); |
| state_ = CREATE_COMPLETE; |
| - return backend_->CreateEntry(key(), &entry_, callback_.get()); |
| + return backend_->CreateEntry( |
| + key(), (disk_cache::Entry**) &callback_->user_data, callback_); |
| } |
| int DiskCacheBasedSSLHostInfo::DoCreateComplete(int rv) { |
| if (rv != OK) { |
| state_ = SET_DONE; |
| } else { |
| + entry_ = (disk_cache::Entry*) callback_->user_data; |
| state_ = WRITE; |
| } |
| return OK; |
| @@ -211,9 +231,9 @@ int DiskCacheBasedSSLHostInfo::DoWrite() { |
| write_buffer_ = new IOBuffer(new_data_.size()); |
| memcpy(write_buffer_->data(), new_data_.data(), new_data_.size()); |
| state_ = WRITE_COMPLETE; |
| + |
| return entry_->WriteData(0 /* index */, 0 /* offset */, write_buffer_, |
| - new_data_.size(), callback_.get(), |
| - true /* truncate */); |
| + new_data_.size(), callback_, true /* truncate */); |
| } |
| int DiskCacheBasedSSLHostInfo::DoWriteComplete(int rv) { |