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 <iterator> | 7 #include <iterator> |
8 | 8 |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/browser/autocomplete/autocomplete_provider.h" | 13 #include "chrome/browser/autocomplete/autocomplete_provider.h" |
14 #include "chrome/browser/autocomplete/autocomplete_result.h" | 14 #include "chrome/browser/autocomplete/autocomplete_result.h" |
15 #include "chrome/browser/autocomplete/search_provider.h" | 15 #include "chrome/browser/autocomplete/search_provider.h" |
16 #include "chrome/browser/history/history_service.h" | 16 #include "chrome/browser/history/history_service.h" |
17 #include "chrome/browser/history/history_service_factory.h" | 17 #include "chrome/browser/history/history_service_factory.h" |
18 #include "chrome/browser/history/history_tab_helper.h" | 18 #include "chrome/browser/history/history_tab_helper.h" |
| 19 #include "chrome/browser/history/top_sites.h" |
19 #include "chrome/browser/platform_util.h" | 20 #include "chrome/browser/platform_util.h" |
20 #include "chrome/browser/search/instant_service.h" | 21 #include "chrome/browser/search/instant_service.h" |
21 #include "chrome/browser/search/instant_service_factory.h" | 22 #include "chrome/browser/search/instant_service_factory.h" |
22 #include "chrome/browser/search/search.h" | 23 #include "chrome/browser/search/search.h" |
23 #include "chrome/browser/search_engines/search_terms_data.h" | 24 #include "chrome/browser/search_engines/search_terms_data.h" |
24 #include "chrome/browser/search_engines/template_url_service.h" | 25 #include "chrome/browser/search_engines/template_url_service.h" |
25 #include "chrome/browser/search_engines/template_url_service_factory.h" | 26 #include "chrome/browser/search_engines/template_url_service_factory.h" |
26 #include "chrome/browser/ui/browser_instant_controller.h" | 27 #include "chrome/browser/ui/browser_instant_controller.h" |
27 #include "chrome/browser/ui/search/instant_ntp.h" | 28 #include "chrome/browser/ui/search/instant_ntp.h" |
28 #include "chrome/browser/ui/search/instant_overlay.h" | 29 #include "chrome/browser/ui/search/instant_overlay.h" |
29 #include "chrome/browser/ui/search/instant_tab.h" | 30 #include "chrome/browser/ui/search/instant_tab.h" |
30 #include "chrome/browser/ui/search/search_tab_helper.h" | 31 #include "chrome/browser/ui/search/search_tab_helper.h" |
| 32 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
31 #include "chrome/common/chrome_notification_types.h" | 33 #include "chrome/common/chrome_notification_types.h" |
32 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
33 #include "chrome/common/url_constants.h" | 35 #include "chrome/common/url_constants.h" |
34 #include "components/sessions/serialized_navigation_entry.h" | 36 #include "components/sessions/serialized_navigation_entry.h" |
35 #include "content/public/browser/navigation_entry.h" | 37 #include "content/public/browser/navigation_entry.h" |
36 #include "content/public/browser/notification_service.h" | 38 #include "content/public/browser/notification_service.h" |
37 #include "content/public/browser/render_process_host.h" | 39 #include "content/public/browser/render_process_host.h" |
38 #include "content/public/browser/render_widget_host_view.h" | 40 #include "content/public/browser/render_widget_host_view.h" |
39 #include "content/public/browser/user_metrics.h" | 41 #include "content/public/browser/user_metrics.h" |
40 #include "content/public/browser/web_contents.h" | 42 #include "content/public/browser/web_contents.h" |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 template <typename T> | 240 template <typename T> |
239 void DeletePageSoon(scoped_ptr<T> page) { | 241 void DeletePageSoon(scoped_ptr<T> page) { |
240 if (page->contents()) { | 242 if (page->contents()) { |
241 base::MessageLoop::current()->DeleteSoon( | 243 base::MessageLoop::current()->DeleteSoon( |
242 FROM_HERE, page->ReleaseContents().release()); | 244 FROM_HERE, page->ReleaseContents().release()); |
243 } | 245 } |
244 | 246 |
245 base::MessageLoop::current()->DeleteSoon(FROM_HERE, page.release()); | 247 base::MessageLoop::current()->DeleteSoon(FROM_HERE, page.release()); |
246 } | 248 } |
247 | 249 |
| 250 // Creates a set containing the canonical URLs of the currently open tabs. |
| 251 void GetOpenUrls(const TabStripModel& tabs, |
| 252 const history::TopSites& ts, |
| 253 std::set<std::string>* urls) { |
| 254 for (int i = 0; i < tabs.count(); ++i) { |
| 255 content::WebContents* web_contents = tabs.GetWebContentsAt(i); |
| 256 if (web_contents) |
| 257 urls->insert(ts.GetCanonicalURLString(web_contents->GetURL())); |
| 258 } |
| 259 } |
| 260 |
248 } // namespace | 261 } // namespace |
249 | 262 |
250 InstantController::InstantController(BrowserInstantController* browser, | 263 InstantController::InstantController(BrowserInstantController* browser, |
251 bool extended_enabled) | 264 bool extended_enabled) |
252 : browser_(browser), | 265 : browser_(browser), |
253 extended_enabled_(extended_enabled), | 266 extended_enabled_(extended_enabled), |
254 instant_enabled_(false), | 267 instant_enabled_(false), |
255 use_local_page_only_(true), | 268 use_local_page_only_(true), |
256 preload_ntp_(true), | 269 preload_ntp_(true), |
257 model_(this), | 270 model_(this), |
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1138 | 1151 |
1139 void InstantController::UpdateMostVisitedItems() { | 1152 void InstantController::UpdateMostVisitedItems() { |
1140 InstantService* instant_service = | 1153 InstantService* instant_service = |
1141 InstantServiceFactory::GetForProfile(profile()); | 1154 InstantServiceFactory::GetForProfile(profile()); |
1142 if (!instant_service) | 1155 if (!instant_service) |
1143 return; | 1156 return; |
1144 | 1157 |
1145 std::vector<InstantMostVisitedItem> items; | 1158 std::vector<InstantMostVisitedItem> items; |
1146 instant_service->GetCurrentMostVisitedItems(&items); | 1159 instant_service->GetCurrentMostVisitedItems(&items); |
1147 | 1160 |
| 1161 MaybeRemoveMostVisitedItems(&items); |
| 1162 |
1148 if (overlay_ && GetOverlayContents() && | 1163 if (overlay_ && GetOverlayContents() && |
1149 SearchTabHelper::FromWebContents(overlay_->contents())-> | 1164 SearchTabHelper::FromWebContents(overlay_->contents())-> |
1150 UpdateLastKnownMostVisitedItems(items)) { | 1165 UpdateLastKnownMostVisitedItems(items)) { |
1151 overlay_->SendMostVisitedItems(items); | 1166 overlay_->SendMostVisitedItems(items); |
1152 } | 1167 } |
1153 | 1168 |
1154 if (ntp_ && ntp_->contents() && | 1169 if (ntp_ && ntp_->contents() && |
1155 SearchTabHelper::FromWebContents(ntp_->contents())-> | 1170 SearchTabHelper::FromWebContents(ntp_->contents())-> |
1156 UpdateLastKnownMostVisitedItems(items)) { | 1171 UpdateLastKnownMostVisitedItems(items)) { |
1157 ntp_->SendMostVisitedItems(items); | 1172 ntp_->SendMostVisitedItems(items); |
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1859 result->transition = match.transition; | 1874 result->transition = match.transition; |
1860 result->relevance = match.relevance; | 1875 result->relevance = match.relevance; |
1861 result->autocomplete_match_index = autocomplete_match_index; | 1876 result->autocomplete_match_index = autocomplete_match_index; |
1862 | 1877 |
1863 DVLOG(1) << " " << result->relevance << " " | 1878 DVLOG(1) << " " << result->relevance << " " |
1864 << UTF8ToUTF16(AutocompleteMatchType::ToString(result->type)) << " " | 1879 << UTF8ToUTF16(AutocompleteMatchType::ToString(result->type)) << " " |
1865 << result->provider << " " << result->destination_url << " '" | 1880 << result->provider << " " << result->destination_url << " '" |
1866 << result->description << "' '" << result->search_query << "' " | 1881 << result->description << "' '" << result->search_query << "' " |
1867 << result->transition << " " << result->autocomplete_match_index; | 1882 << result->transition << " " << result->autocomplete_match_index; |
1868 } | 1883 } |
| 1884 |
| 1885 void InstantController::MaybeRemoveMostVisitedItems( |
| 1886 std::vector<InstantMostVisitedItem>* items) { |
| 1887 #if !defined(OS_ANDROID) |
| 1888 if (!history::TopSites::IsClientInTabsGroup()) |
| 1889 return; |
| 1890 |
| 1891 TabStripModel* tab_strip_model = browser_->tab_strip_model(); |
| 1892 history::TopSites* top_sites = browser_->profile()->GetTopSites(); |
| 1893 if (!tab_strip_model || !top_sites) { |
| 1894 NOTREACHED(); |
| 1895 return; |
| 1896 } |
| 1897 |
| 1898 std::set<std::string> open_urls; |
| 1899 GetOpenUrls(*tab_strip_model, *top_sites, &open_urls); |
| 1900 history::TopSites::RemoveItemsMatchingOpenTabs(open_urls, items); |
| 1901 #endif |
| 1902 } |
OLD | NEW |