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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ChromeBackupWatcher.java

Issue 2511713002: Implement Android key/value backup (Closed)
Patch Set: Created 4 years, 1 month 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/android/java/src/org/chromium/chrome/browser/ChromeBackupWatcher.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ChromeBackupWatcher.java b/chrome/android/java/src/org/chromium/chrome/browser/ChromeBackupWatcher.java
new file mode 100644
index 0000000000000000000000000000000000000000..554b054c57e220a5432cff9127047d3ebf4d800e
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ChromeBackupWatcher.java
@@ -0,0 +1,65 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser;
+
+import android.app.backup.BackupManager;
+import android.content.Context;
+import android.content.SharedPreferences;
+
+import org.chromium.base.ContextUtils;
+import org.chromium.base.VisibleForTesting;
+import org.chromium.base.annotations.CalledByNative;
+import org.chromium.base.annotations.JNINamespace;
+import org.chromium.components.signin.ChromeSigninController;
+
+/**
+ * Class for watching for changes to the Android preferences that are backed up using Android
+ * key/value backup.
+ */
+@JNINamespace("chrome::android")
+public class ChromeBackupWatcher {
+ private BackupManager mBackupManager;
+
+ @VisibleForTesting
+ @CalledByNative
+ static ChromeBackupWatcher createChromeBackupWatcher() {
+ return new ChromeBackupWatcher();
+ }
+
+ private ChromeBackupWatcher() {
+ Context context = ContextUtils.getApplicationContext();
+ if (context == null) return;
+
+ mBackupManager = new BackupManager(context);
+ // Watch the Java preferences that are backed up.
+ SharedPreferences sharedPrefs = ContextUtils.getAppSharedPreferences();
+ sharedPrefs.registerOnSharedPreferenceChangeListener(
+ new SharedPreferences.OnSharedPreferenceChangeListener() {
+
+ @Override
+ public void onSharedPreferenceChanged(
+ SharedPreferences sharedPreferences, String key) {
+ // Update the backup if the user id or any of the backed up Android
+ // preferences change.
+ if (key.equals(ChromeSigninController.SIGNED_IN_ACCOUNT_KEY)) {
+ onBackupPrefsChanged();
+ return;
+ }
+ for (String pref : ChromeBackupAgent.BACKUP_ANDROID_BOOL_PREFS) {
+ if (key.equals(pref)) {
+ onBackupPrefsChanged();
+ return;
+ }
+ }
+ }
+
+ });
+ }
+
+ @CalledByNative
+ private void onBackupPrefsChanged() {
+ mBackupManager.dataChanged();
+ }
+}
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ChromeBackupAgent.java ('k') | chrome/android/java_sources.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698