OLD | NEW |
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_adapter_fetcher_win.h" | 5 #include "net/proxy/dhcp_proxy_script_adapter_fetcher_win.h" |
6 | 6 |
7 #include "base/message_loop_proxy.h" | 7 #include "base/message_loop_proxy.h" |
| 8 #include "base/metrics/histogram.h" |
8 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
9 #include "base/task.h" | 10 #include "base/task.h" |
10 #include "base/threading/worker_pool.h" | 11 #include "base/threading/worker_pool.h" |
11 #include "base/time.h" | 12 #include "base/time.h" |
12 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
13 #include "net/proxy/dhcpcsvc_init_win.h" | 14 #include "net/proxy/dhcpcsvc_init_win.h" |
14 #include "net/proxy/proxy_script_fetcher_impl.h" | 15 #include "net/proxy/proxy_script_fetcher_impl.h" |
15 #include "net/url_request/url_request_context.h" | 16 #include "net/url_request/url_request_context.h" |
16 | 17 |
17 #include <windows.h> | 18 #include <windows.h> |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 | 195 |
195 // At this point, pac_script_ has already been written to. | 196 // At this point, pac_script_ has already been written to. |
196 script_fetcher_.reset(); | 197 script_fetcher_.reset(); |
197 result_ = result; | 198 result_ = result; |
198 TransitionToFinish(); | 199 TransitionToFinish(); |
199 } | 200 } |
200 | 201 |
201 void DhcpProxyScriptAdapterFetcher::TransitionToFinish() { | 202 void DhcpProxyScriptAdapterFetcher::TransitionToFinish() { |
202 DCHECK(state_ == STATE_WAIT_DHCP || state_ == STATE_WAIT_URL); | 203 DCHECK(state_ == STATE_WAIT_DHCP || state_ == STATE_WAIT_URL); |
203 state_ = STATE_FINISH; | 204 state_ = STATE_FINISH; |
204 callback_->Run(result_); | 205 CompletionCallback* callback = callback_; |
205 callback_ = NULL; | 206 callback_ = NULL; |
| 207 |
| 208 // Be careful not to touch any member state after this, as the client |
| 209 // may delete us during this callback. |
| 210 callback->Run(result_); |
206 } | 211 } |
207 | 212 |
208 ProxyScriptFetcher* DhcpProxyScriptAdapterFetcher::ImplCreateScriptFetcher() { | 213 ProxyScriptFetcher* DhcpProxyScriptAdapterFetcher::ImplCreateScriptFetcher() { |
209 return new ProxyScriptFetcherImpl(url_request_context_); | 214 return new ProxyScriptFetcherImpl(url_request_context_); |
210 } | 215 } |
211 | 216 |
212 DhcpProxyScriptAdapterFetcher::WorkerThread* | 217 DhcpProxyScriptAdapterFetcher::WorkerThread* |
213 DhcpProxyScriptAdapterFetcher::ImplCreateWorkerThread( | 218 DhcpProxyScriptAdapterFetcher::ImplCreateWorkerThread( |
214 const base::WeakPtr<DhcpProxyScriptAdapterFetcher>& owner) { | 219 const base::WeakPtr<DhcpProxyScriptAdapterFetcher>& owner) { |
215 return new WorkerThread(owner); | 220 return new WorkerThread(owner); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 NULL, | 267 NULL, |
263 const_cast<LPWSTR>(adapter_name_wide.c_str()), | 268 const_cast<LPWSTR>(adapter_name_wide.c_str()), |
264 NULL, | 269 NULL, |
265 send_params, request_params, | 270 send_params, request_params, |
266 result_buffer.get(), &result_buffer_size, | 271 result_buffer.get(), &result_buffer_size, |
267 NULL); | 272 NULL); |
268 ++retry_count; | 273 ++retry_count; |
269 } while (res == ERROR_MORE_DATA && retry_count <= 3); | 274 } while (res == ERROR_MORE_DATA && retry_count <= 3); |
270 | 275 |
271 if (res != NO_ERROR) { | 276 if (res != NO_ERROR) { |
272 NOTREACHED(); | 277 LOG(INFO) << "Error fetching PAC URL from DHCP: " << res; |
| 278 UMA_HISTOGRAM_COUNTS("Net.DhcpWpadUnhandledDhcpError", 1); |
273 } else if (wpad_params.nBytesData) { | 279 } else if (wpad_params.nBytesData) { |
274 // The result should be ASCII, not wide character. | 280 // The result should be ASCII, not wide character. |
275 DCHECK_EQ(strlen(reinterpret_cast<const char*>(wpad_params.Data)) + 1, | 281 DCHECK_EQ(strlen(reinterpret_cast<const char*>(wpad_params.Data)) + 1, |
276 wpad_params.nBytesData); | 282 wpad_params.nBytesData); |
277 // Return only up to the first null in case of embedded NULLs; if the | 283 // Return only up to the first null in case of embedded NULLs; if the |
278 // server is giving us back a buffer with embedded NULLs, something is | 284 // server is giving us back a buffer with embedded NULLs, something is |
279 // broken anyway. | 285 // broken anyway. |
280 return std::string(reinterpret_cast<const char *>(wpad_params.Data)); | 286 return std::string(reinterpret_cast<const char *>(wpad_params.Data)); |
281 } | 287 } |
282 | 288 |
283 return ""; | 289 return ""; |
284 } | 290 } |
285 | 291 |
286 } // namespace net | 292 } // namespace net |
OLD | NEW |