| Index: net/proxy/proxy_script_fetcher_impl.cc
|
| diff --git a/net/proxy/proxy_script_fetcher_impl.cc b/net/proxy/proxy_script_fetcher_impl.cc
|
| index 321f0f0ae13a1f9d33012c393b7816d070a8f1ec..8bd88584e837956ac0240e2d2a62fab95238172e 100644
|
| --- a/net/proxy/proxy_script_fetcher_impl.cc
|
| +++ b/net/proxy/proxy_script_fetcher_impl.cc
|
| @@ -73,13 +73,12 @@ void ConvertResponseToUTF16(const std::string& charset,
|
|
|
| ProxyScriptFetcherImpl::ProxyScriptFetcherImpl(
|
| URLRequestContext* url_request_context)
|
| - : ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)),
|
| + : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
|
| url_request_context_(url_request_context),
|
| buf_(new IOBuffer(kBufSize)),
|
| next_id_(0),
|
| cur_request_(NULL),
|
| cur_request_id_(0),
|
| - callback_(NULL),
|
| result_code_(OK),
|
| result_text_(NULL),
|
| max_response_bytes_(kDefaultMaxResponseBytes),
|
| @@ -116,13 +115,11 @@ void ProxyScriptFetcherImpl::OnResponseCompleted(URLRequest* request) {
|
| FetchCompleted();
|
| }
|
|
|
| -int ProxyScriptFetcherImpl::Fetch(const GURL& url,
|
| - string16* text,
|
| - OldCompletionCallback* callback) {
|
| +int ProxyScriptFetcherImpl::Fetch(
|
| + const GURL& url, string16* text, const CompletionCallback& callback) {
|
| // It is invalid to call Fetch() while a request is already in progress.
|
| DCHECK(!cur_request_.get());
|
| -
|
| - DCHECK(callback);
|
| + DCHECK(!callback.is_null());
|
| DCHECK(text);
|
|
|
| // Handle base-64 encoded data-urls that contain custom PAC scripts.
|
| @@ -161,9 +158,10 @@ int ProxyScriptFetcherImpl::Fetch(const GURL& url,
|
|
|
| // Post a task to timeout this request if it takes too long.
|
| cur_request_id_ = ++next_id_;
|
| - MessageLoop::current()->PostDelayedTask(FROM_HERE,
|
| - task_factory_.NewRunnableMethod(&ProxyScriptFetcherImpl::OnTimeout,
|
| - cur_request_id_),
|
| + MessageLoop::current()->PostDelayedTask(
|
| + FROM_HERE,
|
| + base::Bind(&ProxyScriptFetcherImpl::OnTimeout, weak_factory_.GetWeakPtr(),
|
| + cur_request_id_),
|
| static_cast<int>(max_duration_.InMilliseconds()));
|
|
|
| // Start the request.
|
| @@ -295,20 +293,20 @@ void ProxyScriptFetcherImpl::FetchCompleted() {
|
| }
|
|
|
| int result_code = result_code_;
|
| - OldCompletionCallback* callback = callback_;
|
| + CompletionCallback callback = callback_;
|
|
|
| // Hold a reference to the URLRequestContext to prevent re-entrancy from
|
| // ~URLRequestContext.
|
| scoped_refptr<const URLRequestContext> context(cur_request_->context());
|
| ResetCurRequestState();
|
|
|
| - callback->Run(result_code);
|
| + callback.Run(result_code);
|
| }
|
|
|
| void ProxyScriptFetcherImpl::ResetCurRequestState() {
|
| cur_request_.reset();
|
| cur_request_id_ = 0;
|
| - callback_ = NULL;
|
| + callback_.Reset();
|
| result_code_ = OK;
|
| result_text_ = NULL;
|
| }
|
|
|