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

Side by Side Diff: net/proxy/dhcp_proxy_script_fetcher_win.cc

Issue 8985012: base::Bind: Convert net/proxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: One more include. Created 9 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/proxy/dhcp_proxy_script_fetcher_win.h" 5 #include "net/proxy/dhcp_proxy_script_fetcher_win.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
8 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
9 #include "base/perftimer.h" 10 #include "base/perftimer.h"
10 #include "base/threading/worker_pool.h" 11 #include "base/threading/worker_pool.h"
11 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
12 #include "net/proxy/dhcp_proxy_script_adapter_fetcher_win.h" 13 #include "net/proxy/dhcp_proxy_script_adapter_fetcher_win.h"
13 14
14 #include <winsock2.h> 15 #include <winsock2.h>
15 #include <iphlpapi.h> 16 #include <iphlpapi.h>
16 #pragma comment(lib, "iphlpapi.lib") 17 #pragma comment(lib, "iphlpapi.lib")
17 18
(...skipping 12 matching lines...) Expand all
30 ERROR_NO_DATA, 31 ERROR_NO_DATA,
31 }; 32 };
32 33
33 } // namespace 34 } // namespace
34 35
35 namespace net { 36 namespace net {
36 37
37 DhcpProxyScriptFetcherWin::DhcpProxyScriptFetcherWin( 38 DhcpProxyScriptFetcherWin::DhcpProxyScriptFetcherWin(
38 URLRequestContext* url_request_context) 39 URLRequestContext* url_request_context)
39 : state_(STATE_START), 40 : state_(STATE_START),
40 ALLOW_THIS_IN_INITIALIZER_LIST(fetcher_callback_(
41 this, &DhcpProxyScriptFetcherWin::OnFetcherDone)),
42 num_pending_fetchers_(0), 41 num_pending_fetchers_(0),
43 url_request_context_(url_request_context) { 42 url_request_context_(url_request_context) {
44 DCHECK(url_request_context_); 43 DCHECK(url_request_context_);
45 } 44 }
46 45
47 DhcpProxyScriptFetcherWin::~DhcpProxyScriptFetcherWin() { 46 DhcpProxyScriptFetcherWin::~DhcpProxyScriptFetcherWin() {
48 // Count as user-initiated if we are not yet in STATE_DONE. 47 // Count as user-initiated if we are not yet in STATE_DONE.
49 Cancel(); 48 Cancel();
50 49
51 // The WeakPtr we passed to the worker thread may be destroyed on the 50 // The WeakPtr we passed to the worker thread may be destroyed on the
52 // worker thread. This detaches any outstanding WeakPtr state from 51 // worker thread. This detaches any outstanding WeakPtr state from
53 // the current thread. 52 // the current thread.
54 base::SupportsWeakPtr<DhcpProxyScriptFetcherWin>::DetachFromThread(); 53 base::SupportsWeakPtr<DhcpProxyScriptFetcherWin>::DetachFromThread();
55 } 54 }
56 55
57 int DhcpProxyScriptFetcherWin::Fetch(string16* utf16_text, 56 int DhcpProxyScriptFetcherWin::Fetch(string16* utf16_text,
58 OldCompletionCallback* callback) { 57 const CompletionCallback& callback) {
59 DCHECK(CalledOnValidThread()); 58 DCHECK(CalledOnValidThread());
60 if (state_ != STATE_START && state_ != STATE_DONE) { 59 if (state_ != STATE_START && state_ != STATE_DONE) {
61 NOTREACHED(); 60 NOTREACHED();
62 return ERR_UNEXPECTED; 61 return ERR_UNEXPECTED;
63 } 62 }
64 63
65 fetch_start_time_ = base::TimeTicks::Now(); 64 fetch_start_time_ = base::TimeTicks::Now();
66 65
67 state_ = STATE_WAIT_ADAPTERS; 66 state_ = STATE_WAIT_ADAPTERS;
68 client_callback_ = callback; 67 callback_ = callback;
69 destination_string_ = utf16_text; 68 destination_string_ = utf16_text;
70 69
71 last_query_ = ImplCreateAdapterQuery(); 70 last_query_ = ImplCreateAdapterQuery();
72 base::WorkerPool::PostTaskAndReply( 71 base::WorkerPool::PostTaskAndReply(
73 FROM_HERE, 72 FROM_HERE,
74 base::Bind( 73 base::Bind(
75 &DhcpProxyScriptFetcherWin::AdapterQuery::GetCandidateAdapterNames, 74 &DhcpProxyScriptFetcherWin::AdapterQuery::GetCandidateAdapterNames,
76 last_query_.get()), 75 last_query_.get()),
77 base::Bind( 76 base::Bind(
78 &DhcpProxyScriptFetcherWin::OnGetCandidateAdapterNamesDone, 77 &DhcpProxyScriptFetcherWin::OnGetCandidateAdapterNamesDone,
(...skipping 14 matching lines...) Expand all
93 base::TimeTicks::Now() - fetch_start_time_); 92 base::TimeTicks::Now() - fetch_start_time_);
94 } 93 }
95 94
96 CancelImpl(); 95 CancelImpl();
97 } 96 }
98 97
99 void DhcpProxyScriptFetcherWin::CancelImpl() { 98 void DhcpProxyScriptFetcherWin::CancelImpl() {
100 DCHECK(CalledOnValidThread()); 99 DCHECK(CalledOnValidThread());
101 100
102 if (state_ != STATE_DONE) { 101 if (state_ != STATE_DONE) {
103 client_callback_ = NULL; 102 callback_.Reset();
104 wait_timer_.Stop(); 103 wait_timer_.Stop();
105 state_ = STATE_DONE; 104 state_ = STATE_DONE;
106 105
107 for (FetcherVector::iterator it = fetchers_.begin(); 106 for (FetcherVector::iterator it = fetchers_.begin();
108 it != fetchers_.end(); 107 it != fetchers_.end();
109 ++it) { 108 ++it) {
110 (*it)->Cancel(); 109 (*it)->Cancel();
111 } 110 }
112 111
113 fetchers_.reset(); 112 fetchers_.reset();
(...skipping 24 matching lines...) Expand all
138 137
139 if (adapter_names.empty()) { 138 if (adapter_names.empty()) {
140 TransitionToDone(); 139 TransitionToDone();
141 return; 140 return;
142 } 141 }
143 142
144 for (std::set<std::string>::const_iterator it = adapter_names.begin(); 143 for (std::set<std::string>::const_iterator it = adapter_names.begin();
145 it != adapter_names.end(); 144 it != adapter_names.end();
146 ++it) { 145 ++it) {
147 DhcpProxyScriptAdapterFetcher* fetcher(ImplCreateAdapterFetcher()); 146 DhcpProxyScriptAdapterFetcher* fetcher(ImplCreateAdapterFetcher());
148 fetcher->Fetch(*it, &fetcher_callback_); 147 fetcher->Fetch(
148 *it, base::Bind(&DhcpProxyScriptFetcherWin::OnFetcherDone,
149 base::Unretained(this)));
149 fetchers_.push_back(fetcher); 150 fetchers_.push_back(fetcher);
150 } 151 }
151 num_pending_fetchers_ = fetchers_.size(); 152 num_pending_fetchers_ = fetchers_.size();
152 } 153 }
153 154
154 std::string DhcpProxyScriptFetcherWin::GetFetcherName() const { 155 std::string DhcpProxyScriptFetcherWin::GetFetcherName() const {
155 DCHECK(CalledOnValidThread()); 156 DCHECK(CalledOnValidThread());
156 return "win"; 157 return "win";
157 } 158 }
158 159
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 if ((*it)->DidFinish()) { 239 if ((*it)->DidFinish()) {
239 result = (*it)->GetResult(); 240 result = (*it)->GetResult();
240 if (result != ERR_PAC_NOT_IN_DHCP) { 241 if (result != ERR_PAC_NOT_IN_DHCP) {
241 break; 242 break;
242 } 243 }
243 } 244 }
244 } 245 }
245 } 246 }
246 } 247 }
247 248
248 OldCompletionCallback* callback = client_callback_; 249 CompletionCallback callback = callback_;
249 CancelImpl(); 250 CancelImpl();
250 DCHECK_EQ(state_, STATE_DONE); 251 DCHECK_EQ(state_, STATE_DONE);
251 DCHECK(fetchers_.empty()); 252 DCHECK(fetchers_.empty());
252 DCHECK(!client_callback_); // Invariant of data. 253 DCHECK(callback_.is_null()); // Invariant of data.
253 254
254 UMA_HISTOGRAM_TIMES("Net.DhcpWpadCompletionTime", 255 UMA_HISTOGRAM_TIMES("Net.DhcpWpadCompletionTime",
255 base::TimeTicks::Now() - fetch_start_time_); 256 base::TimeTicks::Now() - fetch_start_time_);
256 257
257 if (result != OK) { 258 if (result != OK) {
258 UMA_HISTOGRAM_CUSTOM_ENUMERATION( 259 UMA_HISTOGRAM_CUSTOM_ENUMERATION(
259 "Net.DhcpWpadFetchError", std::abs(result), GetAllErrorCodesForUma()); 260 "Net.DhcpWpadFetchError", std::abs(result), GetAllErrorCodesForUma());
260 } 261 }
261 262
262 // We may be deleted re-entrantly within this outcall. 263 // We may be deleted re-entrantly within this outcall.
263 callback->Run(result); 264 callback.Run(result);
264 } 265 }
265 266
266 int DhcpProxyScriptFetcherWin::num_pending_fetchers() const { 267 int DhcpProxyScriptFetcherWin::num_pending_fetchers() const {
267 return num_pending_fetchers_; 268 return num_pending_fetchers_;
268 } 269 }
269 270
270 URLRequestContext* DhcpProxyScriptFetcherWin::url_request_context() const { 271 URLRequestContext* DhcpProxyScriptFetcherWin::url_request_context() const {
271 return url_request_context_; 272 return url_request_context_;
272 } 273 }
273 274
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 DhcpProxyScriptFetcherWin::AdapterQuery::adapter_names() const { 366 DhcpProxyScriptFetcherWin::AdapterQuery::adapter_names() const {
366 return adapter_names_; 367 return adapter_names_;
367 } 368 }
368 369
369 bool DhcpProxyScriptFetcherWin::AdapterQuery::ImplGetCandidateAdapterNames( 370 bool DhcpProxyScriptFetcherWin::AdapterQuery::ImplGetCandidateAdapterNames(
370 std::set<std::string>* adapter_names) { 371 std::set<std::string>* adapter_names) {
371 return DhcpProxyScriptFetcherWin::GetCandidateAdapterNames(adapter_names); 372 return DhcpProxyScriptFetcherWin::GetCandidateAdapterNames(adapter_names);
372 } 373 }
373 374
374 } // namespace net 375 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/dhcp_proxy_script_fetcher_win.h ('k') | net/proxy/dhcp_proxy_script_fetcher_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698