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

Unified Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/bookmarkswidget/BookmarkWidgetUpdateListener.java

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 years, 7 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/android/java_staging/src/org/chromium/chrome/browser/bookmarkswidget/BookmarkWidgetUpdateListener.java
diff --git a/chrome/android/java_staging/src/org/chromium/chrome/browser/bookmarkswidget/BookmarkWidgetUpdateListener.java b/chrome/android/java_staging/src/org/chromium/chrome/browser/bookmarkswidget/BookmarkWidgetUpdateListener.java
new file mode 100644
index 0000000000000000000000000000000000000000..f75ae9a2ddfd9633e80c7cfbe636d95234a74374
--- /dev/null
+++ b/chrome/android/java_staging/src/org/chromium/chrome/browser/bookmarkswidget/BookmarkWidgetUpdateListener.java
@@ -0,0 +1,108 @@
+// Copyright 2015 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.bookmarkswidget;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.database.ContentObserver;
+import android.os.Handler;
+
+import org.chromium.chrome.browser.ChromeBrowserProvider;
+import org.chromium.sync.AndroidSyncSettings;
+
+/**
+ * Encapsulates the different observers that can cause a widget update.
+ */
+public class BookmarkWidgetUpdateListener {
+ private static final String TAG = "BookmarkWidgetUpdateListener";
+
+ /**
+ * Notifies about the different kinds of updates that affect the bookmarks widget.
+ */
+ public interface UpdateListener {
+ /**
+ * Called when the was a change in the bookmark model.
+ */
+ public void onBookmarkModelUpdated();
+
+ /**
+ * Called when the app sync enabled status has changed.
+ *
+ * @param enabled New state of the sync setting after the change.
+ */
+ public void onSyncEnabledStatusUpdated(boolean enabled);
+
+ /**
+ * Called when a page thumbnail has been updated or created.
+ */
+ public void onThumbnailUpdated(String url);
+ }
+
+ /**
+ * Handles changes in the bookmarks.
+ */
+ private class BookmarkUpdateObserver extends ContentObserver {
+ public BookmarkUpdateObserver() {
+ super(new Handler());
+ }
+
+ @Override
+ public void onChange(boolean selfChange) {
+ if (mListener != null) mListener.onBookmarkModelUpdated();
+ }
+ }
+
+ /**
+ * Handles changes in the sync settings.
+ */
+ private class SyncUpdateObserver implements AndroidSyncSettings.AndroidSyncSettingsObserver {
+ private boolean mIsSyncEnabled;
+
+ public SyncUpdateObserver() {
+ AndroidSyncSettings.registerObserver(mContext, this);
+ mIsSyncEnabled = AndroidSyncSettings.isSyncEnabled(mContext);
+ }
+
+ @Override
+ public void androidSyncSettingsChanged() {
+ boolean newSyncStatus = AndroidSyncSettings.isSyncEnabled(mContext);
+ if (mIsSyncEnabled != newSyncStatus) {
+ mIsSyncEnabled = newSyncStatus;
+ if (mListener != null) mListener.onSyncEnabledStatusUpdated(newSyncStatus);
+ }
+ }
+ }
+
+ private final Context mContext;
+ private UpdateListener mListener;
+ private BookmarkUpdateObserver mBookmarkUpdateObserver;
+ private AndroidSyncSettings.AndroidSyncSettingsObserver mSyncObserver;
+
+ public BookmarkWidgetUpdateListener(Context context, UpdateListener listener) {
+ mContext = context;
+
+ if (listener == null) return;
+ mListener = listener;
+
+ // Register observers for bookmark and sync state updates.
+ ContentResolver contentResolver = mContext.getContentResolver();
+ mBookmarkUpdateObserver = new BookmarkUpdateObserver();
+ contentResolver.registerContentObserver(
+ ChromeBrowserProvider.getBookmarksApiUri(mContext), true,
+ mBookmarkUpdateObserver);
+
+ mSyncObserver = new SyncUpdateObserver();
+ }
+
+ public void destroy() {
+ if (mListener == null) return;
+
+ // Unregister observers.
+ ContentResolver contentResolver = mContext.getContentResolver();
+ contentResolver.unregisterContentObserver(mBookmarkUpdateObserver);
+ AndroidSyncSettings.unregisterObserver(mContext, mSyncObserver);
+ mListener = null;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698