Index: chrome/browser/ui/search/instant_controller.cc |
diff --git a/chrome/browser/ui/search/instant_controller.cc b/chrome/browser/ui/search/instant_controller.cc |
index b28322987c56159db68255e7786fb48b0b481e84..43f1ceae82444db25c7e94a2d86626ce54f1bfab 100644 |
--- a/chrome/browser/ui/search/instant_controller.cc |
+++ b/chrome/browser/ui/search/instant_controller.cc |
@@ -7,9 +7,14 @@ |
#include "base/metrics/histogram.h" |
#include "base/prefs/pref_service.h" |
#include "base/strings/stringprintf.h" |
+#include "base/strings/utf_string_conversions.h" |
+#include "chrome/browser/autocomplete/autocomplete_provider.h" |
+#include "chrome/browser/autocomplete/autocomplete_result.h" |
+#include "chrome/browser/autocomplete/search_provider.h" |
#include "chrome/browser/chrome_notification_types.h" |
#include "chrome/browser/content_settings/content_settings_provider.h" |
#include "chrome/browser/content_settings/host_content_settings_map.h" |
+#include "chrome/browser/history/top_sites.h" |
#include "chrome/browser/platform_util.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/search/instant_service.h" |
@@ -22,6 +27,7 @@ |
#include "chrome/browser/ui/search/instant_ntp.h" |
#include "chrome/browser/ui/search/instant_tab.h" |
#include "chrome/browser/ui/search/search_tab_helper.h" |
+#include "chrome/browser/ui/tabs/tab_strip_model.h" |
#include "chrome/common/chrome_switches.h" |
#include "chrome/common/content_settings_types.h" |
#include "chrome/common/pref_names.h" |
@@ -112,6 +118,17 @@ void DeletePageSoon(scoped_ptr<T> page) { |
base::MessageLoop::current()->DeleteSoon(FROM_HERE, page.release()); |
} |
+// 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 |
InstantController::InstantController(BrowserInstantController* browser, |
@@ -318,10 +335,13 @@ void InstantController::ClearDebugEvents() { |
void InstantController::MostVisitedItemsChanged( |
const std::vector<InstantMostVisitedItem>& items) { |
+ std::vector<InstantMostVisitedItem> items_copy(items); |
+ MaybeRemoveMostVisitedItems(&items_copy); |
+ |
if (ntp_) |
- ntp_->sender()->SendMostVisitedItems(items); |
+ ntp_->sender()->SendMostVisitedItems(items_copy); |
if (instant_tab_) |
- instant_tab_->sender()->SendMostVisitedItems(items); |
+ instant_tab_->sender()->SendMostVisitedItems(items_copy); |
content::NotificationService::current()->Notify( |
chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, |
@@ -674,3 +694,26 @@ bool InstantController::InStartup() const { |
InstantService* InstantController::GetInstantService() const { |
return InstantServiceFactory::GetForProfile(profile()); |
} |
+ |
+void InstantController::MaybeRemoveMostVisitedItems( |
+ std::vector<InstantMostVisitedItem>* items) { |
+// The following #if is due to the facts that tabstripmodel cannot be accessed |
+// in the same way, that chrome::FindBrowserWithWebContents 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::TopSites::IsClientInTabsGroup()) |
+ return; |
+ |
+ const TabStripModel* tab_strip_model = browser_->tab_strip_model(); |
+ history::TopSites* top_sites = browser_->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::TopSites::RemoveItemsMatchingOpenTabs(open_urls, items); |
+#endif |
+} |