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

Side by Side Diff: chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.cc

Issue 1296663003: Componentize proxy code from chrome/browser/net (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updating for win p/f Created 5 years, 3 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 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_settings.h" 5 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/metrics/histogram_macros.h" 12 #include "base/metrics/histogram_macros.h"
13 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
14 #include "base/prefs/scoped_user_pref_update.h" 14 #include "base/prefs/scoped_user_pref_update.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" 18 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/profiles/profile_manager.h" 20 #include "chrome/browser/profiles/profile_manager.h"
21 #include "chrome/common/pref_names.h"
22 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_comp ression_stats.h" 21 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_comp ression_stats.h"
23 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf ig.h" 22 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf ig.h"
24 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d ata.h" 23 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d ata.h"
25 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv ice.h" 24 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_serv ice.h"
26 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h" 25 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett ings.h"
27 #include "components/data_reduction_proxy/core/browser/data_store.h" 26 #include "components/data_reduction_proxy/core/browser/data_store.h"
28 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h" 27 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s.h"
28 #include "components/proxy_config/proxy_config_pref_names.h"
29 #include "components/proxy_config/proxy_prefs.h" 29 #include "components/proxy_config/proxy_prefs.h"
30 #include "net/base/host_port_pair.h" 30 #include "net/base/host_port_pair.h"
31 #include "net/proxy/proxy_config.h" 31 #include "net/proxy/proxy_config.h"
32 #include "net/proxy/proxy_list.h" 32 #include "net/proxy/proxy_list.h"
33 #include "net/proxy/proxy_server.h" 33 #include "net/proxy/proxy_server.h"
34 #include "net/url_request/url_request_context_getter.h" 34 #include "net/url_request/url_request_context_getter.h"
35 35
36 namespace { 36 namespace {
37 37
38 // Assume that any proxy host ending with this suffix is a Data Reduction Proxy. 38 // Assume that any proxy host ending with this suffix is a Data Reduction Proxy.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 ProxyPrefMigrationResult proxy_pref_status = 87 ProxyPrefMigrationResult proxy_pref_status =
88 MigrateDataReductionProxyOffProxyPrefsHelper(prefs); 88 MigrateDataReductionProxyOffProxyPrefsHelper(prefs);
89 UMA_HISTOGRAM_ENUMERATION("DataReductionProxy.ProxyPrefMigrationResult", 89 UMA_HISTOGRAM_ENUMERATION("DataReductionProxy.ProxyPrefMigrationResult",
90 proxy_pref_status, 90 proxy_pref_status,
91 DataReductionProxyChromeSettings::PROXY_PREF_MAX); 91 DataReductionProxyChromeSettings::PROXY_PREF_MAX);
92 } 92 }
93 93
94 DataReductionProxyChromeSettings::ProxyPrefMigrationResult 94 DataReductionProxyChromeSettings::ProxyPrefMigrationResult
95 DataReductionProxyChromeSettings::MigrateDataReductionProxyOffProxyPrefsHelper( 95 DataReductionProxyChromeSettings::MigrateDataReductionProxyOffProxyPrefsHelper(
96 PrefService* prefs) { 96 PrefService* prefs) {
97 base::DictionaryValue* dict = 97 base::DictionaryValue* dict = (base::DictionaryValue*)prefs->GetUserPrefValue(
98 (base::DictionaryValue*)prefs->GetUserPrefValue(prefs::kProxy); 98 proxy_config::prefs::kProxy);
99 if (!dict) 99 if (!dict)
100 return PROXY_PREF_NOT_CLEARED; 100 return PROXY_PREF_NOT_CLEARED;
101 101
102 // Clear empty "proxy" dictionary created by a bug. See http://crbug/448172. 102 // Clear empty "proxy" dictionary created by a bug. See http://crbug/448172.
103 if (dict->empty()) { 103 if (dict->empty()) {
104 prefs->ClearPref(prefs::kProxy); 104 prefs->ClearPref(proxy_config::prefs::kProxy);
105 return PROXY_PREF_CLEARED_EMPTY; 105 return PROXY_PREF_CLEARED_EMPTY;
106 } 106 }
107 107
108 std::string mode; 108 std::string mode;
109 if (!dict->GetString("mode", &mode)) 109 if (!dict->GetString("mode", &mode))
110 return PROXY_PREF_NOT_CLEARED; 110 return PROXY_PREF_NOT_CLEARED;
111 // Clear "system" proxy entry since this is the default. This entry was 111 // Clear "system" proxy entry since this is the default. This entry was
112 // created by bug (http://crbug/448172). 112 // created by bug (http://crbug/448172).
113 if (ProxyModeToString(ProxyPrefs::MODE_SYSTEM) == mode) { 113 if (ProxyModeToString(ProxyPrefs::MODE_SYSTEM) == mode) {
114 prefs->ClearPref(prefs::kProxy); 114 prefs->ClearPref(proxy_config::prefs::kProxy);
115 return PROXY_PREF_CLEARED_MODE_SYSTEM; 115 return PROXY_PREF_CLEARED_MODE_SYSTEM;
116 } 116 }
117 117
118 // From M36 to M40, the DRP was configured using MODE_FIXED_SERVERS in the 118 // From M36 to M40, the DRP was configured using MODE_FIXED_SERVERS in the
119 // proxy pref. 119 // proxy pref.
120 if (ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS) == mode) { 120 if (ProxyModeToString(ProxyPrefs::MODE_FIXED_SERVERS) == mode) {
121 std::string proxy_server; 121 std::string proxy_server;
122 if (!dict->GetString("server", &proxy_server)) 122 if (!dict->GetString("server", &proxy_server))
123 return PROXY_PREF_NOT_CLEARED; 123 return PROXY_PREF_NOT_CLEARED;
124 net::ProxyConfig::ProxyRules proxy_rules; 124 net::ProxyConfig::ProxyRules proxy_rules;
125 proxy_rules.ParseFromString(proxy_server); 125 proxy_rules.ParseFromString(proxy_server);
126 // Clear the proxy pref if it matches a currently configured Data Reduction 126 // Clear the proxy pref if it matches a currently configured Data Reduction
127 // Proxy, or if the proxy host ends with ".googlezip.net", in order to 127 // Proxy, or if the proxy host ends with ".googlezip.net", in order to
128 // ensure that any DRP in the pref is cleared even if the DRP configuration 128 // ensure that any DRP in the pref is cleared even if the DRP configuration
129 // was changed. See http://crbug.com/476610. 129 // was changed. See http://crbug.com/476610.
130 ProxyPrefMigrationResult rv; 130 ProxyPrefMigrationResult rv;
131 if (Config()->ContainsDataReductionProxy(proxy_rules)) 131 if (Config()->ContainsDataReductionProxy(proxy_rules))
132 rv = PROXY_PREF_CLEARED_DRP; 132 rv = PROXY_PREF_CLEARED_DRP;
133 else if (ContainsDataReductionProxyDefaultHostSuffix(proxy_rules)) 133 else if (ContainsDataReductionProxyDefaultHostSuffix(proxy_rules))
134 rv = PROXY_PREF_CLEARED_GOOGLEZIP; 134 rv = PROXY_PREF_CLEARED_GOOGLEZIP;
135 else 135 else
136 return PROXY_PREF_NOT_CLEARED; 136 return PROXY_PREF_NOT_CLEARED;
137 137
138 prefs->ClearPref(prefs::kProxy); 138 prefs->ClearPref(proxy_config::prefs::kProxy);
139 return rv; 139 return rv;
140 } 140 }
141 141
142 // Before M35, the DRP was configured using a PAC script base64 encoded into a 142 // Before M35, the DRP was configured using a PAC script base64 encoded into a
143 // PAC url. 143 // PAC url.
144 if (ProxyModeToString(ProxyPrefs::MODE_PAC_SCRIPT) == mode) { 144 if (ProxyModeToString(ProxyPrefs::MODE_PAC_SCRIPT) == mode) {
145 std::string pac_url; 145 std::string pac_url;
146 std::string pac_script; 146 std::string pac_script;
147 if (!dict->GetString("pac_url", &pac_url) || 147 if (!dict->GetString("pac_url", &pac_url) ||
148 !GetEmbeddedPacScript(pac_url, &pac_script)) { 148 !GetEmbeddedPacScript(pac_url, &pac_script)) {
149 return PROXY_PREF_NOT_CLEARED; 149 return PROXY_PREF_NOT_CLEARED;
150 } 150 }
151 151
152 // In M35 and earlier, the way of specifying the DRP in a PAC script would 152 // In M35 and earlier, the way of specifying the DRP in a PAC script would
153 // always include the port number after the host even if the port number 153 // always include the port number after the host even if the port number
154 // could be implied, so searching for ".googlezip.net:" in the PAC script 154 // could be implied, so searching for ".googlezip.net:" in the PAC script
155 // indicates whether there's a proxy in that PAC script with a host of the 155 // indicates whether there's a proxy in that PAC script with a host of the
156 // form "*.googlezip.net". 156 // form "*.googlezip.net".
157 if (pac_script.find(".googlezip.net:") == std::string::npos) 157 if (pac_script.find(".googlezip.net:") == std::string::npos)
158 return PROXY_PREF_NOT_CLEARED; 158 return PROXY_PREF_NOT_CLEARED;
159 159
160 prefs->ClearPref(prefs::kProxy); 160 prefs->ClearPref(proxy_config::prefs::kProxy);
161 return PROXY_PREF_CLEARED_PAC_GOOGLEZIP; 161 return PROXY_PREF_CLEARED_PAC_GOOGLEZIP;
162 } 162 }
163 163
164 return PROXY_PREF_NOT_CLEARED; 164 return PROXY_PREF_NOT_CLEARED;
165 } 165 }
166 166
167 DataReductionProxyChromeSettings::DataReductionProxyChromeSettings() 167 DataReductionProxyChromeSettings::DataReductionProxyChromeSettings()
168 : data_reduction_proxy::DataReductionProxySettings() { 168 : data_reduction_proxy::DataReductionProxySettings() {
169 } 169 }
170 170
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 #elif defined(OS_OPENBSD) 230 #elif defined(OS_OPENBSD)
231 return data_reduction_proxy::Client::CHROME_OPENBSD; 231 return data_reduction_proxy::Client::CHROME_OPENBSD;
232 #elif defined(OS_SOLARIS) 232 #elif defined(OS_SOLARIS)
233 return data_reduction_proxy::Client::CHROME_SOLARIS; 233 return data_reduction_proxy::Client::CHROME_SOLARIS;
234 #elif defined(OS_QNX) 234 #elif defined(OS_QNX)
235 return data_reduction_proxy::Client::CHROME_QNX; 235 return data_reduction_proxy::Client::CHROME_QNX;
236 #else 236 #else
237 return data_reduction_proxy::Client::UNKNOWN; 237 return data_reduction_proxy::Client::UNKNOWN;
238 #endif 238 #endif
239 } 239 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698