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

Side by Side Diff: chrome/browser/ui/search/instant_controller.cc

Issue 17114002: Field trial removing tiles from NTP if URL is already open - for 1993 clients (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed asvitkines comments Created 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/search/instant_controller.h" 5 #include "chrome/browser/ui/search/instant_controller.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/autocomplete/autocomplete_provider.h"
12 #include "chrome/browser/autocomplete/autocomplete_result.h"
13 #include "chrome/browser/autocomplete/search_provider.h"
10 #include "chrome/browser/chrome_notification_types.h" 14 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/content_settings/content_settings_provider.h" 15 #include "chrome/browser/content_settings/content_settings_provider.h"
12 #include "chrome/browser/content_settings/host_content_settings_map.h" 16 #include "chrome/browser/content_settings/host_content_settings_map.h"
17 #include "chrome/browser/history/top_sites.h"
13 #include "chrome/browser/platform_util.h" 18 #include "chrome/browser/platform_util.h"
14 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/search/instant_service.h" 20 #include "chrome/browser/search/instant_service.h"
16 #include "chrome/browser/search/instant_service_factory.h" 21 #include "chrome/browser/search/instant_service_factory.h"
17 #include "chrome/browser/search/search.h" 22 #include "chrome/browser/search/search.h"
18 #include "chrome/browser/search_engines/search_terms_data.h" 23 #include "chrome/browser/search_engines/search_terms_data.h"
19 #include "chrome/browser/search_engines/template_url_service.h" 24 #include "chrome/browser/search_engines/template_url_service.h"
20 #include "chrome/browser/search_engines/template_url_service_factory.h" 25 #include "chrome/browser/search_engines/template_url_service_factory.h"
21 #include "chrome/browser/ui/browser_instant_controller.h" 26 #include "chrome/browser/ui/browser_instant_controller.h"
22 #include "chrome/browser/ui/search/instant_ntp.h" 27 #include "chrome/browser/ui/search/instant_ntp.h"
23 #include "chrome/browser/ui/search/instant_tab.h" 28 #include "chrome/browser/ui/search/instant_tab.h"
24 #include "chrome/browser/ui/search/search_tab_helper.h" 29 #include "chrome/browser/ui/search/search_tab_helper.h"
30 #include "chrome/browser/ui/tabs/tab_strip_model.h"
25 #include "chrome/common/chrome_switches.h" 31 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/content_settings_types.h" 32 #include "chrome/common/content_settings_types.h"
27 #include "chrome/common/pref_names.h" 33 #include "chrome/common/pref_names.h"
28 #include "chrome/common/url_constants.h" 34 #include "chrome/common/url_constants.h"
29 #include "components/sessions/serialized_navigation_entry.h" 35 #include "components/sessions/serialized_navigation_entry.h"
30 #include "content/public/browser/navigation_entry.h" 36 #include "content/public/browser/navigation_entry.h"
31 #include "content/public/browser/notification_service.h" 37 #include "content/public/browser/notification_service.h"
32 #include "content/public/browser/render_process_host.h" 38 #include "content/public/browser/render_process_host.h"
33 #include "content/public/browser/render_widget_host_view.h" 39 #include "content/public/browser/render_widget_host_view.h"
34 #include "content/public/browser/user_metrics.h" 40 #include "content/public/browser/user_metrics.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 template <typename T> 111 template <typename T>
106 void DeletePageSoon(scoped_ptr<T> page) { 112 void DeletePageSoon(scoped_ptr<T> page) {
107 if (page->contents()) { 113 if (page->contents()) {
108 base::MessageLoop::current()->DeleteSoon( 114 base::MessageLoop::current()->DeleteSoon(
109 FROM_HERE, page->ReleaseContents().release()); 115 FROM_HERE, page->ReleaseContents().release());
110 } 116 }
111 117
112 base::MessageLoop::current()->DeleteSoon(FROM_HERE, page.release()); 118 base::MessageLoop::current()->DeleteSoon(FROM_HERE, page.release());
113 } 119 }
114 120
121 // Creates a set containing the canonical URLs of the currently open tabs.
122 void GetOpenUrls(const TabStripModel& tabs,
123 const history::TopSites& top_sites,
124 std::set<std::string>* urls) {
125 for (int i = 0; i < tabs.count(); ++i) {
126 content::WebContents* web_contents = tabs.GetWebContentsAt(i);
127 if (web_contents)
128 urls->insert(top_sites.GetCanonicalURLString(web_contents->GetURL()));
129 }
130 }
131
115 } // namespace 132 } // namespace
116 133
117 InstantController::InstantController(BrowserInstantController* browser, 134 InstantController::InstantController(BrowserInstantController* browser,
118 bool extended_enabled) 135 bool extended_enabled)
119 : browser_(browser), 136 : browser_(browser),
120 extended_enabled_(extended_enabled), 137 extended_enabled_(extended_enabled),
121 omnibox_focus_state_(OMNIBOX_FOCUS_NONE), 138 omnibox_focus_state_(OMNIBOX_FOCUS_NONE),
122 omnibox_focus_change_reason_(OMNIBOX_FOCUS_CHANGE_EXPLICIT), 139 omnibox_focus_change_reason_(OMNIBOX_FOCUS_CHANGE_EXPLICIT),
123 omnibox_bounds_(-1, -1, 0, 0) { 140 omnibox_bounds_(-1, -1, 0, 0) {
124 141
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 if (debug_events_.size() > kMaxDebugEventSize) 328 if (debug_events_.size() > kMaxDebugEventSize)
312 debug_events_.pop_back(); 329 debug_events_.pop_back();
313 } 330 }
314 331
315 void InstantController::ClearDebugEvents() { 332 void InstantController::ClearDebugEvents() {
316 debug_events_.clear(); 333 debug_events_.clear();
317 } 334 }
318 335
319 void InstantController::MostVisitedItemsChanged( 336 void InstantController::MostVisitedItemsChanged(
320 const std::vector<InstantMostVisitedItem>& items) { 337 const std::vector<InstantMostVisitedItem>& items) {
338 std::vector<InstantMostVisitedItem> items_copy(items);
339 MaybeRemoveMostVisitedItems(&items_copy);
340
321 if (ntp_) 341 if (ntp_)
322 ntp_->sender()->SendMostVisitedItems(items); 342 ntp_->sender()->SendMostVisitedItems(items_copy);
323 if (instant_tab_) 343 if (instant_tab_)
324 instant_tab_->sender()->SendMostVisitedItems(items); 344 instant_tab_->sender()->SendMostVisitedItems(items_copy);
325 345
326 content::NotificationService::current()->Notify( 346 content::NotificationService::current()->Notify(
327 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, 347 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS,
328 content::Source<InstantController>(this), 348 content::Source<InstantController>(this),
329 content::NotificationService::NoDetails()); 349 content::NotificationService::NoDetails());
330 } 350 }
331 351
332 void InstantController::DeleteMostVisitedItem(const GURL& url) { 352 void InstantController::DeleteMostVisitedItem(const GURL& url) {
333 DCHECK(!url.is_empty()); 353 DCHECK(!url.is_empty());
334 InstantService* instant_service = GetInstantService(); 354 InstantService* instant_service = GetInstantService();
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 687
668 bool InstantController::InStartup() const { 688 bool InstantController::InStartup() const {
669 // TODO(shishir): This is not completely reliable. Find a better way to detect 689 // TODO(shishir): This is not completely reliable. Find a better way to detect
670 // startup time. 690 // startup time.
671 return !browser_->GetActiveWebContents(); 691 return !browser_->GetActiveWebContents();
672 } 692 }
673 693
674 InstantService* InstantController::GetInstantService() const { 694 InstantService* InstantController::GetInstantService() const {
675 return InstantServiceFactory::GetForProfile(profile()); 695 return InstantServiceFactory::GetForProfile(profile());
676 } 696 }
697
698 void InstantController::MaybeRemoveMostVisitedItems(
699 std::vector<InstantMostVisitedItem>* items) {
700 // The following #if is due to the facts that tabstripmodel cannot be accessed
701 // in the same way, that chrome::FindBrowserWithWebContents is undefined in
702 // Android and, moreover, that this experiment is not designed to run on Android
703 // devices due to different NTP presentation.
704 #if !defined(OS_ANDROID)
705 if (!history::TopSites::IsClientInTabsGroup())
706 return;
707
708 const TabStripModel* tab_strip_model = browser_->tab_strip_model();
709 history::TopSites* top_sites = browser_->profile()->GetTopSites();
710 if (!tab_strip_model || !top_sites) {
711 NOTREACHED();
712 return;
713 }
714
715 std::set<std::string> open_urls;
716 GetOpenUrls(*tab_strip_model, *top_sites, &open_urls);
717 history::TopSites::RemoveItemsMatchingOpenTabs(open_urls, items);
718 #endif
719 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698