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 "components/data_reduction_proxy/browser/data_reduction_proxy_settings.
h" | 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings.
h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 prefs::kDataReductionProxyAltEnabled, | 114 prefs::kDataReductionProxyAltEnabled, |
115 GetOriginalProfilePrefs(), | 115 GetOriginalProfilePrefs(), |
116 base::Bind( | 116 base::Bind( |
117 &DataReductionProxySettings::OnProxyAlternativeEnabledPrefChange, | 117 &DataReductionProxySettings::OnProxyAlternativeEnabledPrefChange, |
118 base::Unretained(this))); | 118 base::Unretained(this))); |
119 } | 119 } |
120 | 120 |
121 void DataReductionProxySettings::InitDataReductionProxySettings( | 121 void DataReductionProxySettings::InitDataReductionProxySettings( |
122 PrefService* prefs, | 122 PrefService* prefs, |
123 PrefService* local_state_prefs, | 123 PrefService* local_state_prefs, |
124 net::URLRequestContextGetter* url_request_context_getter) { | 124 net::URLRequestContextGetter* url_request_context_getter, |
| 125 const base::Callback<void(bool)>& on_data_reduction_proxy_enabled) { |
125 DCHECK(thread_checker_.CalledOnValidThread()); | 126 DCHECK(thread_checker_.CalledOnValidThread()); |
126 DCHECK(prefs); | 127 DCHECK(prefs); |
127 DCHECK(local_state_prefs); | 128 DCHECK(local_state_prefs); |
128 DCHECK(url_request_context_getter); | 129 DCHECK(url_request_context_getter); |
129 prefs_ = prefs; | 130 prefs_ = prefs; |
130 local_state_prefs_ = local_state_prefs; | 131 local_state_prefs_ = local_state_prefs; |
131 url_request_context_getter_ = url_request_context_getter; | 132 url_request_context_getter_ = url_request_context_getter; |
| 133 on_data_reduction_proxy_enabled_ = on_data_reduction_proxy_enabled; |
132 InitPrefMembers(); | 134 InitPrefMembers(); |
133 RecordDataReductionInit(); | 135 RecordDataReductionInit(); |
| 136 |
| 137 on_data_reduction_proxy_enabled_.Run(IsDataReductionProxyEnabled()); |
| 138 |
134 // Disable the proxy if it is not allowed to be used. | 139 // Disable the proxy if it is not allowed to be used. |
135 if (!params_->allowed()) | 140 if (!params_->allowed()) |
136 return; | 141 return; |
137 | 142 |
138 AddDefaultProxyBypassRules(); | 143 AddDefaultProxyBypassRules(); |
139 net::NetworkChangeNotifier::AddIPAddressObserver(this); | 144 net::NetworkChangeNotifier::AddIPAddressObserver(this); |
140 | 145 |
141 // We set or reset the proxy pref at startup. | 146 // We set or reset the proxy pref at startup. |
142 MaybeActivateDataReductionProxy(true); | 147 MaybeActivateDataReductionProxy(true); |
143 } | 148 } |
144 | 149 |
145 void DataReductionProxySettings::InitDataReductionProxySettings( | 150 void DataReductionProxySettings::InitDataReductionProxySettings( |
146 PrefService* prefs, | 151 PrefService* prefs, |
147 PrefService* local_state_prefs, | 152 PrefService* local_state_prefs, |
148 net::URLRequestContextGetter* url_request_context_getter, | 153 net::URLRequestContextGetter* url_request_context_getter, |
149 scoped_ptr<DataReductionProxyConfigurator> configurator) { | 154 scoped_ptr<DataReductionProxyConfigurator> configurator, |
| 155 const base::Callback<void(bool)>& on_data_reduction_proxy_enabled) { |
150 InitDataReductionProxySettings(prefs, | 156 InitDataReductionProxySettings(prefs, |
151 local_state_prefs, | 157 local_state_prefs, |
152 url_request_context_getter); | 158 url_request_context_getter, |
| 159 on_data_reduction_proxy_enabled); |
153 SetProxyConfigurator(configurator.Pass()); | 160 SetProxyConfigurator(configurator.Pass()); |
154 } | 161 } |
155 | 162 |
156 void DataReductionProxySettings::SetProxyConfigurator( | 163 void DataReductionProxySettings::SetProxyConfigurator( |
157 scoped_ptr<DataReductionProxyConfigurator> configurator) { | 164 scoped_ptr<DataReductionProxyConfigurator> configurator) { |
158 DCHECK(configurator); | 165 DCHECK(configurator); |
159 configurator_ = configurator.Pass(); | 166 configurator_ = configurator.Pass(); |
160 } | 167 } |
161 | 168 |
162 bool DataReductionProxySettings::IsDataReductionProxyEnabled() { | 169 bool DataReductionProxySettings::IsDataReductionProxyEnabled() { |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 RecordNetworkChangeEvent(IP_CHANGED); | 358 RecordNetworkChangeEvent(IP_CHANGED); |
352 if (DisableIfVPN()) | 359 if (DisableIfVPN()) |
353 return; | 360 return; |
354 ProbeWhetherDataReductionProxyIsAvailable(); | 361 ProbeWhetherDataReductionProxyIsAvailable(); |
355 WarmProxyConnection(); | 362 WarmProxyConnection(); |
356 } | 363 } |
357 } | 364 } |
358 | 365 |
359 void DataReductionProxySettings::OnProxyEnabledPrefChange() { | 366 void DataReductionProxySettings::OnProxyEnabledPrefChange() { |
360 DCHECK(thread_checker_.CalledOnValidThread()); | 367 DCHECK(thread_checker_.CalledOnValidThread()); |
| 368 on_data_reduction_proxy_enabled_.Run(IsDataReductionProxyEnabled()); |
361 if (!params_->allowed()) | 369 if (!params_->allowed()) |
362 return; | 370 return; |
363 MaybeActivateDataReductionProxy(false); | 371 MaybeActivateDataReductionProxy(false); |
364 } | 372 } |
365 | 373 |
366 void DataReductionProxySettings::OnProxyAlternativeEnabledPrefChange() { | 374 void DataReductionProxySettings::OnProxyAlternativeEnabledPrefChange() { |
367 DCHECK(thread_checker_.CalledOnValidThread()); | 375 DCHECK(thread_checker_.CalledOnValidThread()); |
368 if (!params_->alternative_allowed()) | 376 if (!params_->alternative_allowed()) |
369 return; | 377 return; |
370 MaybeActivateDataReductionProxy(false); | 378 MaybeActivateDataReductionProxy(false); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 SetProxyConfigs(enabled_by_user_, | 611 SetProxyConfigs(enabled_by_user_, |
604 IsDataReductionProxyAlternativeEnabled(), | 612 IsDataReductionProxyAlternativeEnabled(), |
605 restricted_by_carrier_, | 613 restricted_by_carrier_, |
606 false); | 614 false); |
607 } | 615 } |
608 disabled_on_vpn_ = false; | 616 disabled_on_vpn_ = false; |
609 return false; | 617 return false; |
610 } | 618 } |
611 | 619 |
612 } // namespace data_reduction_proxy | 620 } // namespace data_reduction_proxy |
OLD | NEW |