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" |
15 #include "net/proxy/proxy_service.h" | 16 #include "net/proxy/proxy_service.h" |
16 | 17 |
17 DataReductionProxyChromeConfigurator::DataReductionProxyChromeConfigurator( | 18 DataReductionProxyChromeConfigurator::DataReductionProxyChromeConfigurator( |
18 PrefService* prefs, | 19 PrefService* prefs, |
19 scoped_refptr<base::SequencedTaskRunner> network_task_runner) | 20 scoped_refptr<base::SequencedTaskRunner> network_task_runner) |
20 : prefs_(prefs), network_task_runner_(network_task_runner) { | 21 : prefs_(prefs), network_task_runner_(network_task_runner) { |
21 } | 22 } |
22 | 23 |
23 DataReductionProxyChromeConfigurator::~DataReductionProxyChromeConfigurator() { | 24 DataReductionProxyChromeConfigurator::~DataReductionProxyChromeConfigurator() { |
24 } | 25 } |
25 | 26 |
27 // static | |
28 void DataReductionProxyChromeConfigurator::Disable(PrefService* prefs) { | |
29 DCHECK(prefs); | |
30 DictionaryPrefUpdate update(prefs, prefs::kProxy); | |
31 base::DictionaryValue* dict = update.Get(); | |
32 std::string mode; | |
33 dict->GetString("mode", &mode); | |
34 std::string server; | |
35 dict->GetString("server", &server); | |
36 if (mode != ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS) | |
37 || !ContainsDataReductionProxy(server)) | |
38 return; | |
bengr
2014/10/28 21:03:41
I prefer using curly braces when the if clause spa
Not at Google. Contact bengr
2014/10/28 22:31:44
Done.
| |
39 | |
40 dict->SetString("mode", ProxyModeToString(ProxyPrefs::MODE_SYSTEM)); | |
41 dict->SetString("server", ""); | |
42 dict->SetString("bypass_list", ""); | |
43 } | |
44 | |
26 void DataReductionProxyChromeConfigurator::Enable( | 45 void DataReductionProxyChromeConfigurator::Enable( |
27 bool primary_restricted, | 46 bool primary_restricted, |
28 bool fallback_restricted, | 47 bool fallback_restricted, |
29 const std::string& primary_origin, | 48 const std::string& primary_origin, |
30 const std::string& fallback_origin, | 49 const std::string& fallback_origin, |
31 const std::string& ssl_origin) { | 50 const std::string& ssl_origin) { |
32 DCHECK(prefs_); | 51 DCHECK(prefs_); |
33 DictionaryPrefUpdate update(prefs_, prefs::kProxy); | 52 DictionaryPrefUpdate update(prefs_, prefs::kProxy); |
34 // TODO(bengr): Consider relying on the proxy config for all data reduction | 53 // TODO(bengr): Consider relying on the proxy config for all data reduction |
35 // proxy configuration. | 54 // proxy configuration. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 config.set_id(unused_id); | 97 config.set_id(unused_id); |
79 network_task_runner_->PostTask( | 98 network_task_runner_->PostTask( |
80 FROM_HERE, | 99 FROM_HERE, |
81 base::Bind( | 100 base::Bind( |
82 &DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO, | 101 &DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO, |
83 base::Unretained(this), | 102 base::Unretained(this), |
84 config)); | 103 config)); |
85 } | 104 } |
86 | 105 |
87 void DataReductionProxyChromeConfigurator::Disable() { | 106 void DataReductionProxyChromeConfigurator::Disable() { |
88 DCHECK(prefs_); | 107 Disable(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(); | 108 net::ProxyConfig config = net::ProxyConfig::CreateDirect(); |
95 network_task_runner_->PostTask( | 109 network_task_runner_->PostTask( |
96 FROM_HERE, | 110 FROM_HERE, |
97 base::Bind( | 111 base::Bind( |
98 &DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO, | 112 &DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO, |
99 base::Unretained(this), | 113 base::Unretained(this), |
100 config)); | 114 config)); |
101 } | 115 } |
102 | 116 |
103 void DataReductionProxyChromeConfigurator::AddHostPatternToBypass( | 117 void DataReductionProxyChromeConfigurator::AddHostPatternToBypass( |
104 const std::string& pattern) { | 118 const std::string& pattern) { |
105 bypass_rules_.push_back(pattern); | 119 bypass_rules_.push_back(pattern); |
106 } | 120 } |
107 | 121 |
108 void DataReductionProxyChromeConfigurator::AddURLPatternToBypass( | 122 void DataReductionProxyChromeConfigurator::AddURLPatternToBypass( |
109 const std::string& pattern) { | 123 const std::string& pattern) { |
110 size_t pos = pattern.find('/'); | 124 size_t pos = pattern.find('/'); |
111 if (pattern.find('/', pos + 1) == pos + 1) | 125 if (pattern.find('/', pos + 1) == pos + 1) |
112 pos = pattern.find('/', pos + 2); | 126 pos = pattern.find('/', pos + 2); |
113 | 127 |
114 std::string host_pattern; | 128 std::string host_pattern; |
115 if (pos != std::string::npos) | 129 if (pos != std::string::npos) |
116 host_pattern = pattern.substr(0, pos); | 130 host_pattern = pattern.substr(0, pos); |
117 else | 131 else |
118 host_pattern = pattern; | 132 host_pattern = pattern; |
119 | 133 |
120 AddHostPatternToBypass(host_pattern); | 134 AddHostPatternToBypass(host_pattern); |
121 } | 135 } |
122 | 136 |
137 // static | |
138 bool DataReductionProxyChromeConfigurator::ContainsDataReductionProxy( | |
bengr
2014/10/28 21:03:41
Why can't you use DRPParams::IsDataReductionProxy?
Not at Google. Contact bengr
2014/10/28 22:31:44
Done.
| |
139 const std::string& server) { | |
140 data_reduction_proxy::DataReductionProxyParams params(0); | |
141 return HasProxy(server, params.origin()) || | |
142 HasProxy(server, params.fallback_origin()) || | |
143 HasProxy(server, params.alt_origin()) || | |
144 HasProxy(server, params.ssl_origin()); | |
145 } | |
146 | |
147 // static | |
148 bool DataReductionProxyChromeConfigurator::HasProxy(const std::string& server, | |
bengr
2014/10/28 21:03:41
I don't think you'll need this if you use the meth
Not at Google. Contact bengr
2014/10/28 22:31:44
Done.
| |
149 const GURL& proxy) { | |
150 std::string trimmed_proxy_url; | |
151 base::TrimString(proxy.spec(), "/", &trimmed_proxy_url); | |
152 return server.find(trimmed_proxy_url) != std::string::npos; | |
153 } | |
154 | |
123 void DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO( | 155 void DataReductionProxyChromeConfigurator::UpdateProxyConfigOnIO( |
124 const net::ProxyConfig& config) { | 156 const net::ProxyConfig& config) { |
125 config_ = config; | 157 config_ = config; |
126 } | 158 } |
127 | 159 |
128 const net::ProxyConfig& | 160 const net::ProxyConfig& |
129 DataReductionProxyChromeConfigurator::GetProxyConfigOnIO() const { | 161 DataReductionProxyChromeConfigurator::GetProxyConfigOnIO() const { |
130 return config_; | 162 return config_; |
131 } | 163 } |
OLD | NEW |