Skip to content

Commit

Permalink
base::Bind: Convert net/proxy.
Browse files Browse the repository at this point in the history
BUG=none
TEST=none
R=csilv

Review URL: http://codereview.chromium.org/8985012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115068 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jhawkins@chromium.org committed Dec 20, 2011
1 parent 05769e3 commit 2357868
Show file tree
Hide file tree
Showing 45 changed files with 600 additions and 664 deletions.
15 changes: 8 additions & 7 deletions content/browser/resolve_proxy_msg_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "content/browser/resolve_proxy_msg_helper.h"

#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/compiler_specific.h"
#include "content/common/view_messages.h"
#include "net/base/net_errors.h"
Expand All @@ -12,16 +14,12 @@

ResolveProxyMsgHelper::ResolveProxyMsgHelper(
net::URLRequestContextGetter* getter)
: ALLOW_THIS_IN_INITIALIZER_LIST(callback_(
this, &ResolveProxyMsgHelper::OnResolveProxyCompleted)),
context_getter_(getter),
: context_getter_(getter),
proxy_service_(NULL) {
}

ResolveProxyMsgHelper::ResolveProxyMsgHelper(net::ProxyService* proxy_service)
: ALLOW_THIS_IN_INITIALIZER_LIST(callback_(
this, &ResolveProxyMsgHelper::OnResolveProxyCompleted)),
proxy_service_(proxy_service) {
: proxy_service_(proxy_service) {
}

bool ResolveProxyMsgHelper::OnMessageReceived(const IPC::Message& message,
Expand Down Expand Up @@ -73,7 +71,10 @@ void ResolveProxyMsgHelper::StartPendingRequest() {

// Start the request.
int result = proxy_service_->ResolveProxy(
req.url, &proxy_info_, &callback_, &req.pac_req, net::BoundNetLog());
req.url, &proxy_info_,
base::Bind(&ResolveProxyMsgHelper::OnResolveProxyCompleted,
base::Unretained(this)),
&req.pac_req, net::BoundNetLog());

// Completed synchronously.
if (result != net::ERR_IO_PENDING)
Expand Down
3 changes: 1 addition & 2 deletions content/browser/resolve_proxy_msg_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ class CONTENT_EXPORT ResolveProxyMsgHelper
net::ProxyService::PacRequest* pac_req;
};

// Members for the current outstanding proxy request.
net::OldCompletionCallbackImpl<ResolveProxyMsgHelper> callback_;
// Info about the current outstanding proxy request.
net::ProxyInfo proxy_info_;

// FIFO queue of pending requests. The first entry is always the current one.
Expand Down
4 changes: 2 additions & 2 deletions net/http/http_network_transaction_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7075,7 +7075,7 @@ class CapturingProxyResolver : public ProxyResolver {

virtual int GetProxyForURL(const GURL& url,
ProxyInfo* results,
OldCompletionCallback* callback,
const CompletionCallback& callback,
RequestHandle* request,
const BoundNetLog& net_log) {
ProxyServer proxy_server(ProxyServer::SCHEME_HTTP,
Expand Down Expand Up @@ -7105,7 +7105,7 @@ class CapturingProxyResolver : public ProxyResolver {
}

virtual int SetPacScript(const scoped_refptr<ProxyResolverScriptData>&,
OldCompletionCallback* /*callback*/) {
const CompletionCallback& /*callback*/) {
return OK;
}

Expand Down
20 changes: 10 additions & 10 deletions net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "net/proxy/dhcp_proxy_script_adapter_fetcher_win.h"

#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/message_loop_proxy.h"
#include "base/metrics/histogram.h"
#include "base/sys_string_conversions.h"
Expand Down Expand Up @@ -33,10 +34,6 @@ DhcpProxyScriptAdapterFetcher::DhcpProxyScriptAdapterFetcher(
URLRequestContext* url_request_context)
: state_(STATE_START),
result_(ERR_IO_PENDING),
callback_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST(
script_fetcher_callback_(
this, &DhcpProxyScriptAdapterFetcher::OnFetcherDone)),
url_request_context_(url_request_context) {
}

Expand All @@ -50,7 +47,7 @@ DhcpProxyScriptAdapterFetcher::~DhcpProxyScriptAdapterFetcher() {
}

void DhcpProxyScriptAdapterFetcher::Fetch(
const std::string& adapter_name, OldCompletionCallback* callback) {
const std::string& adapter_name, const CompletionCallback& callback) {
DCHECK(CalledOnValidThread());
DCHECK_EQ(state_, STATE_START);
result_ = ERR_IO_PENDING;
Expand All @@ -76,7 +73,7 @@ void DhcpProxyScriptAdapterFetcher::Fetch(

void DhcpProxyScriptAdapterFetcher::Cancel() {
DCHECK(CalledOnValidThread());
callback_ = NULL;
callback_.Reset();
wait_timer_.Stop();
script_fetcher_.reset();

Expand Down Expand Up @@ -161,7 +158,10 @@ void DhcpProxyScriptAdapterFetcher::OnDhcpQueryDone(
} else {
state_ = STATE_WAIT_URL;
script_fetcher_.reset(ImplCreateScriptFetcher());
script_fetcher_->Fetch(pac_url_, &pac_script_, &script_fetcher_callback_);
script_fetcher_->Fetch(
pac_url_, &pac_script_,
base::Bind(&DhcpProxyScriptAdapterFetcher::OnFetcherDone,
base::Unretained(this)));
}
}

Expand All @@ -186,12 +186,12 @@ void DhcpProxyScriptAdapterFetcher::OnFetcherDone(int result) {
void DhcpProxyScriptAdapterFetcher::TransitionToFinish() {
DCHECK(state_ == STATE_WAIT_DHCP || state_ == STATE_WAIT_URL);
state_ = STATE_FINISH;
OldCompletionCallback* callback = callback_;
callback_ = NULL;
CompletionCallback callback = callback_;
callback_.Reset();

// Be careful not to touch any member state after this, as the client
// may delete us during this callback.
callback->Run(result_);
callback.Run(result_);
}

DhcpProxyScriptAdapterFetcher::State
Expand Down
8 changes: 2 additions & 6 deletions net/proxy/dhcp_proxy_script_adapter_fetcher_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class NET_EXPORT_PRIVATE DhcpProxyScriptAdapterFetcher
// You may only call Fetch() once on a given instance of
// DhcpProxyScriptAdapterFetcher.
virtual void Fetch(const std::string& adapter_name,
OldCompletionCallback* callback);
const net::CompletionCallback& callback);

// Cancels the fetch on this adapter.
virtual void Cancel();
Expand Down Expand Up @@ -159,15 +159,11 @@ class NET_EXPORT_PRIVATE DhcpProxyScriptAdapterFetcher

// Callback to let our client know we're done. Invalid in states
// START, FINISH and CANCEL.
OldCompletionCallback* callback_;
net::CompletionCallback callback_;

// Fetcher to retrieve PAC files once URL is known.
scoped_ptr<ProxyScriptFetcher> script_fetcher_;

// Callback from the script fetcher.
OldCompletionCallbackImpl<DhcpProxyScriptAdapterFetcher>
script_fetcher_callback_;

// Implements a timeout on the call to the Win32 DHCP API.
base::OneShotTimer<DhcpProxyScriptAdapterFetcher> wait_timer_;

Expand Down
4 changes: 2 additions & 2 deletions net/proxy/dhcp_proxy_script_adapter_fetcher_win_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ class FetcherClient {
}

void RunTest() {
fetcher_->Fetch("adapter name", &callback_);
fetcher_->Fetch("adapter name", callback_.callback());
}

void FinishTestAllowCleanup() {
fetcher_->FinishTest();
MessageLoop::current()->RunAllPending();
}

TestOldCompletionCallback callback_;
TestCompletionCallback callback_;
scoped_refptr<URLRequestContext> url_request_context_;
scoped_ptr<MockDhcpProxyScriptAdapterFetcher> fetcher_;
string16 pac_text_;
Expand Down
4 changes: 2 additions & 2 deletions net/proxy/dhcp_proxy_script_fetcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ DoNothingDhcpProxyScriptFetcher::DoNothingDhcpProxyScriptFetcher() {
DoNothingDhcpProxyScriptFetcher::~DoNothingDhcpProxyScriptFetcher() {
}

int DoNothingDhcpProxyScriptFetcher::Fetch(string16* utf16_text,
OldCompletionCallback* callback) {
int DoNothingDhcpProxyScriptFetcher::Fetch(
string16* utf16_text, const CompletionCallback& callback) {
return ERR_NOT_IMPLEMENTED;
}

Expand Down
4 changes: 2 additions & 2 deletions net/proxy/dhcp_proxy_script_fetcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class NET_EXPORT_PRIVATE DhcpProxyScriptFetcher {
//
// Only one fetch is allowed to be outstanding at a time.
virtual int Fetch(string16* utf16_text,
OldCompletionCallback* callback) = 0;
const CompletionCallback& callback) = 0;

// Aborts the in-progress fetch (if any).
virtual void Cancel() = 0;
Expand Down Expand Up @@ -87,7 +87,7 @@ class NET_EXPORT_PRIVATE DoNothingDhcpProxyScriptFetcher
virtual ~DoNothingDhcpProxyScriptFetcher();

virtual int Fetch(string16* utf16_text,
OldCompletionCallback* callback) OVERRIDE;
const CompletionCallback& callback) OVERRIDE;
virtual void Cancel() OVERRIDE;
virtual const GURL& GetPacURL() const OVERRIDE;
private:
Expand Down
19 changes: 10 additions & 9 deletions net/proxy/dhcp_proxy_script_fetcher_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "net/proxy/dhcp_proxy_script_fetcher_win.h"

#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/metrics/histogram.h"
#include "base/perftimer.h"
#include "base/threading/worker_pool.h"
Expand Down Expand Up @@ -37,8 +38,6 @@ namespace net {
DhcpProxyScriptFetcherWin::DhcpProxyScriptFetcherWin(
URLRequestContext* url_request_context)
: state_(STATE_START),
ALLOW_THIS_IN_INITIALIZER_LIST(fetcher_callback_(
this, &DhcpProxyScriptFetcherWin::OnFetcherDone)),
num_pending_fetchers_(0),
url_request_context_(url_request_context) {
DCHECK(url_request_context_);
Expand All @@ -55,7 +54,7 @@ DhcpProxyScriptFetcherWin::~DhcpProxyScriptFetcherWin() {
}

int DhcpProxyScriptFetcherWin::Fetch(string16* utf16_text,
OldCompletionCallback* callback) {
const CompletionCallback& callback) {
DCHECK(CalledOnValidThread());
if (state_ != STATE_START && state_ != STATE_DONE) {
NOTREACHED();
Expand All @@ -65,7 +64,7 @@ int DhcpProxyScriptFetcherWin::Fetch(string16* utf16_text,
fetch_start_time_ = base::TimeTicks::Now();

state_ = STATE_WAIT_ADAPTERS;
client_callback_ = callback;
callback_ = callback;
destination_string_ = utf16_text;

last_query_ = ImplCreateAdapterQuery();
Expand Down Expand Up @@ -100,7 +99,7 @@ void DhcpProxyScriptFetcherWin::CancelImpl() {
DCHECK(CalledOnValidThread());

if (state_ != STATE_DONE) {
client_callback_ = NULL;
callback_.Reset();
wait_timer_.Stop();
state_ = STATE_DONE;

Expand Down Expand Up @@ -145,7 +144,9 @@ void DhcpProxyScriptFetcherWin::OnGetCandidateAdapterNamesDone(
it != adapter_names.end();
++it) {
DhcpProxyScriptAdapterFetcher* fetcher(ImplCreateAdapterFetcher());
fetcher->Fetch(*it, &fetcher_callback_);
fetcher->Fetch(
*it, base::Bind(&DhcpProxyScriptFetcherWin::OnFetcherDone,
base::Unretained(this)));
fetchers_.push_back(fetcher);
}
num_pending_fetchers_ = fetchers_.size();
Expand Down Expand Up @@ -245,11 +246,11 @@ void DhcpProxyScriptFetcherWin::TransitionToDone() {
}
}

OldCompletionCallback* callback = client_callback_;
CompletionCallback callback = callback_;
CancelImpl();
DCHECK_EQ(state_, STATE_DONE);
DCHECK(fetchers_.empty());
DCHECK(!client_callback_); // Invariant of data.
DCHECK(callback_.is_null()); // Invariant of data.

UMA_HISTOGRAM_TIMES("Net.DhcpWpadCompletionTime",
base::TimeTicks::Now() - fetch_start_time_);
Expand All @@ -260,7 +261,7 @@ void DhcpProxyScriptFetcherWin::TransitionToDone() {
}

// We may be deleted re-entrantly within this outcall.
callback->Run(result);
callback.Run(result);
}

int DhcpProxyScriptFetcherWin::num_pending_fetchers() const {
Expand Down
8 changes: 3 additions & 5 deletions net/proxy/dhcp_proxy_script_fetcher_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class NET_EXPORT_PRIVATE DhcpProxyScriptFetcherWin
virtual ~DhcpProxyScriptFetcherWin();

// DhcpProxyScriptFetcher implementation.
int Fetch(string16* utf16_text, OldCompletionCallback* callback) OVERRIDE;
int Fetch(string16* utf16_text,
const net::CompletionCallback& callback) OVERRIDE;
void Cancel() OVERRIDE;
const GURL& GetPacURL() const OVERRIDE;
std::string GetFetcherName() const OVERRIDE;
Expand Down Expand Up @@ -138,14 +139,11 @@ class NET_EXPORT_PRIVATE DhcpProxyScriptFetcherWin
typedef ScopedVector<DhcpProxyScriptAdapterFetcher> FetcherVector;
FetcherVector fetchers_;

// Callback invoked when any fetcher completes.
OldCompletionCallbackImpl<DhcpProxyScriptFetcherWin> fetcher_callback_;

// Number of fetchers we are waiting for.
int num_pending_fetchers_;

// Lets our client know we're done. Not valid in states START or DONE.
OldCompletionCallback* client_callback_;
net::CompletionCallback callback_;

// Pointer to string we will write results to. Not valid in states
// START and DONE.
Expand Down
Loading

0 comments on commit 2357868

Please sign in to comment.