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

Unified Diff: chrome/browser/chromeos/arc/intent_helper/arc_settings_service.cc

Issue 2682833003: Skip ARC initial screen when everything is set up by policy (Closed)
Patch Set: Sync during managed->unmanaged transition 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/arc/intent_helper/arc_settings_service.cc
diff --git a/chrome/browser/chromeos/arc/intent_helper/arc_settings_service.cc b/chrome/browser/chromeos/arc/intent_helper/arc_settings_service.cc
index b52c9cac018f5bcfe45e98757899b1efb867c2e4..ae2dfd417d90c88c72b502d6bcd402633d5303e2 100644
--- a/chrome/browser/chromeos/arc/intent_helper/arc_settings_service.cc
+++ b/chrome/browser/chromeos/arc/intent_helper/arc_settings_service.cc
@@ -115,8 +115,19 @@ class ArcSettingsServiceImpl
// Retrieves Chrome's state for the settings that need to be synced on each
// Android boot and send it to Android.
void SyncRuntimeSettings() const;
- // Send settings that need to be synced only on Android first start to
- // Android.
+ // Determines whether the particular setting should be synced to Android. This
+ // should happen if the pref is managed or if it transitions from the managed
+ // to unmanaged state (which is captured by unsetting the user pref when the
+ // pref is managed and by setting it to |default_value| when the pref is
+ // unset).
+ bool ShouldSyncPolicyOrUserControlledPref(
+ const std::string& pref,
+ const base::Value& default_value) const;
+ // Determine whether a particular setting needs to be synced to Android.
+ // Keep these lines ordered lexicographically.
+ bool ShouldSyncBackupEnabled() const;
+ bool ShouldSyncLocationServiceEnabled() const;
+ // Send particular settings to Android.
// Keep these lines ordered lexicographically.
void SyncAccessibilityLargeMouseCursorEnabled() const;
void SyncAccessibilityVirtualKeyboardEnabled() const;
@@ -204,10 +215,11 @@ void ArcSettingsServiceImpl::OnPrefChanged(const std::string& pref_name) const {
SyncSpokenFeedbackEnabled();
} else if (pref_name == prefs::kAccessibilityVirtualKeyboardEnabled) {
SyncAccessibilityVirtualKeyboardEnabled();
+ } else if (pref_name == prefs::kArcBackupRestoreEnabled) {
+ if (ShouldSyncBackupEnabled())
+ SyncBackupEnabled();
} else if (pref_name == prefs::kArcLocationServiceEnabled) {
- const PrefService* const prefs =
- ProfileManager::GetActiveUserProfile()->GetPrefs();
- if (prefs->IsManagedPreference(prefs::kArcLocationServiceEnabled))
+ if (ShouldSyncLocationServiceEnabled())
SyncLocationServiceEnabled();
} else if (pref_name == prefs::kUse24HourClock) {
SyncUse24HourClock();
@@ -306,14 +318,40 @@ void ArcSettingsServiceImpl::SyncRuntimeSettings() const {
SyncTimeZone();
SyncUse24HourClock();
- const PrefService* const prefs =
- ProfileManager::GetActiveUserProfile()->GetPrefs();
- if (prefs->IsManagedPreference(prefs::kArcBackupRestoreEnabled))
+ if (ShouldSyncBackupEnabled())
SyncBackupEnabled();
- if (prefs->IsManagedPreference(prefs::kArcLocationServiceEnabled))
+ if (ShouldSyncLocationServiceEnabled())
SyncLocationServiceEnabled();
}
+bool ArcSettingsServiceImpl::ShouldSyncPolicyOrUserControlledPref(
+ const std::string& pref,
+ const base::Value& default_value) const {
+ PrefService* const prefs = ProfileManager::GetActiveUserProfile()->GetPrefs();
+ if (prefs->IsManagedPreference(pref)) {
+ // Unset the user pref so that if the pref becomes unmanaged at some point,
+ // this change will be synced.
+ 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
+ return true;
+ }
+ if (!prefs->HasPrefPath(pref)) {
+ // Set the pref value in order to prevent the subsequent syncing.
+ prefs->Set(pref, default_value);
+ return true;
+ }
+ return false;
+}
+
+bool ArcSettingsServiceImpl::ShouldSyncBackupEnabled() const {
+ return ShouldSyncPolicyOrUserControlledPref(prefs::kArcBackupRestoreEnabled,
+ base::Value(false));
+}
+
+bool ArcSettingsServiceImpl::ShouldSyncLocationServiceEnabled() const {
+ return ShouldSyncPolicyOrUserControlledPref(prefs::kArcLocationServiceEnabled,
+ base::Value(false));
+}
+
void ArcSettingsServiceImpl::SyncAccessibilityLargeMouseCursorEnabled() const {
SendBoolPrefSettingsBroadcast(
prefs::kAccessibilityLargeCursorEnabled,

Powered by Google App Engine
This is Rietveld 408576698