OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_settings_android.h" | 5 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.h" |
6 | 6 |
7 #include "base/android/build_info.h" | 7 #include "base/android/build_info.h" |
8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/prefs/pref_member.h" | 14 #include "base/prefs/pref_member.h" |
15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
16 #include "base/prefs/scoped_user_pref_update.h" | 16 #include "base/prefs/scoped_user_pref_update.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
19 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
21 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
22 #include "chrome/browser/prefs/proxy_prefs.h" | 22 #include "chrome/browser/prefs/proxy_prefs.h" |
23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/profiles/profile_manager.h" | 24 #include "chrome/browser/profiles/profile_manager.h" |
25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
27 #include "content/public/browser/user_metrics.h" | |
mmenke
2013/11/06 19:24:03
This isn't used.
bengr
2013/11/06 19:44:11
Done.
| |
27 #include "jni/DataReductionProxySettings_jni.h" | 28 #include "jni/DataReductionProxySettings_jni.h" |
28 #include "net/base/auth.h" | 29 #include "net/base/auth.h" |
29 #include "net/base/host_port_pair.h" | 30 #include "net/base/host_port_pair.h" |
30 #include "net/base/load_flags.h" | 31 #include "net/base/load_flags.h" |
31 #include "net/base/net_errors.h" | 32 #include "net/base/net_errors.h" |
32 #include "net/url_request/url_fetcher.h" | 33 #include "net/url_request/url_fetcher.h" |
33 #include "net/url_request/url_fetcher_delegate.h" | 34 #include "net/url_request/url_fetcher_delegate.h" |
34 #include "net/url_request/url_request_status.h" | 35 #include "net/url_request/url_request_status.h" |
35 #include "url/gurl.h" | 36 #include "url/gurl.h" |
36 | 37 |
37 using base::android::CheckException; | 38 using base::android::CheckException; |
38 using base::android::ConvertJavaStringToUTF8; | 39 using base::android::ConvertJavaStringToUTF8; |
39 using base::android::ConvertUTF16ToJavaString; | 40 using base::android::ConvertUTF16ToJavaString; |
40 using base::android::ConvertUTF8ToJavaString; | 41 using base::android::ConvertUTF8ToJavaString; |
41 using base::android::ScopedJavaLocalRef; | 42 using base::android::ScopedJavaLocalRef; |
42 using base::StringPrintf; | 43 using base::StringPrintf; |
44 using content::RecordAction; | |
45 using content::UserMetricsAction; | |
mmenke
2013/11/06 19:24:03
These aren't used.
bengr
2013/11/06 19:44:11
Done.
| |
43 | 46 |
44 namespace { | 47 namespace { |
45 | 48 |
46 // The C++ definition of enum SpdyProxyAuthState defined in | 49 // The C++ definition of enum SpdyProxyAuthState defined in |
47 // tools/histograms/histograms.xml. | 50 // tools/histograms/histograms.xml. |
48 // New values should be added at the end before |NUM_SPDY_PROXY_AUTH_STATE|. | 51 // New values should be added at the end before |NUM_SPDY_PROXY_AUTH_STATE|. |
49 enum { | 52 enum { |
50 CHROME_STARTUP, | 53 CHROME_STARTUP, |
51 SPDY_PROXY_AUTH_ON_AT_STARTUP, | 54 SPDY_PROXY_AUTH_ON_AT_STARTUP, |
52 SPDY_PROXY_AUTH_ON_BY_USER, | 55 SPDY_PROXY_AUTH_ON_BY_USER, |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 JNIEnv* env, jobject obj) { | 200 JNIEnv* env, jobject obj) { |
198 return GetDailyContentLengths(env, prefs::kDailyHttpReceivedContentLength); | 201 return GetDailyContentLengths(env, prefs::kDailyHttpReceivedContentLength); |
199 } | 202 } |
200 | 203 |
201 // static | 204 // static |
202 bool DataReductionProxySettingsAndroid::Register(JNIEnv* env) { | 205 bool DataReductionProxySettingsAndroid::Register(JNIEnv* env) { |
203 bool register_natives_impl_result = RegisterNativesImpl(env); | 206 bool register_natives_impl_result = RegisterNativesImpl(env); |
204 return register_natives_impl_result; | 207 return register_natives_impl_result; |
205 } | 208 } |
206 | 209 |
207 // Metrics methods -- obsolete; see crbug/241518 | |
208 void DataReductionProxySettingsAndroid::RecordDataReductionInit() { | |
209 UMA_HISTOGRAM_ENUMERATION("SpdyProxyAuth.State", CHROME_STARTUP, | |
210 NUM_SPDY_PROXY_AUTH_STATE); | |
211 } | |
212 | |
213 void DataReductionProxySettingsAndroid::AddDefaultProxyBypassRules() { | 210 void DataReductionProxySettingsAndroid::AddDefaultProxyBypassRules() { |
214 DataReductionProxySettings::AddDefaultProxyBypassRules(); | 211 DataReductionProxySettings::AddDefaultProxyBypassRules(); |
215 | 212 |
216 // TODO(bengr): See http://crbug.com/169959. For some reason the data | 213 // TODO(bengr): See http://crbug.com/169959. For some reason the data |
217 // reduction proxy is breaking the omnibox SearchProvider. Remove this rule | 214 // reduction proxy is breaking the omnibox SearchProvider. Remove this rule |
218 // when this is fixed. | 215 // when this is fixed. |
219 AddURLPatternToBypass("http://www.google.com/complete/search*"); | 216 AddURLPatternToBypass("http://www.google.com/complete/search*"); |
220 } | 217 } |
221 | 218 |
222 void DataReductionProxySettingsAndroid::SetProxyConfigs(bool enabled, | 219 void DataReductionProxySettingsAndroid::SetProxyConfigs(bool enabled, |
223 bool at_startup) { | 220 bool at_startup) { |
224 // Keys duplicated from proxy_config_dictionary.cc | 221 // Keys duplicated from proxy_config_dictionary.cc |
225 // TODO(bengr): Move these to proxy_config_dictionary.h and reuse them here. | 222 // TODO(bengr): Move these to proxy_config_dictionary.h and reuse them here. |
226 const char kProxyMode[] = "mode"; | 223 const char kProxyMode[] = "mode"; |
227 const char kProxyPacURL[] = "pac_url"; | 224 const char kProxyPacURL[] = "pac_url"; |
228 const char kProxyBypassList[] = "bypass_list"; | 225 const char kProxyBypassList[] = "bypass_list"; |
229 | 226 |
230 LogProxyState(enabled, at_startup); | 227 LogProxyState(enabled, at_startup); |
231 | 228 |
232 PrefService* prefs = GetOriginalProfilePrefs(); | 229 PrefService* prefs = GetOriginalProfilePrefs(); |
233 DCHECK(prefs); | 230 DCHECK(prefs); |
234 DictionaryPrefUpdate update(prefs, prefs::kProxy); | 231 DictionaryPrefUpdate update(prefs, prefs::kProxy); |
235 base::DictionaryValue* dict = update.Get(); | 232 base::DictionaryValue* dict = update.Get(); |
236 // TODO(marq): All of the UMA in here are obsolete. | |
237 if (enabled) { | 233 if (enabled) { |
238 // Convert to a data URI and update the PAC settings. | 234 // Convert to a data URI and update the PAC settings. |
239 std::string base64_pac; | 235 std::string base64_pac; |
240 base::Base64Encode(GetProxyPacScript(), &base64_pac); | 236 base::Base64Encode(GetProxyPacScript(), &base64_pac); |
241 | 237 |
242 dict->SetString(kProxyPacURL, | 238 dict->SetString(kProxyPacURL, |
243 "data:application/x-ns-proxy-autoconfig;base64," + | 239 "data:application/x-ns-proxy-autoconfig;base64," + |
244 base64_pac); | 240 base64_pac); |
245 dict->SetString(kProxyMode, | 241 dict->SetString(kProxyMode, |
246 ProxyModeToString(ProxyPrefs::MODE_PAC_SCRIPT)); | 242 ProxyModeToString(ProxyPrefs::MODE_PAC_SCRIPT)); |
247 dict->SetString(kProxyBypassList, JoinString(BypassRules(), ", ")); | 243 dict->SetString(kProxyBypassList, JoinString(BypassRules(), ", ")); |
248 | 244 |
249 if (at_startup) { | |
250 UMA_HISTOGRAM_ENUMERATION("SpdyProxyAuth.State", | |
251 SPDY_PROXY_AUTH_ON_AT_STARTUP, | |
252 NUM_SPDY_PROXY_AUTH_STATE); | |
253 } else if (!DataReductionProxySettings::HasTurnedOn()) { | |
254 // SPDY proxy auth is turned on by user action for the first time in | |
255 // this session. | |
256 UMA_HISTOGRAM_ENUMERATION("SpdyProxyAuth.State", | |
257 SPDY_PROXY_AUTH_ON_BY_USER, | |
258 NUM_SPDY_PROXY_AUTH_STATE); | |
259 DataReductionProxySettings::SetHasTurnedOn(); | |
mmenke
2013/11/06 19:24:03
If these methods aren't being used any more, they
bengr
2013/11/06 19:44:11
Done.
| |
260 } | |
261 } else { | 245 } else { |
262 dict->SetString(kProxyMode, ProxyModeToString(ProxyPrefs::MODE_SYSTEM)); | 246 dict->SetString(kProxyMode, ProxyModeToString(ProxyPrefs::MODE_SYSTEM)); |
263 dict->SetString(kProxyPacURL, ""); | 247 dict->SetString(kProxyPacURL, ""); |
264 dict->SetString(kProxyBypassList, ""); | 248 dict->SetString(kProxyBypassList, ""); |
265 | |
266 if (!at_startup && !DataReductionProxySettings::HasTurnedOff()) { | |
267 UMA_HISTOGRAM_ENUMERATION("SpdyProxyAuth.State", | |
268 SPDY_PROXY_AUTH_OFF_BY_USER, | |
269 NUM_SPDY_PROXY_AUTH_STATE); | |
270 DataReductionProxySettings::SetHasTurnedOff(); | |
271 } | |
272 } | 249 } |
273 } | 250 } |
274 | 251 |
275 ScopedJavaLocalRef<jlongArray> | 252 ScopedJavaLocalRef<jlongArray> |
276 DataReductionProxySettingsAndroid::GetDailyContentLengths( | 253 DataReductionProxySettingsAndroid::GetDailyContentLengths( |
277 JNIEnv* env, const char* pref_name) { | 254 JNIEnv* env, const char* pref_name) { |
278 jlongArray result = env->NewLongArray(spdyproxy::kNumDaysInHistory); | 255 jlongArray result = env->NewLongArray(spdyproxy::kNumDaysInHistory); |
279 | 256 |
280 DataReductionProxySettings::ContentLengthList lengths = | 257 DataReductionProxySettings::ContentLengthList lengths = |
281 DataReductionProxySettings::GetDailyContentLengths(pref_name); | 258 DataReductionProxySettings::GetDailyContentLengths(pref_name); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 "}"; | 292 "}"; |
316 return pac; | 293 return pac; |
317 } | 294 } |
318 | 295 |
319 // Used by generated jni code. | 296 // Used by generated jni code. |
320 static jint Init(JNIEnv* env, jobject obj) { | 297 static jint Init(JNIEnv* env, jobject obj) { |
321 DataReductionProxySettingsAndroid* settings = | 298 DataReductionProxySettingsAndroid* settings = |
322 new DataReductionProxySettingsAndroid(env, obj); | 299 new DataReductionProxySettingsAndroid(env, obj); |
323 return reinterpret_cast<jint>(settings); | 300 return reinterpret_cast<jint>(settings); |
324 } | 301 } |
OLD | NEW |