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

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

Issue 12498002: InstantExtended: Adding InstantRestrictedIDCache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressing chris's and david'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"
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 std::string(), 191 std::string(),
192 contents->GetBrowserContext()); 192 contents->GetBrowserContext());
193 transient->SetExtraData(chrome::search::kInstantExtendedSearchTermsKey, 193 transient->SetExtraData(chrome::search::kInstantExtendedSearchTermsKey,
194 search_terms); 194 search_terms);
195 controller->SetTransientEntry(transient); 195 controller->SetTransientEntry(transient);
196 196
197 chrome::search::SearchTabHelper::FromWebContents(contents)-> 197 chrome::search::SearchTabHelper::FromWebContents(contents)->
198 NavigationEntryUpdated(); 198 NavigationEntryUpdated();
199 } 199 }
200 200
201 bool GetURLForMostVisitedItemId(Profile* profile, 201 bool GetURLForMostVisitedItemID(Profile* profile,
202 uint64 most_visited_item_id, 202 InstantRestrictedID most_visited_item_id,
203 GURL* url) { 203 GURL* url) {
204 InstantService* instant_service = 204 InstantService* instant_service =
205 InstantServiceFactory::GetForProfile(profile); 205 InstantServiceFactory::GetForProfile(profile);
206 if (!instant_service) 206 if (!instant_service)
207 return false; 207 return false;
208 return instant_service->GetURLForMostVisitedItemId(most_visited_item_id, url);
209 }
210 208
211 // Creates a new restriced id if one is not found. 209 InstantMostVisitedItem item;
212 size_t GetMostVisitedItemIDForURL(Profile* profile, const GURL& url) { 210 if (!instant_service->GetMostVisitedItemForID(most_visited_item_id, &item))
213 InstantService* instant_service = 211 return false;
214 InstantServiceFactory::GetForProfile(profile); 212
215 if (!instant_service) 213 *url = item.url;
216 return 0; 214 return true;
217 return instant_service->AddURL(url);
218 } 215 }
219 216
220 } // namespace 217 } // namespace
221 218
222 InstantController::InstantController(chrome::BrowserInstantController* browser, 219 InstantController::InstantController(chrome::BrowserInstantController* browser,
223 bool extended_enabled) 220 bool extended_enabled)
224 : browser_(browser), 221 : browser_(browser),
225 extended_enabled_(extended_enabled), 222 extended_enabled_(extended_enabled),
226 instant_enabled_(false), 223 instant_enabled_(false),
227 use_local_overlay_only_(true), 224 use_local_overlay_only_(true),
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 base::Time::Now().ToInternalValue(), info)); 900 base::Time::Now().ToInternalValue(), info));
904 static const size_t kMaxDebugEventSize = 2000; 901 static const size_t kMaxDebugEventSize = 2000;
905 if (debug_events_.size() > kMaxDebugEventSize) 902 if (debug_events_.size() > kMaxDebugEventSize)
906 debug_events_.pop_back(); 903 debug_events_.pop_back();
907 } 904 }
908 905
909 void InstantController::ClearDebugEvents() { 906 void InstantController::ClearDebugEvents() {
910 debug_events_.clear(); 907 debug_events_.clear();
911 } 908 }
912 909
913 void InstantController::DeleteMostVisitedItem(uint64 most_visited_item_id) { 910 void InstantController::DeleteMostVisitedItem(
911 InstantRestrictedID most_visited_item_id) {
914 history::TopSites* top_sites = browser_->profile()->GetTopSites(); 912 history::TopSites* top_sites = browser_->profile()->GetTopSites();
915 if (!top_sites) 913 if (!top_sites)
916 return; 914 return;
917 915
918 GURL url; 916 GURL url;
919 if (GetURLForMostVisitedItemId(browser_->profile(), 917 if (GetURLForMostVisitedItemID(browser_->profile(),
920 most_visited_item_id, &url)) 918 most_visited_item_id, &url))
921 top_sites->AddBlacklistedURL(url); 919 top_sites->AddBlacklistedURL(url);
922 } 920 }
923 921
924 void InstantController::UndoMostVisitedDeletion(uint64 most_visited_item_id) { 922 void InstantController::UndoMostVisitedDeletion(
923 InstantRestrictedID most_visited_item_id) {
925 history::TopSites* top_sites = browser_->profile()->GetTopSites(); 924 history::TopSites* top_sites = browser_->profile()->GetTopSites();
926 if (!top_sites) 925 if (!top_sites)
927 return; 926 return;
928 927
929 GURL url; 928 GURL url;
930 if (GetURLForMostVisitedItemId(browser_->profile(), 929 if (GetURLForMostVisitedItemID(browser_->profile(),
931 most_visited_item_id, &url)) 930 most_visited_item_id, &url))
932 top_sites->RemoveBlacklistedURL(url); 931 top_sites->RemoveBlacklistedURL(url);
933 } 932 }
934 933
935 void InstantController::UndoAllMostVisitedDeletions() { 934 void InstantController::UndoAllMostVisitedDeletions() {
936 history::TopSites* top_sites = browser_->profile()->GetTopSites(); 935 history::TopSites* top_sites = browser_->profile()->GetTopSites();
937 if (!top_sites) 936 if (!top_sites)
938 return; 937 return;
939 938
940 top_sites->ClearBlacklistedURLs(); 939 top_sites->ClearBlacklistedURLs();
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
1509 history::TopSites* top_sites = browser_->profile()->GetTopSites(); 1508 history::TopSites* top_sites = browser_->profile()->GetTopSites();
1510 if (top_sites) { 1509 if (top_sites) {
1511 top_sites->GetMostVisitedURLs( 1510 top_sites->GetMostVisitedURLs(
1512 base::Bind(&InstantController::OnMostVisitedItemsReceived, 1511 base::Bind(&InstantController::OnMostVisitedItemsReceived,
1513 weak_ptr_factory_.GetWeakPtr())); 1512 weak_ptr_factory_.GetWeakPtr()));
1514 } 1513 }
1515 } 1514 }
1516 1515
1517 void InstantController::OnMostVisitedItemsReceived( 1516 void InstantController::OnMostVisitedItemsReceived(
1518 const history::MostVisitedURLList& data) { 1517 const history::MostVisitedURLList& data) {
1518 InstantService* instant_service =
1519 InstantServiceFactory::GetForProfile(browser_->profile());
1520 if (!instant_service)
1521 return;
1522
1519 std::vector<InstantMostVisitedItem> most_visited_items; 1523 std::vector<InstantMostVisitedItem> most_visited_items;
1520 for (size_t i = 0; i < data.size(); i++) { 1524 for (size_t i = 0; i < data.size(); i++) {
1521 const history::MostVisitedURL& url = data[i]; 1525 const history::MostVisitedURL& url = data[i];
1522
1523 InstantMostVisitedItem item; 1526 InstantMostVisitedItem item;
1524 item.most_visited_item_id = GetMostVisitedItemIDForURL(browser_->profile(),
1525 url.url);
1526 item.url = url.url; 1527 item.url = url.url;
1527 item.title = url.title; 1528 item.title = url.title;
1528
1529 most_visited_items.push_back(item); 1529 most_visited_items.push_back(item);
1530 } 1530 }
1531 SendMostVisitedItems(most_visited_items); 1531
1532 instant_service->AddMostVisitedItems(most_visited_items);
1533
1534 std::vector<InstantMostVisitedItemIDPair> items_with_ids;
1535 instant_service->GetCurrentMostVisitedItems(&items_with_ids);
1536 SendMostVisitedItems(items_with_ids);
1532 } 1537 }
1533 1538
1534 void InstantController::SendMostVisitedItems( 1539 void InstantController::SendMostVisitedItems(
1535 const std::vector<InstantMostVisitedItem>& items) { 1540 const std::vector<InstantMostVisitedItemIDPair>& items) {
1536 if (overlay_) 1541 if (overlay_)
1537 overlay_->SendMostVisitedItems(items); 1542 overlay_->SendMostVisitedItems(items);
1538 if (ntp_) 1543 if (ntp_)
1539 ntp_->SendMostVisitedItems(items); 1544 ntp_->SendMostVisitedItems(items);
1540 if (instant_tab_) 1545 if (instant_tab_)
1541 instant_tab_->SendMostVisitedItems(items); 1546 instant_tab_->SendMostVisitedItems(items);
1542 content::NotificationService::current()->Notify( 1547 content::NotificationService::current()->Notify(
1543 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, 1548 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS,
1544 content::Source<InstantController>(this), 1549 content::Source<InstantController>(this),
1545 content::NotificationService::NoDetails()); 1550 content::NotificationService::NoDetails());
1546 } 1551 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698