Chromium Code Reviews| 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/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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 std::string(), | 190 std::string(), |
| 191 contents->GetBrowserContext()); | 191 contents->GetBrowserContext()); |
| 192 transient->SetExtraData(chrome::search::kInstantExtendedSearchTermsKey, | 192 transient->SetExtraData(chrome::search::kInstantExtendedSearchTermsKey, |
| 193 search_terms); | 193 search_terms); |
| 194 controller->SetTransientEntry(transient); | 194 controller->SetTransientEntry(transient); |
| 195 | 195 |
| 196 chrome::search::SearchTabHelper::FromWebContents(contents)-> | 196 chrome::search::SearchTabHelper::FromWebContents(contents)-> |
| 197 NavigationEntryUpdated(); | 197 NavigationEntryUpdated(); |
| 198 } | 198 } |
| 199 | 199 |
| 200 bool GetURLForMostVisitedItemId(Profile* profile, | 200 bool GetURLForMostVisitedItemID(Profile* profile, |
| 201 uint64 most_visited_item_id, | 201 InstantRestrictedID restricted_id, |
|
dhollowa
2013/03/14 00:02:43
Keep |most_visited_item_id|.
Shishir
2013/03/14 19:53:03
Done.
| |
| 202 GURL* url) { | 202 GURL* url) { |
| 203 InstantService* instant_service = | 203 InstantService* instant_service = |
| 204 InstantServiceFactory::GetForProfile(profile); | 204 InstantServiceFactory::GetForProfile(profile); |
| 205 if (!instant_service) | 205 if (!instant_service) |
| 206 return false; | 206 return false; |
| 207 return instant_service->GetURLForMostVisitedItemId(most_visited_item_id, url); | |
| 208 } | |
| 209 | 207 |
| 210 // Creates a new restriced id if one is not found. | 208 InstantMostVisitedItem item; |
| 211 size_t GetMostVisitedItemIDForURL(Profile* profile, const GURL& url) { | 209 if (!instant_service->GetMostVisitedItemForID(restricted_id, &item)) |
| 212 InstantService* instant_service = | 210 return false; |
| 213 InstantServiceFactory::GetForProfile(profile); | 211 |
| 214 if (!instant_service) | 212 *url = item.url; |
| 215 return 0; | 213 return true; |
| 216 return instant_service->AddURL(url); | |
| 217 } | 214 } |
| 218 | 215 |
| 219 } // namespace | 216 } // namespace |
| 220 | 217 |
| 221 InstantController::InstantController(chrome::BrowserInstantController* browser, | 218 InstantController::InstantController(chrome::BrowserInstantController* browser, |
| 222 bool extended_enabled) | 219 bool extended_enabled) |
| 223 : browser_(browser), | 220 : browser_(browser), |
| 224 extended_enabled_(extended_enabled), | 221 extended_enabled_(extended_enabled), |
| 225 instant_enabled_(false), | 222 instant_enabled_(false), |
| 226 use_local_overlay_only_(true), | 223 use_local_overlay_only_(true), |
| (...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 882 base::Time::Now().ToInternalValue(), info)); | 879 base::Time::Now().ToInternalValue(), info)); |
| 883 static const size_t kMaxDebugEventSize = 2000; | 880 static const size_t kMaxDebugEventSize = 2000; |
| 884 if (debug_events_.size() > kMaxDebugEventSize) | 881 if (debug_events_.size() > kMaxDebugEventSize) |
| 885 debug_events_.pop_back(); | 882 debug_events_.pop_back(); |
| 886 } | 883 } |
| 887 | 884 |
| 888 void InstantController::ClearDebugEvents() { | 885 void InstantController::ClearDebugEvents() { |
| 889 debug_events_.clear(); | 886 debug_events_.clear(); |
| 890 } | 887 } |
| 891 | 888 |
| 892 void InstantController::DeleteMostVisitedItem(uint64 most_visited_item_id) { | 889 void InstantController::DeleteMostVisitedItem( |
| 890 InstantRestrictedID restricted_id) { | |
|
dhollowa
2013/03/14 00:02:43
Keep |most_visited_item_id|. (Throughout).
Shishir
2013/03/14 19:53:03
Done.
| |
| 893 history::TopSites* top_sites = browser_->profile()->GetTopSites(); | 891 history::TopSites* top_sites = browser_->profile()->GetTopSites(); |
| 894 if (!top_sites) | 892 if (!top_sites) |
| 895 return; | 893 return; |
| 896 | 894 |
| 897 GURL url; | 895 GURL url; |
| 898 if (GetURLForMostVisitedItemId(browser_->profile(), | 896 if (GetURLForMostVisitedItemID(browser_->profile(), restricted_id, &url)) |
| 899 most_visited_item_id, &url)) | |
| 900 top_sites->AddBlacklistedURL(url); | 897 top_sites->AddBlacklistedURL(url); |
| 901 } | 898 } |
| 902 | 899 |
| 903 void InstantController::UndoMostVisitedDeletion(uint64 most_visited_item_id) { | 900 void InstantController::UndoMostVisitedDeletion( |
| 901 InstantRestrictedID restricted_id) { | |
| 904 history::TopSites* top_sites = browser_->profile()->GetTopSites(); | 902 history::TopSites* top_sites = browser_->profile()->GetTopSites(); |
| 905 if (!top_sites) | 903 if (!top_sites) |
| 906 return; | 904 return; |
| 907 | 905 |
| 908 GURL url; | 906 GURL url; |
| 909 if (GetURLForMostVisitedItemId(browser_->profile(), | 907 if (GetURLForMostVisitedItemID(browser_->profile(), restricted_id, &url)) |
| 910 most_visited_item_id, &url)) | |
| 911 top_sites->RemoveBlacklistedURL(url); | 908 top_sites->RemoveBlacklistedURL(url); |
| 912 } | 909 } |
| 913 | 910 |
| 914 void InstantController::UndoAllMostVisitedDeletions() { | 911 void InstantController::UndoAllMostVisitedDeletions() { |
| 915 history::TopSites* top_sites = browser_->profile()->GetTopSites(); | 912 history::TopSites* top_sites = browser_->profile()->GetTopSites(); |
| 916 if (!top_sites) | 913 if (!top_sites) |
| 917 return; | 914 return; |
| 918 | 915 |
| 919 top_sites->ClearBlacklistedURLs(); | 916 top_sites->ClearBlacklistedURLs(); |
| 920 } | 917 } |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1488 history::TopSites* top_sites = browser_->profile()->GetTopSites(); | 1485 history::TopSites* top_sites = browser_->profile()->GetTopSites(); |
| 1489 if (top_sites) { | 1486 if (top_sites) { |
| 1490 top_sites->GetMostVisitedURLs( | 1487 top_sites->GetMostVisitedURLs( |
| 1491 base::Bind(&InstantController::OnMostVisitedItemsReceived, | 1488 base::Bind(&InstantController::OnMostVisitedItemsReceived, |
| 1492 weak_ptr_factory_.GetWeakPtr())); | 1489 weak_ptr_factory_.GetWeakPtr())); |
| 1493 } | 1490 } |
| 1494 } | 1491 } |
| 1495 | 1492 |
| 1496 void InstantController::OnMostVisitedItemsReceived( | 1493 void InstantController::OnMostVisitedItemsReceived( |
| 1497 const history::MostVisitedURLList& data) { | 1494 const history::MostVisitedURLList& data) { |
| 1495 InstantService* instant_service = | |
| 1496 InstantServiceFactory::GetForProfile(browser_->profile()); | |
| 1497 if (!instant_service) | |
| 1498 return; | |
| 1499 | |
| 1498 std::vector<InstantMostVisitedItem> most_visited_items; | 1500 std::vector<InstantMostVisitedItem> most_visited_items; |
| 1499 for (size_t i = 0; i < data.size(); i++) { | 1501 for (size_t i = 0; i < data.size(); i++) { |
| 1500 const history::MostVisitedURL& url = data[i]; | 1502 const history::MostVisitedURL& url = data[i]; |
| 1501 | |
| 1502 InstantMostVisitedItem item; | 1503 InstantMostVisitedItem item; |
| 1503 item.most_visited_item_id = GetMostVisitedItemIDForURL(browser_->profile(), | |
| 1504 url.url); | |
| 1505 item.url = url.url; | 1504 item.url = url.url; |
| 1506 item.title = url.title; | 1505 item.title = url.title; |
| 1507 | |
| 1508 most_visited_items.push_back(item); | 1506 most_visited_items.push_back(item); |
| 1509 } | 1507 } |
| 1510 SendMostVisitedItems(most_visited_items); | 1508 |
| 1509 instant_service->AddMostVisitedItems(most_visited_items); | |
| 1510 | |
| 1511 std::vector<InstantMostVisitedItemIDPair> items_with_ids; | |
| 1512 instant_service->GetCurrentMostVisitedItems(&items_with_ids); | |
| 1513 SendMostVisitedItems(items_with_ids); | |
| 1511 } | 1514 } |
| 1512 | 1515 |
| 1513 void InstantController::SendMostVisitedItems( | 1516 void InstantController::SendMostVisitedItems( |
| 1514 const std::vector<InstantMostVisitedItem>& items) { | 1517 const std::vector<InstantMostVisitedItemIDPair>& items) { |
| 1515 if (overlay_) | 1518 if (overlay_) |
| 1516 overlay_->SendMostVisitedItems(items); | 1519 overlay_->SendMostVisitedItems(items); |
| 1517 if (ntp_) | 1520 if (ntp_) |
| 1518 ntp_->SendMostVisitedItems(items); | 1521 ntp_->SendMostVisitedItems(items); |
| 1519 if (instant_tab_) | 1522 if (instant_tab_) |
| 1520 instant_tab_->SendMostVisitedItems(items); | 1523 instant_tab_->SendMostVisitedItems(items); |
| 1521 content::NotificationService::current()->Notify( | 1524 content::NotificationService::current()->Notify( |
| 1522 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, | 1525 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, |
| 1523 content::Source<InstantController>(this), | 1526 content::Source<InstantController>(this), |
| 1524 content::NotificationService::NoDetails()); | 1527 content::NotificationService::NoDetails()); |
| 1525 } | 1528 } |
| OLD | NEW |