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

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

Issue 15070: Split ProxyResolver into two interfaces:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 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
« no previous file with comments | « net/proxy/proxy_service.h ('k') | net/proxy/proxy_service_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/proxy_service.h" 5 #include "net/proxy/proxy_service.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <winhttp.h> 9 #include <winhttp.h>
10 #endif 10 #endif
11 11
12 #include <algorithm> 12 #include <algorithm>
13 13
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/message_loop.h" 15 #include "base/message_loop.h"
16 #include "base/string_tokenizer.h" 16 #include "base/string_tokenizer.h"
17 #include "base/string_util.h" 17 #include "base/string_util.h"
18 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
19 #include "net/base/net_errors.h" 19 #include "net/base/net_errors.h"
20 #include "net/proxy/proxy_resolver_fixed.h" 20 #include "net/proxy/proxy_config_service_fixed.h"
21 #include "net/proxy/proxy_resolver_null.h"
22 #if defined(OS_WIN) 21 #if defined(OS_WIN)
23 #include "net/http/http_transaction_winhttp.h" 22 #include "net/http/http_transaction_winhttp.h"
23 #include "net/proxy/proxy_config_service_win.h"
24 #include "net/proxy/proxy_resolver_winhttp.h" 24 #include "net/proxy/proxy_resolver_winhttp.h"
25 #elif defined(OS_MACOSX) 25 #elif defined(OS_MACOSX)
26 #include "net/proxy/proxy_resolver_mac.h" 26 #include "net/proxy/proxy_resolver_mac.h"
27 #endif 27 #endif
28 28
29 using base::TimeDelta; 29 using base::TimeDelta;
30 using base::TimeTicks; 30 using base::TimeTicks;
31 31
32 namespace net { 32 namespace net {
33 33
34 // Config getter that fails every time.
35 class ProxyConfigServiceNull : public ProxyConfigService {
36 public:
37 virtual int GetProxyConfig(ProxyConfig* config) {
38 return ERR_NOT_IMPLEMENTED;
39 }
40 };
41
42
34 // ProxyConfig ---------------------------------------------------------------- 43 // ProxyConfig ----------------------------------------------------------------
35 44
36 // static 45 // static
37 ProxyConfig::ID ProxyConfig::last_id_ = ProxyConfig::INVALID_ID; 46 ProxyConfig::ID ProxyConfig::last_id_ = ProxyConfig::INVALID_ID;
38 47
39 ProxyConfig::ProxyConfig() 48 ProxyConfig::ProxyConfig()
40 : auto_detect(false), 49 : auto_detect(false),
41 proxy_bypass_local_names(false), 50 proxy_bypass_local_names(false),
42 id_(++last_id_) { 51 id_(++last_id_) {
43 } 52 }
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 ProxyConfig::ID config_id_; 274 ProxyConfig::ID config_id_;
266 275
267 // Usable from within DoQuery on the PAC thread. 276 // Usable from within DoQuery on the PAC thread.
268 ProxyInfo results_buf_; 277 ProxyInfo results_buf_;
269 GURL pac_url_; 278 GURL pac_url_;
270 MessageLoop* origin_loop_; 279 MessageLoop* origin_loop_;
271 }; 280 };
272 281
273 // ProxyService --------------------------------------------------------------- 282 // ProxyService ---------------------------------------------------------------
274 283
275 ProxyService::ProxyService(ProxyResolver* resolver) 284 ProxyService::ProxyService(ProxyConfigService* config_service,
276 : resolver_(resolver), 285 ProxyResolver* resolver)
286 : config_service_(config_service),
287 resolver_(resolver),
277 config_is_bad_(false), 288 config_is_bad_(false),
278 config_has_been_updated_(false) { 289 config_has_been_updated_(false) {
279 } 290 }
280 291
281 // static 292 // static
282 ProxyService* ProxyService::Create(const ProxyInfo* pi) { 293 ProxyService* ProxyService::Create(const ProxyInfo* pi) {
283 if (pi) { 294 if (pi) {
295 // The ProxyResolver is set to NULL, since it should never be called
296 // (because the configuration will never require PAC).
284 ProxyService* proxy_service = 297 ProxyService* proxy_service =
285 new ProxyService(new ProxyResolverFixed(*pi)); 298 new ProxyService(new ProxyConfigServiceFixed(*pi), NULL);
286 299
287 // TODO(eroman): remove this WinHTTP hack once it is no more. 300 // TODO(eroman): remove this WinHTTP hack once it is no more.
288 // We keep a copy of the ProxyInfo that was used to create the 301 // We keep a copy of the ProxyInfo that was used to create the
289 // proxy service, so we can pass it to WinHTTP. 302 // proxy service, so we can pass it to WinHTTP.
290 proxy_service->proxy_info_.reset(new ProxyInfo(*pi)); 303 proxy_service->proxy_info_.reset(new ProxyInfo(*pi));
291 304
292 return proxy_service; 305 return proxy_service;
293 } 306 }
294 #if defined(OS_WIN) 307 #if defined(OS_WIN)
295 return new ProxyService(new ProxyResolverWinHttp()); 308 return new ProxyService(new ProxyConfigServiceWin(),
309 new ProxyResolverWinHttp());
296 #elif defined(OS_MACOSX) 310 #elif defined(OS_MACOSX)
297 return new ProxyService(new ProxyResolverMac()); 311 return new ProxyService(new ProxyConfigServiceMac(),
312 new ProxyResolverMac());
298 #else 313 #else
299 // This used to be a NOTIMPLEMENTED(), but that logs as an error, 314 // This used to be a NOTIMPLEMENTED(), but that logs as an error,
300 // screwing up layout tests. 315 // screwing up layout tests.
301 LOG(WARNING) << "Proxies are not implemented; remove me once that's fixed."; 316 LOG(WARNING) << "Proxies are not implemented; remove me once that's fixed.";
302 // http://code.google.com/p/chromium/issues/detail?id=4523 is the bug 317 // http://code.google.com/p/chromium/issues/detail?id=4523 is the bug
303 // to implement this. 318 // to implement this.
304 return new ProxyService(new ProxyResolverNull()); 319 return CreateNull();
305 #endif 320 #endif
306 } 321 }
307 322
323 // static
324 ProxyService* ProxyService::CreateNull() {
325 // The ProxyResolver is set to NULL, since it should never be called
326 // (because the configuration will never require PAC).
327 return new ProxyService(new ProxyConfigServiceNull, NULL);
328 }
329
308 int ProxyService::ResolveProxy(const GURL& url, ProxyInfo* result, 330 int ProxyService::ResolveProxy(const GURL& url, ProxyInfo* result,
309 CompletionCallback* callback, 331 CompletionCallback* callback,
310 PacRequest** pac_request) { 332 PacRequest** pac_request) {
311 // The overhead of calling WinHttpGetIEProxyConfigForCurrentUser is very low. 333 // The overhead of calling ProxyConfigService::GetProxyConfig is very low.
312 const TimeDelta kProxyConfigMaxAge = TimeDelta::FromSeconds(5); 334 const TimeDelta kProxyConfigMaxAge = TimeDelta::FromSeconds(5);
313 335
314 // Periodically check for a new config. 336 // Periodically check for a new config.
315 if (!config_has_been_updated_ || 337 if (!config_has_been_updated_ ||
316 (TimeTicks::Now() - config_last_update_time_) > kProxyConfigMaxAge) 338 (TimeTicks::Now() - config_last_update_time_) > kProxyConfigMaxAge)
317 UpdateConfig(); 339 UpdateConfig();
318 result->config_id_ = config_.id(); 340 result->config_id_ = config_.id();
319 341
320 // Fallback to a "direct" (no proxy) connection if the current configuration 342 // Fallback to a "direct" (no proxy) connection if the current configuration
321 // is known to be bad. 343 // is known to be bad.
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 return; 496 return;
475 497
476 // Remember that this configuration doesn't work. 498 // Remember that this configuration doesn't work.
477 config_is_bad_ = true; 499 config_is_bad_ = true;
478 } 500 }
479 501
480 void ProxyService::UpdateConfig() { 502 void ProxyService::UpdateConfig() {
481 config_has_been_updated_ = true; 503 config_has_been_updated_ = true;
482 504
483 ProxyConfig latest; 505 ProxyConfig latest;
484 if (resolver_->GetProxyConfig(&latest) != OK) 506 if (config_service_->GetProxyConfig(&latest) != OK)
485 return; 507 return;
486 config_last_update_time_ = TimeTicks::Now(); 508 config_last_update_time_ = TimeTicks::Now();
487 509
488 if (latest.Equals(config_)) 510 if (latest.Equals(config_))
489 return; 511 return;
490 512
491 config_ = latest; 513 config_ = latest;
492 config_is_bad_ = false; 514 config_is_bad_ = false;
493 515
494 // We have a new config, we should clear the list of bad proxies. 516 // We have a new config, we should clear the list of bad proxies.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 // http://www.tcd.ie/iss/internet/osx_proxy.php for a real-world example). 558 // http://www.tcd.ie/iss/internet/osx_proxy.php for a real-world example).
537 // That's kinda cool so we'll provide that for everyone. 559 // That's kinda cool so we'll provide that for everyone.
538 // TODO(avi): implement here 560 // TODO(avi): implement here
539 } 561 }
540 562
541 return false; 563 return false;
542 } 564 }
543 565
544 } // namespace net 566 } // namespace net
545 567
OLDNEW
« no previous file with comments | « net/proxy/proxy_service.h ('k') | net/proxy/proxy_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698