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

Side by Side Diff: chrome/browser/chromeos/arc/intent_helper/arc_settings_service.cc

Issue 2702893002: Revert of Skip ARC initial screen when everything is set up by policy (Closed)
Patch Set: Created 3 years, 10 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 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/intent_helper/arc_settings_service.h" 5 #include "chrome/browser/chromeos/arc/intent_helper/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"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 } 58 }
59 if (!proxy_list || proxy_list->IsEmpty()) 59 if (!proxy_list || proxy_list->IsEmpty())
60 return false; 60 return false;
61 61
62 const net::ProxyServer& server = proxy_list->Get(); 62 const net::ProxyServer& server = proxy_list->Get();
63 *host = server.host_port_pair().host(); 63 *host = server.host_port_pair().host();
64 *port = server.host_port_pair().port(); 64 *port = server.host_port_pair().port();
65 return !host->empty() && *port; 65 return !host->empty() && *port;
66 } 66 }
67 67
68 PrefService* GetPrefs() {
69 return ProfileManager::GetActiveUserProfile()->GetPrefs();
70 }
71
72 // Returns whether kProxy pref proxy config is applied. 68 // Returns whether kProxy pref proxy config is applied.
73 bool IsPrefProxyConfigApplied() { 69 bool IsPrefProxyConfigApplied() {
74 net::ProxyConfig config; 70 net::ProxyConfig config;
71 Profile* profile = ProfileManager::GetActiveUserProfile();
75 return PrefProxyConfigTrackerImpl::PrefPrecedes( 72 return PrefProxyConfigTrackerImpl::PrefPrecedes(
76 PrefProxyConfigTrackerImpl::ReadPrefConfig(GetPrefs(), &config)); 73 PrefProxyConfigTrackerImpl::ReadPrefConfig(profile->GetPrefs(), &config));
77 } 74 }
78 75
79 } // namespace 76 } // namespace
80 77
81 namespace arc { 78 namespace arc {
82 79
83 // Listens to changes for select Chrome settings (prefs) that Android cares 80 // Listens to changes for select Chrome settings (prefs) that Android cares
84 // about and sends the new values to Android to keep the state in sync. 81 // about and sends the new values to Android to keep the state in sync.
85 class ArcSettingsServiceImpl 82 class ArcSettingsServiceImpl
86 : public chromeos::system::TimezoneSettings::Observer, 83 : public chromeos::system::TimezoneSettings::Observer,
(...skipping 21 matching lines...) Expand all
108 // NetworkStateHandlerObserver: 105 // NetworkStateHandlerObserver:
109 void DefaultNetworkChanged(const chromeos::NetworkState* network) override; 106 void DefaultNetworkChanged(const chromeos::NetworkState* network) override;
110 107
111 private: 108 private:
112 // Registers to observe changes for Chrome settings we care about. 109 // Registers to observe changes for Chrome settings we care about.
113 void StartObservingSettingsChanges(); 110 void StartObservingSettingsChanges();
114 111
115 // Stops listening for Chrome settings changes. 112 // Stops listening for Chrome settings changes.
116 void StopObservingSettingsChanges(); 113 void StopObservingSettingsChanges();
117 114
118 // Retrieves Chrome's state for the settings that need to be synced on the
119 // initial Android boot and send it to Android.
120 void SyncInitialSettings() const;
121 // Retrieves Chrome's state for the settings that need to be synced on each 115 // Retrieves Chrome's state for the settings that need to be synced on each
122 // Android boot and send it to Android. 116 // Android boot and send it to Android.
123 void SyncRuntimeSettings() const; 117 void SyncRuntimeSettings() const;
124 // Determine whether a particular setting needs to be synced to Android. 118 // Send settings that need to be synced only on Android first start to
125 // Keep these lines ordered lexicographically. 119 // Android.
126 bool ShouldSyncBackupEnabled() const;
127 bool ShouldSyncLocationServiceEnabled() const;
128 // Send particular settings to Android.
129 // Keep these lines ordered lexicographically. 120 // Keep these lines ordered lexicographically.
130 void SyncAccessibilityLargeMouseCursorEnabled() const; 121 void SyncAccessibilityLargeMouseCursorEnabled() const;
131 void SyncAccessibilityVirtualKeyboardEnabled() const; 122 void SyncAccessibilityVirtualKeyboardEnabled() const;
132 void SyncBackupEnabled() const; 123 void SyncBackupEnabled() const;
133 void SyncFocusHighlightEnabled() const; 124 void SyncFocusHighlightEnabled() const;
134 void SyncFontSize() const; 125 void SyncFontSize() const;
126 void SyncInitialSettings() const;
135 void SyncLocale() const; 127 void SyncLocale() const;
136 void SyncLocationServiceEnabled() const; 128 void SyncLocationServiceEnabled() const;
137 void SyncProxySettings() const; 129 void SyncProxySettings() const;
138 void SyncReportingConsent() const; 130 void SyncReportingConsent() const;
139 void SyncSpokenFeedbackEnabled() const; 131 void SyncSpokenFeedbackEnabled() const;
140 void SyncTimeZone() const; 132 void SyncTimeZone() const;
141 void SyncUse24HourClock() const; 133 void SyncUse24HourClock() const;
142 134
143 void OnBluetoothAdapterInitialized( 135 void OnBluetoothAdapterInitialized(
144 scoped_refptr<device::BluetoothAdapter> adapter); 136 scoped_refptr<device::BluetoothAdapter> adapter);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 } 197 }
206 SyncProxySettings(); 198 SyncProxySettings();
207 } else if (pref_name == prefs::kAccessibilityFocusHighlightEnabled) { 199 } else if (pref_name == prefs::kAccessibilityFocusHighlightEnabled) {
208 SyncFocusHighlightEnabled(); 200 SyncFocusHighlightEnabled();
209 } else if (pref_name == prefs::kAccessibilityLargeCursorEnabled) { 201 } else if (pref_name == prefs::kAccessibilityLargeCursorEnabled) {
210 SyncAccessibilityLargeMouseCursorEnabled(); 202 SyncAccessibilityLargeMouseCursorEnabled();
211 } else if (pref_name == prefs::kAccessibilitySpokenFeedbackEnabled) { 203 } else if (pref_name == prefs::kAccessibilitySpokenFeedbackEnabled) {
212 SyncSpokenFeedbackEnabled(); 204 SyncSpokenFeedbackEnabled();
213 } else if (pref_name == prefs::kAccessibilityVirtualKeyboardEnabled) { 205 } else if (pref_name == prefs::kAccessibilityVirtualKeyboardEnabled) {
214 SyncAccessibilityVirtualKeyboardEnabled(); 206 SyncAccessibilityVirtualKeyboardEnabled();
215 } else if (pref_name == prefs::kArcBackupRestoreEnabled) {
216 if (ShouldSyncBackupEnabled())
217 SyncBackupEnabled();
218 } else if (pref_name == prefs::kArcLocationServiceEnabled) { 207 } else if (pref_name == prefs::kArcLocationServiceEnabled) {
219 if (ShouldSyncLocationServiceEnabled()) 208 const PrefService* const prefs =
209 ProfileManager::GetActiveUserProfile()->GetPrefs();
210 if (prefs->IsManagedPreference(prefs::kArcLocationServiceEnabled))
220 SyncLocationServiceEnabled(); 211 SyncLocationServiceEnabled();
221 } else if (pref_name == prefs::kUse24HourClock) { 212 } else if (pref_name == prefs::kUse24HourClock) {
222 SyncUse24HourClock(); 213 SyncUse24HourClock();
223 } else if (pref_name == prefs::kWebKitDefaultFixedFontSize || 214 } else if (pref_name == prefs::kWebKitDefaultFixedFontSize ||
224 pref_name == prefs::kWebKitDefaultFontSize || 215 pref_name == prefs::kWebKitDefaultFontSize ||
225 pref_name == prefs::kWebKitMinimumFontSize) { 216 pref_name == prefs::kWebKitMinimumFontSize) {
226 SyncFontSize(); 217 SyncFontSize();
227 } else if (pref_name == proxy_config::prefs::kProxy) { 218 } else if (pref_name == proxy_config::prefs::kProxy) {
228 SyncProxySettings(); 219 SyncProxySettings();
229 } else { 220 } else {
(...skipping 21 matching lines...) Expand all
251 void ArcSettingsServiceImpl::DefaultNetworkChanged( 242 void ArcSettingsServiceImpl::DefaultNetworkChanged(
252 const chromeos::NetworkState* network) { 243 const chromeos::NetworkState* network) {
253 // kProxy pref has more priority than the default network update. 244 // kProxy pref has more priority than the default network update.
254 // If a default network is changed to the network with ONC policy with proxy 245 // If a default network is changed to the network with ONC policy with proxy
255 // settings, it should be translated here. 246 // settings, it should be translated here.
256 if (network && !IsPrefProxyConfigApplied()) 247 if (network && !IsPrefProxyConfigApplied())
257 SyncProxySettings(); 248 SyncProxySettings();
258 } 249 }
259 250
260 void ArcSettingsServiceImpl::StartObservingSettingsChanges() { 251 void ArcSettingsServiceImpl::StartObservingSettingsChanges() {
261 registrar_.Init(GetPrefs()); 252 Profile* profile = ProfileManager::GetActiveUserProfile();
253 registrar_.Init(profile->GetPrefs());
262 254
263 // Keep these lines ordered lexicographically. 255 // Keep these lines ordered lexicographically.
264 AddPrefToObserve(prefs::kAccessibilityFocusHighlightEnabled); 256 AddPrefToObserve(prefs::kAccessibilityFocusHighlightEnabled);
265 AddPrefToObserve(prefs::kAccessibilityLargeCursorEnabled); 257 AddPrefToObserve(prefs::kAccessibilityLargeCursorEnabled);
266 AddPrefToObserve(prefs::kAccessibilitySpokenFeedbackEnabled); 258 AddPrefToObserve(prefs::kAccessibilitySpokenFeedbackEnabled);
267 AddPrefToObserve(prefs::kAccessibilityVirtualKeyboardEnabled); 259 AddPrefToObserve(prefs::kAccessibilityVirtualKeyboardEnabled);
268 AddPrefToObserve(prefs::kArcBackupRestoreEnabled); 260 AddPrefToObserve(prefs::kArcBackupRestoreEnabled);
269 AddPrefToObserve(prefs::kArcLocationServiceEnabled); 261 AddPrefToObserve(prefs::kArcLocationServiceEnabled);
270 AddPrefToObserve(prefs::kUse24HourClock); 262 AddPrefToObserve(prefs::kUse24HourClock);
271 AddPrefToObserve(prefs::kWebKitDefaultFixedFontSize); 263 AddPrefToObserve(prefs::kWebKitDefaultFixedFontSize);
(...skipping 22 matching lines...) Expand all
294 286
295 void ArcSettingsServiceImpl::StopObservingSettingsChanges() { 287 void ArcSettingsServiceImpl::StopObservingSettingsChanges() {
296 registrar_.RemoveAll(); 288 registrar_.RemoveAll();
297 reporting_consent_subscription_.reset(); 289 reporting_consent_subscription_.reset();
298 290
299 TimezoneSettings::GetInstance()->RemoveObserver(this); 291 TimezoneSettings::GetInstance()->RemoveObserver(this);
300 chromeos::NetworkHandler::Get()->network_state_handler()->RemoveObserver( 292 chromeos::NetworkHandler::Get()->network_state_handler()->RemoveObserver(
301 this, FROM_HERE); 293 this, FROM_HERE);
302 } 294 }
303 295
304 void ArcSettingsServiceImpl::SyncInitialSettings() const {
305 // Keep these lines ordered lexicographically.
306 SyncBackupEnabled();
307 SyncLocationServiceEnabled();
308 }
309
310 void ArcSettingsServiceImpl::SyncRuntimeSettings() const { 296 void ArcSettingsServiceImpl::SyncRuntimeSettings() const {
311 // Keep these lines ordered lexicographically. 297 // Keep these lines ordered lexicographically.
312 SyncAccessibilityLargeMouseCursorEnabled(); 298 SyncAccessibilityLargeMouseCursorEnabled();
313 SyncAccessibilityVirtualKeyboardEnabled(); 299 SyncAccessibilityVirtualKeyboardEnabled();
314 SyncFocusHighlightEnabled(); 300 SyncFocusHighlightEnabled();
315 SyncFontSize(); 301 SyncFontSize();
316 SyncLocale(); 302 SyncLocale();
317 SyncProxySettings(); 303 SyncProxySettings();
318 SyncReportingConsent(); 304 SyncReportingConsent();
319 SyncSpokenFeedbackEnabled(); 305 SyncSpokenFeedbackEnabled();
320 SyncTimeZone(); 306 SyncTimeZone();
321 SyncUse24HourClock(); 307 SyncUse24HourClock();
322 308
323 if (ShouldSyncBackupEnabled()) 309 const PrefService* const prefs =
310 ProfileManager::GetActiveUserProfile()->GetPrefs();
311 if (prefs->IsManagedPreference(prefs::kArcBackupRestoreEnabled))
324 SyncBackupEnabled(); 312 SyncBackupEnabled();
325 if (ShouldSyncLocationServiceEnabled()) 313 if (prefs->IsManagedPreference(prefs::kArcLocationServiceEnabled))
326 SyncLocationServiceEnabled(); 314 SyncLocationServiceEnabled();
327 } 315 }
328 316
329 bool ArcSettingsServiceImpl::ShouldSyncBackupEnabled() const {
330 // Always sync the managed setting. Also sync when the pref is unset, which
331 // normally happens once after the pref changes from the managed state to
332 // unmanaged.
333 return GetPrefs()->IsManagedPreference(prefs::kArcBackupRestoreEnabled) ||
334 !GetPrefs()->HasPrefPath(prefs::kArcBackupRestoreEnabled);
335 }
336
337 bool ArcSettingsServiceImpl::ShouldSyncLocationServiceEnabled() const {
338 // Always sync the managed setting. Also sync when the pref is unset, which
339 // normally happens once after the pref changes from the managed state to
340 // unmanaged.
341 return GetPrefs()->IsManagedPreference(prefs::kArcLocationServiceEnabled) ||
342 !GetPrefs()->HasPrefPath(prefs::kArcLocationServiceEnabled);
343 }
344
345 void ArcSettingsServiceImpl::SyncAccessibilityLargeMouseCursorEnabled() const { 317 void ArcSettingsServiceImpl::SyncAccessibilityLargeMouseCursorEnabled() const {
346 SendBoolPrefSettingsBroadcast( 318 SendBoolPrefSettingsBroadcast(
347 prefs::kAccessibilityLargeCursorEnabled, 319 prefs::kAccessibilityLargeCursorEnabled,
348 "org.chromium.arc.intent_helper.ACCESSIBILITY_LARGE_POINTER_ICON"); 320 "org.chromium.arc.intent_helper.ACCESSIBILITY_LARGE_POINTER_ICON");
349 } 321 }
350 322
351 void ArcSettingsServiceImpl::SyncAccessibilityVirtualKeyboardEnabled() const { 323 void ArcSettingsServiceImpl::SyncAccessibilityVirtualKeyboardEnabled() const {
352 SendBoolPrefSettingsBroadcast( 324 SendBoolPrefSettingsBroadcast(
353 prefs::kAccessibilityVirtualKeyboardEnabled, 325 prefs::kAccessibilityVirtualKeyboardEnabled,
354 "org.chromium.arc.intent_helper.SET_SHOW_IME_WITH_HARD_KEYBOARD"); 326 "org.chromium.arc.intent_helper.SET_SHOW_IME_WITH_HARD_KEYBOARD");
355 } 327 }
356 328
357 void ArcSettingsServiceImpl::SyncBackupEnabled() const { 329 void ArcSettingsServiceImpl::SyncBackupEnabled() const {
358 SendBoolPrefSettingsBroadcast( 330 SendBoolPrefSettingsBroadcast(
359 prefs::kArcBackupRestoreEnabled, 331 prefs::kArcBackupRestoreEnabled,
360 "org.chromium.arc.intent_helper.SET_BACKUP_ENABLED"); 332 "org.chromium.arc.intent_helper.SET_BACKUP_ENABLED");
361 if (GetPrefs()->IsManagedPreference(prefs::kArcBackupRestoreEnabled)) {
362 // Unset the user pref so that if the pref becomes unmanaged at some point,
363 // this change will be synced.
364 GetPrefs()->ClearPref(prefs::kArcBackupRestoreEnabled);
365 } else if (!GetPrefs()->HasPrefPath(prefs::kArcBackupRestoreEnabled)) {
366 // Set the pref value in order to prevent the subsequent syncing. The
367 // "false" value is a safe default from the legal/privacy perspective.
368 GetPrefs()->SetBoolean(prefs::kArcBackupRestoreEnabled, false);
369 }
370 } 333 }
371 334
372 void ArcSettingsServiceImpl::SyncFocusHighlightEnabled() const { 335 void ArcSettingsServiceImpl::SyncFocusHighlightEnabled() const {
373 SendBoolPrefSettingsBroadcast( 336 SendBoolPrefSettingsBroadcast(
374 prefs::kAccessibilityFocusHighlightEnabled, 337 prefs::kAccessibilityFocusHighlightEnabled,
375 "org.chromium.arc.intent_helper.SET_FOCUS_HIGHLIGHT_ENABLED"); 338 "org.chromium.arc.intent_helper.SET_FOCUS_HIGHLIGHT_ENABLED");
376 } 339 }
377 340
378 void ArcSettingsServiceImpl::SyncFontSize() const { 341 void ArcSettingsServiceImpl::SyncFontSize() const {
379 int default_size = GetIntegerPref(prefs::kWebKitDefaultFontSize); 342 int default_size = GetIntegerPref(prefs::kWebKitDefaultFontSize);
380 int default_fixed_size = GetIntegerPref(prefs::kWebKitDefaultFixedFontSize); 343 int default_fixed_size = GetIntegerPref(prefs::kWebKitDefaultFixedFontSize);
381 int minimum_size = GetIntegerPref(prefs::kWebKitMinimumFontSize); 344 int minimum_size = GetIntegerPref(prefs::kWebKitMinimumFontSize);
382 345
383 double android_scale = ConvertFontSizeChromeToAndroid( 346 double android_scale = ConvertFontSizeChromeToAndroid(
384 default_size, default_fixed_size, minimum_size); 347 default_size, default_fixed_size, minimum_size);
385 348
386 base::DictionaryValue extras; 349 base::DictionaryValue extras;
387 extras.SetDouble("scale", android_scale); 350 extras.SetDouble("scale", android_scale);
388 SendSettingsBroadcast("org.chromium.arc.intent_helper.SET_FONT_SCALE", 351 SendSettingsBroadcast("org.chromium.arc.intent_helper.SET_FONT_SCALE",
389 extras); 352 extras);
390 } 353 }
391 354
355 void ArcSettingsServiceImpl::SyncInitialSettings() const {
356 SyncBackupEnabled();
357 SyncLocationServiceEnabled();
358 }
359
392 void ArcSettingsServiceImpl::SyncLocale() const { 360 void ArcSettingsServiceImpl::SyncLocale() const {
393 const PrefService::Preference* pref = 361 const PrefService::Preference* pref =
394 registrar_.prefs()->FindPreference(prefs::kApplicationLocale); 362 registrar_.prefs()->FindPreference(prefs::kApplicationLocale);
395 DCHECK(pref); 363 DCHECK(pref);
396 std::string locale; 364 std::string locale;
397 bool value_exists = pref->GetValue()->GetAsString(&locale); 365 bool value_exists = pref->GetValue()->GetAsString(&locale);
398 DCHECK(value_exists); 366 DCHECK(value_exists);
399 base::DictionaryValue extras; 367 base::DictionaryValue extras;
400 extras.SetString("locale", locale); 368 extras.SetString("locale", locale);
401 SendSettingsBroadcast("org.chromium.arc.intent_helper.SET_LOCALE", extras); 369 SendSettingsBroadcast("org.chromium.arc.intent_helper.SET_LOCALE", extras);
402 } 370 }
403 371
404 void ArcSettingsServiceImpl::SyncLocationServiceEnabled() const { 372 void ArcSettingsServiceImpl::SyncLocationServiceEnabled() const {
405 SendBoolPrefSettingsBroadcast( 373 SendBoolPrefSettingsBroadcast(
406 prefs::kArcLocationServiceEnabled, 374 prefs::kArcLocationServiceEnabled,
407 "org.chromium.arc.intent_helper.SET_LOCATION_SERVICE_ENABLED"); 375 "org.chromium.arc.intent_helper.SET_LOCATION_SERVICE_ENABLED");
408 if (GetPrefs()->IsManagedPreference(prefs::kArcLocationServiceEnabled)) {
409 // Unset the user pref so that if the pref becomes unmanaged at some point,
410 // this change will be synced.
411 GetPrefs()->ClearPref(prefs::kArcLocationServiceEnabled);
412 } else if (!GetPrefs()->HasPrefPath(prefs::kArcLocationServiceEnabled)) {
413 // Set the pref value in order to prevent the subsequent syncing. The
414 // "false" value is a safe default from the legal/privacy perspective.
415 GetPrefs()->SetBoolean(prefs::kArcLocationServiceEnabled, false);
416 }
417 } 376 }
418 377
419 void ArcSettingsServiceImpl::SyncProxySettings() const { 378 void ArcSettingsServiceImpl::SyncProxySettings() const {
420 std::unique_ptr<ProxyConfigDictionary> proxy_config_dict = 379 std::unique_ptr<ProxyConfigDictionary> proxy_config_dict =
421 chromeos::ProxyConfigServiceImpl::GetActiveProxyConfigDictionary( 380 chromeos::ProxyConfigServiceImpl::GetActiveProxyConfigDictionary(
422 GetPrefs(), g_browser_process->local_state()); 381 ProfileManager::GetActiveUserProfile()->GetPrefs(),
382 g_browser_process->local_state());
423 if (!proxy_config_dict) 383 if (!proxy_config_dict)
424 return; 384 return;
425 385
426 ProxyPrefs::ProxyMode mode; 386 ProxyPrefs::ProxyMode mode;
427 if (!proxy_config_dict || !proxy_config_dict->GetMode(&mode)) 387 if (!proxy_config_dict || !proxy_config_dict->GetMode(&mode))
428 mode = ProxyPrefs::MODE_DIRECT; 388 mode = ProxyPrefs::MODE_DIRECT;
429 389
430 base::DictionaryValue extras; 390 base::DictionaryValue extras;
431 extras.SetString("mode", ProxyPrefs::ProxyModeToString(mode)); 391 extras.SetString("mode", ProxyPrefs::ProxyModeToString(mode));
432 392
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 535
576 void ArcSettingsService::OnInstanceReady() { 536 void ArcSettingsService::OnInstanceReady() {
577 impl_.reset(new ArcSettingsServiceImpl(arc_bridge_service())); 537 impl_.reset(new ArcSettingsServiceImpl(arc_bridge_service()));
578 } 538 }
579 539
580 void ArcSettingsService::OnInstanceClosed() { 540 void ArcSettingsService::OnInstanceClosed() {
581 impl_.reset(); 541 impl_.reset();
582 } 542 }
583 543
584 } // namespace arc 544 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698