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

Unified Diff: net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc

Issue 8139028: Add WorkerPool::PostTaskAndReply and use in DHCP code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressing review comments. Fixing flakiness in reuse test. Created 9 years, 2 months 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 side-by-side diff with in-line comments
Download patch
Index: net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc
diff --git a/net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc b/net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc
index eae0ba4ac12eafb97db07eea77ea5204c8606388..02813d5bf66aa46870d5b4ac7aaf35b142aad921 100644
--- a/net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc
+++ b/net/proxy/dhcp_proxy_script_adapter_fetcher_win.cc
@@ -4,10 +4,10 @@
#include "net/proxy/dhcp_proxy_script_adapter_fetcher_win.h"
+#include "base/bind.h"
#include "base/message_loop_proxy.h"
#include "base/metrics/histogram.h"
#include "base/sys_string_conversions.h"
-#include "base/task.h"
#include "base/threading/worker_pool.h"
#include "base/time.h"
#include "net/base/net_errors.h"
@@ -60,8 +60,18 @@ void DhcpProxyScriptAdapterFetcher::Fetch(
wait_timer_.Start(FROM_HERE, ImplGetTimeout(),
this, &DhcpProxyScriptAdapterFetcher::OnTimeout);
- worker_thread_ = ImplCreateWorkerThread(AsWeakPtr());
- worker_thread_->Start(adapter_name);
+ scoped_refptr<DhcpQuery> dhcp_query(ImplCreateDhcpQuery());
awong 2011/10/07 17:53:22 I wonder if it would be possible to not bother wit
Jói 2011/10/11 19:51:02 I think if this way works, it seems more correct?
+ base::WorkerPool::PostTaskAndReply(
+ FROM_HERE,
+ base::Bind(
+ &DhcpProxyScriptAdapterFetcher::DhcpQuery::GetPacURLForAdapter,
+ dhcp_query.get(),
awong 2011/10/07 17:53:22 FYI, You no longer need the .get(). Submitted CL
Jói 2011/10/11 19:51:02 Done.
+ adapter_name),
+ base::Bind(
+ &DhcpProxyScriptAdapterFetcher::OnDhcpQueryDone,
+ AsWeakPtr(),
+ dhcp_query),
+ true);
}
void DhcpProxyScriptAdapterFetcher::Cancel() {
@@ -109,55 +119,29 @@ GURL DhcpProxyScriptAdapterFetcher::GetPacURL() const {
return pac_url_;
}
-DhcpProxyScriptAdapterFetcher::WorkerThread::WorkerThread(
- const base::WeakPtr<DhcpProxyScriptAdapterFetcher>& owner)
- : owner_(owner),
- origin_loop_(base::MessageLoopProxy::current()) {
+DhcpProxyScriptAdapterFetcher::DhcpQuery::DhcpQuery() {
}
-DhcpProxyScriptAdapterFetcher::WorkerThread::~WorkerThread() {
+DhcpProxyScriptAdapterFetcher::DhcpQuery::~DhcpQuery() {
}
-void DhcpProxyScriptAdapterFetcher::WorkerThread::Start(
+void DhcpProxyScriptAdapterFetcher::DhcpQuery::GetPacURLForAdapter(
const std::string& adapter_name) {
- bool succeeded = base::WorkerPool::PostTask(
- FROM_HERE,
- NewRunnableMethod(
- this,
- &DhcpProxyScriptAdapterFetcher::WorkerThread::ThreadFunc,
- adapter_name),
- true);
- DCHECK(succeeded);
-}
-
-void DhcpProxyScriptAdapterFetcher::WorkerThread::ThreadFunc(
- const std::string& adapter_name) {
- std::string url = ImplGetPacURLFromDhcp(adapter_name);
-
- bool succeeded = origin_loop_->PostTask(
- FROM_HERE,
- NewRunnableMethod(
- this,
- &DhcpProxyScriptAdapterFetcher::WorkerThread::OnThreadDone,
- url));
- DCHECK(succeeded);
+ url_ = ImplGetPacURLFromDhcp(adapter_name);
}
-void DhcpProxyScriptAdapterFetcher::WorkerThread::OnThreadDone(
- const std::string& url) {
- DCHECK(thread_checker_.CalledOnValidThread());
- if (owner_)
- owner_->OnQueryDhcpDone(url);
+std::string DhcpProxyScriptAdapterFetcher::DhcpQuery::url() const {
+ return url_;
}
std::string
- DhcpProxyScriptAdapterFetcher::WorkerThread::ImplGetPacURLFromDhcp(
+ DhcpProxyScriptAdapterFetcher::DhcpQuery::ImplGetPacURLFromDhcp(
const std::string& adapter_name) {
return DhcpProxyScriptAdapterFetcher::GetPacURLFromDhcp(adapter_name);
}
-void DhcpProxyScriptAdapterFetcher::OnQueryDhcpDone(
- const std::string& url) {
+void DhcpProxyScriptAdapterFetcher::OnDhcpQueryDone(
+ scoped_refptr<DhcpQuery> dhcp_query) {
DCHECK(CalledOnValidThread());
// Because we can't cancel the call to the Win32 API, we can expect
// it to finish while we are in a few different states. The expected
@@ -170,7 +154,7 @@ void DhcpProxyScriptAdapterFetcher::OnQueryDhcpDone(
wait_timer_.Stop();
- pac_url_ = GURL(url);
+ pac_url_ = GURL(dhcp_query->url());
if (pac_url_.is_empty() || !pac_url_.is_valid()) {
result_ = ERR_PAC_NOT_IN_DHCP;
TransitionToFinish();
@@ -219,10 +203,9 @@ ProxyScriptFetcher* DhcpProxyScriptAdapterFetcher::ImplCreateScriptFetcher() {
return new ProxyScriptFetcherImpl(url_request_context_);
}
-DhcpProxyScriptAdapterFetcher::WorkerThread*
- DhcpProxyScriptAdapterFetcher::ImplCreateWorkerThread(
- const base::WeakPtr<DhcpProxyScriptAdapterFetcher>& owner) {
- return new WorkerThread(owner);
+DhcpProxyScriptAdapterFetcher::DhcpQuery*
+ DhcpProxyScriptAdapterFetcher::ImplCreateDhcpQuery() {
+ return new DhcpQuery();
}
base::TimeDelta DhcpProxyScriptAdapterFetcher::ImplGetTimeout() const {

Powered by Google App Engine
This is Rietveld 408576698