OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/chromeos/arc/arc_settings_service.h" | 5 #include "chrome/browser/chromeos/arc/arc_settings_service.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/gtest_prod_util.h" | 9 #include "base/gtest_prod_util.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/browser_process.h" | |
13 #include "chrome/browser/chromeos/arc/arc_auth_service.h" | 14 #include "chrome/browser/chromeos/arc/arc_auth_service.h" |
15 #include "chrome/browser/chromeos/net/proxy_config_handler.h" | |
16 #include "chrome/browser/chromeos/proxy_config_service_impl.h" | |
14 #include "chrome/browser/chromeos/settings/cros_settings.h" | 17 #include "chrome/browser/chromeos/settings/cros_settings.h" |
15 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
16 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
20 #include "chromeos/network/network_handler.h" | |
21 #include "chromeos/network/network_state.h" | |
22 #include "chromeos/network/network_state_handler.h" | |
23 #include "chromeos/network/network_state_handler_observer.h" | |
17 #include "chromeos/settings/cros_settings_names.h" | 24 #include "chromeos/settings/cros_settings_names.h" |
18 #include "chromeos/settings/timezone_settings.h" | 25 #include "chromeos/settings/timezone_settings.h" |
19 #include "components/arc/intent_helper/font_size_util.h" | 26 #include "components/arc/intent_helper/font_size_util.h" |
20 #include "components/prefs/pref_change_registrar.h" | 27 #include "components/prefs/pref_change_registrar.h" |
21 #include "components/prefs/pref_service.h" | 28 #include "components/prefs/pref_service.h" |
29 #include "components/proxy_config/pref_proxy_config_tracker_impl.h" | |
22 #include "components/proxy_config/proxy_config_dictionary.h" | 30 #include "components/proxy_config/proxy_config_dictionary.h" |
23 #include "components/proxy_config/proxy_config_pref_names.h" | 31 #include "components/proxy_config/proxy_config_pref_names.h" |
24 #include "device/bluetooth/bluetooth_adapter.h" | 32 #include "device/bluetooth/bluetooth_adapter.h" |
25 #include "device/bluetooth/bluetooth_adapter_factory.h" | 33 #include "device/bluetooth/bluetooth_adapter_factory.h" |
26 #include "net/proxy/proxy_config.h" | 34 #include "net/proxy/proxy_config.h" |
27 | 35 |
28 using ::chromeos::CrosSettings; | 36 using ::chromeos::CrosSettings; |
29 using ::chromeos::system::TimezoneSettings; | 37 using ::chromeos::system::TimezoneSettings; |
30 | 38 |
31 namespace { | 39 namespace { |
32 | 40 |
33 bool GetHttpProxyServer(const ProxyConfigDictionary& proxy_config_dict, | 41 std::unique_ptr<ProxyConfigDictionary> GetProxyConfig( |
42 const chromeos::NetworkState* network) { | |
43 Profile* profile = ProfileManager::GetActiveUserProfile(); | |
44 | |
45 // Apply Pref Proxy configuration if available. | |
46 net::ProxyConfig pref_proxy_config; | |
47 ProxyPrefs::ConfigState pref_state = | |
48 PrefProxyConfigTrackerImpl::ReadPrefConfig(profile->GetPrefs(), | |
49 &pref_proxy_config); | |
50 if (PrefProxyConfigTrackerImpl::PrefPrecedes(pref_state)) { | |
51 const PrefService::Preference* const pref = | |
52 profile->GetPrefs()->FindPreference(proxy_config::prefs::kProxy); | |
53 const base::DictionaryValue* proxy_config_value; | |
54 bool value_exists = pref->GetValue()->GetAsDictionary(&proxy_config_value); | |
55 DCHECK(value_exists); | |
56 | |
57 return base::MakeUnique<ProxyConfigDictionary>(proxy_config_value); | |
58 } | |
59 | |
60 // Apply network proxy configuration. | |
61 onc::ONCSource onc_source; | |
62 std::unique_ptr<ProxyConfigDictionary> proxy_config = | |
63 chromeos::proxy_config::GetProxyConfigForNetwork( | |
64 profile->GetPrefs(), g_browser_process->local_state(), *network, | |
65 &onc_source); | |
66 if (chromeos::ProxyConfigServiceImpl::IgnoreProxy( | |
67 profile->GetPrefs(), network->profile_path(), onc_source)) { | |
stevenjb
2016/09/02 16:20:55
Can we put this logic into proxy_config_service_im
Polina Bondarenko
2016/09/05 20:08:45
Moved all logic to ProxyConfigServiceImpl and remo
| |
68 return base::MakeUnique<ProxyConfigDictionary>( | |
69 ProxyConfigDictionary::CreateDirect()); | |
70 } | |
stevenjb
2016/09/02 16:20:55
nit: I would invert this to make the positive resu
Polina Bondarenko
2016/09/05 20:08:45
Done.
| |
71 return proxy_config; | |
72 } | |
73 | |
74 bool GetHttpProxyServer(const ProxyConfigDictionary* proxy_config_dict, | |
34 std::string* host, | 75 std::string* host, |
35 int* port) { | 76 int* port) { |
36 std::string proxy_rules_string; | 77 std::string proxy_rules_string; |
37 if (!proxy_config_dict.GetProxyServer(&proxy_rules_string)) | 78 if (!proxy_config_dict->GetProxyServer(&proxy_rules_string)) |
38 return false; | 79 return false; |
39 | 80 |
40 net::ProxyConfig::ProxyRules proxy_rules; | 81 net::ProxyConfig::ProxyRules proxy_rules; |
41 proxy_rules.ParseFromString(proxy_rules_string); | 82 proxy_rules.ParseFromString(proxy_rules_string); |
42 | 83 |
43 const net::ProxyList* proxy_list = nullptr; | 84 const net::ProxyList* proxy_list = nullptr; |
44 if (proxy_rules.type == net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY) { | 85 if (proxy_rules.type == net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY) { |
45 proxy_list = &proxy_rules.single_proxies; | 86 proxy_list = &proxy_rules.single_proxies; |
46 } else if (proxy_rules.type == | 87 } else if (proxy_rules.type == |
47 net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME) { | 88 net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME) { |
(...skipping 10 matching lines...) Expand all Loading... | |
58 | 99 |
59 } // namespace | 100 } // namespace |
60 | 101 |
61 namespace arc { | 102 namespace arc { |
62 | 103 |
63 // Listens to changes for select Chrome settings (prefs) that Android cares | 104 // Listens to changes for select Chrome settings (prefs) that Android cares |
64 // about and sends the new values to Android to keep the state in sync. | 105 // about and sends the new values to Android to keep the state in sync. |
65 class ArcSettingsServiceImpl | 106 class ArcSettingsServiceImpl |
66 : public chromeos::system::TimezoneSettings::Observer, | 107 : public chromeos::system::TimezoneSettings::Observer, |
67 public device::BluetoothAdapter::Observer, | 108 public device::BluetoothAdapter::Observer, |
68 public ArcAuthService::Observer { | 109 public ArcAuthService::Observer, |
110 public chromeos::NetworkStateHandlerObserver { | |
69 public: | 111 public: |
70 explicit ArcSettingsServiceImpl(ArcBridgeService* arc_bridge_service); | 112 explicit ArcSettingsServiceImpl(ArcBridgeService* arc_bridge_service); |
71 ~ArcSettingsServiceImpl() override; | 113 ~ArcSettingsServiceImpl() override; |
72 | 114 |
73 // Called when a Chrome pref we have registered an observer for has changed. | 115 // Called when a Chrome pref we have registered an observer for has changed. |
74 // Obtains the new pref value and sends it to Android. | 116 // Obtains the new pref value and sends it to Android. |
75 void OnPrefChanged(const std::string& pref_name) const; | 117 void OnPrefChanged(const std::string& pref_name) const; |
76 | 118 |
77 // TimezoneSettings::Observer: | 119 // TimezoneSettings::Observer: |
78 void TimezoneChanged(const icu::TimeZone& timezone) override; | 120 void TimezoneChanged(const icu::TimeZone& timezone) override; |
79 | 121 |
80 // BluetoothAdapter::Observer: | 122 // BluetoothAdapter::Observer: |
81 void AdapterPoweredChanged(device::BluetoothAdapter* adapter, | 123 void AdapterPoweredChanged(device::BluetoothAdapter* adapter, |
82 bool powered) override; | 124 bool powered) override; |
83 | 125 |
84 // ArcAuthService::Observer: | 126 // ArcAuthService::Observer: |
85 void OnInitialStart() override; | 127 void OnInitialStart() override; |
86 | 128 |
129 // NetworkStateHandlerObserver: | |
130 void DefaultNetworkChanged(const chromeos::NetworkState* network) override; | |
131 | |
87 private: | 132 private: |
88 // Registers to observe changes for Chrome settings we care about. | 133 // Registers to observe changes for Chrome settings we care about. |
89 void StartObservingSettingsChanges(); | 134 void StartObservingSettingsChanges(); |
90 | 135 |
91 // Stops listening for Chrome settings changes. | 136 // Stops listening for Chrome settings changes. |
92 void StopObservingSettingsChanges(); | 137 void StopObservingSettingsChanges(); |
93 | 138 |
94 // Retrieves Chrome's state for the settings that need to be synced on each | 139 // Retrieves Chrome's state for the settings that need to be synced on each |
95 // Android boot and send it to Android. | 140 // Android boot and send it to Android. |
96 void SyncRuntimeSettings() const; | 141 void SyncRuntimeSettings() const; |
97 // Send settings that need to be synced only on Android first start to | 142 // Send settings that need to be synced only on Android first start to |
98 // Android. | 143 // Android. |
99 void SyncInitialSettings() const; | 144 void SyncInitialSettings() const; |
100 void SyncFontSize() const; | 145 void SyncFontSize() const; |
101 void SyncLocale() const; | 146 void SyncLocale() const; |
102 void SyncProxySettings() const; | |
103 void SyncReportingConsent() const; | 147 void SyncReportingConsent() const; |
104 void SyncSpokenFeedbackEnabled() const; | 148 void SyncSpokenFeedbackEnabled() const; |
105 void SyncTimeZone() const; | 149 void SyncTimeZone() const; |
106 void SyncUse24HourClock() const; | 150 void SyncUse24HourClock() const; |
107 void SyncBackupEnabled() const; | 151 void SyncBackupEnabled() const; |
108 void SyncLocationServiceEnabled() const; | 152 void SyncLocationServiceEnabled() const; |
109 | 153 |
110 void OnBluetoothAdapterInitialized( | 154 void OnBluetoothAdapterInitialized( |
111 scoped_refptr<device::BluetoothAdapter> adapter); | 155 scoped_refptr<device::BluetoothAdapter> adapter); |
112 | 156 |
113 // Registers to listen to a particular perf. | 157 // Registers to listen to a particular perf. |
114 void AddPrefToObserve(const std::string& pref_name); | 158 void AddPrefToObserve(const std::string& pref_name); |
115 | 159 |
116 // Returns the integer value of the pref. pref_name must exist. | 160 // Returns the integer value of the pref. pref_name must exist. |
117 int GetIntegerPref(const std::string& pref_name) const; | 161 int GetIntegerPref(const std::string& pref_name) const; |
118 | 162 |
119 // Sends boolean pref broadcast to the delegate. | 163 // Sends boolean pref broadcast to the delegate. |
120 void SendBoolPrefSettingsBroadcast(const std::string& pref_name, | 164 void SendBoolPrefSettingsBroadcast(const std::string& pref_name, |
121 const std::string& action) const; | 165 const std::string& action) const; |
122 | 166 |
123 // Sends a broadcast to the delegate. | 167 // Sends a broadcast to the delegate. |
124 void SendSettingsBroadcast(const std::string& action, | 168 void SendSettingsBroadcast(const std::string& action, |
125 const base::DictionaryValue& extras) const; | 169 const base::DictionaryValue& extras) const; |
126 | 170 |
171 // Sends proxy settings broadcast to the delegate. | |
172 void SendProxySettingsBroadcast(const ProxyConfigDictionary* proxy_config); | |
173 | |
127 // Manages pref observation registration. | 174 // Manages pref observation registration. |
128 PrefChangeRegistrar registrar_; | 175 PrefChangeRegistrar registrar_; |
129 | 176 |
130 std::unique_ptr<chromeos::CrosSettings::ObserverSubscription> | 177 std::unique_ptr<chromeos::CrosSettings::ObserverSubscription> |
131 reporting_consent_subscription_; | 178 reporting_consent_subscription_; |
132 ArcBridgeService* const arc_bridge_service_; | 179 ArcBridgeService* const arc_bridge_service_; |
133 | 180 |
134 scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_; | 181 scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_; |
135 | 182 |
183 // Do not send the same proxy configuration. | |
184 std::unique_ptr<base::DictionaryValue> last_proxy_extras_; | |
185 | |
136 // WeakPtrFactory to use for callback for getting the bluetooth adapter. | 186 // WeakPtrFactory to use for callback for getting the bluetooth adapter. |
137 base::WeakPtrFactory<ArcSettingsServiceImpl> weak_factory_; | 187 base::WeakPtrFactory<ArcSettingsServiceImpl> weak_factory_; |
138 | 188 |
139 DISALLOW_COPY_AND_ASSIGN(ArcSettingsServiceImpl); | 189 DISALLOW_COPY_AND_ASSIGN(ArcSettingsServiceImpl); |
140 }; | 190 }; |
141 | 191 |
142 ArcSettingsServiceImpl::ArcSettingsServiceImpl( | 192 ArcSettingsServiceImpl::ArcSettingsServiceImpl( |
143 ArcBridgeService* arc_bridge_service) | 193 ArcBridgeService* arc_bridge_service) |
144 : arc_bridge_service_(arc_bridge_service), weak_factory_(this) { | 194 : arc_bridge_service_(arc_bridge_service), weak_factory_(this) { |
145 StartObservingSettingsChanges(); | 195 StartObservingSettingsChanges(); |
(...skipping 15 matching lines...) Expand all Loading... | |
161 | 211 |
162 void ArcSettingsServiceImpl::StartObservingSettingsChanges() { | 212 void ArcSettingsServiceImpl::StartObservingSettingsChanges() { |
163 Profile* profile = ProfileManager::GetActiveUserProfile(); | 213 Profile* profile = ProfileManager::GetActiveUserProfile(); |
164 registrar_.Init(profile->GetPrefs()); | 214 registrar_.Init(profile->GetPrefs()); |
165 | 215 |
166 AddPrefToObserve(prefs::kWebKitDefaultFixedFontSize); | 216 AddPrefToObserve(prefs::kWebKitDefaultFixedFontSize); |
167 AddPrefToObserve(prefs::kWebKitDefaultFontSize); | 217 AddPrefToObserve(prefs::kWebKitDefaultFontSize); |
168 AddPrefToObserve(prefs::kWebKitMinimumFontSize); | 218 AddPrefToObserve(prefs::kWebKitMinimumFontSize); |
169 AddPrefToObserve(prefs::kAccessibilitySpokenFeedbackEnabled); | 219 AddPrefToObserve(prefs::kAccessibilitySpokenFeedbackEnabled); |
170 AddPrefToObserve(prefs::kUse24HourClock); | 220 AddPrefToObserve(prefs::kUse24HourClock); |
171 AddPrefToObserve(proxy_config::prefs::kProxy); | |
172 AddPrefToObserve(prefs::kArcBackupRestoreEnabled); | 221 AddPrefToObserve(prefs::kArcBackupRestoreEnabled); |
173 | 222 |
174 reporting_consent_subscription_ = CrosSettings::Get()->AddSettingsObserver( | 223 reporting_consent_subscription_ = CrosSettings::Get()->AddSettingsObserver( |
175 chromeos::kStatsReportingPref, | 224 chromeos::kStatsReportingPref, |
176 base::Bind(&ArcSettingsServiceImpl::SyncReportingConsent, | 225 base::Bind(&ArcSettingsServiceImpl::SyncReportingConsent, |
177 base::Unretained(this))); | 226 base::Unretained(this))); |
178 | 227 |
179 TimezoneSettings::GetInstance()->AddObserver(this); | 228 TimezoneSettings::GetInstance()->AddObserver(this); |
180 | 229 |
181 if (device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) { | 230 if (device::BluetoothAdapterFactory::IsBluetoothAdapterAvailable()) { |
182 device::BluetoothAdapterFactory::GetAdapter( | 231 device::BluetoothAdapterFactory::GetAdapter( |
183 base::Bind(&ArcSettingsServiceImpl::OnBluetoothAdapterInitialized, | 232 base::Bind(&ArcSettingsServiceImpl::OnBluetoothAdapterInitialized, |
184 weak_factory_.GetWeakPtr())); | 233 weak_factory_.GetWeakPtr())); |
185 } | 234 } |
235 | |
236 chromeos::NetworkHandler::Get()->network_state_handler()->AddObserver( | |
237 this, FROM_HERE); | |
238 const chromeos::NetworkState* network = chromeos::NetworkHandler::Get() | |
239 ->network_state_handler() | |
240 ->DefaultNetwork(); | |
241 if (network) { | |
242 std::unique_ptr<ProxyConfigDictionary> proxy_config = | |
243 GetProxyConfig(network); | |
244 SendProxySettingsBroadcast(proxy_config.get()); | |
245 } | |
stevenjb
2016/09/02 16:20:55
This could be:
proxy_config = GetProxyConfig();
if
Polina Bondarenko
2016/09/05 20:08:45
Done.
| |
186 } | 246 } |
187 | 247 |
188 void ArcSettingsServiceImpl::OnBluetoothAdapterInitialized( | 248 void ArcSettingsServiceImpl::OnBluetoothAdapterInitialized( |
189 scoped_refptr<device::BluetoothAdapter> adapter) { | 249 scoped_refptr<device::BluetoothAdapter> adapter) { |
190 DCHECK(adapter); | 250 DCHECK(adapter); |
191 bluetooth_adapter_ = adapter; | 251 bluetooth_adapter_ = adapter; |
192 bluetooth_adapter_->AddObserver(this); | 252 bluetooth_adapter_->AddObserver(this); |
193 | 253 |
194 AdapterPoweredChanged(adapter.get(), adapter->IsPowered()); | 254 AdapterPoweredChanged(adapter.get(), adapter->IsPowered()); |
195 } | 255 } |
196 | 256 |
197 void ArcSettingsServiceImpl::OnInitialStart() { | 257 void ArcSettingsServiceImpl::OnInitialStart() { |
198 SyncInitialSettings(); | 258 SyncInitialSettings(); |
199 } | 259 } |
200 | 260 |
201 void ArcSettingsServiceImpl::SyncRuntimeSettings() const { | 261 void ArcSettingsServiceImpl::SyncRuntimeSettings() const { |
202 SyncFontSize(); | 262 SyncFontSize(); |
203 SyncLocale(); | 263 SyncLocale(); |
204 SyncProxySettings(); | |
205 SyncReportingConsent(); | 264 SyncReportingConsent(); |
206 SyncSpokenFeedbackEnabled(); | 265 SyncSpokenFeedbackEnabled(); |
207 SyncTimeZone(); | 266 SyncTimeZone(); |
208 SyncUse24HourClock(); | 267 SyncUse24HourClock(); |
209 | 268 |
210 const PrefService* const prefs = | 269 const PrefService* const prefs = |
211 ProfileManager::GetActiveUserProfile()->GetPrefs(); | 270 ProfileManager::GetActiveUserProfile()->GetPrefs(); |
212 if (prefs->IsManagedPreference(prefs::kArcBackupRestoreEnabled)) | 271 if (prefs->IsManagedPreference(prefs::kArcBackupRestoreEnabled)) |
213 SyncBackupEnabled(); | 272 SyncBackupEnabled(); |
214 if (prefs->IsManagedPreference(prefs::kArcLocationServiceEnabled)) | 273 if (prefs->IsManagedPreference(prefs::kArcLocationServiceEnabled)) |
215 SyncLocationServiceEnabled(); | 274 SyncLocationServiceEnabled(); |
216 } | 275 } |
217 | 276 |
218 void ArcSettingsServiceImpl::SyncInitialSettings() const { | 277 void ArcSettingsServiceImpl::SyncInitialSettings() const { |
219 SyncBackupEnabled(); | 278 SyncBackupEnabled(); |
220 SyncLocationServiceEnabled(); | 279 SyncLocationServiceEnabled(); |
221 } | 280 } |
222 | 281 |
223 void ArcSettingsServiceImpl::StopObservingSettingsChanges() { | 282 void ArcSettingsServiceImpl::StopObservingSettingsChanges() { |
224 registrar_.RemoveAll(); | 283 registrar_.RemoveAll(); |
225 reporting_consent_subscription_.reset(); | 284 reporting_consent_subscription_.reset(); |
226 | 285 |
227 TimezoneSettings::GetInstance()->RemoveObserver(this); | 286 TimezoneSettings::GetInstance()->RemoveObserver(this); |
287 chromeos::NetworkHandler::Get()->network_state_handler()->RemoveObserver( | |
288 this, FROM_HERE); | |
228 } | 289 } |
229 | 290 |
230 void ArcSettingsServiceImpl::AddPrefToObserve(const std::string& pref_name) { | 291 void ArcSettingsServiceImpl::AddPrefToObserve(const std::string& pref_name) { |
231 registrar_.Add(pref_name, base::Bind(&ArcSettingsServiceImpl::OnPrefChanged, | 292 registrar_.Add(pref_name, base::Bind(&ArcSettingsServiceImpl::OnPrefChanged, |
232 base::Unretained(this))); | 293 base::Unretained(this))); |
233 } | 294 } |
234 | 295 |
235 void ArcSettingsServiceImpl::AdapterPoweredChanged( | 296 void ArcSettingsServiceImpl::AdapterPoweredChanged( |
236 device::BluetoothAdapter* adapter, | 297 device::BluetoothAdapter* adapter, |
237 bool powered) { | 298 bool powered) { |
238 base::DictionaryValue extras; | 299 base::DictionaryValue extras; |
239 extras.SetBoolean("enable", powered); | 300 extras.SetBoolean("enable", powered); |
240 SendSettingsBroadcast("org.chromium.arc.intent_helper.SET_BLUETOOTH_STATE", | 301 SendSettingsBroadcast("org.chromium.arc.intent_helper.SET_BLUETOOTH_STATE", |
241 extras); | 302 extras); |
242 } | 303 } |
243 | 304 |
244 void ArcSettingsServiceImpl::OnPrefChanged(const std::string& pref_name) const { | 305 void ArcSettingsServiceImpl::OnPrefChanged(const std::string& pref_name) const { |
245 if (pref_name == prefs::kAccessibilitySpokenFeedbackEnabled) { | 306 if (pref_name == prefs::kAccessibilitySpokenFeedbackEnabled) { |
246 SyncSpokenFeedbackEnabled(); | 307 SyncSpokenFeedbackEnabled(); |
247 } else if (pref_name == prefs::kWebKitDefaultFixedFontSize || | 308 } else if (pref_name == prefs::kWebKitDefaultFixedFontSize || |
248 pref_name == prefs::kWebKitDefaultFontSize || | 309 pref_name == prefs::kWebKitDefaultFontSize || |
249 pref_name == prefs::kWebKitMinimumFontSize) { | 310 pref_name == prefs::kWebKitMinimumFontSize) { |
250 SyncFontSize(); | 311 SyncFontSize(); |
251 } else if (pref_name == prefs::kUse24HourClock) { | 312 } else if (pref_name == prefs::kUse24HourClock) { |
252 SyncUse24HourClock(); | 313 SyncUse24HourClock(); |
253 } else if (pref_name == proxy_config::prefs::kProxy) { | |
254 SyncProxySettings(); | |
255 } else { | 314 } else { |
256 LOG(ERROR) << "Unknown pref changed."; | 315 LOG(ERROR) << "Unknown pref changed."; |
257 } | 316 } |
258 } | 317 } |
259 | 318 |
260 void ArcSettingsServiceImpl::TimezoneChanged(const icu::TimeZone& timezone) { | 319 void ArcSettingsServiceImpl::TimezoneChanged(const icu::TimeZone& timezone) { |
261 SyncTimeZone(); | 320 SyncTimeZone(); |
262 } | 321 } |
263 | 322 |
264 int ArcSettingsServiceImpl::GetIntegerPref(const std::string& pref_name) const { | 323 int ArcSettingsServiceImpl::GetIntegerPref(const std::string& pref_name) const { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
341 DCHECK(pref); | 400 DCHECK(pref); |
342 bool use24HourClock = false; | 401 bool use24HourClock = false; |
343 bool value_exists = pref->GetValue()->GetAsBoolean(&use24HourClock); | 402 bool value_exists = pref->GetValue()->GetAsBoolean(&use24HourClock); |
344 DCHECK(value_exists); | 403 DCHECK(value_exists); |
345 base::DictionaryValue extras; | 404 base::DictionaryValue extras; |
346 extras.SetBoolean("use24HourClock", use24HourClock); | 405 extras.SetBoolean("use24HourClock", use24HourClock); |
347 SendSettingsBroadcast("org.chromium.arc.intent_helper.SET_USE_24_HOUR_CLOCK", | 406 SendSettingsBroadcast("org.chromium.arc.intent_helper.SET_USE_24_HOUR_CLOCK", |
348 extras); | 407 extras); |
349 } | 408 } |
350 | 409 |
351 void ArcSettingsServiceImpl::SyncProxySettings() const { | 410 void ArcSettingsServiceImpl::SendProxySettingsBroadcast( |
352 const PrefService::Preference* const pref = | 411 const ProxyConfigDictionary* proxy_config_dict) { |
353 registrar_.prefs()->FindPreference(proxy_config::prefs::kProxy); | |
354 const base::DictionaryValue* proxy_config_value; | |
355 bool value_exists = pref->GetValue()->GetAsDictionary(&proxy_config_value); | |
356 DCHECK(value_exists); | |
357 | |
358 ProxyConfigDictionary proxy_config_dict(proxy_config_value); | |
359 | |
360 ProxyPrefs::ProxyMode mode; | 412 ProxyPrefs::ProxyMode mode; |
361 if (!proxy_config_dict.GetMode(&mode)) | 413 if (!proxy_config_dict || !proxy_config_dict->GetMode(&mode)) |
362 mode = ProxyPrefs::MODE_DIRECT; | 414 mode = ProxyPrefs::MODE_DIRECT; |
363 | 415 |
364 base::DictionaryValue extras; | 416 base::DictionaryValue extras; |
365 extras.SetString("mode", ProxyPrefs::ProxyModeToString(mode)); | 417 extras.SetString("mode", ProxyPrefs::ProxyModeToString(mode)); |
366 | 418 |
367 switch (mode) { | 419 switch (mode) { |
368 case ProxyPrefs::MODE_DIRECT: | 420 case ProxyPrefs::MODE_DIRECT: |
369 break; | 421 break; |
370 case ProxyPrefs::MODE_SYSTEM: | 422 case ProxyPrefs::MODE_SYSTEM: |
371 VLOG(1) << "The system mode is not translated."; | 423 VLOG(1) << "The system mode is not translated."; |
372 return; | 424 return; |
373 case ProxyPrefs::MODE_AUTO_DETECT: | 425 case ProxyPrefs::MODE_AUTO_DETECT: |
374 extras.SetString("pacUrl", "http://wpad/wpad.dat"); | 426 extras.SetString("pacUrl", "http://wpad/wpad.dat"); |
375 break; | 427 break; |
376 case ProxyPrefs::MODE_PAC_SCRIPT: { | 428 case ProxyPrefs::MODE_PAC_SCRIPT: { |
377 std::string pac_url; | 429 std::string pac_url; |
378 if (!proxy_config_dict.GetPacUrl(&pac_url)) { | 430 if (!proxy_config_dict->GetPacUrl(&pac_url)) { |
379 LOG(ERROR) << "No pac URL for pac_script proxy mode."; | 431 LOG(ERROR) << "No pac URL for pac_script proxy mode."; |
380 return; | 432 return; |
381 } | 433 } |
382 extras.SetString("pacUrl", pac_url); | 434 extras.SetString("pacUrl", pac_url); |
383 break; | 435 break; |
384 } | 436 } |
385 case ProxyPrefs::MODE_FIXED_SERVERS: { | 437 case ProxyPrefs::MODE_FIXED_SERVERS: { |
386 std::string host; | 438 std::string host; |
387 int port = 0; | 439 int port = 0; |
388 if (!GetHttpProxyServer(proxy_config_dict, &host, &port)) { | 440 if (!GetHttpProxyServer(proxy_config_dict, &host, &port)) { |
389 LOG(ERROR) << "No Http proxy server is sent."; | 441 LOG(ERROR) << "No Http proxy server is sent."; |
390 return; | 442 return; |
391 } | 443 } |
392 extras.SetString("host", host); | 444 extras.SetString("host", host); |
393 extras.SetInteger("port", port); | 445 extras.SetInteger("port", port); |
394 | 446 |
395 std::string bypass_list; | 447 std::string bypass_list; |
396 if (proxy_config_dict.GetBypassList(&bypass_list) && | 448 if (proxy_config_dict->GetBypassList(&bypass_list) && |
397 !bypass_list.empty()) { | 449 !bypass_list.empty()) { |
398 extras.SetString("bypassList", bypass_list); | 450 extras.SetString("bypassList", bypass_list); |
399 } | 451 } |
400 break; | 452 break; |
401 } | 453 } |
402 default: | 454 default: |
403 LOG(ERROR) << "Incorrect proxy mode."; | 455 LOG(ERROR) << "Incorrect proxy mode."; |
404 return; | 456 return; |
405 } | 457 } |
406 | 458 |
407 SendSettingsBroadcast("org.chromium.arc.intent_helper.SET_PROXY", extras); | 459 if (!last_proxy_extras_ || !last_proxy_extras_->Equals(&extras)) { |
460 last_proxy_extras_.reset(); | |
461 last_proxy_extras_ = base::DictionaryValue::From(extras.CreateDeepCopy()); | |
462 SendSettingsBroadcast("org.chromium.arc.intent_helper.SET_PROXY", extras); | |
463 } | |
408 } | 464 } |
409 | 465 |
410 void ArcSettingsServiceImpl::SyncBackupEnabled() const { | 466 void ArcSettingsServiceImpl::SyncBackupEnabled() const { |
411 SendBoolPrefSettingsBroadcast( | 467 SendBoolPrefSettingsBroadcast( |
412 prefs::kArcBackupRestoreEnabled, | 468 prefs::kArcBackupRestoreEnabled, |
413 "org.chromium.arc.intent_helper.SET_BACKUP_ENABLED"); | 469 "org.chromium.arc.intent_helper.SET_BACKUP_ENABLED"); |
414 } | 470 } |
415 | 471 |
416 void ArcSettingsServiceImpl::SyncLocationServiceEnabled() const { | 472 void ArcSettingsServiceImpl::SyncLocationServiceEnabled() const { |
417 SendBoolPrefSettingsBroadcast( | 473 SendBoolPrefSettingsBroadcast( |
(...skipping 13 matching lines...) Expand all Loading... | |
431 bool write_success = base::JSONWriter::Write(extras, &extras_json); | 487 bool write_success = base::JSONWriter::Write(extras, &extras_json); |
432 DCHECK(write_success); | 488 DCHECK(write_success); |
433 | 489 |
434 if (arc_bridge_service_->intent_helper()->version() >= 1) { | 490 if (arc_bridge_service_->intent_helper()->version() >= 1) { |
435 arc_bridge_service_->intent_helper()->instance()->SendBroadcast( | 491 arc_bridge_service_->intent_helper()->instance()->SendBroadcast( |
436 action, "org.chromium.arc.intent_helper", | 492 action, "org.chromium.arc.intent_helper", |
437 "org.chromium.arc.intent_helper.SettingsReceiver", extras_json); | 493 "org.chromium.arc.intent_helper.SettingsReceiver", extras_json); |
438 } | 494 } |
439 } | 495 } |
440 | 496 |
497 void ArcSettingsServiceImpl::DefaultNetworkChanged( | |
498 const chromeos::NetworkState* network) { | |
499 std::unique_ptr<ProxyConfigDictionary> proxy_config = GetProxyConfig(network); | |
500 SendProxySettingsBroadcast(proxy_config.get()); | |
stevenjb
2016/09/02 16:20:55
Do we want to cache the proxy config and only broa
Polina Bondarenko
2016/09/05 20:08:45
Yes, added check of the source to reduce the amoun
| |
501 } | |
502 | |
441 ArcSettingsService::ArcSettingsService(ArcBridgeService* bridge_service) | 503 ArcSettingsService::ArcSettingsService(ArcBridgeService* bridge_service) |
442 : ArcService(bridge_service) { | 504 : ArcService(bridge_service) { |
443 arc_bridge_service()->intent_helper()->AddObserver(this); | 505 arc_bridge_service()->intent_helper()->AddObserver(this); |
444 } | 506 } |
445 | 507 |
446 ArcSettingsService::~ArcSettingsService() { | 508 ArcSettingsService::~ArcSettingsService() { |
447 arc_bridge_service()->intent_helper()->RemoveObserver(this); | 509 arc_bridge_service()->intent_helper()->RemoveObserver(this); |
448 } | 510 } |
449 | 511 |
450 void ArcSettingsService::OnInstanceReady() { | 512 void ArcSettingsService::OnInstanceReady() { |
451 impl_.reset(new ArcSettingsServiceImpl(arc_bridge_service())); | 513 impl_.reset(new ArcSettingsServiceImpl(arc_bridge_service())); |
452 } | 514 } |
453 | 515 |
454 void ArcSettingsService::OnInstanceClosed() { | 516 void ArcSettingsService::OnInstanceClosed() { |
455 impl_.reset(); | 517 impl_.reset(); |
456 } | 518 } |
457 | 519 |
458 } // namespace arc | 520 } // namespace arc |
OLD | NEW |