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 "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(); | |
34 std::string mode; | |
35 dict->GetString("mode", &mode); | |
36 std::string server; | |
37 dict->GetString("server", &server); | |
38 if (mode != ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS) | |
39 || !ContainsDataReductionProxy(server)) { | |
40 return; | |
41 } | |
42 | |
43 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM)); | |
44 dict->SetString("server", ""); | |
45 dict->SetString("bypass_list", ""); | |
46 } | |
47 | |
26 void DataReductionProxyChromeConfigurator::Enable( | 48 void DataReductionProxyChromeConfigurator::Enable( |
27 bool primary_restricted, | 49 bool primary_restricted, |
28 bool fallback_restricted, | 50 bool fallback_restricted, |
29 const std::string& primary_origin, | 51 const std::string& primary_origin, |
30 const std::string& fallback_origin, | 52 const std::string& fallback_origin, |
31 const std::string& ssl_origin) { | 53 const std::string& ssl_origin) { |
32 DCHECK(prefs_); | 54 DCHECK(prefs_); |
33 DictionaryPrefUpdate update(prefs_, prefs::kProxy); | 55 DictionaryPrefUpdate update(prefs_, prefs::kProxy); |
34 // TODO(bengr): Consider relying on the proxy config for all data reduction | 56 // TODO(bengr): Consider relying on the proxy config for all data reduction |
35 // proxy configuration. | 57 // proxy configuration. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 config.set_id(unused_id); | 100 config.set_id(unused_id); |
79 network_task_runner_->PostTask( | 101 network_task_runner_->PostTask( |
80 FROM_HERE, | 102 FROM_HERE, |
81 base::Bind( | 103 base::Bind( |
82 &DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO, | 104 &DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO, |
83 base::Unretained(this), | 105 base::Unretained(this), |
84 config)); | 106 config)); |
85 } | 107 } |
86 | 108 |
87 void DataReductionProxyChromeConfigurator::Disable() { | 109 void DataReductionProxyChromeConfigurator::Disable() { |
88 DCHECK(prefs_); | 110 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(); | 111 net::ProxyConfig config = net::ProxyConfig::CreateDirect(); |
95 network_task_runner_->PostTask( | 112 network_task_runner_->PostTask( |
96 FROM_HERE, | 113 FROM_HERE, |
97 base::Bind( | 114 base::Bind( |
98 &DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO, | 115 &DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO, |
99 base::Unretained(this), | 116 base::Unretained(this), |
100 config)); | 117 config)); |
101 } | 118 } |
102 | 119 |
103 void DataReductionProxyChromeConfigurator::AddHostPatternToBypass( | 120 void DataReductionProxyChromeConfigurator::AddHostPatternToBypass( |
104 const std::string& pattern) { | 121 const std::string& pattern) { |
105 bypass_rules_.push_back(pattern); | 122 bypass_rules_.push_back(pattern); |
106 } | 123 } |
107 | 124 |
108 void DataReductionProxyChromeConfigurator::AddURLPatternToBypass( | 125 void DataReductionProxyChromeConfigurator::AddURLPatternToBypass( |
109 const std::string& pattern) { | 126 const std::string& pattern) { |
110 size_t pos = pattern.find('/'); | 127 size_t pos = pattern.find('/'); |
111 if (pattern.find('/', pos + 1) == pos + 1) | 128 if (pattern.find('/', pos + 1) == pos + 1) |
112 pos = pattern.find('/', pos + 2); | 129 pos = pattern.find('/', pos + 2); |
113 | 130 |
114 std::string host_pattern; | 131 std::string host_pattern; |
115 if (pos != std::string::npos) | 132 if (pos != std::string::npos) |
116 host_pattern = pattern.substr(0, pos); | 133 host_pattern = pattern.substr(0, pos); |
117 else | 134 else |
118 host_pattern = pattern; | 135 host_pattern = pattern; |
119 | 136 |
120 AddHostPatternToBypass(host_pattern); | 137 AddHostPatternToBypass(host_pattern); |
121 } | 138 } |
122 | 139 |
140 // static | |
141 bool DataReductionProxyChromeConfigurator::ContainsDataReductionProxy( | |
142 const std::string& server) { | |
143 data_reduction_proxy::DataReductionProxyParams params(0); | |
bengr
2014/10/29 20:58:46
How does this work? Nothing is allowed, so IsDataR
Not at Google. Contact bengr
2014/10/29 22:30:14
You are right. Added the correct parameters.
This
| |
144 net::ProxyConfig::ProxyRules proxy_rules; | |
145 proxy_rules.ParseFromString(server); | |
146 if (proxy_rules.type != net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME) { | |
147 return false; | |
148 } | |
149 | |
150 const net::ProxyList* https_proxy_list = | |
151 proxy_rules.MapUrlSchemeToProxyList("https"); | |
152 if (https_proxy_list && !https_proxy_list->IsEmpty() && | |
153 params.IsDataReductionProxy(https_proxy_list->Get().host_port_pair(), | |
154 NULL)) { | |
155 return true; | |
156 } | |
157 | |
158 const net::ProxyList* http_proxy_list = | |
159 proxy_rules.MapUrlSchemeToProxyList("http"); | |
160 if (http_proxy_list && !http_proxy_list->IsEmpty() && | |
bengr
2014/10/29 20:58:46
// It is sufficient to check only the first proxy
Not at Google. Contact bengr
2014/10/29 22:30:14
Done.
| |
161 params.IsDataReductionProxy(http_proxy_list->Get().host_port_pair(), | |
162 NULL)) { | |
163 return true; | |
164 } | |
165 | |
166 return false; | |
167 } | |
168 | |
123 void DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO( | 169 void DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO( |
124 const net::ProxyConfig& config) { | 170 const net::ProxyConfig& config) { |
125 config_ = config; | 171 config_ = config; |
126 } | 172 } |
127 | 173 |
128 const net::ProxyConfig& | 174 const net::ProxyConfig& |
129 DataReductionProxyChromeConfigurator::GetProxyConfigOnIO() const { | 175 DataReductionProxyChromeConfigurator::GetProxyConfigOnIO() const { |
130 return config_; | 176 return config_; |
131 } | 177 } |
OLD | NEW |