diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-22 05:18:12 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-22 05:18:12 +0000 |
commit | a32f758447553c5d7e1684e2527cd92e3825ebaa (patch) | |
tree | 64da8b6278f6d26ea207809e5cc2dcbfeb072665 | |
parent | 72a3ce556f70637bfa196901c92652d023b96f7f (diff) | |
download | chromium_src-a32f758447553c5d7e1684e2527cd92e3825ebaa.zip chromium_src-a32f758447553c5d7e1684e2527cd92e3825ebaa.tar.gz chromium_src-a32f758447553c5d7e1684e2527cd92e3825ebaa.tar.bz2 |
base::Bind: Finish up net/url_request.
BUG=none
TEST=none
R=csilv
Review URL: http://codereview.chromium.org/9017041
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115487 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | net/url_request/url_request_file_job.cc | 11 | ||||
-rw-r--r-- | net/url_request/view_cache_helper.cc | 15 | ||||
-rw-r--r-- | net/url_request/view_cache_helper.h | 3 |
3 files changed, 12 insertions, 17 deletions
diff --git a/net/url_request/url_request_file_job.cc b/net/url_request/url_request_file_job.cc index db61784..e42a938 100644 --- a/net/url_request/url_request_file_job.cc +++ b/net/url_request/url_request_file_job.cc @@ -53,8 +53,9 @@ class URLRequestFileJob::AsyncResolver bool exists = file_util::GetFileInfo(file_path, &file_info); base::AutoLock locked(lock_); if (owner_loop_) { - owner_loop_->PostTask(FROM_HERE, NewRunnableMethod( - this, &AsyncResolver::ReturnResults, exists, file_info)); + owner_loop_->PostTask( + FROM_HERE, + base::Bind(&AsyncResolver::ReturnResults, this, exists, file_info)); } } @@ -149,8 +150,10 @@ bool URLRequestFileJob::AccessDisabled(const FilePath& file_path) { void URLRequestFileJob::Start() { DCHECK(!async_resolver_); async_resolver_ = new AsyncResolver(this); - base::WorkerPool::PostTask(FROM_HERE, NewRunnableMethod( - async_resolver_.get(), &AsyncResolver::Resolve, file_path_), true); + base::WorkerPool::PostTask( + FROM_HERE, + base::Bind(&AsyncResolver::Resolve, async_resolver_.get(), file_path_), + true); } void URLRequestFileJob::Kill() { diff --git a/net/url_request/view_cache_helper.cc b/net/url_request/view_cache_helper.cc index e5980d9..4dab89d 100644 --- a/net/url_request/view_cache_helper.cc +++ b/net/url_request/view_cache_helper.cc @@ -48,17 +48,12 @@ ViewCacheHelper::ViewCacheHelper() index_(0), data_(NULL), next_state_(STATE_NONE), - ALLOW_THIS_IN_INITIALIZER_LIST( - entry_callback_(new CancelableOldCompletionCallback<ViewCacheHelper>( - this, &ViewCacheHelper::OnIOComplete))) { + ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { } ViewCacheHelper::~ViewCacheHelper() { if (entry_) entry_->Close(); - - // Cancel any pending entry callback. - entry_callback_->Cancel(); } int ViewCacheHelper::GetEntryInfoHTML(const std::string& key, @@ -286,18 +281,16 @@ int ViewCacheHelper::DoOpenEntryComplete(int result) { int ViewCacheHelper::DoReadResponse() { next_state_ = STATE_READ_RESPONSE_COMPLETE; buf_len_ = entry_->GetDataSize(0); - entry_callback_->AddRef(); if (!buf_len_) return buf_len_; buf_ = new IOBuffer(buf_len_); return entry_->ReadData( 0, 0, buf_, buf_len_, - base::Bind(&net::OldCompletionCallbackAdapter, entry_callback_)); + base::Bind(&ViewCacheHelper::OnIOComplete, weak_factory_.GetWeakPtr())); } int ViewCacheHelper::DoReadResponseComplete(int result) { - entry_callback_->Release(); if (result && result == buf_len_) { HttpResponseInfo response; bool truncated; @@ -333,18 +326,16 @@ int ViewCacheHelper::DoReadData() { next_state_ = STATE_READ_DATA_COMPLETE; buf_len_ = entry_->GetDataSize(index_); - entry_callback_->AddRef(); if (!buf_len_) return buf_len_; buf_ = new IOBuffer(buf_len_); return entry_->ReadData( index_, 0, buf_, buf_len_, - base::Bind(&net::OldCompletionCallbackAdapter, entry_callback_)); + base::Bind(&ViewCacheHelper::OnIOComplete, weak_factory_.GetWeakPtr())); } int ViewCacheHelper::DoReadDataComplete(int result) { - entry_callback_->Release(); if (result && result == buf_len_) { HexDump(buf_->data(), buf_len_, data_); } diff --git a/net/url_request/view_cache_helper.h b/net/url_request/view_cache_helper.h index cd9b0f2..2723d332 100644 --- a/net/url_request/view_cache_helper.h +++ b/net/url_request/view_cache_helper.h @@ -8,6 +8,7 @@ #include <string> +#include "base/memory/weak_ptr.h" #include "net/base/completion_callback.h" #include "net/base/io_buffer.h" #include "net/base/net_export.h" @@ -114,7 +115,7 @@ class NET_EXPORT ViewCacheHelper { State next_state_; - scoped_refptr<CancelableOldCompletionCallback<ViewCacheHelper> > entry_callback_; + base::WeakPtrFactory<ViewCacheHelper> weak_factory_; DISALLOW_COPY_AND_ASSIGN(ViewCacheHelper); }; |