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

Side by Side Diff: chrome/browser/instant/instant_controller.cc

Issue 12732005: Most visited thumbnails and favicons need id-based urls (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address estade's comments. Created 7 years, 9 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 | Annotate | Revision Log
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/instant/instant_controller.h" 5 #include "chrome/browser/instant/instant_controller.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/autocomplete/autocomplete_provider.h" 11 #include "chrome/browser/autocomplete/autocomplete_provider.h"
12 #include "chrome/browser/history/history_service.h" 12 #include "chrome/browser/history/history_service.h"
13 #include "chrome/browser/history/history_service_factory.h" 13 #include "chrome/browser/history/history_service_factory.h"
14 #include "chrome/browser/history/history_tab_helper.h" 14 #include "chrome/browser/history/history_tab_helper.h"
15 #include "chrome/browser/history/top_sites.h" 15 #include "chrome/browser/history/top_sites.h"
16 #include "chrome/browser/instant/instant_ntp.h" 16 #include "chrome/browser/instant/instant_ntp.h"
17 #include "chrome/browser/instant/instant_overlay.h" 17 #include "chrome/browser/instant/instant_overlay.h"
18 #include "chrome/browser/instant/instant_service.h"
19 #include "chrome/browser/instant/instant_service_factory.h"
18 #include "chrome/browser/instant/instant_tab.h" 20 #include "chrome/browser/instant/instant_tab.h"
19 #include "chrome/browser/instant/search.h" 21 #include "chrome/browser/instant/search.h"
20 #include "chrome/browser/platform_util.h" 22 #include "chrome/browser/platform_util.h"
21 #include "chrome/browser/search_engines/search_terms_data.h" 23 #include "chrome/browser/search_engines/search_terms_data.h"
22 #include "chrome/browser/search_engines/template_url_service.h" 24 #include "chrome/browser/search_engines/template_url_service.h"
23 #include "chrome/browser/search_engines/template_url_service_factory.h" 25 #include "chrome/browser/search_engines/template_url_service_factory.h"
24 #include "chrome/browser/ui/browser_instant_controller.h" 26 #include "chrome/browser/ui/browser_instant_controller.h"
25 #include "chrome/browser/ui/search/search_tab_helper.h" 27 #include "chrome/browser/ui/search/search_tab_helper.h"
26 #include "chrome/common/chrome_notification_types.h" 28 #include "chrome/common/chrome_notification_types.h"
27 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 std::string(), 190 std::string(),
189 contents->GetBrowserContext()); 191 contents->GetBrowserContext());
190 transient->SetExtraData(chrome::search::kInstantExtendedSearchTermsKey, 192 transient->SetExtraData(chrome::search::kInstantExtendedSearchTermsKey,
191 search_terms); 193 search_terms);
192 controller->SetTransientEntry(transient); 194 controller->SetTransientEntry(transient);
193 195
194 chrome::search::SearchTabHelper::FromWebContents(contents)-> 196 chrome::search::SearchTabHelper::FromWebContents(contents)->
195 NavigationEntryUpdated(); 197 NavigationEntryUpdated();
196 } 198 }
197 199
200 bool GetURLForMostVisitedItemId(Profile* profile,
201 uint64 most_visited_item_id,
202 GURL* url) {
203 InstantService* instant_service =
204 InstantServiceFactory::GetForProfile(profile);
205 if (!instant_service)
206 return false;
207 return instant_service->GetURLForMostVisitedItemId(most_visited_item_id, url);
208 }
209
210 // Creates a new restriced id if one is not found.
211 size_t GetMostVisitedItemIDForURL(Profile* profile, const GURL& url) {
212 InstantService* instant_service =
213 InstantServiceFactory::GetForProfile(profile);
214 if (!instant_service)
215 return 0;
216 return instant_service->AddURL(url);
217 }
218
198 } // namespace 219 } // namespace
199 220
200 InstantController::InstantController(chrome::BrowserInstantController* browser, 221 InstantController::InstantController(chrome::BrowserInstantController* browser,
201 bool extended_enabled) 222 bool extended_enabled)
202 : browser_(browser), 223 : browser_(browser),
203 extended_enabled_(extended_enabled), 224 extended_enabled_(extended_enabled),
204 instant_enabled_(false), 225 instant_enabled_(false),
205 use_local_overlay_only_(true), 226 use_local_overlay_only_(true),
206 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 227 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
207 last_omnibox_text_has_inline_autocompletion_(false), 228 last_omnibox_text_has_inline_autocompletion_(false),
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 base::Time::Now().ToInternalValue(), info)); 877 base::Time::Now().ToInternalValue(), info));
857 static const size_t kMaxDebugEventSize = 2000; 878 static const size_t kMaxDebugEventSize = 2000;
858 if (debug_events_.size() > kMaxDebugEventSize) 879 if (debug_events_.size() > kMaxDebugEventSize)
859 debug_events_.pop_back(); 880 debug_events_.pop_back();
860 } 881 }
861 882
862 void InstantController::ClearDebugEvents() { 883 void InstantController::ClearDebugEvents() {
863 debug_events_.clear(); 884 debug_events_.clear();
864 } 885 }
865 886
866 void InstantController::DeleteMostVisitedItem(const GURL& url) { 887 void InstantController::DeleteMostVisitedItem(uint64 most_visited_item_id) {
867 history::TopSites* top_sites = browser_->profile()->GetTopSites(); 888 history::TopSites* top_sites = browser_->profile()->GetTopSites();
868 if (!top_sites) 889 if (!top_sites)
869 return; 890 return;
870 891
871 top_sites->AddBlacklistedURL(url); 892 GURL url;
893 if (GetURLForMostVisitedItemId(browser_->profile(),
894 most_visited_item_id, &url))
895 top_sites->AddBlacklistedURL(url);
872 } 896 }
873 897
874 void InstantController::UndoMostVisitedDeletion(const GURL& url) { 898 void InstantController::UndoMostVisitedDeletion(uint64 most_visited_item_id) {
875 history::TopSites* top_sites = browser_->profile()->GetTopSites(); 899 history::TopSites* top_sites = browser_->profile()->GetTopSites();
876 if (!top_sites) 900 if (!top_sites)
877 return; 901 return;
878 902
879 top_sites->RemoveBlacklistedURL(url); 903 GURL url;
904 if (GetURLForMostVisitedItemId(browser_->profile(),
905 most_visited_item_id, &url))
906 top_sites->RemoveBlacklistedURL(url);
880 } 907 }
881 908
882 void InstantController::UndoAllMostVisitedDeletions() { 909 void InstantController::UndoAllMostVisitedDeletions() {
883 history::TopSites* top_sites = browser_->profile()->GetTopSites(); 910 history::TopSites* top_sites = browser_->profile()->GetTopSites();
884 if (!top_sites) 911 if (!top_sites)
885 return; 912 return;
886 913
887 top_sites->ClearBlacklistedURLs(); 914 top_sites->ClearBlacklistedURLs();
888 } 915 }
889 916
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 history::TopSites* top_sites = browser_->profile()->GetTopSites(); 1483 history::TopSites* top_sites = browser_->profile()->GetTopSites();
1457 if (top_sites) { 1484 if (top_sites) {
1458 top_sites->GetMostVisitedURLs( 1485 top_sites->GetMostVisitedURLs(
1459 base::Bind(&InstantController::OnMostVisitedItemsReceived, 1486 base::Bind(&InstantController::OnMostVisitedItemsReceived,
1460 weak_ptr_factory_.GetWeakPtr())); 1487 weak_ptr_factory_.GetWeakPtr()));
1461 } 1488 }
1462 } 1489 }
1463 1490
1464 void InstantController::OnMostVisitedItemsReceived( 1491 void InstantController::OnMostVisitedItemsReceived(
1465 const history::MostVisitedURLList& data) { 1492 const history::MostVisitedURLList& data) {
1466 std::vector<MostVisitedItem> most_visited_items; 1493 std::vector<InstantMostVisitedItem> most_visited_items;
1467 for (size_t i = 0; i < data.size(); i++) { 1494 for (size_t i = 0; i < data.size(); i++) {
1468 const history::MostVisitedURL& url = data[i]; 1495 const history::MostVisitedURL& url = data[i];
1469 1496
1470 MostVisitedItem item; 1497 InstantMostVisitedItem item;
1498 item.most_visited_item_id = GetMostVisitedItemIDForURL(browser_->profile(),
1499 url.url);
1471 item.url = url.url; 1500 item.url = url.url;
1472 item.title = url.title; 1501 item.title = url.title;
1473 1502
1474 most_visited_items.push_back(item); 1503 most_visited_items.push_back(item);
1475 } 1504 }
1476 SendMostVisitedItems(most_visited_items); 1505 SendMostVisitedItems(most_visited_items);
1477 } 1506 }
1478 1507
1479 void InstantController::SendMostVisitedItems( 1508 void InstantController::SendMostVisitedItems(
1480 const std::vector<MostVisitedItem>& items) { 1509 const std::vector<InstantMostVisitedItem>& items) {
1481 if (overlay_) 1510 if (overlay_)
1482 overlay_->SendMostVisitedItems(items); 1511 overlay_->SendMostVisitedItems(items);
1483 if (ntp_) 1512 if (ntp_)
1484 ntp_->SendMostVisitedItems(items); 1513 ntp_->SendMostVisitedItems(items);
1485 if (instant_tab_) 1514 if (instant_tab_)
1486 instant_tab_->SendMostVisitedItems(items); 1515 instant_tab_->SendMostVisitedItems(items);
1487 content::NotificationService::current()->Notify( 1516 content::NotificationService::current()->Notify(
1488 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, 1517 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS,
1489 content::Source<InstantController>(this), 1518 content::Source<InstantController>(this),
1490 content::NotificationService::NoDetails()); 1519 content::NotificationService::NoDetails());
1491 } 1520 }
OLDNEW
« no previous file with comments | « chrome/browser/instant/instant_controller.h ('k') | chrome/browser/instant/instant_io_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698