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

Unified Diff: chrome/browser/android/most_visited_sites.cc

Issue 815983002: Topsites become keyedService based. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 6 years 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/browser/android/most_visited_sites.cc
diff --git a/chrome/browser/android/most_visited_sites.cc b/chrome/browser/android/most_visited_sites.cc
index ed6a5d7e6c99f021adc36875f7574bf2b4908c3b..e7325e0bfcd7dec23c4eb85595beba0063095148 100644
--- a/chrome/browser/android/most_visited_sites.cc
+++ b/chrome/browser/android/most_visited_sites.cc
@@ -19,7 +19,8 @@
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "chrome/browser/chrome_notification_types.h"
-#include "chrome/browser/history/top_sites.h"
+#include "chrome/browser/history/top_sites_provider.h"
+#include "chrome/browser/history/top_sites_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_android.h"
#include "chrome/browser/search/suggestions/suggestions_service_factory.h"
@@ -44,7 +45,7 @@ using base::android::ScopedJavaGlobalRef;
using base::android::ToJavaArrayOfStrings;
using base::android::CheckException;
using content::BrowserThread;
-using history::TopSites;
+using history::TopSitesProvider;
using suggestions::ChromeSuggestion;
using suggestions::SuggestionsProfile;
using suggestions::SuggestionsService;
@@ -106,16 +107,17 @@ SkBitmap ExtractThumbnail(const base::RefCountedMemory& image_data) {
return image.get() ? *image : SkBitmap();
}
-void AddForcedURLOnUIThread(scoped_refptr<history::TopSites> top_sites,
- const GURL& url) {
+void AddForcedURLOnUIThread(
+ scoped_refptr<history::TopSitesProvider> top_sites_provider,
+ const GURL& url) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- top_sites->AddForcedURL(url, base::Time::Now());
+ top_sites_provider->AddForcedURL(url, base::Time::Now());
}
// Runs on the DB thread.
void GetUrlThumbnailTask(
std::string url_string,
- scoped_refptr<TopSites> top_sites,
+ scoped_refptr<TopSitesProvider> top_sites_provider,
ScopedJavaGlobalRef<jobject>* j_callback,
MostVisitedSites::LookupSuccessCallback lookup_success_ui_callback,
base::Closure lookup_failed_ui_callback) {
@@ -127,7 +129,7 @@ void GetUrlThumbnailTask(
GURL gurl(url_string);
scoped_refptr<base::RefCountedMemory> data;
- if (top_sites->GetPageThumbnail(gurl, false, &data)) {
+ if (top_sites_provider->GetPageThumbnail(gurl, false, &data)) {
SkBitmap thumbnail_bitmap = ExtractThumbnail(*data.get());
if (!thumbnail_bitmap.empty()) {
j_bitmap_ref->Reset(
@@ -139,7 +141,7 @@ void GetUrlThumbnailTask(
// the list to be fetched at the next visit to this site.
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
- base::Bind(AddForcedURLOnUIThread, top_sites, gurl));
+ base::Bind(AddForcedURLOnUIThread, top_sites_provider, gurl));
// If appropriate, return on the UI thread to execute the proper callback.
if (!lookup_failed_ui_callback.is_null()) {
@@ -232,16 +234,18 @@ void MostVisitedSites::SetMostVisitedURLsObserver(JNIEnv* env,
QueryMostVisitedURLs();
- history::TopSites* top_sites = profile_->GetTopSites();
- if (top_sites) {
+ history::TopSitesProvider* top_sites_provider =
+ TopSitesServiceFactory::GetForProfile(profile_);
+ if (top_sites_provider) {
// TopSites updates itself after a delay. To ensure up-to-date results,
// force an update now.
- top_sites->SyncWithHistory();
+ top_sites_provider->SyncWithHistory();
// Register for notification when TopSites changes so that we can update
// ourself.
- registrar_.Add(this, chrome::NOTIFICATION_TOP_SITES_CHANGED,
- content::Source<history::TopSites>(top_sites));
+ registrar_.Add(
+ this, chrome::NOTIFICATION_TOP_SITES_CHANGED,
+ content::Source<history::TopSitesProvider>(top_sites_provider));
}
}
@@ -256,7 +260,8 @@ void MostVisitedSites::GetURLThumbnail(JNIEnv* env,
j_callback->Reset(env, j_callback_obj);
std::string url_string = ConvertJavaStringToUTF8(env, url);
- scoped_refptr<TopSites> top_sites(profile_->GetTopSites());
+ scoped_refptr<TopSitesProvider> top_sites_provider(
+ TopSitesServiceFactory::GetForProfile(profile_));
// If the Suggestions service is enabled and in use, create a callback to
// fetch a server thumbnail from it, in case the local thumbnail is not found.
@@ -276,10 +281,9 @@ void MostVisitedSites::GetURLThumbnail(JNIEnv* env,
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
- base::Bind(
- &GetUrlThumbnailTask, url_string, top_sites,
- base::Owned(j_callback), lookup_success_callback,
- lookup_failed_callback));
+ base::Bind(&GetUrlThumbnailTask, url_string, top_sites_provider,
+ base::Owned(j_callback), lookup_success_callback,
+ lookup_failed_callback));
}
void MostVisitedSites::BlacklistUrl(JNIEnv* env,
@@ -289,9 +293,10 @@ void MostVisitedSites::BlacklistUrl(JNIEnv* env,
switch (mv_source_) {
case TOP_SITES: {
- TopSites* top_sites = profile_->GetTopSites();
- DCHECK(top_sites);
- top_sites->AddBlacklistedURL(GURL(url));
+ TopSitesProvider* top_sites_provider =
+ TopSitesServiceFactory::GetForProfile(profile_);
+ DCHECK(top_sites_provider);
+ top_sites_provider->AddBlacklistedURL(GURL(url));
break;
}
@@ -377,16 +382,16 @@ void MostVisitedSites::QueryMostVisitedURLs() {
}
void MostVisitedSites::InitiateTopSitesQuery() {
- TopSites* top_sites = profile_->GetTopSites();
- if (!top_sites)
+ TopSitesProvider* top_sites_provider =
+ TopSitesServiceFactory::GetForProfile(profile_);
+ if (!top_sites_provider)
return;
- top_sites->GetMostVisitedURLs(
- base::Bind(
- &MostVisitedSites::OnMostVisitedURLsAvailable,
- weak_ptr_factory_.GetWeakPtr(),
- base::Owned(new ScopedJavaGlobalRef<jobject>(observer_)),
- num_sites_),
+ top_sites_provider->GetMostVisitedURLs(
+ base::Bind(&MostVisitedSites::OnMostVisitedURLsAvailable,
+ weak_ptr_factory_.GetWeakPtr(),
+ base::Owned(new ScopedJavaGlobalRef<jobject>(observer_)),
+ num_sites_),
false);
}

Powered by Google App Engine
This is Rietveld 408576698