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/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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 private: | 108 private: |
109 // Registers to observe changes for Chrome settings we care about. | 109 // Registers to observe changes for Chrome settings we care about. |
110 void StartObservingSettingsChanges(); | 110 void StartObservingSettingsChanges(); |
111 | 111 |
112 // Stops listening for Chrome settings changes. | 112 // Stops listening for Chrome settings changes. |
113 void StopObservingSettingsChanges(); | 113 void StopObservingSettingsChanges(); |
114 | 114 |
115 // 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 |
116 // Android boot and send it to Android. | 116 // Android boot and send it to Android. |
117 void SyncRuntimeSettings() const; | 117 void SyncRuntimeSettings() const; |
118 // Send settings that need to be synced only on Android first start to | 118 // Determines whether the particular setting should be synced to Android. This |
119 // Android. | 119 // should happen if the pref is managed or if it transitions from the managed |
120 // to unmanaged state (which is captured by unsetting the user pref when the | |
121 // pref is managed and by setting it to |default_value| when the pref is | |
122 // unset). | |
123 bool ShouldSyncPolicyOrUserControlledPref( | |
124 const std::string& pref, | |
125 const base::Value& default_value) const; | |
126 // Determine whether a particular setting needs to be synced to Android. | |
127 // Keep these lines ordered lexicographically. | |
128 bool ShouldSyncBackupEnabled() const; | |
129 bool ShouldSyncLocationServiceEnabled() const; | |
130 // Send particular settings to Android. | |
120 // Keep these lines ordered lexicographically. | 131 // Keep these lines ordered lexicographically. |
121 void SyncAccessibilityLargeMouseCursorEnabled() const; | 132 void SyncAccessibilityLargeMouseCursorEnabled() const; |
122 void SyncAccessibilityVirtualKeyboardEnabled() const; | 133 void SyncAccessibilityVirtualKeyboardEnabled() const; |
123 void SyncBackupEnabled() const; | 134 void SyncBackupEnabled() const; |
124 void SyncFocusHighlightEnabled() const; | 135 void SyncFocusHighlightEnabled() const; |
125 void SyncFontSize() const; | 136 void SyncFontSize() const; |
126 void SyncInitialSettings() const; | 137 void SyncInitialSettings() const; |
127 void SyncLocale() const; | 138 void SyncLocale() const; |
128 void SyncLocationServiceEnabled() const; | 139 void SyncLocationServiceEnabled() const; |
129 void SyncProxySettings() const; | 140 void SyncProxySettings() const; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 } | 208 } |
198 SyncProxySettings(); | 209 SyncProxySettings(); |
199 } else if (pref_name == prefs::kAccessibilityFocusHighlightEnabled) { | 210 } else if (pref_name == prefs::kAccessibilityFocusHighlightEnabled) { |
200 SyncFocusHighlightEnabled(); | 211 SyncFocusHighlightEnabled(); |
201 } else if (pref_name == prefs::kAccessibilityLargeCursorEnabled) { | 212 } else if (pref_name == prefs::kAccessibilityLargeCursorEnabled) { |
202 SyncAccessibilityLargeMouseCursorEnabled(); | 213 SyncAccessibilityLargeMouseCursorEnabled(); |
203 } else if (pref_name == prefs::kAccessibilitySpokenFeedbackEnabled) { | 214 } else if (pref_name == prefs::kAccessibilitySpokenFeedbackEnabled) { |
204 SyncSpokenFeedbackEnabled(); | 215 SyncSpokenFeedbackEnabled(); |
205 } else if (pref_name == prefs::kAccessibilityVirtualKeyboardEnabled) { | 216 } else if (pref_name == prefs::kAccessibilityVirtualKeyboardEnabled) { |
206 SyncAccessibilityVirtualKeyboardEnabled(); | 217 SyncAccessibilityVirtualKeyboardEnabled(); |
218 } else if (pref_name == prefs::kArcBackupRestoreEnabled) { | |
219 if (ShouldSyncBackupEnabled()) | |
220 SyncBackupEnabled(); | |
207 } else if (pref_name == prefs::kArcLocationServiceEnabled) { | 221 } else if (pref_name == prefs::kArcLocationServiceEnabled) { |
208 const PrefService* const prefs = | 222 if (ShouldSyncLocationServiceEnabled()) |
209 ProfileManager::GetActiveUserProfile()->GetPrefs(); | |
210 if (prefs->IsManagedPreference(prefs::kArcLocationServiceEnabled)) | |
211 SyncLocationServiceEnabled(); | 223 SyncLocationServiceEnabled(); |
212 } else if (pref_name == prefs::kUse24HourClock) { | 224 } else if (pref_name == prefs::kUse24HourClock) { |
213 SyncUse24HourClock(); | 225 SyncUse24HourClock(); |
214 } else if (pref_name == prefs::kWebKitDefaultFixedFontSize || | 226 } else if (pref_name == prefs::kWebKitDefaultFixedFontSize || |
215 pref_name == prefs::kWebKitDefaultFontSize || | 227 pref_name == prefs::kWebKitDefaultFontSize || |
216 pref_name == prefs::kWebKitMinimumFontSize) { | 228 pref_name == prefs::kWebKitMinimumFontSize) { |
217 SyncFontSize(); | 229 SyncFontSize(); |
218 } else if (pref_name == proxy_config::prefs::kProxy) { | 230 } else if (pref_name == proxy_config::prefs::kProxy) { |
219 SyncProxySettings(); | 231 SyncProxySettings(); |
220 } else { | 232 } else { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 SyncAccessibilityVirtualKeyboardEnabled(); | 311 SyncAccessibilityVirtualKeyboardEnabled(); |
300 SyncFocusHighlightEnabled(); | 312 SyncFocusHighlightEnabled(); |
301 SyncFontSize(); | 313 SyncFontSize(); |
302 SyncLocale(); | 314 SyncLocale(); |
303 SyncProxySettings(); | 315 SyncProxySettings(); |
304 SyncReportingConsent(); | 316 SyncReportingConsent(); |
305 SyncSpokenFeedbackEnabled(); | 317 SyncSpokenFeedbackEnabled(); |
306 SyncTimeZone(); | 318 SyncTimeZone(); |
307 SyncUse24HourClock(); | 319 SyncUse24HourClock(); |
308 | 320 |
309 const PrefService* const prefs = | 321 if (ShouldSyncBackupEnabled()) |
310 ProfileManager::GetActiveUserProfile()->GetPrefs(); | |
311 if (prefs->IsManagedPreference(prefs::kArcBackupRestoreEnabled)) | |
312 SyncBackupEnabled(); | 322 SyncBackupEnabled(); |
313 if (prefs->IsManagedPreference(prefs::kArcLocationServiceEnabled)) | 323 if (ShouldSyncLocationServiceEnabled()) |
314 SyncLocationServiceEnabled(); | 324 SyncLocationServiceEnabled(); |
315 } | 325 } |
316 | 326 |
327 bool ArcSettingsServiceImpl::ShouldSyncPolicyOrUserControlledPref( | |
328 const std::string& pref, | |
329 const base::Value& default_value) const { | |
330 PrefService* const prefs = ProfileManager::GetActiveUserProfile()->GetPrefs(); | |
331 if (prefs->IsManagedPreference(pref)) { | |
332 // Unset the user pref so that if the pref becomes unmanaged at some point, | |
333 // this change will be synced. | |
334 prefs->ClearPref(pref); | |
hidehiko
2017/02/14 11:51:36
In general, side effect in a function to check the
emaxx
2017/02/15 03:40:59
Done. I left only non-modifying operations in the
| |
335 return true; | |
336 } | |
337 if (!prefs->HasPrefPath(pref)) { | |
338 // Set the pref value in order to prevent the subsequent syncing. | |
339 prefs->Set(pref, default_value); | |
340 return true; | |
341 } | |
342 return false; | |
343 } | |
344 | |
345 bool ArcSettingsServiceImpl::ShouldSyncBackupEnabled() const { | |
346 return ShouldSyncPolicyOrUserControlledPref(prefs::kArcBackupRestoreEnabled, | |
347 base::Value(false)); | |
348 } | |
349 | |
350 bool ArcSettingsServiceImpl::ShouldSyncLocationServiceEnabled() const { | |
351 return ShouldSyncPolicyOrUserControlledPref(prefs::kArcLocationServiceEnabled, | |
352 base::Value(false)); | |
353 } | |
354 | |
317 void ArcSettingsServiceImpl::SyncAccessibilityLargeMouseCursorEnabled() const { | 355 void ArcSettingsServiceImpl::SyncAccessibilityLargeMouseCursorEnabled() const { |
318 SendBoolPrefSettingsBroadcast( | 356 SendBoolPrefSettingsBroadcast( |
319 prefs::kAccessibilityLargeCursorEnabled, | 357 prefs::kAccessibilityLargeCursorEnabled, |
320 "org.chromium.arc.intent_helper.ACCESSIBILITY_LARGE_POINTER_ICON"); | 358 "org.chromium.arc.intent_helper.ACCESSIBILITY_LARGE_POINTER_ICON"); |
321 } | 359 } |
322 | 360 |
323 void ArcSettingsServiceImpl::SyncAccessibilityVirtualKeyboardEnabled() const { | 361 void ArcSettingsServiceImpl::SyncAccessibilityVirtualKeyboardEnabled() const { |
324 SendBoolPrefSettingsBroadcast( | 362 SendBoolPrefSettingsBroadcast( |
325 prefs::kAccessibilityVirtualKeyboardEnabled, | 363 prefs::kAccessibilityVirtualKeyboardEnabled, |
326 "org.chromium.arc.intent_helper.SET_SHOW_IME_WITH_HARD_KEYBOARD"); | 364 "org.chromium.arc.intent_helper.SET_SHOW_IME_WITH_HARD_KEYBOARD"); |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
535 | 573 |
536 void ArcSettingsService::OnInstanceReady() { | 574 void ArcSettingsService::OnInstanceReady() { |
537 impl_.reset(new ArcSettingsServiceImpl(arc_bridge_service())); | 575 impl_.reset(new ArcSettingsServiceImpl(arc_bridge_service())); |
538 } | 576 } |
539 | 577 |
540 void ArcSettingsService::OnInstanceClosed() { | 578 void ArcSettingsService::OnInstanceClosed() { |
541 impl_.reset(); | 579 impl_.reset(); |
542 } | 580 } |
543 | 581 |
544 } // namespace arc | 582 } // namespace arc |
OLD | NEW |