| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser; |
| 6 |
| 7 import android.app.backup.BackupManager; |
| 8 import android.content.Context; |
| 9 import android.content.SharedPreferences; |
| 10 |
| 11 import org.chromium.base.ContextUtils; |
| 12 import org.chromium.base.VisibleForTesting; |
| 13 import org.chromium.base.annotations.CalledByNative; |
| 14 import org.chromium.base.annotations.JNINamespace; |
| 15 import org.chromium.components.signin.ChromeSigninController; |
| 16 |
| 17 /** |
| 18 * Class for watching for changes to the Android preferences that are backed up
using Android |
| 19 * key/value backup. |
| 20 */ |
| 21 @JNINamespace("chrome::android") |
| 22 public class ChromeBackupWatcher { |
| 23 private BackupManager mBackupManager; |
| 24 |
| 25 @VisibleForTesting |
| 26 @CalledByNative |
| 27 static ChromeBackupWatcher createChromeBackupWatcher() { |
| 28 return new ChromeBackupWatcher(); |
| 29 } |
| 30 |
| 31 private ChromeBackupWatcher() { |
| 32 Context context = ContextUtils.getApplicationContext(); |
| 33 if (context == null) return; |
| 34 |
| 35 mBackupManager = new BackupManager(context); |
| 36 // Watch the Java preferences that are backed up. |
| 37 SharedPreferences sharedPrefs = ContextUtils.getAppSharedPreferences(); |
| 38 sharedPrefs.registerOnSharedPreferenceChangeListener( |
| 39 new SharedPreferences.OnSharedPreferenceChangeListener() { |
| 40 |
| 41 @Override |
| 42 public void onSharedPreferenceChanged( |
| 43 SharedPreferences sharedPreferences, String key) { |
| 44 // Update the backup if the user id or any of the backed
up Android |
| 45 // preferences change. |
| 46 if (key.equals(ChromeSigninController.SIGNED_IN_ACCOUNT_
KEY)) { |
| 47 onBackupPrefsChanged(); |
| 48 return; |
| 49 } |
| 50 for (String pref : ChromeBackupAgent.BACKUP_ANDROID_BOOL
_PREFS) { |
| 51 if (key.equals(pref)) { |
| 52 onBackupPrefsChanged(); |
| 53 return; |
| 54 } |
| 55 } |
| 56 } |
| 57 |
| 58 }); |
| 59 } |
| 60 |
| 61 @CalledByNative |
| 62 private void onBackupPrefsChanged() { |
| 63 mBackupManager.dataChanged(); |
| 64 } |
| 65 } |
| OLD | NEW |