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

Unified Diff: net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc

Issue 8139028: Add WorkerPool::PostTaskAndReply and use in DHCP code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Mark private 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
« no previous file with comments | « net/proxy/dhcp_proxy_script_fetcher_win.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc
diff --git a/net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc b/net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc
index 8f17456a0026cab1d887e6a7241cdf9c962d2c3e..9c2dc2489aaa12323f5f37e108da58b80443c854 100644
--- a/net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc
+++ b/net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc
@@ -160,23 +160,21 @@ class DelayingDhcpProxyScriptAdapterFetcher
: DhcpProxyScriptAdapterFetcher(url_request_context) {
}
- class DelayingWorkerThread : public WorkerThread {
+ class DelayingDhcpQuery : public DhcpQuery {
public:
- explicit DelayingWorkerThread(
- const base::WeakPtr<DhcpProxyScriptAdapterFetcher>& owner)
- : WorkerThread(owner) {
+ explicit DelayingDhcpQuery()
+ : DhcpQuery() {
}
std::string ImplGetPacURLFromDhcp(
const std::string& adapter_name) OVERRIDE {
base::PlatformThread::Sleep(20);
- return WorkerThread::ImplGetPacURLFromDhcp(adapter_name);
+ return DhcpQuery::ImplGetPacURLFromDhcp(adapter_name);
}
};
- WorkerThread* ImplCreateWorkerThread(
- const base::WeakPtr<DhcpProxyScriptAdapterFetcher>& owner) OVERRIDE {
- return new DelayingWorkerThread(owner);
+ DhcpQuery* ImplCreateDhcpQuery() OVERRIDE {
+ return new DelayingDhcpQuery();
}
};
@@ -268,16 +266,12 @@ class DummyDhcpProxyScriptAdapterFetcher
class MockDhcpProxyScriptFetcherWin : public DhcpProxyScriptFetcherWin {
public:
- class MockWorkerThread : public WorkerThread {
+ class MockAdapterQuery : public AdapterQuery {
public:
- MockWorkerThread() : worker_finished_event_(true, false) {
+ MockAdapterQuery() {
}
- virtual ~MockWorkerThread() {
- }
-
- void Init(const base::WeakPtr<DhcpProxyScriptFetcherWin>& owner) {
- WorkerThread::Init(owner);
+ virtual ~MockAdapterQuery() {
}
virtual bool ImplGetCandidateAdapterNames(
@@ -287,18 +281,13 @@ class MockDhcpProxyScriptFetcherWin : public DhcpProxyScriptFetcherWin {
return true;
}
- virtual void OnThreadDone() OVERRIDE {
- WorkerThread::OnThreadDone();
- worker_finished_event_.Signal();
- }
-
std::vector<std::string> mock_adapter_names_;
- base::WaitableEvent worker_finished_event_;
};
MockDhcpProxyScriptFetcherWin()
: DhcpProxyScriptFetcherWin(new TestURLRequestContext()),
- num_fetchers_created_(0) {
+ num_fetchers_created_(0),
+ worker_finished_event_(true, false) {
ResetTestState();
}
@@ -311,7 +300,7 @@ class MockDhcpProxyScriptFetcherWin : public DhcpProxyScriptFetcherWin {
// returned by ImplGetCandidateAdapterNames.
void PushBackAdapter(const std::string& adapter_name,
DhcpProxyScriptAdapterFetcher* fetcher) {
- worker_thread_->mock_adapter_names_.push_back(adapter_name);
+ adapter_query_->mock_adapter_names_.push_back(adapter_name);
adapter_fetchers_.push_back(fetcher);
}
@@ -331,17 +320,19 @@ class MockDhcpProxyScriptFetcherWin : public DhcpProxyScriptFetcherWin {
return adapter_fetchers_[next_adapter_fetcher_index_++];
}
- virtual WorkerThread* ImplCreateWorkerThread(
- const base::WeakPtr<DhcpProxyScriptFetcherWin>& owner) OVERRIDE {
- DCHECK(worker_thread_);
- worker_thread_->Init(owner);
- return worker_thread_.get();
+ virtual AdapterQuery* ImplCreateAdapterQuery() OVERRIDE {
+ DCHECK(adapter_query_);
+ return adapter_query_.get();
}
int ImplGetMaxWaitMs() OVERRIDE {
return max_wait_ms_;
}
+ void ImplOnGetCandidateAdapterNamesDone() OVERRIDE {
+ worker_finished_event_.Signal();
+ }
+
void ResetTestState() {
// Delete any adapter fetcher objects we didn't hand out.
std::vector<DhcpProxyScriptAdapterFetcher*>::const_iterator it
@@ -355,7 +346,7 @@ class MockDhcpProxyScriptFetcherWin : public DhcpProxyScriptFetcherWin {
next_adapter_fetcher_index_ = 0;
num_fetchers_created_ = 0;
adapter_fetchers_.clear();
- worker_thread_ = new MockWorkerThread();
+ adapter_query_ = new MockAdapterQuery();
max_wait_ms_ = TestTimeouts::tiny_timeout_ms();
}
@@ -370,10 +361,11 @@ class MockDhcpProxyScriptFetcherWin : public DhcpProxyScriptFetcherWin {
// deleted on destruction.
std::vector<DhcpProxyScriptAdapterFetcher*> adapter_fetchers_;
- scoped_refptr<MockWorkerThread> worker_thread_;
+ scoped_refptr<MockAdapterQuery> adapter_query_;
int max_wait_ms_;
int num_fetchers_created_;
+ base::WaitableEvent worker_finished_event_;
};
class FetcherClient {
@@ -398,8 +390,8 @@ public:
}
void RunMessageLoopUntilWorkerDone() {
- DCHECK(fetcher_.worker_thread_.get());
- while (!fetcher_.worker_thread_->worker_finished_event_.TimedWait(
+ DCHECK(fetcher_.adapter_query_.get());
+ while (!fetcher_.worker_finished_event_.TimedWait(
base::TimeDelta::FromMilliseconds(10))) {
MessageLoop::current()->RunAllPending();
}
« no previous file with comments | « net/proxy/dhcp_proxy_script_fetcher_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698