Bug 994734 - Set cursor notification URI in HomeProvider (r=margaret)
authorLucas Rocha <lucasr@mozilla.com>
Wed, 23 Apr 2014 15:22:34 +0100
changeset 180183 cb8bf883a0cd0eddf24c91a757ac7b11336d5c1c
parent 180182 7d9d72c9cfac53a5b9b4406446f94e8b0ae0ce59
child 180184 3cd4615c60ba0f4c0197fcf8691edc8e287a8a45
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersmargaret
bugs994734
milestone31.0a1
Bug 994734 - Set cursor notification URI in HomeProvider (r=margaret)
mobile/android/base/db/HomeProvider.java
mobile/android/base/home/DynamicPanel.java
--- a/mobile/android/base/db/HomeProvider.java
+++ b/mobile/android/base/db/HomeProvider.java
@@ -10,16 +10,17 @@ import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.db.BrowserContract.HomeItems;
 import org.mozilla.gecko.db.DBUtils;
 import org.mozilla.gecko.sqlite.SQLiteBridge;
 import org.mozilla.gecko.util.RawResource;
 
+import android.content.ContentResolver;
 import android.content.ContentValues;
 import android.content.UriMatcher;
 import android.database.Cursor;
 import android.database.MatrixCursor;
 import android.net.Uri;
 import android.util.Log;
 
 public class HomeProvider extends SQLiteBridgeContentProvider {
@@ -79,17 +80,23 @@ public class HomeProvider extends SQLite
             throw new IllegalArgumentException("All queries should contain a dataset ID parameter");
         }
 
         selection = DBUtils.concatenateWhere(selection, HomeItems.DATASET_ID + " = ?");
         selectionArgs = DBUtils.appendSelectionArgs(selectionArgs,
                                                     new String[] { datasetId });
 
         // Otherwise, let the SQLiteContentProvider implementation take care of this query for us!
-        return super.query(uri, projection, selection, selectionArgs, sortOrder);
+        final Cursor c = super.query(uri, projection, selection, selectionArgs, sortOrder);
+        if (c != null) {
+            final ContentResolver cr = getContext().getContentResolver();
+            c.setNotificationUri(cr, getDatasetNotificationUri(datasetId));
+        }
+
+        return c;
     }
 
     /**
      * Returns a cursor populated with static fake data.
      */
     private Cursor queryFakeItems(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
         JSONArray items = null;
         try {
@@ -175,10 +182,12 @@ public class HomeProvider extends SQLite
     public void onPreInsert(ContentValues values, Uri uri, SQLiteBridge db) { }
 
     @Override
     public void onPreUpdate(ContentValues values, Uri uri, SQLiteBridge db) { }
 
     @Override
     public void onPostQuery(Cursor cursor, Uri uri, SQLiteBridge db) { }
 
-
+    public static Uri getDatasetNotificationUri(String datasetId) {
+        return Uri.withAppendedPath(HomeItems.CONTENT_URI, datasetId);
+    }
 }
--- a/mobile/android/base/home/DynamicPanel.java
+++ b/mobile/android/base/home/DynamicPanel.java
@@ -7,16 +7,17 @@ package org.mozilla.gecko.home;
 
 import org.json.JSONException;
 import org.json.JSONObject;
 
 import org.mozilla.gecko.GeckoAppShell;
 import org.mozilla.gecko.db.BrowserContract;
 import org.mozilla.gecko.db.BrowserContract.HomeItems;
 import org.mozilla.gecko.db.DBUtils;
+import org.mozilla.gecko.db.HomeProvider;
 import org.mozilla.gecko.home.HomeConfig.PanelConfig;
 import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
 import org.mozilla.gecko.home.PanelLayout.DatasetHandler;
 import org.mozilla.gecko.home.PanelLayout.DatasetRequest;
 import org.mozilla.gecko.util.GeckoEventListener;
 import org.mozilla.gecko.util.ThreadUtils;
 import org.mozilla.gecko.util.UiAsyncTask;
 
@@ -316,21 +317,17 @@ public class DynamicPanel extends HomeFr
         final Activity activity = getActivity();
         if (activity == null) {
             return;
         }
 
         Log.d(LOGTAG, "Refresh request for dataset: " + datasetId);
 
         final ContentResolver cr = activity.getContentResolver();
-        cr.notifyChange(getDatasetNotificationUri(datasetId), null);
-    }
-
-    private static Uri getDatasetNotificationUri(String datasetId) {
-        return Uri.withAppendedPath(HomeItems.CONTENT_URI, datasetId);
+        cr.notifyChange(HomeProvider.getDatasetNotificationUri(datasetId), null);
     }
 
     /**
      * Used by the PanelLayout to make load and reset requests to
      * the holding fragment.
      */
     private class PanelDatasetHandler implements DatasetHandler {
         @Override
@@ -413,25 +410,17 @@ public class DynamicPanel extends HomeFr
 
             final Uri queryUri = HomeItems.CONTENT_URI.buildUpon()
                                                       .appendQueryParameter(BrowserContract.PARAM_DATASET_ID,
                                                                             mRequest.getDatasetId())
                                                       .build();
 
             // XXX: You can use HomeItems.CONTENT_FAKE_URI for development
             // to pull items from fake_home_items.json.
-            final Cursor c = cr.query(queryUri, null, selection, selectionArgs, null);
-
-            // SQLiteBridgeContentProvider may return a null Cursor if the database hasn't been created yet.
-            if (c != null) {
-                final Uri notificationUri = getDatasetNotificationUri(mRequest.getDatasetId());
-                c.setNotificationUri(cr, notificationUri);
-            }
-
-            return c;
+            return cr.query(queryUri, null, selection, selectionArgs, null);
         }
     }
 
     /**
      * LoaderCallbacks implementation that interacts with the LoaderManager.
      */
     private class PanelLoaderCallbacks implements LoaderCallbacks<Cursor> {
         @Override