Index: chrome/browser/search/instant_service.cc |
diff --git a/chrome/browser/search/instant_service.cc b/chrome/browser/search/instant_service.cc |
index 9470eed421117d2ad55d6b96977a911485358213..55a950af0f9ef6d4cb585345c7d3160905e93625 100644 |
--- a/chrome/browser/search/instant_service.cc |
+++ b/chrome/browser/search/instant_service.cc |
@@ -6,10 +6,12 @@ |
#include <stddef.h> |
-#include "base/strings/string_util.h" |
+#include "base/bind.h" |
+#include "base/feature_list.h" |
#include "build/build_config.h" |
#include "chrome/browser/chrome_notification_types.h" |
#include "chrome/browser/favicon/fallback_icon_service_factory.h" |
+#include "chrome/browser/favicon/favicon_service_factory.h" |
#include "chrome/browser/favicon/large_icon_service_factory.h" |
#include "chrome/browser/history/top_sites_factory.h" |
#include "chrome/browser/profiles/profile.h" |
@@ -17,6 +19,8 @@ |
#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/image_decoder_impl.h" |
+#include "chrome/browser/search/suggestions/suggestions_service_factory.h" |
#include "chrome/browser/search/thumbnail_source.h" |
#include "chrome/browser/search_engines/template_url_service_factory.h" |
#include "chrome/browser/search_engines/ui_thread_search_terms_data.h" |
@@ -31,21 +35,19 @@ |
#include "components/favicon/core/fallback_icon_service.h" |
#include "components/favicon/core/large_icon_service.h" |
#include "components/history/core/browser/top_sites.h" |
+#include "components/image_fetcher/image_fetcher_impl.h" |
#include "components/keyed_service/core/service_access_type.h" |
+#include "components/ntp_tiles/icon_cacher.h" |
#include "components/search/search.h" |
#include "components/search_engines/template_url_service.h" |
#include "content/public/browser/browser_thread.h" |
-#include "content/public/browser/child_process_security_policy.h" |
#include "content/public/browser/notification_service.h" |
#include "content/public/browser/notification_types.h" |
#include "content/public/browser/render_process_host.h" |
#include "content/public/browser/url_data_source.h" |
-#include "content/public/common/url_constants.h" |
-#include "extensions/common/constants.h" |
#include "third_party/skia/include/core/SkColor.h" |
#include "ui/gfx/color_utils.h" |
#include "ui/gfx/image/image_skia.h" |
-#include "url/url_constants.h" |
#if !defined(OS_ANDROID) |
#include "chrome/browser/search/local_ntp_source.h" |
@@ -57,6 +59,13 @@ |
#include "chrome/browser/themes/theme_service_factory.h" |
#endif // defined(ENABLE_THEMES) |
+namespace { |
+ |
+const base::Feature kNtpTilesFeature{"NTPTilesInInstantService", |
+ base::FEATURE_DISABLED_BY_DEFAULT}; |
+ |
+} // namespace |
+ |
InstantService::InstantService(Profile* profile) |
: profile_(profile), |
template_url_service_(TemplateURLServiceFactory::GetForProfile(profile_)), |
@@ -93,13 +102,32 @@ InstantService::InstantService(Profile* profile) |
content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
content::NotificationService::AllSources()); |
- scoped_refptr<history::TopSites> top_sites = |
- TopSitesFactory::GetForProfile(profile_); |
- if (top_sites) { |
- top_sites->AddObserver(this); |
- // Immediately query the TopSites state. |
- TopSitesChanged(top_sites.get(), |
- history::TopSitesObserver::ChangeReason::MOST_VISITED); |
+ if (base::FeatureList::IsEnabled(kNtpTilesFeature)) { |
+ most_visited_sites_ = base::MakeUnique<ntp_tiles::MostVisitedSites>( |
+ profile_->GetPrefs(), TopSitesFactory::GetForProfile(profile_), |
+ suggestions::SuggestionsServiceFactory::GetForProfile(profile_), |
+ /*popular_sites=*/nullptr, |
+ base::MakeUnique<ntp_tiles::IconCacher>( |
+ FaviconServiceFactory::GetForProfile( |
+ profile, ServiceAccessType::IMPLICIT_ACCESS), |
+ base::MakeUnique<image_fetcher::ImageFetcherImpl>( |
+ base::MakeUnique<suggestions::ImageDecoderImpl>(), |
+ profile->GetRequestContext())), |
+ /*supervisor=*/nullptr); |
+ // TODO(treib): Add supervisor. |
+ } |
+ |
+ if (most_visited_sites_) { |
sfiera
2016/11/29 10:24:03
base::MakeUnique<>() cannot return nullptr, can it
Marc Treib
2016/11/29 15:20:13
Done.
|
+ most_visited_sites_->SetMostVisitedURLsObserver(this, 8); |
+ } else { |
+ scoped_refptr<history::TopSites> top_sites = |
sfiera
2016/11/29 10:24:03
We repeat this call a lot below. Is there a reason
Marc Treib
2016/11/29 15:20:13
I don't see a reason not to keep a ref to the TopS
|
+ TopSitesFactory::GetForProfile(profile_); |
+ if (top_sites) { |
+ top_sites->AddObserver(this); |
+ // Immediately query the TopSites state. |
+ TopSitesChanged(top_sites.get(), |
+ history::TopSitesObserver::ChangeReason::MOST_VISITED); |
+ } |
} |
if (profile_ && profile_->GetResourceContext()) { |
@@ -170,31 +198,47 @@ void InstantService::RemoveObserver(InstantServiceObserver* observer) { |
} |
void InstantService::OnNewTabPageOpened() { |
- scoped_refptr<history::TopSites> top_sites = |
- TopSitesFactory::GetForProfile(profile_); |
- if (top_sites) |
- top_sites->SyncWithHistory(); |
+ if (most_visited_sites_) { |
+ most_visited_sites_->Refresh(); |
+ } else { |
+ scoped_refptr<history::TopSites> top_sites = |
+ TopSitesFactory::GetForProfile(profile_); |
+ if (top_sites) |
+ top_sites->SyncWithHistory(); |
+ } |
} |
void InstantService::DeleteMostVisitedItem(const GURL& url) { |
- scoped_refptr<history::TopSites> top_sites = |
- TopSitesFactory::GetForProfile(profile_); |
- if (top_sites) |
- top_sites->AddBlacklistedURL(url); |
+ if (most_visited_sites_) { |
+ most_visited_sites_->AddOrRemoveBlacklistedUrl(url, true); |
+ } else { |
+ scoped_refptr<history::TopSites> top_sites = |
+ TopSitesFactory::GetForProfile(profile_); |
+ if (top_sites) |
+ top_sites->AddBlacklistedURL(url); |
+ } |
} |
void InstantService::UndoMostVisitedDeletion(const GURL& url) { |
- scoped_refptr<history::TopSites> top_sites = |
- TopSitesFactory::GetForProfile(profile_); |
- if (top_sites) |
- top_sites->RemoveBlacklistedURL(url); |
+ if (most_visited_sites_) { |
+ most_visited_sites_->AddOrRemoveBlacklistedUrl(url, false); |
+ } else { |
+ scoped_refptr<history::TopSites> top_sites = |
+ TopSitesFactory::GetForProfile(profile_); |
+ if (top_sites) |
+ top_sites->RemoveBlacklistedURL(url); |
+ } |
} |
void InstantService::UndoAllMostVisitedDeletions() { |
- scoped_refptr<history::TopSites> top_sites = |
- TopSitesFactory::GetForProfile(profile_); |
- if (top_sites) |
- top_sites->ClearBlacklistedURLs(); |
+ if (most_visited_sites_) { |
+ most_visited_sites_->ClearBlacklistedUrls(); |
+ } else { |
+ scoped_refptr<history::TopSites> top_sites = |
+ TopSitesFactory::GetForProfile(profile_); |
+ if (top_sites) |
+ top_sites->ClearBlacklistedURLs(); |
+ } |
} |
void InstantService::UpdateThemeInfo() { |
@@ -236,10 +280,14 @@ void InstantService::Shutdown() { |
instant_io_context_)); |
} |
- scoped_refptr<history::TopSites> top_sites = |
- TopSitesFactory::GetForProfile(profile_); |
- if (top_sites) |
- top_sites->RemoveObserver(this); |
+ if (most_visited_sites_) { |
+ most_visited_sites_.reset(); |
+ } else { |
+ scoped_refptr<history::TopSites> top_sites = |
+ TopSitesFactory::GetForProfile(profile_); |
+ if (top_sites) |
+ top_sites->RemoveObserver(this); |
+ } |
instant_io_context_ = NULL; |
} |
@@ -291,6 +339,26 @@ void InstantService::OnMostVisitedItemsReceived( |
NotifyAboutMostVisitedItems(); |
} |
+void InstantService::OnMostVisitedURLsAvailable( |
+ const ntp_tiles::NTPTilesVector& tiles) { |
+ DCHECK(most_visited_sites_); |
+ most_visited_items_.clear(); |
+ for (const ntp_tiles::NTPTile& tile : tiles) { |
+ InstantMostVisitedItem item; |
+ item.url = tile.url; |
+ item.title = tile.title; |
+ item.thumbnail = tile.thumbnail_url; |
+ item.favicon = tile.favicon_url; |
+ item.is_server_side_suggestion = |
+ tile.source == ntp_tiles::NTPTileSource::SUGGESTIONS_SERVICE; |
+ most_visited_items_.push_back(item); |
+ } |
+ |
+ NotifyAboutMostVisitedItems(); |
+} |
+ |
+void InstantService::OnIconMadeAvailable(const GURL& site_url) {} |
+ |
void InstantService::NotifyAboutMostVisitedItems() { |
for (InstantServiceObserver& observer : observers_) |
observer.MostVisitedItemsChanged(most_visited_items_); |
@@ -451,10 +519,12 @@ void InstantService::OnTemplateURLServiceChanged() { |
} |
void InstantService::TopSitesLoaded(history::TopSites* top_sites) { |
+ DCHECK(!most_visited_sites_); |
} |
void InstantService::TopSitesChanged(history::TopSites* top_sites, |
ChangeReason change_reason) { |
+ DCHECK(!most_visited_sites_); |
// As forced urls already come from tiles, we can safely ignore those updates. |
if (change_reason == history::TopSitesObserver::ChangeReason::FORCED_URL) |
return; |