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: chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator.cc

Issue 669163003: Handle disabling data reduction proxy for all platforms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed bengr's changes Created 6 years, 1 month 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 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 "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator. h" 5 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_configurator. h"
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/prefs/scoped_user_pref_update.h" 8 #include "base/prefs/scoped_user_pref_update.h"
9 #include "base/sequenced_task_runner.h" 9 #include "base/sequenced_task_runner.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
11 #include "chrome/browser/prefs/proxy_prefs.h" 11 #include "chrome/browser/prefs/proxy_prefs.h"
12 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
13 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_para ms.h"
13 #include "net/proxy/proxy_config.h" 14 #include "net/proxy/proxy_config.h"
14 #include "net/proxy/proxy_info.h" 15 #include "net/proxy/proxy_info.h"
16 #include "net/proxy/proxy_list.h"
15 #include "net/proxy/proxy_service.h" 17 #include "net/proxy/proxy_service.h"
16 18
17 DataReductionProxyChromeConfigurator::DataReductionProxyChromeConfigurator( 19 DataReductionProxyChromeConfigurator::DataReductionProxyChromeConfigurator(
18 PrefService* prefs, 20 PrefService* prefs,
19 scoped_refptr<base::SequencedTaskRunner> network_task_runner) 21 scoped_refptr<base::SequencedTaskRunner> network_task_runner)
20 : prefs_(prefs), network_task_runner_(network_task_runner) { 22 : prefs_(prefs), network_task_runner_(network_task_runner) {
21 } 23 }
22 24
23 DataReductionProxyChromeConfigurator::~DataReductionProxyChromeConfigurator() { 25 DataReductionProxyChromeConfigurator::~DataReductionProxyChromeConfigurator() {
24 } 26 }
25 27
28 // static
29 void DataReductionProxyChromeConfigurator::DisableInProxyConfigPref(
30 PrefService* prefs) {
31 DCHECK(prefs);
32 DictionaryPrefUpdate update(prefs, prefs::kProxy);
33 base::DictionaryValue* dict = update.Get();
bengr 2014/10/29 23:41:25 #include "base/values.h"
Not at Google. Contact bengr 2014/10/30 00:05:03 Done.
34 std::string mode;
35 dict->GetString("mode", &mode);
36 std::string server;
37 dict->GetString("server", &server);
38 net::ProxyConfig::ProxyRules proxy_rules;
39 proxy_rules.ParseFromString(server);
40 if (mode != ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS)
bengr 2014/10/29 23:41:25 Add comment: The data reduction proxy uses MODE_FI
Not at Google. Contact bengr 2014/10/30 00:05:03 Done.
41 || !ContainsDataReductionProxy(proxy_rules)) {
42 return;
43 }
44 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM));
45 dict->SetString("server", "");
46 dict->SetString("bypass_list", "");
47 }
48
26 void DataReductionProxyChromeConfigurator::Enable( 49 void DataReductionProxyChromeConfigurator::Enable(
27 bool primary_restricted, 50 bool primary_restricted,
28 bool fallback_restricted, 51 bool fallback_restricted,
29 const std::string& primary_origin, 52 const std::string& primary_origin,
30 const std::string& fallback_origin, 53 const std::string& fallback_origin,
31 const std::string& ssl_origin) { 54 const std::string& ssl_origin) {
32 DCHECK(prefs_); 55 DCHECK(prefs_);
33 DictionaryPrefUpdate update(prefs_, prefs::kProxy); 56 DictionaryPrefUpdate update(prefs_, prefs::kProxy);
34 // TODO(bengr): Consider relying on the proxy config for all data reduction 57 // TODO(bengr): Consider relying on the proxy config for all data reduction
35 // proxy configuration. 58 // proxy configuration.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 config.set_id(unused_id); 101 config.set_id(unused_id);
79 network_task_runner_->PostTask( 102 network_task_runner_->PostTask(
80 FROM_HERE, 103 FROM_HERE,
81 base::Bind( 104 base::Bind(
82 &DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO, 105 &DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO,
83 base::Unretained(this), 106 base::Unretained(this),
84 config)); 107 config));
85 } 108 }
86 109
87 void DataReductionProxyChromeConfigurator::Disable() { 110 void DataReductionProxyChromeConfigurator::Disable() {
88 DCHECK(prefs_); 111 DisableInProxyConfigPref(prefs_);
89 DictionaryPrefUpdate update(prefs_, prefs::kProxy);
90 base::DictionaryValue* dict = update.Get();
91 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM));
92 dict->SetString("server", "");
93 dict->SetString("bypass_list", "");
94 net::ProxyConfig config = net::ProxyConfig::CreateDirect(); 112 net::ProxyConfig config = net::ProxyConfig::CreateDirect();
95 network_task_runner_->PostTask( 113 network_task_runner_->PostTask(
96 FROM_HERE, 114 FROM_HERE,
97 base::Bind( 115 base::Bind(
98 &DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO, 116 &DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO,
99 base::Unretained(this), 117 base::Unretained(this),
100 config)); 118 config));
101 } 119 }
102 120
103 void DataReductionProxyChromeConfigurator::AddHostPatternToBypass( 121 void DataReductionProxyChromeConfigurator::AddHostPatternToBypass(
104 const std::string& pattern) { 122 const std::string& pattern) {
105 bypass_rules_.push_back(pattern); 123 bypass_rules_.push_back(pattern);
106 } 124 }
107 125
108 void DataReductionProxyChromeConfigurator::AddURLPatternToBypass( 126 void DataReductionProxyChromeConfigurator::AddURLPatternToBypass(
109 const std::string& pattern) { 127 const std::string& pattern) {
110 size_t pos = pattern.find('/'); 128 size_t pos = pattern.find('/');
111 if (pattern.find('/', pos + 1) == pos + 1) 129 if (pattern.find('/', pos + 1) == pos + 1)
112 pos = pattern.find('/', pos + 2); 130 pos = pattern.find('/', pos + 2);
113 131
114 std::string host_pattern; 132 std::string host_pattern;
115 if (pos != std::string::npos) 133 if (pos != std::string::npos)
116 host_pattern = pattern.substr(0, pos); 134 host_pattern = pattern.substr(0, pos);
117 else 135 else
118 host_pattern = pattern; 136 host_pattern = pattern;
119 137
120 AddHostPatternToBypass(host_pattern); 138 AddHostPatternToBypass(host_pattern);
121 } 139 }
122 140
141 // static
142 bool DataReductionProxyChromeConfigurator::ContainsDataReductionProxy(
bengr 2014/10/29 23:41:25 Again, talk to megjablon@
Not at Google. Contact bengr 2014/10/30 00:05:03 Done.
143 const net::ProxyConfig::ProxyRules& proxy_rules) {
144 data_reduction_proxy::DataReductionProxyParams params(
bengr 2014/10/29 23:41:25 Suggestion (not required): Add a flag for kEveryth
Not at Google. Contact bengr 2014/10/30 00:05:03 Done.
145 data_reduction_proxy::DataReductionProxyParams::kAllowed |
146 data_reduction_proxy::DataReductionProxyParams::kFallbackAllowed |
147 data_reduction_proxy::DataReductionProxyParams::kAlternativeAllowed |
148 data_reduction_proxy::DataReductionProxyParams::
149 kAlternativeFallbackAllowed);
150 if (proxy_rules.type != net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME) {
bengr 2014/10/29 23:41:25 Curly braces not needed.
Not at Google. Contact bengr 2014/10/30 00:05:03 Done.
151 return false;
152 }
153
154 const net::ProxyList* https_proxy_list =
155 proxy_rules.MapUrlSchemeToProxyList("https");
156 if (https_proxy_list && !https_proxy_list->IsEmpty() &&
157 // Sufficient to check only the first proxy.
158 params.IsDataReductionProxy(https_proxy_list->Get().host_port_pair(),
159 NULL)) {
160 return true;
161 }
162
163 const net::ProxyList* http_proxy_list =
164 proxy_rules.MapUrlSchemeToProxyList("http");
165 if (http_proxy_list && !http_proxy_list->IsEmpty() &&
166 // Sufficient to check only the first proxy.
167 params.IsDataReductionProxy(http_proxy_list->Get().host_port_pair(),
168 NULL)) {
169 return true;
170 }
171
172 return false;
173 }
174
123 void DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO( 175 void DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO(
124 const net::ProxyConfig& config) { 176 const net::ProxyConfig& config) {
125 config_ = config; 177 config_ = config;
126 } 178 }
127 179
128 const net::ProxyConfig& 180 const net::ProxyConfig&
129 DataReductionProxyChromeConfigurator::GetProxyConfigOnIO() const { 181 DataReductionProxyChromeConfigurator::GetProxyConfigOnIO() const {
130 return config_; 182 return config_;
131 } 183 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698