| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/chromeos/proxy_config_service_impl.h" | 5 #include "chrome/browser/chromeos/proxy_config_service_impl.h" |
| 6 | 6 |
| 7 #include <ostream> | 7 #include <ostream> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 reference_config_.mode = ProxyConfig::MODE_AUTO_DETECT; | 402 reference_config_.mode = ProxyConfig::MODE_AUTO_DETECT; |
| 403 OnUISetProxyConfig(true); | 403 OnUISetProxyConfig(true); |
| 404 return true; | 404 return true; |
| 405 } | 405 } |
| 406 | 406 |
| 407 bool ProxyConfigServiceImpl::UISetProxyConfigToPACScript(const GURL& pac_url) { | 407 bool ProxyConfigServiceImpl::UISetProxyConfigToPACScript(const GURL& pac_url) { |
| 408 // Should be called from UI thread. | 408 // Should be called from UI thread. |
| 409 CheckCurrentlyOnUIThread(); | 409 CheckCurrentlyOnUIThread(); |
| 410 reference_config_.mode = ProxyConfig::MODE_PAC_SCRIPT; | 410 reference_config_.mode = ProxyConfig::MODE_PAC_SCRIPT; |
| 411 reference_config_.automatic_proxy.pac_url = pac_url; | 411 reference_config_.automatic_proxy.pac_url = pac_url; |
| 412 if (pac_url.is_valid()) { | 412 OnUISetProxyConfig(true); |
| 413 OnUISetProxyConfig(true); | 413 return true; |
| 414 return true; | |
| 415 } | |
| 416 LOG(INFO) << "Cannot set proxy: invalid pac url"; | |
| 417 return false; | |
| 418 } | 414 } |
| 419 | 415 |
| 420 bool ProxyConfigServiceImpl::UISetProxyConfigToSingleProxy( | 416 bool ProxyConfigServiceImpl::UISetProxyConfigToSingleProxy( |
| 421 const net::ProxyServer& server) { | 417 const net::ProxyServer& server) { |
| 422 // Should be called from UI thread. | 418 // Should be called from UI thread. |
| 423 CheckCurrentlyOnUIThread(); | 419 CheckCurrentlyOnUIThread(); |
| 424 reference_config_.mode = ProxyConfig::MODE_SINGLE_PROXY; | 420 reference_config_.mode = ProxyConfig::MODE_SINGLE_PROXY; |
| 425 reference_config_.single_proxy.server = server; | 421 reference_config_.single_proxy.server = server; |
| 426 if (server.is_valid()) { | 422 OnUISetProxyConfig(true); |
| 427 OnUISetProxyConfig(true); | 423 return true; |
| 428 return true; | |
| 429 } | |
| 430 LOG(INFO) << "Cannot set proxy: invalid single server"; | |
| 431 return false; | |
| 432 } | 424 } |
| 433 | 425 |
| 434 bool ProxyConfigServiceImpl::UISetProxyConfigToProxyPerScheme( | 426 bool ProxyConfigServiceImpl::UISetProxyConfigToProxyPerScheme( |
| 435 const std::string& scheme, const net::ProxyServer& server) { | 427 const std::string& scheme, const net::ProxyServer& server) { |
| 436 // Should be called from UI thread. | 428 // Should be called from UI thread. |
| 437 CheckCurrentlyOnUIThread(); | 429 CheckCurrentlyOnUIThread(); |
| 438 ProxyConfig::ManualProxy* proxy = NULL; | 430 ProxyConfig::ManualProxy* proxy = NULL; |
| 439 if (scheme == "http") | 431 if (scheme == "http") |
| 440 proxy = &reference_config_.http_proxy; | 432 proxy = &reference_config_.http_proxy; |
| 441 else if (scheme == "https") | 433 else if (scheme == "https") |
| 442 proxy = &reference_config_.https_proxy; | 434 proxy = &reference_config_.https_proxy; |
| 443 else if (scheme == "ftp") | 435 else if (scheme == "ftp") |
| 444 proxy = &reference_config_.ftp_proxy; | 436 proxy = &reference_config_.ftp_proxy; |
| 445 else if (scheme == "socks") | 437 else if (scheme == "socks") |
| 446 proxy = &reference_config_.socks_proxy; | 438 proxy = &reference_config_.socks_proxy; |
| 447 if (!proxy) { | 439 if (!proxy) { |
| 448 NOTREACHED() << "Cannot set proxy: invalid scheme [" << scheme << "]"; | 440 NOTREACHED() << "Cannot set proxy: invalid scheme [" << scheme << "]"; |
| 449 return false; | 441 return false; |
| 450 } | 442 } |
| 451 reference_config_.mode = ProxyConfig::MODE_PROXY_PER_SCHEME; | 443 reference_config_.mode = ProxyConfig::MODE_PROXY_PER_SCHEME; |
| 452 proxy->server = server; | 444 proxy->server = server; |
| 453 if (server.is_valid()) { | 445 OnUISetProxyConfig(true); |
| 454 OnUISetProxyConfig(true); | 446 return true; |
| 455 return true; | |
| 456 } | |
| 457 LOG(INFO) << "Cannot set proxy: invalid " << scheme << " server"; | |
| 458 return false; | |
| 459 } | 447 } |
| 460 | 448 |
| 461 bool ProxyConfigServiceImpl::UISetProxyConfigBypassRules( | 449 bool ProxyConfigServiceImpl::UISetProxyConfigBypassRules( |
| 462 const net::ProxyBypassRules& bypass_rules) { | 450 const net::ProxyBypassRules& bypass_rules) { |
| 463 // Should be called from UI thread. | 451 // Should be called from UI thread. |
| 464 CheckCurrentlyOnUIThread(); | 452 CheckCurrentlyOnUIThread(); |
| 465 DCHECK(reference_config_.mode == ProxyConfig::MODE_SINGLE_PROXY || | 453 DCHECK(reference_config_.mode == ProxyConfig::MODE_SINGLE_PROXY || |
| 466 reference_config_.mode == ProxyConfig::MODE_PROXY_PER_SCHEME); | 454 reference_config_.mode == ProxyConfig::MODE_PROXY_PER_SCHEME); |
| 467 if (reference_config_.mode != ProxyConfig::MODE_SINGLE_PROXY && | 455 if (reference_config_.mode != ProxyConfig::MODE_SINGLE_PROXY && |
| 468 reference_config_.mode != ProxyConfig::MODE_PROXY_PER_SCHEME) { | 456 reference_config_.mode != ProxyConfig::MODE_PROXY_PER_SCHEME) { |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 has_config_ = true; | 584 has_config_ = true; |
| 597 cached_config_ = new_config; | 585 cached_config_ = new_config; |
| 598 // Notify observers of new proxy config. | 586 // Notify observers of new proxy config. |
| 599 net::ProxyConfig net_config; | 587 net::ProxyConfig net_config; |
| 600 cached_config_.ToNetProxyConfig(&net_config); | 588 cached_config_.ToNetProxyConfig(&net_config); |
| 601 FOR_EACH_OBSERVER(net::ProxyConfigService::Observer, observers_, | 589 FOR_EACH_OBSERVER(net::ProxyConfigService::Observer, observers_, |
| 602 OnProxyConfigChanged(net_config)); | 590 OnProxyConfigChanged(net_config)); |
| 603 } | 591 } |
| 604 | 592 |
| 605 } // namespace chromeos | 593 } // namespace chromeos |
| OLD | NEW |