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

Unified Diff: chrome/browser/search/instant_service.cc

Issue 1260113002: Adds an experiment that enabled SuggestionsService suggestions (MostLikely) on LocalNTP (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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/browser/search/instant_service.cc
diff --git a/chrome/browser/search/instant_service.cc b/chrome/browser/search/instant_service.cc
index 5f668effb17431b5f644491abaeffea26079ed2a..7980c81bc86936a4ca8e7c23b2164a67f37c1ed5 100644
--- a/chrome/browser/search/instant_service.cc
+++ b/chrome/browser/search/instant_service.cc
@@ -4,6 +4,8 @@
#include "chrome/browser/search/instant_service.h"
+#include "base/metrics/field_trial.h"
+#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/favicon/fallback_icon_service_factory.h"
#include "chrome/browser/favicon/large_icon_service_factory.h"
@@ -13,6 +15,7 @@
#include "chrome/browser/search/instant_service_observer.h"
#include "chrome/browser/search/most_visited_iframe_source.h"
#include "chrome/browser/search/search.h"
+#include "chrome/browser/search/suggestions/suggestions_service_factory.h"
#include "chrome/browser/search/suggestions/suggestions_source.h"
#include "chrome/browser/search/thumbnail_source.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
@@ -29,6 +32,8 @@
#include "components/history/core/browser/top_sites.h"
#include "components/keyed_service/core/service_access_type.h"
#include "components/search_engines/template_url_service.h"
+#include "components/suggestions/proto/suggestions.pb.h"
+#include "components/suggestions/suggestions_service.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h"
@@ -53,6 +58,7 @@ InstantService::InstantService(Profile* profile)
: profile_(profile),
template_url_service_(TemplateURLServiceFactory::GetForProfile(profile_)),
omnibox_start_margin_(chrome::kDisableStartMargin),
+ suggestions_service_(NULL),
weak_ptr_factory_(this) {
// The initialization below depends on a typical set of browser threads. Skip
// it if we are running in a unit test without the full suite.
@@ -130,6 +136,20 @@ InstantService::InstantService(Profile* profile)
content::URLDataSource::Add(profile_, new MostVisitedIframeSource());
content::URLDataSource::Add(
profile_, new suggestions::SuggestionsSource(profile_));
+
+ if (base::StartsWith(
kmadhusu 2015/07/30 21:57:02 Define a helper function in the anonymous namespac
fserb 2015/07/31 17:08:17 Done.
+ base::FieldTrialList::FindFullName("LocalNTPSuggestionsService"),
+ "Enabled", base::CompareCase::INSENSITIVE_ASCII)) {
+ suggestions_service_ =
+ suggestions::SuggestionsServiceFactory::GetForProfile(profile_);
+ }
+
+ if (suggestions_service_) {
+ suggestions_service_->FetchSuggestionsData(
+ suggestions::INITIALIZED_ENABLED_HISTORY,
+ base::Bind(&InstantService::OnSuggestionsAvailable,
+ weak_ptr_factory_.GetWeakPtr()));
+ }
}
InstantService::~InstantService() {
@@ -167,6 +187,12 @@ void InstantService::DeleteMostVisitedItem(const GURL& url) {
return;
top_sites->AddBlacklistedURL(url);
+ if (suggestions_service_) {
+ suggestions_service_->BlacklistURL(
+ url, base::Bind(&InstantService::OnSuggestionsAvailable,
+ weak_ptr_factory_.GetWeakPtr()),
+ base::Closure());
+ }
}
void InstantService::UndoMostVisitedDeletion(const GURL& url) {
@@ -176,6 +202,12 @@ void InstantService::UndoMostVisitedDeletion(const GURL& url) {
return;
top_sites->RemoveBlacklistedURL(url);
+ if (suggestions_service_) {
+ suggestions_service_->UndoBlacklistURL(
+ url, base::Bind(&InstantService::OnSuggestionsAvailable,
+ weak_ptr_factory_.GetWeakPtr()),
+ base::Closure());
+ }
}
void InstantService::UndoAllMostVisitedDeletions() {
@@ -185,6 +217,11 @@ void InstantService::UndoAllMostVisitedDeletions() {
return;
top_sites->ClearBlacklistedURLs();
+ if (suggestions_service_) {
+ suggestions_service_->ClearBlacklist(
+ base::Bind(&InstantService::OnSuggestionsAvailable,
+ weak_ptr_factory_.GetWeakPtr()));
+ }
}
void InstantService::UpdateThemeInfo() {
@@ -265,6 +302,23 @@ void InstantService::OnRendererProcessTerminated(int process_id) {
}
}
+void InstantService::OnSuggestionsAvailable(
+ const suggestions::SuggestionsProfile& profile) {
+ std::vector<InstantMostVisitedItem> new_suggestions_items;
+ for (int i = 0; i < profile.suggestions_size(); ++i) {
+ const suggestions::ChromeSuggestion& suggestion = profile.suggestions(i);
+
+ InstantMostVisitedItem item;
+ item.url = GURL(suggestion.url());
+ item.title = base::UTF8ToUTF16(suggestion.title());
+ item.thumbnail = GURL(suggestion.thumbnail());
+ item.favicon = GURL(suggestion.favicon_url());
+ new_suggestions_items.push_back(item);
+ }
+ suggestions_items_ = new_suggestions_items;
+ NotifyAboutMostVisitedItems();
+}
+
void InstantService::OnMostVisitedItemsReceived(
const history::MostVisitedURLList& data) {
history::MostVisitedURLList reordered_data(data);
@@ -282,8 +336,13 @@ void InstantService::OnMostVisitedItemsReceived(
}
void InstantService::NotifyAboutMostVisitedItems() {
- FOR_EACH_OBSERVER(InstantServiceObserver, observers_,
- MostVisitedItemsChanged(most_visited_items_));
+ if (suggestions_service_ && !suggestions_items_.empty()) {
+ FOR_EACH_OBSERVER(InstantServiceObserver, observers_,
+ MostVisitedItemsChanged(suggestions_items_));
+ } else {
+ FOR_EACH_OBSERVER(InstantServiceObserver, observers_,
+ MostVisitedItemsChanged(most_visited_items_));
+ }
}
#if defined(ENABLE_THEMES)

Powered by Google App Engine
This is Rietveld 408576698