Index: chrome/browser/ui/search/instant_page.cc |
diff --git a/chrome/browser/ui/search/instant_page.cc b/chrome/browser/ui/search/instant_page.cc |
index 9177352ceaf91302af700ebf926b2036c93d1002..0beacb91b827a9b13e2fa6c38a0f9239f61b836e 100644 |
--- a/chrome/browser/ui/search/instant_page.cc |
+++ b/chrome/browser/ui/search/instant_page.cc |
@@ -7,13 +7,17 @@ |
#include "apps/app_launcher.h" |
#include "base/strings/utf_string_conversions.h" |
#include "chrome/browser/chrome_notification_types.h" |
+#include "chrome/browser/history/most_visited_tiles_experiment.h" |
+#include "chrome/browser/history/top_sites.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/search/instant_service.h" |
#include "chrome/browser/search/instant_service_factory.h" |
#include "chrome/browser/search/search.h" |
+#include "chrome/browser/ui/browser_finder.h" |
#include "chrome/browser/ui/search/instant_tab.h" |
#include "chrome/browser/ui/search/search_model.h" |
#include "chrome/browser/ui/search/search_tab_helper.h" |
+#include "chrome/browser/ui/tabs/tab_strip_model.h" |
#include "chrome/common/render_messages.h" |
#include "chrome/common/url_constants.h" |
#include "content/public/browser/navigation_controller.h" |
@@ -26,6 +30,21 @@ |
#include "ui/base/resource/resource_bundle.h" |
#include "ui/gfx/font.h" |
+namespace { |
+ |
+// Creates a set containing the canonical URLs of the currently open tabs. |
+void GetOpenUrls(const TabStripModel& tabs, |
+ const history::TopSites& top_sites, |
+ std::set<std::string>* urls) { |
+ for (int i = 0; i < tabs.count(); ++i) { |
+ content::WebContents* web_contents = tabs.GetWebContentsAt(i); |
+ if (web_contents) |
+ urls->insert(top_sites.GetCanonicalURLString(web_contents->GetURL())); |
+ } |
+} |
+ |
+} // namespace |
+ |
InstantPage::Delegate::~Delegate() { |
} |
@@ -187,7 +206,10 @@ void InstantPage::ThemeInfoChanged(const ThemeBackgroundInfo& theme_info) { |
void InstantPage::MostVisitedItemsChanged( |
const std::vector<InstantMostVisitedItem>& items) { |
- sender()->SendMostVisitedItems(items); |
+ std::vector<InstantMostVisitedItem> items_copy(items); |
+ MaybeRemoveMostVisitedItems(&items_copy); |
+ |
+ sender()->SendMostVisitedItems(items_copy); |
content::NotificationService::current()->Notify( |
chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, |
@@ -283,3 +305,31 @@ void InstantPage::ClearContents() { |
sender()->SetContents(NULL); |
Observe(NULL); |
} |
+ |
+void InstantPage::MaybeRemoveMostVisitedItems( |
+ std::vector<InstantMostVisitedItem>* items) { |
+// The following #if is due to the facts that tabstripmodel cannot be accessed |
+// in the same way, that chrome::FindBrowserWithProfile is undefined in Android |
+// and, moreover, that this experiment is not designed to run on Android devices |
+// due to different NTP presentation. |
+#if !defined(OS_ANDROID) |
+ if (!history::MostVisitedTilesExperiment::IsDontShowOpenURLsEnabled()) { |
+ return; |
+ } |
+ |
+ TabStripModel* tab_strip_model = chrome::FindBrowserWithProfile( |
+ profile_, |
+ chrome::GetActiveDesktop())->tab_strip_model(); |
+ history::TopSites* top_sites = profile_->GetTopSites(); |
+ if (!tab_strip_model || !top_sites) { |
+ NOTREACHED(); |
+ return; |
+ } |
+ |
+ std::set<std::string> open_urls; |
+ GetOpenUrls(*tab_strip_model, *top_sites, &open_urls); |
+ history::MostVisitedTilesExperiment::RemoveItemsMatchingOpenTabs( |
+ open_urls, items); |
+ |
+#endif |
+} |