OLD | NEW |
---|---|
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/most_visited_tiles_experiment.h" | |
18 #include "chrome/browser/history/top_sites.h" | |
13 #include "chrome/browser/platform_util.h" | 19 #include "chrome/browser/platform_util.h" |
14 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/search/instant_service.h" | 21 #include "chrome/browser/search/instant_service.h" |
16 #include "chrome/browser/search/instant_service_factory.h" | 22 #include "chrome/browser/search/instant_service_factory.h" |
17 #include "chrome/browser/search/search.h" | 23 #include "chrome/browser/search/search.h" |
18 #include "chrome/browser/search_engines/search_terms_data.h" | 24 #include "chrome/browser/search_engines/search_terms_data.h" |
19 #include "chrome/browser/search_engines/template_url_service.h" | 25 #include "chrome/browser/search_engines/template_url_service.h" |
20 #include "chrome/browser/search_engines/template_url_service_factory.h" | 26 #include "chrome/browser/search_engines/template_url_service_factory.h" |
21 #include "chrome/browser/ui/browser_instant_controller.h" | 27 #include "chrome/browser/ui/browser_instant_controller.h" |
22 #include "chrome/browser/ui/search/instant_ntp.h" | 28 #include "chrome/browser/ui/search/instant_ntp.h" |
23 #include "chrome/browser/ui/search/instant_tab.h" | 29 #include "chrome/browser/ui/search/instant_tab.h" |
24 #include "chrome/browser/ui/search/search_tab_helper.h" | 30 #include "chrome/browser/ui/search/search_tab_helper.h" |
31 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
25 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/content_settings_types.h" | 33 #include "chrome/common/content_settings_types.h" |
27 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
28 #include "chrome/common/url_constants.h" | 35 #include "chrome/common/url_constants.h" |
29 #include "components/sessions/serialized_navigation_entry.h" | 36 #include "components/sessions/serialized_navigation_entry.h" |
30 #include "content/public/browser/navigation_entry.h" | 37 #include "content/public/browser/navigation_entry.h" |
31 #include "content/public/browser/notification_service.h" | 38 #include "content/public/browser/notification_service.h" |
32 #include "content/public/browser/render_process_host.h" | 39 #include "content/public/browser/render_process_host.h" |
33 #include "content/public/browser/render_widget_host_view.h" | 40 #include "content/public/browser/render_widget_host_view.h" |
34 #include "content/public/browser/user_metrics.h" | 41 #include "content/public/browser/user_metrics.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 template <typename T> | 112 template <typename T> |
106 void DeletePageSoon(scoped_ptr<T> page) { | 113 void DeletePageSoon(scoped_ptr<T> page) { |
107 if (page->contents()) { | 114 if (page->contents()) { |
108 base::MessageLoop::current()->DeleteSoon( | 115 base::MessageLoop::current()->DeleteSoon( |
109 FROM_HERE, page->ReleaseContents().release()); | 116 FROM_HERE, page->ReleaseContents().release()); |
110 } | 117 } |
111 | 118 |
112 base::MessageLoop::current()->DeleteSoon(FROM_HERE, page.release()); | 119 base::MessageLoop::current()->DeleteSoon(FROM_HERE, page.release()); |
113 } | 120 } |
114 | 121 |
122 // Creates a set containing the canonical URLs of the currently open tabs. | |
123 void GetOpenUrls(const TabStripModel& tabs, | |
124 const history::TopSites& top_sites, | |
125 std::set<std::string>* urls) { | |
126 for (int i = 0; i < tabs.count(); ++i) { | |
127 content::WebContents* web_contents = tabs.GetWebContentsAt(i); | |
128 if (web_contents) | |
129 urls->insert(top_sites.GetCanonicalURLString(web_contents->GetURL())); | |
130 } | |
131 } | |
132 | |
115 } // namespace | 133 } // namespace |
116 | 134 |
117 InstantController::InstantController(BrowserInstantController* browser, | 135 InstantController::InstantController(BrowserInstantController* browser, |
118 bool extended_enabled) | 136 bool extended_enabled) |
119 : browser_(browser), | 137 : browser_(browser), |
120 extended_enabled_(extended_enabled), | 138 extended_enabled_(extended_enabled), |
121 omnibox_focus_state_(OMNIBOX_FOCUS_NONE), | 139 omnibox_focus_state_(OMNIBOX_FOCUS_NONE), |
122 omnibox_focus_change_reason_(OMNIBOX_FOCUS_CHANGE_EXPLICIT), | 140 omnibox_focus_change_reason_(OMNIBOX_FOCUS_CHANGE_EXPLICIT), |
123 omnibox_bounds_(-1, -1, 0, 0) { | 141 omnibox_bounds_(-1, -1, 0, 0) { |
124 | 142 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
311 if (debug_events_.size() > kMaxDebugEventSize) | 329 if (debug_events_.size() > kMaxDebugEventSize) |
312 debug_events_.pop_back(); | 330 debug_events_.pop_back(); |
313 } | 331 } |
314 | 332 |
315 void InstantController::ClearDebugEvents() { | 333 void InstantController::ClearDebugEvents() { |
316 debug_events_.clear(); | 334 debug_events_.clear(); |
317 } | 335 } |
318 | 336 |
319 void InstantController::MostVisitedItemsChanged( | 337 void InstantController::MostVisitedItemsChanged( |
320 const std::vector<InstantMostVisitedItem>& items) { | 338 const std::vector<InstantMostVisitedItem>& items) { |
339 std::vector<InstantMostVisitedItem> items_copy(items); | |
340 MaybeRemoveMostVisitedItems(&items_copy); | |
341 | |
321 if (ntp_) | 342 if (ntp_) |
322 ntp_->sender()->SendMostVisitedItems(items); | 343 ntp_->sender()->SendMostVisitedItems(items_copy); |
323 if (instant_tab_) | 344 if (instant_tab_) |
324 instant_tab_->sender()->SendMostVisitedItems(items); | 345 instant_tab_->sender()->SendMostVisitedItems(items_copy); |
325 | 346 |
326 content::NotificationService::current()->Notify( | 347 content::NotificationService::current()->Notify( |
327 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, | 348 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, |
328 content::Source<InstantController>(this), | 349 content::Source<InstantController>(this), |
329 content::NotificationService::NoDetails()); | 350 content::NotificationService::NoDetails()); |
330 } | 351 } |
331 | 352 |
332 void InstantController::DeleteMostVisitedItem(const GURL& url) { | 353 void InstantController::DeleteMostVisitedItem(const GURL& url) { |
333 DCHECK(!url.is_empty()); | 354 DCHECK(!url.is_empty()); |
334 InstantService* instant_service = GetInstantService(); | 355 InstantService* instant_service = GetInstantService(); |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
667 | 688 |
668 bool InstantController::InStartup() const { | 689 bool InstantController::InStartup() const { |
669 // TODO(shishir): This is not completely reliable. Find a better way to detect | 690 // TODO(shishir): This is not completely reliable. Find a better way to detect |
670 // startup time. | 691 // startup time. |
671 return !browser_->GetActiveWebContents(); | 692 return !browser_->GetActiveWebContents(); |
672 } | 693 } |
673 | 694 |
674 InstantService* InstantController::GetInstantService() const { | 695 InstantService* InstantController::GetInstantService() const { |
675 return InstantServiceFactory::GetForProfile(profile()); | 696 return InstantServiceFactory::GetForProfile(profile()); |
676 } | 697 } |
698 | |
699 void InstantController::MaybeRemoveMostVisitedItems( | |
700 std::vector<InstantMostVisitedItem>* items) { | |
701 // The following #if is due to the facts that tabstripmodel cannot be accessed | |
702 // in the same way, that chrome::FindBrowserWithWebContents is undefined in | |
703 // Android and, moreover, that this experiment is not designed to run on Android | |
704 // devices due to different NTP presentation. | |
705 #if !defined(OS_ANDROID) | |
706 if (!history::MostVisitedTilesExperiment::IsDontShowOpenURLsEnabled()) | |
Alexei Svitkine (slow)
2013/07/22 21:14:10
This function seems to have identical logic betwee
annark1
2013/07/23 19:52:21
That's how I had originally tried to do this, but
Alexei Svitkine (slow)
2013/07/23 20:10:51
Then it sounds like the helper function should be
annark1
2013/07/24 01:23:58
I was able to consolidate the two GetOpenURLs func
| |
707 return; | |
708 | |
709 const TabStripModel* tab_strip_model = browser_->tab_strip_model(); | |
710 history::TopSites* top_sites = browser_->profile()->GetTopSites(); | |
711 if (!tab_strip_model || !top_sites) { | |
712 NOTREACHED(); | |
713 return; | |
714 } | |
715 | |
716 std::set<std::string> open_urls; | |
717 GetOpenUrls(*tab_strip_model, *top_sites, &open_urls); | |
718 history::MostVisitedTilesExperiment::RemoveItemsMatchingOpenTabs( | |
719 open_urls, items); | |
720 #endif | |
721 } | |
OLD | NEW |