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

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: Adds proper handling of ThumbnailSource 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 GetURLForRestrictedId(Profile* profile, uint64 restricted_id, GURL* url) {
palmer 2013/03/11 20:42:31 |profile| should be declared const, or const & — i
dhollowa 2013/03/11 23:27:59 This is endemic in Chrome code. Pretty much nowhe
201 InstantService* instant_service =
202 InstantServiceFactory::GetForProfile(profile);
203 if (!instant_service)
204 return false;
205 return instant_service->GetURLForRestrictedId(restricted_id, url);
206 }
207
208 // Creates a new restriced id if one is not found.
209 size_t GetRestrictedIDForURL(Profile* profile, const GURL& url) {
palmer 2013/03/11 20:42:31 const |profile|.
dhollowa 2013/03/11 23:27:59 Ditto.
210 InstantService* instant_service =
palmer 2013/03/11 20:42:31 Perhaps the caller of these two functions should p
dhollowa 2013/03/11 23:27:59 Pushing that up to the caller becomes quite clutte
211 InstantServiceFactory::GetForProfile(profile);
212 if (!instant_service)
213 return 0;
214 return instant_service->AddURL(url);
215 }
216
198 } // namespace 217 } // namespace
199 218
200 InstantController::InstantController(chrome::BrowserInstantController* browser, 219 InstantController::InstantController(chrome::BrowserInstantController* browser,
201 bool extended_enabled) 220 bool extended_enabled)
202 : browser_(browser), 221 : browser_(browser),
203 extended_enabled_(extended_enabled), 222 extended_enabled_(extended_enabled),
204 instant_enabled_(false), 223 instant_enabled_(false),
205 use_local_overlay_only_(true), 224 use_local_overlay_only_(true),
206 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 225 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
207 last_omnibox_text_has_inline_autocompletion_(false), 226 last_omnibox_text_has_inline_autocompletion_(false),
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 base::Time::Now().ToInternalValue(), info)); 872 base::Time::Now().ToInternalValue(), info));
854 static const size_t kMaxDebugEventSize = 2000; 873 static const size_t kMaxDebugEventSize = 2000;
855 if (debug_events_.size() > kMaxDebugEventSize) 874 if (debug_events_.size() > kMaxDebugEventSize)
856 debug_events_.pop_back(); 875 debug_events_.pop_back();
857 } 876 }
858 877
859 void InstantController::ClearDebugEvents() { 878 void InstantController::ClearDebugEvents() {
860 debug_events_.clear(); 879 debug_events_.clear();
861 } 880 }
862 881
863 void InstantController::DeleteMostVisitedItem(const GURL& url) { 882 void InstantController::DeleteMostVisitedItem(uint64 restricted_id) {
864 history::TopSites* top_sites = browser_->profile()->GetTopSites(); 883 history::TopSites* top_sites = browser_->profile()->GetTopSites();
865 if (!top_sites) 884 if (!top_sites)
866 return; 885 return;
867 886
868 top_sites->AddBlacklistedURL(url); 887 GURL url;
888 if (GetURLForRestrictedId(browser_->profile(), restricted_id, &url))
889 top_sites->AddBlacklistedURL(url);
869 } 890 }
870 891
871 void InstantController::UndoMostVisitedDeletion(const GURL& url) { 892 void InstantController::UndoMostVisitedDeletion(uint64 restricted_id) {
872 history::TopSites* top_sites = browser_->profile()->GetTopSites(); 893 history::TopSites* top_sites = browser_->profile()->GetTopSites();
873 if (!top_sites) 894 if (!top_sites)
874 return; 895 return;
875 896
876 top_sites->RemoveBlacklistedURL(url); 897 GURL url;
898 if (GetURLForRestrictedId(browser_->profile(), restricted_id, &url))
899 top_sites->RemoveBlacklistedURL(url);
877 } 900 }
878 901
879 void InstantController::UndoAllMostVisitedDeletions() { 902 void InstantController::UndoAllMostVisitedDeletions() {
880 history::TopSites* top_sites = browser_->profile()->GetTopSites(); 903 history::TopSites* top_sites = browser_->profile()->GetTopSites();
881 if (!top_sites) 904 if (!top_sites)
882 return; 905 return;
883 906
884 top_sites->ClearBlacklistedURLs(); 907 top_sites->ClearBlacklistedURLs();
885 } 908 }
886 909
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
1453 history::TopSites* top_sites = browser_->profile()->GetTopSites(); 1476 history::TopSites* top_sites = browser_->profile()->GetTopSites();
1454 if (top_sites) { 1477 if (top_sites) {
1455 top_sites->GetMostVisitedURLs( 1478 top_sites->GetMostVisitedURLs(
1456 base::Bind(&InstantController::OnMostVisitedItemsReceived, 1479 base::Bind(&InstantController::OnMostVisitedItemsReceived,
1457 weak_ptr_factory_.GetWeakPtr())); 1480 weak_ptr_factory_.GetWeakPtr()));
1458 } 1481 }
1459 } 1482 }
1460 1483
1461 void InstantController::OnMostVisitedItemsReceived( 1484 void InstantController::OnMostVisitedItemsReceived(
1462 const history::MostVisitedURLList& data) { 1485 const history::MostVisitedURLList& data) {
1463 std::vector<MostVisitedItem> most_visited_items; 1486 std::vector<InstantMostVisitedItem> most_visited_items;
1464 for (size_t i = 0; i < data.size(); i++) { 1487 for (size_t i = 0; i < data.size(); i++) {
1465 const history::MostVisitedURL& url = data[i]; 1488 const history::MostVisitedURL& url = data[i];
1466 1489
1467 MostVisitedItem item; 1490 InstantMostVisitedItem item;
1491 item.restricted_id = GetRestrictedIDForURL(browser_->profile(), url.url);
1468 item.url = url.url; 1492 item.url = url.url;
1469 item.title = url.title; 1493 item.title = url.title;
1470 1494
1471 most_visited_items.push_back(item); 1495 most_visited_items.push_back(item);
1472 } 1496 }
1473 SendMostVisitedItems(most_visited_items); 1497 SendMostVisitedItems(most_visited_items);
1474 } 1498 }
1475 1499
1476 void InstantController::SendMostVisitedItems( 1500 void InstantController::SendMostVisitedItems(
1477 const std::vector<MostVisitedItem>& items) { 1501 const std::vector<InstantMostVisitedItem>& items) {
1478 if (overlay_) 1502 if (overlay_)
1479 overlay_->SendMostVisitedItems(items); 1503 overlay_->SendMostVisitedItems(items);
1480 if (ntp_) 1504 if (ntp_)
1481 ntp_->SendMostVisitedItems(items); 1505 ntp_->SendMostVisitedItems(items);
1482 if (instant_tab_) 1506 if (instant_tab_)
1483 instant_tab_->SendMostVisitedItems(items); 1507 instant_tab_->SendMostVisitedItems(items);
1484 content::NotificationService::current()->Notify( 1508 content::NotificationService::current()->Notify(
1485 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, 1509 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS,
1486 content::Source<InstantController>(this), 1510 content::Source<InstantController>(this),
1487 content::NotificationService::NoDetails()); 1511 content::NotificationService::NoDetails());
1488 } 1512 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698