зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1241810 - Add EnrollAction for finding bookmarks of known sites to subscribe to. r=mcomella
MozReview-Commit-ID: LS59SRlAjH0 --HG-- extra : rebase_source : 1049dd5c4bab0fdcab6c796f6d2c556c9520fbb9
This commit is contained in:
Родитель
5c8f9083fa
Коммит
8ad808b071
|
@ -110,6 +110,7 @@ public interface BrowserDB {
|
|||
public abstract boolean isBookmark(ContentResolver cr, String uri);
|
||||
public abstract boolean addBookmark(ContentResolver cr, String title, String uri);
|
||||
public abstract Cursor getBookmarkForUrl(ContentResolver cr, String url);
|
||||
public abstract Cursor getBookmarksForPartialUrl(ContentResolver cr, String partialUrl);
|
||||
public abstract void removeBookmarksWithURL(ContentResolver cr, String uri);
|
||||
public abstract void registerBookmarkObserver(ContentResolver cr, ContentObserver observer);
|
||||
public abstract void updateBookmark(ContentResolver cr, int id, String uri, String title, String keyword);
|
||||
|
|
|
@ -1581,6 +1581,22 @@ public class LocalBrowserDB implements BrowserDB {
|
|||
return c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor getBookmarksForPartialUrl(ContentResolver cr, String partialUrl) {
|
||||
Cursor c = cr.query(mBookmarksUriWithProfile,
|
||||
new String[] { Bookmarks.GUID, Bookmarks._ID, Bookmarks.URL },
|
||||
Bookmarks.URL + " LIKE '%" + partialUrl + "%'", // TODO: Escaping!
|
||||
null,
|
||||
null);
|
||||
|
||||
if (c != null && c.getCount() == 0) {
|
||||
c.close();
|
||||
c = null;
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSuggestedSites(SuggestedSites suggestedSites) {
|
||||
mSuggestedSites = suggestedSites;
|
||||
|
|
|
@ -374,6 +374,11 @@ public class StubBrowserDB implements BrowserDB {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor getBookmarksForPartialUrl(ContentResolver cr, String partialUrl) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setSuggestedSites(SuggestedSites suggestedSites) {
|
||||
this.suggestedSites = suggestedSites;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
package org.mozilla.gecko.feeds;
|
||||
|
||||
import android.app.IntentService;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
|
@ -13,6 +14,7 @@ import com.keepsafe.switchboard.SwitchBoard;
|
|||
|
||||
import org.mozilla.gecko.AppConstants;
|
||||
import org.mozilla.gecko.feeds.action.CheckAction;
|
||||
import org.mozilla.gecko.feeds.action.EnrollAction;
|
||||
import org.mozilla.gecko.feeds.action.SubscribeAction;
|
||||
import org.mozilla.gecko.feeds.subscriptions.SubscriptionStorage;
|
||||
import org.mozilla.gecko.util.Experiments;
|
||||
|
@ -25,6 +27,15 @@ public class FeedService extends IntentService {
|
|||
|
||||
public static final String ACTION_SUBSCRIBE = AppConstants.ANDROID_PACKAGE_NAME + ".FEEDS.SUBSCRIBE";
|
||||
public static final String ACTION_CHECK = AppConstants.ANDROID_PACKAGE_NAME + ".FEEDS.CHECK";
|
||||
public static final String ACTION_ENROLL = AppConstants.ANDROID_PACKAGE_NAME + ".FEEDS.ENROLL";
|
||||
|
||||
public static void subscribe(Context context, String guid, String feedUrl) {
|
||||
Intent intent = new Intent(context, FeedService.class);
|
||||
intent.setAction(ACTION_SUBSCRIBE);
|
||||
intent.putExtra(SubscribeAction.EXTRA_GUID, guid);
|
||||
intent.putExtra(SubscribeAction.EXTRA_FEED_URL, feedUrl);
|
||||
context.startService(intent);
|
||||
}
|
||||
|
||||
private SubscriptionStorage storage;
|
||||
|
||||
|
@ -59,6 +70,10 @@ public class FeedService extends IntentService {
|
|||
new CheckAction(this, storage).perform();
|
||||
break;
|
||||
|
||||
case ACTION_ENROLL:
|
||||
new EnrollAction(this).perform();
|
||||
break;
|
||||
|
||||
default:
|
||||
Log.e(LOGTAG, "Unknown action: " + intent.getAction());
|
||||
}
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.gecko.feeds.action;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import org.mozilla.gecko.GeckoProfile;
|
||||
import org.mozilla.gecko.db.BrowserContract;
|
||||
import org.mozilla.gecko.db.BrowserDB;
|
||||
import org.mozilla.gecko.feeds.FeedService;
|
||||
import org.mozilla.gecko.feeds.knownsites.KnownSiteBlogger;
|
||||
import org.mozilla.gecko.feeds.knownsites.KnownSite;
|
||||
import org.mozilla.gecko.feeds.knownsites.KnownSiteMedium;
|
||||
|
||||
/**
|
||||
* EnrollAction: Search for bookmarks of known sites we can subscribe to.
|
||||
*/
|
||||
public class EnrollAction {
|
||||
private static final String LOGTAG = "FeedEnrollAction";
|
||||
|
||||
private static final KnownSite[] knownSites = {
|
||||
new KnownSiteMedium(),
|
||||
new KnownSiteBlogger(),
|
||||
};
|
||||
|
||||
private Context context;
|
||||
|
||||
public EnrollAction(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void perform() {
|
||||
Log.i(LOGTAG, "Searching for bookmarks to enroll in updates");
|
||||
|
||||
BrowserDB db = GeckoProfile.get(context).getDB();
|
||||
|
||||
for (KnownSite knownSite : knownSites) {
|
||||
searchFor(db, knownSite);
|
||||
}
|
||||
}
|
||||
|
||||
private void searchFor(BrowserDB db, KnownSite knownSite) {
|
||||
Cursor cursor = db.getBookmarksForPartialUrl(context.getContentResolver(), "://" + knownSite.getURLSearchString() + "/");
|
||||
if (cursor == null) {
|
||||
Log.d(LOGTAG, "Nothing found");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Log.d(LOGTAG, "Found " + cursor.getCount() + " websites");
|
||||
|
||||
while (cursor.moveToNext()) {
|
||||
final String guid = cursor.getString(cursor.getColumnIndex(BrowserContract.Bookmarks.GUID));
|
||||
final String url = cursor.getString(cursor.getColumnIndex(BrowserContract.Bookmarks.URL));
|
||||
|
||||
Log.d(LOGTAG, " (" + guid + ") " + url);
|
||||
|
||||
String feedUrl = knownSite.getFeedFromURL(url);
|
||||
if (!TextUtils.isEmpty(feedUrl)) {
|
||||
FeedService.subscribe(context, guid, feedUrl);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -273,6 +273,7 @@ gbjar.sources += ['java/org/mozilla/gecko/' + x for x in [
|
|||
'favicons/OnFaviconLoadedListener.java',
|
||||
'favicons/RemoteFavicon.java',
|
||||
'feeds/action/CheckAction.java',
|
||||
'feeds/action/EnrollAction.java',
|
||||
'feeds/action/SubscribeAction.java',
|
||||
'feeds/FeedFetcher.java',
|
||||
'feeds/FeedService.java',
|
||||
|
|
Загрузка…
Ссылка в новой задаче