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 "chrome/browser/content_settings/content_settings_provider.h" | 10 #include "chrome/browser/content_settings/content_settings_provider.h" |
11 #include "chrome/browser/content_settings/host_content_settings_map.h" | 11 #include "chrome/browser/content_settings/host_content_settings_map.h" |
12 #include "chrome/browser/history/top_sites.h" | |
12 #include "chrome/browser/platform_util.h" | 13 #include "chrome/browser/platform_util.h" |
13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/search/instant_service.h" | 15 #include "chrome/browser/search/instant_service.h" |
15 #include "chrome/browser/search/instant_service_factory.h" | 16 #include "chrome/browser/search/instant_service_factory.h" |
16 #include "chrome/browser/search/search.h" | 17 #include "chrome/browser/search/search.h" |
17 #include "chrome/browser/search_engines/search_terms_data.h" | 18 #include "chrome/browser/search_engines/search_terms_data.h" |
18 #include "chrome/browser/search_engines/template_url_service.h" | 19 #include "chrome/browser/search_engines/template_url_service.h" |
19 #include "chrome/browser/search_engines/template_url_service_factory.h" | 20 #include "chrome/browser/search_engines/template_url_service_factory.h" |
20 #include "chrome/browser/ui/browser_instant_controller.h" | 21 #include "chrome/browser/ui/browser_instant_controller.h" |
21 #include "chrome/browser/ui/search/instant_ntp.h" | 22 #include "chrome/browser/ui/search/instant_ntp.h" |
22 #include "chrome/browser/ui/search/instant_tab.h" | 23 #include "chrome/browser/ui/search/instant_tab.h" |
23 #include "chrome/browser/ui/search/search_tab_helper.h" | 24 #include "chrome/browser/ui/search/search_tab_helper.h" |
25 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
24 #include "chrome/common/chrome_notification_types.h" | 26 #include "chrome/common/chrome_notification_types.h" |
25 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/content_settings_types.h" | 28 #include "chrome/common/content_settings_types.h" |
27 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
28 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
29 #include "components/sessions/serialized_navigation_entry.h" | 31 #include "components/sessions/serialized_navigation_entry.h" |
30 #include "content/public/browser/navigation_entry.h" | 32 #include "content/public/browser/navigation_entry.h" |
31 #include "content/public/browser/notification_service.h" | 33 #include "content/public/browser/notification_service.h" |
32 #include "content/public/browser/render_process_host.h" | 34 #include "content/public/browser/render_process_host.h" |
33 #include "content/public/browser/render_widget_host_view.h" | 35 #include "content/public/browser/render_widget_host_view.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 template <typename T> | 107 template <typename T> |
106 void DeletePageSoon(scoped_ptr<T> page) { | 108 void DeletePageSoon(scoped_ptr<T> page) { |
107 if (page->contents()) { | 109 if (page->contents()) { |
108 base::MessageLoop::current()->DeleteSoon( | 110 base::MessageLoop::current()->DeleteSoon( |
109 FROM_HERE, page->ReleaseContents().release()); | 111 FROM_HERE, page->ReleaseContents().release()); |
110 } | 112 } |
111 | 113 |
112 base::MessageLoop::current()->DeleteSoon(FROM_HERE, page.release()); | 114 base::MessageLoop::current()->DeleteSoon(FROM_HERE, page.release()); |
113 } | 115 } |
114 | 116 |
117 // Creates a set containing the canonical URLs of the currently open tabs. | |
118 void GetOpenUrls(const TabStripModel& tabs, | |
119 const history::TopSites& ts, | |
Alexei Svitkine (slow)
2013/07/04 20:28:30
Nit: ts -> top_sites
annark1
2013/07/16 18:07:09
Done.
| |
120 std::set<std::string>* urls) { | |
121 for (int i = 0; i < tabs.count(); ++i) { | |
122 content::WebContents* web_contents = tabs.GetWebContentsAt(i); | |
123 if (web_contents) | |
124 urls->insert(ts.GetCanonicalURLString(web_contents->GetURL())); | |
125 } | |
126 } | |
127 | |
115 } // namespace | 128 } // namespace |
116 | 129 |
117 InstantController::InstantController(BrowserInstantController* browser, | 130 InstantController::InstantController(BrowserInstantController* browser, |
118 bool extended_enabled) | 131 bool extended_enabled) |
119 : browser_(browser), | 132 : browser_(browser), |
120 extended_enabled_(extended_enabled), | 133 extended_enabled_(extended_enabled), |
121 omnibox_focus_state_(OMNIBOX_FOCUS_NONE), | 134 omnibox_focus_state_(OMNIBOX_FOCUS_NONE), |
122 omnibox_focus_change_reason_(OMNIBOX_FOCUS_CHANGE_EXPLICIT), | 135 omnibox_focus_change_reason_(OMNIBOX_FOCUS_CHANGE_EXPLICIT), |
123 omnibox_bounds_(-1, -1, 0, 0) { | 136 omnibox_bounds_(-1, -1, 0, 0) { |
124 | 137 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
307 if (debug_events_.size() > kMaxDebugEventSize) | 320 if (debug_events_.size() > kMaxDebugEventSize) |
308 debug_events_.pop_back(); | 321 debug_events_.pop_back(); |
309 } | 322 } |
310 | 323 |
311 void InstantController::ClearDebugEvents() { | 324 void InstantController::ClearDebugEvents() { |
312 debug_events_.clear(); | 325 debug_events_.clear(); |
313 } | 326 } |
314 | 327 |
315 void InstantController::MostVisitedItemsChanged( | 328 void InstantController::MostVisitedItemsChanged( |
316 const std::vector<InstantMostVisitedItem>& items) { | 329 const std::vector<InstantMostVisitedItem>& items) { |
330 | |
331 std::vector<InstantMostVisitedItem> items_copy(items); | |
332 MaybeRemoveMostVisitedItems(&items_copy); | |
Alexei Svitkine (slow)
2013/07/04 20:28:30
Is |items_copy| being used anywhere? Did you mean
annark1
2013/07/16 18:07:09
Yes, I did. Thank you for catching this error.
On
| |
333 | |
317 if (ntp_) | 334 if (ntp_) |
318 ntp_->sender()->SendMostVisitedItems(items); | 335 ntp_->sender()->SendMostVisitedItems(items); |
319 if (instant_tab_) | 336 if (instant_tab_) |
320 instant_tab_->sender()->SendMostVisitedItems(items); | 337 instant_tab_->sender()->SendMostVisitedItems(items); |
321 | 338 |
322 content::NotificationService::current()->Notify( | 339 content::NotificationService::current()->Notify( |
323 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, | 340 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, |
324 content::Source<InstantController>(this), | 341 content::Source<InstantController>(this), |
325 content::NotificationService::NoDetails()); | 342 content::NotificationService::NoDetails()); |
326 } | 343 } |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
669 | 686 |
670 bool InstantController::InStartup() const { | 687 bool InstantController::InStartup() const { |
671 // TODO(shishir): This is not completely reliable. Find a better way to detect | 688 // TODO(shishir): This is not completely reliable. Find a better way to detect |
672 // startup time. | 689 // startup time. |
673 return !browser_->GetActiveWebContents(); | 690 return !browser_->GetActiveWebContents(); |
674 } | 691 } |
675 | 692 |
676 InstantService* InstantController::GetInstantService() const { | 693 InstantService* InstantController::GetInstantService() const { |
677 return InstantServiceFactory::GetForProfile(profile()); | 694 return InstantServiceFactory::GetForProfile(profile()); |
678 } | 695 } |
696 | |
697 void InstantController::MaybeRemoveMostVisitedItems( | |
698 std::vector<InstantMostVisitedItem>* items) { | |
699 #if !defined(OS_ANDROID) | |
Alexei Svitkine (slow)
2013/07/04 20:28:30
Add a comment about why this shouldn't apply to an
annark1
2013/07/16 18:07:09
Done.
| |
700 if (!history::TopSites::IsClientInTabsGroup()) | |
701 return; | |
702 | |
703 const TabStripModel* tab_strip_model = browser_->tab_strip_model(); | |
704 history::TopSites* top_sites = browser_->profile()->GetTopSites(); | |
705 if (!tab_strip_model || !top_sites) { | |
706 NOTREACHED(); | |
707 return; | |
708 } | |
709 | |
710 std::set<std::string> open_urls; | |
711 GetOpenUrls(*tab_strip_model, *top_sites, &open_urls); | |
712 history::TopSites::RemoveItemsMatchingOpenTabs(open_urls, items); | |
713 #endif | |
714 } | |
OLD | NEW |