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_settings.h" | 5 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/prefs/scoped_user_pref_update.h" | 9 #include "base/prefs/scoped_user_pref_update.h" |
| 10 #include "base/time/time.h" |
10 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | 12 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
12 #include "chrome/browser/prefs/proxy_prefs.h" | 13 #include "chrome/browser/prefs/proxy_prefs.h" |
13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
15 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
16 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
igurator.h" | 17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
igurator.h" |
17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d
ata.h" | 18 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d
ata.h" |
18 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett
ings.h" | 19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_sett
ings.h" |
19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_stat
istics_prefs.h" | 20 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_stat
istics_prefs.h" |
| 21 #include "components/data_reduction_proxy/core/browser/data_saver_service.h" |
20 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s.h" | 22 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s.h" |
21 #include "net/url_request/url_request_context_getter.h" | 23 #include "net/url_request/url_request_context_getter.h" |
22 | 24 |
23 using data_reduction_proxy::Client; | 25 using data_reduction_proxy::Client; |
24 using data_reduction_proxy::DataReductionProxyParams; | 26 using data_reduction_proxy::DataReductionProxyParams; |
25 using data_reduction_proxy::DataReductionProxySettings; | 27 using data_reduction_proxy::DataReductionProxySettings; |
26 | 28 |
27 // The Data Reduction Proxy has been turned into a "best effort" proxy, | 29 // The Data Reduction Proxy has been turned into a "best effort" proxy, |
28 // meaning it is used only if the effective proxy configuration resolves to | 30 // meaning it is used only if the effective proxy configuration resolves to |
29 // DIRECT for a URL. It no longer can be a ProxyConfig in the proxy preference | 31 // DIRECT for a URL. It no longer can be a ProxyConfig in the proxy preference |
(...skipping 21 matching lines...) Expand all Loading... |
51 return; | 53 return; |
52 net::ProxyConfig::ProxyRules proxy_rules; | 54 net::ProxyConfig::ProxyRules proxy_rules; |
53 proxy_rules.ParseFromString(proxy_server); | 55 proxy_rules.ParseFromString(proxy_server); |
54 if (!data_reduction_proxy::DataReductionProxyConfigurator:: | 56 if (!data_reduction_proxy::DataReductionProxyConfigurator:: |
55 ContainsDataReductionProxy(proxy_rules)) { | 57 ContainsDataReductionProxy(proxy_rules)) { |
56 return; | 58 return; |
57 } | 59 } |
58 prefs->ClearPref(prefs::kProxy); | 60 prefs->ClearPref(prefs::kProxy); |
59 } | 61 } |
60 | 62 |
61 DataReductionProxyChromeSettings::DataReductionProxyChromeSettings( | 63 DataReductionProxyChromeSettings::DataReductionProxyChromeSettings() |
62 scoped_ptr<DataReductionProxyParams> params) | 64 : DataReductionProxySettings() { |
63 : DataReductionProxySettings(params.Pass()) { | |
64 } | 65 } |
65 | 66 |
66 DataReductionProxyChromeSettings::~DataReductionProxyChromeSettings() { | 67 DataReductionProxyChromeSettings::~DataReductionProxyChromeSettings() { |
67 } | 68 } |
68 | 69 |
| 70 void DataReductionProxyChromeSettings::Shutdown() { |
| 71 SaverService()->Shutdown(); |
| 72 } |
| 73 |
69 void DataReductionProxyChromeSettings::InitDataReductionProxySettings( | 74 void DataReductionProxyChromeSettings::InitDataReductionProxySettings( |
70 data_reduction_proxy::DataReductionProxyIOData* io_data, | 75 data_reduction_proxy::DataReductionProxyIOData* io_data, |
71 PrefService* profile_prefs, | 76 PrefService* profile_prefs, |
72 PrefService* local_state_prefs, | 77 net::URLRequestContextGetter* request_context, |
73 net::URLRequestContextGetter* request_context) { | 78 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner) { |
74 SetProxyConfigurator(io_data->configurator()); | 79 #if defined(OS_ANDROID) || defined(OS_IOS) |
| 80 // On mobile we write data reduction proxy prefs directly to the pref service. |
| 81 // On desktop we store data reduction proxy prefs in memory, writing to disk |
| 82 // every 60 minutes and on termination. Shutdown hooks must be added for |
| 83 // Android and iOS in order for non-zero delays to be supported. |
| 84 // (http://crbug.com/408264) |
| 85 base::TimeDelta commit_delay = base::TimeDelta(); |
| 86 #else |
| 87 base::TimeDelta commit_delay = base::TimeDelta::FromMinutes(60); |
| 88 #endif |
| 89 |
| 90 scoped_ptr<data_reduction_proxy::DataReductionProxyStatisticsPrefs> |
| 91 statistics_prefs = make_scoped_ptr( |
| 92 new data_reduction_proxy::DataReductionProxyStatisticsPrefs( |
| 93 profile_prefs, ui_task_runner, commit_delay)); |
| 94 scoped_ptr<data_reduction_proxy::DataSaverService> data_saver_service = |
| 95 make_scoped_ptr(new data_reduction_proxy::DataSaverService( |
| 96 statistics_prefs.Pass(), this, request_context)); |
75 DataReductionProxySettings::InitDataReductionProxySettings( | 97 DataReductionProxySettings::InitDataReductionProxySettings( |
76 profile_prefs, | 98 profile_prefs, io_data, data_saver_service.Pass()); |
77 io_data->PassStatisticsPrefs(), | 99 io_data->SetDataSaverService(SaverService()->GetWeakPtr()); |
78 request_context, | 100 |
79 io_data->net_log(), | |
80 io_data->event_store()); | |
81 DataReductionProxySettings::SetOnDataReductionEnabledCallback( | 101 DataReductionProxySettings::SetOnDataReductionEnabledCallback( |
82 base::Bind(&DataReductionProxyChromeSettings::RegisterSyntheticFieldTrial, | 102 base::Bind(&DataReductionProxyChromeSettings::RegisterSyntheticFieldTrial, |
83 base::Unretained(this))); | 103 base::Unretained(this))); |
84 SetDataReductionProxyAlternativeEnabled( | 104 SetDataReductionProxyAlternativeEnabled( |
85 DataReductionProxyParams::IsIncludedInAlternativeFieldTrial()); | 105 DataReductionProxyParams::IsIncludedInAlternativeFieldTrial()); |
86 // TODO(bengr): Remove after M46. See http://crbug.com/445599. | 106 // TODO(bengr): Remove after M46. See http://crbug.com/445599. |
87 MigrateDataReductionProxyOffProxyPrefs(profile_prefs); | 107 MigrateDataReductionProxyOffProxyPrefs(profile_prefs); |
88 } | 108 } |
89 | 109 |
90 void DataReductionProxyChromeSettings::RegisterSyntheticFieldTrial( | 110 void DataReductionProxyChromeSettings::RegisterSyntheticFieldTrial( |
(...skipping 22 matching lines...) Expand all Loading... |
113 #elif defined(OS_OPENBSD) | 133 #elif defined(OS_OPENBSD) |
114 return Client::CHROME_OPENBSD; | 134 return Client::CHROME_OPENBSD; |
115 #elif defined(OS_SOLARIS) | 135 #elif defined(OS_SOLARIS) |
116 return Client::CHROME_SOLARIS; | 136 return Client::CHROME_SOLARIS; |
117 #elif defined(OS_QNX) | 137 #elif defined(OS_QNX) |
118 return Client::CHROME_QNX; | 138 return Client::CHROME_QNX; |
119 #else | 139 #else |
120 return Client::UNKNOWN; | 140 return Client::UNKNOWN; |
121 #endif | 141 #endif |
122 } | 142 } |
OLD | NEW |