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

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

Issue 2845643003: Allow ProxyService to share URLRequestContext with everything else. (Closed)
Patch Set: Fix Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after
1037 const CompletionCallback& callback, 1037 const CompletionCallback& callback,
1038 PacRequest** pac_request, 1038 PacRequest** pac_request,
1039 ProxyDelegate* proxy_delegate, 1039 ProxyDelegate* proxy_delegate,
1040 const NetLogWithSource& net_log) { 1040 const NetLogWithSource& net_log) {
1041 DCHECK(CalledOnValidThread()); 1041 DCHECK(CalledOnValidThread());
1042 1042
1043 net_log.BeginEvent(NetLogEventType::PROXY_SERVICE); 1043 net_log.BeginEvent(NetLogEventType::PROXY_SERVICE);
1044 1044
1045 // Notify our polling-based dependencies that a resolve is taking place. 1045 // Notify our polling-based dependencies that a resolve is taking place.
1046 // This way they can schedule their polls in response to network activity. 1046 // This way they can schedule their polls in response to network activity.
1047 config_service_->OnLazyPoll(); 1047 if (config_service_)
1048 config_service_->OnLazyPoll();
1048 if (script_poller_.get()) 1049 if (script_poller_.get())
1049 script_poller_->OnLazyPoll(); 1050 script_poller_->OnLazyPoll();
1050 1051
1051 if (current_state_ == STATE_NONE) 1052 if (current_state_ == STATE_NONE)
1052 ApplyProxyConfigIfAvailable(); 1053 ApplyProxyConfigIfAvailable();
1053 1054
1054 // Sanitize the URL before passing it on to the proxy resolver (i.e. PAC 1055 // Sanitize the URL before passing it on to the proxy resolver (i.e. PAC
1055 // script). The goal is to remove sensitive data (like embedded user names 1056 // script). The goal is to remove sensitive data (like embedded user names
1056 // and password), and local data (i.e. reference fragment) which does not need 1057 // and password), and local data (i.e. reference fragment) which does not need
1057 // to be disclosed to the resolver. 1058 // to be disclosed to the resolver.
1058 GURL url = SanitizeUrl(raw_url, sanitize_url_policy_); 1059 GURL url = SanitizeUrl(raw_url, sanitize_url_policy_);
1059 1060
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1128 config_.proxy_rules().Apply(url, result); 1129 config_.proxy_rules().Apply(url, result);
1129 result->config_source_ = config_.source(); 1130 result->config_source_ = config_.source();
1130 result->config_id_ = config_.id(); 1131 result->config_id_ = config_.id();
1131 1132
1132 return OK; 1133 return OK;
1133 } 1134 }
1134 1135
1135 ProxyService::~ProxyService() { 1136 ProxyService::~ProxyService() {
1136 NetworkChangeNotifier::RemoveIPAddressObserver(this); 1137 NetworkChangeNotifier::RemoveIPAddressObserver(this);
1137 NetworkChangeNotifier::RemoveDNSObserver(this); 1138 NetworkChangeNotifier::RemoveDNSObserver(this);
1138 config_service_->RemoveObserver(this); 1139 if (config_service_)
1140 config_service_->RemoveObserver(this);
1139 1141
1140 // Cancel any inprogress requests. 1142 // Cancel any inprogress requests.
1141 for (PendingRequests::iterator it = pending_requests_.begin(); 1143 for (PendingRequests::iterator it = pending_requests_.begin();
1142 it != pending_requests_.end(); 1144 it != pending_requests_.end();
1143 ++it) { 1145 ++it) {
1144 (*it)->Cancel(); 1146 (*it)->Cancel();
1145 } 1147 }
1146 } 1148 }
1147 1149
1148 void ProxyService::SuspendAllPendingRequests() { 1150 void ProxyService::SuspendAllPendingRequests() {
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
1442 ApplyProxyConfigIfAvailable(); 1444 ApplyProxyConfigIfAvailable();
1443 } 1445 }
1444 } 1446 }
1445 1447
1446 net_log.EndEvent(NetLogEventType::PROXY_SERVICE); 1448 net_log.EndEvent(NetLogEventType::PROXY_SERVICE);
1447 return result_code; 1449 return result_code;
1448 } 1450 }
1449 1451
1450 void ProxyService::SetProxyScriptFetchers( 1452 void ProxyService::SetProxyScriptFetchers(
1451 ProxyScriptFetcher* proxy_script_fetcher, 1453 ProxyScriptFetcher* proxy_script_fetcher,
1452 std::unique_ptr<DhcpProxyScriptFetcher> dhcp_proxy_script_fetcher) { 1454 std::unique_ptr<DhcpProxyScriptFetcher> dhcp_proxy_script_fetcher) {
mmenke 2017/04/27 18:37:31 Another option would be to just call this method w
1453 DCHECK(CalledOnValidThread()); 1455 DCHECK(CalledOnValidThread());
1454 State previous_state = ResetProxyConfig(false); 1456 State previous_state = ResetProxyConfig(false);
1455 proxy_script_fetcher_.reset(proxy_script_fetcher); 1457 proxy_script_fetcher_.reset(proxy_script_fetcher);
1456 dhcp_proxy_script_fetcher_ = std::move(dhcp_proxy_script_fetcher); 1458 dhcp_proxy_script_fetcher_ = std::move(dhcp_proxy_script_fetcher);
1457 if (previous_state != STATE_NONE) 1459 if (previous_state != STATE_NONE)
1458 ApplyProxyConfigIfAvailable(); 1460 ApplyProxyConfigIfAvailable();
1459 } 1461 }
1460 1462
1461 ProxyScriptFetcher* ProxyService::GetProxyScriptFetcher() const { 1463 void ProxyService::ShutDown() {
1462 DCHECK(CalledOnValidThread()); 1464 DCHECK(CalledOnValidThread());
1463 return proxy_script_fetcher_.get(); 1465
1466 // Cancel up in progress work, and destroy all objects that depend on the two
eroman 2017/04/27 19:35:41 ProxyService is already a huge mess. I would rathe
mmenke 2017/04/27 20:02:13 I agree that this class is a complete mess. Unwra
1467 // fetchers.
1468 ResetProxyConfig(true);
1469
1470 // Prevent proxy service changes from waking up the ProxyService.
eroman 2017/04/27 19:35:42 config service
1471 if (config_service_) {
1472 config_service_->RemoveObserver(this);
1473 config_service_.reset();
1474 }
1475
1476 // Destroy fetchers, which also cancels in-progress network requests.
1477 proxy_script_fetcher_.reset();
1478 dhcp_proxy_script_fetcher_.reset();
1479
1480 current_state_ = STATE_SHUTDOWN;
1464 } 1481 }
1465 1482
1466 ProxyService::State ProxyService::ResetProxyConfig(bool reset_fetched_config) { 1483 ProxyService::State ProxyService::ResetProxyConfig(bool reset_fetched_config) {
1467 DCHECK(CalledOnValidThread()); 1484 DCHECK(CalledOnValidThread());
1468 State previous_state = current_state_; 1485 State previous_state = current_state_;
1469 1486
1470 permanent_error_ = OK; 1487 permanent_error_ = OK;
1471 proxy_retry_info_.clear(); 1488 proxy_retry_info_.clear();
1472 script_poller_.reset(); 1489 script_poller_.reset();
1473 init_proxy_resolver_.reset(); 1490 init_proxy_resolver_.reset();
(...skipping 19 matching lines...) Expand all
1493 // Set the new configuration service. 1510 // Set the new configuration service.
1494 config_service_ = std::move(new_proxy_config_service); 1511 config_service_ = std::move(new_proxy_config_service);
1495 config_service_->AddObserver(this); 1512 config_service_->AddObserver(this);
1496 1513
1497 if (previous_state != STATE_NONE) 1514 if (previous_state != STATE_NONE)
1498 ApplyProxyConfigIfAvailable(); 1515 ApplyProxyConfigIfAvailable();
1499 } 1516 }
1500 1517
1501 void ProxyService::ForceReloadProxyConfig() { 1518 void ProxyService::ForceReloadProxyConfig() {
1502 DCHECK(CalledOnValidThread()); 1519 DCHECK(CalledOnValidThread());
1520
1521 // Refuse to reload proxy config if already shut down.
1522 if (current_state_ == STATE_SHUTDOWN)
1523 return;
1524
1503 ResetProxyConfig(false); 1525 ResetProxyConfig(false);
1504 ApplyProxyConfigIfAvailable(); 1526 ApplyProxyConfigIfAvailable();
1505 } 1527 }
1506 1528
1507 // static 1529 // static
1508 std::unique_ptr<ProxyConfigService> 1530 std::unique_ptr<ProxyConfigService>
1509 ProxyService::CreateSystemProxyConfigService( 1531 ProxyService::CreateSystemProxyConfigService(
1510 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner, 1532 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner,
1511 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) { 1533 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) {
1512 #if defined(OS_WIN) 1534 #if defined(OS_WIN)
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1656 State previous_state = ResetProxyConfig(false); 1678 State previous_state = ResetProxyConfig(false);
1657 if (previous_state != STATE_NONE) 1679 if (previous_state != STATE_NONE)
1658 ApplyProxyConfigIfAvailable(); 1680 ApplyProxyConfigIfAvailable();
1659 } 1681 }
1660 1682
1661 void ProxyService::OnDNSChanged() { 1683 void ProxyService::OnDNSChanged() {
1662 OnIPAddressChanged(); 1684 OnIPAddressChanged();
1663 } 1685 }
1664 1686
1665 } // namespace net 1687 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698