| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/data_reduction_proxy/browser/data_reduction_proxy_config_se
rvice.h" | 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_config_se
rvice.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 DCHECK(config_service); | 123 DCHECK(config_service); |
| 124 } | 124 } |
| 125 | 125 |
| 126 DataReductionProxyConfigTracker::~DataReductionProxyConfigTracker() { | 126 DataReductionProxyConfigTracker::~DataReductionProxyConfigTracker() { |
| 127 } | 127 } |
| 128 | 128 |
| 129 void DataReductionProxyConfigTracker::Enable( | 129 void DataReductionProxyConfigTracker::Enable( |
| 130 bool primary_restricted, | 130 bool primary_restricted, |
| 131 bool fallback_restricted, | 131 bool fallback_restricted, |
| 132 const std::string& primary_origin, | 132 const std::string& primary_origin, |
| 133 const std::string& fallback_origin) { | 133 const std::string& fallback_origin, |
| 134 const std::string& ssl_origin) { |
| 134 | 135 |
| 135 std::vector<std::string> proxies; | 136 std::vector<std::string> proxies; |
| 136 if (!primary_restricted) { | 137 if (!primary_restricted) { |
| 137 std::string trimmed_primary; | 138 std::string trimmed_primary; |
| 138 base::TrimString(primary_origin, "/", &trimmed_primary); | 139 base::TrimString(primary_origin, "/", &trimmed_primary); |
| 139 if (!trimmed_primary.empty()) | 140 if (!trimmed_primary.empty()) |
| 140 proxies.push_back(trimmed_primary); | 141 proxies.push_back(trimmed_primary); |
| 141 } | 142 } |
| 142 if (!fallback_restricted) { | 143 if (!fallback_restricted) { |
| 143 std::string trimmed_fallback; | 144 std::string trimmed_fallback; |
| 144 base::TrimString(fallback_origin, "/", &trimmed_fallback); | 145 base::TrimString(fallback_origin, "/", &trimmed_fallback); |
| 145 if (!trimmed_fallback.empty()) | 146 if (!trimmed_fallback.empty()) |
| 146 proxies.push_back(trimmed_fallback); | 147 proxies.push_back(trimmed_fallback); |
| 147 } | 148 } |
| 148 if (proxies.empty()) { | 149 if (proxies.empty()) { |
| 149 std::string mode; | 150 std::string mode; |
| 150 Disable(); | 151 Disable(); |
| 151 return; | 152 return; |
| 152 } | 153 } |
| 153 | 154 |
| 155 std::string trimmed_ssl; |
| 156 base::TrimString(ssl_origin, "/", &trimmed_ssl); |
| 157 |
| 158 std::string server = "http=" + JoinString(proxies, ",") + ",direct://;" |
| 159 + (ssl_origin.empty() ? "" : ("https=" + ssl_origin + ",direct://;")); |
| 160 |
| 154 net::ProxyConfig config; | 161 net::ProxyConfig config; |
| 155 config.proxy_rules().ParseFromString( | 162 config.proxy_rules().ParseFromString(server); |
| 156 "http=" + JoinString(proxies, ",") + ",direct://;"); | |
| 157 config.proxy_rules().bypass_rules.ParseFromString( | 163 config.proxy_rules().bypass_rules.ParseFromString( |
| 158 JoinString(bypass_rules_, ", ")); | 164 JoinString(bypass_rules_, ", ")); |
| 159 UpdateProxyConfigOnIOThread(true, config); | 165 UpdateProxyConfigOnIOThread(true, config); |
| 160 } | 166 } |
| 161 | 167 |
| 162 | 168 |
| 163 void DataReductionProxyConfigTracker::Disable() { | 169 void DataReductionProxyConfigTracker::Disable() { |
| 164 net::ProxyConfig config = net::ProxyConfig::CreateDirect(); | 170 net::ProxyConfig config = net::ProxyConfig::CreateDirect(); |
| 165 UpdateProxyConfigOnIOThread(false, config); | 171 UpdateProxyConfigOnIOThread(false, config); |
| 166 } | 172 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 189 bool enabled, | 195 bool enabled, |
| 190 const net::ProxyConfig& config) { | 196 const net::ProxyConfig& config) { |
| 191 task_runner_->PostTask(FROM_HERE, | 197 task_runner_->PostTask(FROM_HERE, |
| 192 base::Bind( | 198 base::Bind( |
| 193 &DataReductionProxyConfigService::UpdateProxyConfig, | 199 &DataReductionProxyConfigService::UpdateProxyConfig, |
| 194 base::Unretained(config_service_), | 200 base::Unretained(config_service_), |
| 195 enabled, config)); | 201 enabled, config)); |
| 196 } | 202 } |
| 197 | 203 |
| 198 } // namespace data_reduction_proxy | 204 } // namespace data_reduction_proxy |
| OLD | NEW |