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 "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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 std::string(), | 192 std::string(), |
193 contents->GetBrowserContext()); | 193 contents->GetBrowserContext()); |
194 transient->SetExtraData(chrome::search::kInstantExtendedSearchTermsKey, | 194 transient->SetExtraData(chrome::search::kInstantExtendedSearchTermsKey, |
195 search_terms); | 195 search_terms); |
196 controller->SetTransientEntry(transient); | 196 controller->SetTransientEntry(transient); |
197 | 197 |
198 chrome::search::SearchTabHelper::FromWebContents(contents)-> | 198 chrome::search::SearchTabHelper::FromWebContents(contents)-> |
199 NavigationEntryUpdated(); | 199 NavigationEntryUpdated(); |
200 } | 200 } |
201 | 201 |
202 bool GetURLForMostVisitedItemId(Profile* profile, | 202 bool GetURLForMostVisitedItemID(Profile* profile, |
203 uint64 most_visited_item_id, | 203 InstantRestrictedID most_visited_item_id, |
204 GURL* url) { | 204 GURL* url) { |
205 InstantService* instant_service = | 205 InstantService* instant_service = |
206 InstantServiceFactory::GetForProfile(profile); | 206 InstantServiceFactory::GetForProfile(profile); |
207 if (!instant_service) | 207 if (!instant_service) |
208 return false; | 208 return false; |
209 return instant_service->GetURLForMostVisitedItemId(most_visited_item_id, url); | |
210 } | |
211 | 209 |
212 // Creates a new restriced id if one is not found. | 210 InstantMostVisitedItem item; |
213 size_t GetMostVisitedItemIDForURL(Profile* profile, const GURL& url) { | 211 if (!instant_service->GetMostVisitedItemForID(most_visited_item_id, &item)) |
214 InstantService* instant_service = | 212 return false; |
215 InstantServiceFactory::GetForProfile(profile); | 213 |
216 if (!instant_service) | 214 *url = item.url; |
217 return 0; | 215 return true; |
218 return instant_service->AddURL(url); | |
219 } | 216 } |
220 | 217 |
221 } // namespace | 218 } // namespace |
222 | 219 |
223 InstantController::InstantController(chrome::BrowserInstantController* browser, | 220 InstantController::InstantController(chrome::BrowserInstantController* browser, |
224 bool extended_enabled) | 221 bool extended_enabled) |
225 : browser_(browser), | 222 : browser_(browser), |
226 extended_enabled_(extended_enabled), | 223 extended_enabled_(extended_enabled), |
227 instant_enabled_(false), | 224 instant_enabled_(false), |
228 use_local_overlay_only_(true), | 225 use_local_overlay_only_(true), |
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
921 base::Time::Now().ToInternalValue(), info)); | 918 base::Time::Now().ToInternalValue(), info)); |
922 static const size_t kMaxDebugEventSize = 2000; | 919 static const size_t kMaxDebugEventSize = 2000; |
923 if (debug_events_.size() > kMaxDebugEventSize) | 920 if (debug_events_.size() > kMaxDebugEventSize) |
924 debug_events_.pop_back(); | 921 debug_events_.pop_back(); |
925 } | 922 } |
926 | 923 |
927 void InstantController::ClearDebugEvents() { | 924 void InstantController::ClearDebugEvents() { |
928 debug_events_.clear(); | 925 debug_events_.clear(); |
929 } | 926 } |
930 | 927 |
931 void InstantController::DeleteMostVisitedItem(uint64 most_visited_item_id) { | 928 void InstantController::DeleteMostVisitedItem( |
| 929 InstantRestrictedID most_visited_item_id) { |
932 history::TopSites* top_sites = browser_->profile()->GetTopSites(); | 930 history::TopSites* top_sites = browser_->profile()->GetTopSites(); |
933 if (!top_sites) | 931 if (!top_sites) |
934 return; | 932 return; |
935 | 933 |
936 GURL url; | 934 GURL url; |
937 if (GetURLForMostVisitedItemId(browser_->profile(), | 935 if (GetURLForMostVisitedItemID(browser_->profile(), |
938 most_visited_item_id, &url)) | 936 most_visited_item_id, &url)) |
939 top_sites->AddBlacklistedURL(url); | 937 top_sites->AddBlacklistedURL(url); |
940 } | 938 } |
941 | 939 |
942 void InstantController::UndoMostVisitedDeletion(uint64 most_visited_item_id) { | 940 void InstantController::UndoMostVisitedDeletion( |
| 941 InstantRestrictedID most_visited_item_id) { |
943 history::TopSites* top_sites = browser_->profile()->GetTopSites(); | 942 history::TopSites* top_sites = browser_->profile()->GetTopSites(); |
944 if (!top_sites) | 943 if (!top_sites) |
945 return; | 944 return; |
946 | 945 |
947 GURL url; | 946 GURL url; |
948 if (GetURLForMostVisitedItemId(browser_->profile(), | 947 if (GetURLForMostVisitedItemID(browser_->profile(), |
949 most_visited_item_id, &url)) | 948 most_visited_item_id, &url)) |
950 top_sites->RemoveBlacklistedURL(url); | 949 top_sites->RemoveBlacklistedURL(url); |
951 } | 950 } |
952 | 951 |
953 void InstantController::UndoAllMostVisitedDeletions() { | 952 void InstantController::UndoAllMostVisitedDeletions() { |
954 history::TopSites* top_sites = browser_->profile()->GetTopSites(); | 953 history::TopSites* top_sites = browser_->profile()->GetTopSites(); |
955 if (!top_sites) | 954 if (!top_sites) |
956 return; | 955 return; |
957 | 956 |
958 top_sites->ClearBlacklistedURLs(); | 957 top_sites->ClearBlacklistedURLs(); |
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1491 history::TopSites* top_sites = browser_->profile()->GetTopSites(); | 1490 history::TopSites* top_sites = browser_->profile()->GetTopSites(); |
1492 if (top_sites) { | 1491 if (top_sites) { |
1493 top_sites->GetMostVisitedURLs( | 1492 top_sites->GetMostVisitedURLs( |
1494 base::Bind(&InstantController::OnMostVisitedItemsReceived, | 1493 base::Bind(&InstantController::OnMostVisitedItemsReceived, |
1495 weak_ptr_factory_.GetWeakPtr())); | 1494 weak_ptr_factory_.GetWeakPtr())); |
1496 } | 1495 } |
1497 } | 1496 } |
1498 | 1497 |
1499 void InstantController::OnMostVisitedItemsReceived( | 1498 void InstantController::OnMostVisitedItemsReceived( |
1500 const history::MostVisitedURLList& data) { | 1499 const history::MostVisitedURLList& data) { |
| 1500 InstantService* instant_service = |
| 1501 InstantServiceFactory::GetForProfile(browser_->profile()); |
| 1502 if (!instant_service) |
| 1503 return; |
| 1504 |
1501 std::vector<InstantMostVisitedItem> most_visited_items; | 1505 std::vector<InstantMostVisitedItem> most_visited_items; |
1502 for (size_t i = 0; i < data.size(); i++) { | 1506 for (size_t i = 0; i < data.size(); i++) { |
1503 const history::MostVisitedURL& url = data[i]; | 1507 const history::MostVisitedURL& url = data[i]; |
1504 | |
1505 InstantMostVisitedItem item; | 1508 InstantMostVisitedItem item; |
1506 item.most_visited_item_id = GetMostVisitedItemIDForURL(browser_->profile(), | |
1507 url.url); | |
1508 item.url = url.url; | 1509 item.url = url.url; |
1509 item.title = url.title; | 1510 item.title = url.title; |
1510 | |
1511 most_visited_items.push_back(item); | 1511 most_visited_items.push_back(item); |
1512 } | 1512 } |
1513 SendMostVisitedItems(most_visited_items); | 1513 |
| 1514 instant_service->AddMostVisitedItems(most_visited_items); |
| 1515 |
| 1516 std::vector<InstantMostVisitedItemIDPair> items_with_ids; |
| 1517 instant_service->GetCurrentMostVisitedItems(&items_with_ids); |
| 1518 SendMostVisitedItems(items_with_ids); |
1514 } | 1519 } |
1515 | 1520 |
1516 void InstantController::SendMostVisitedItems( | 1521 void InstantController::SendMostVisitedItems( |
1517 const std::vector<InstantMostVisitedItem>& items) { | 1522 const std::vector<InstantMostVisitedItemIDPair>& items) { |
1518 if (overlay_) | 1523 if (overlay_) |
1519 overlay_->SendMostVisitedItems(items); | 1524 overlay_->SendMostVisitedItems(items); |
1520 if (ntp_) | 1525 if (ntp_) |
1521 ntp_->SendMostVisitedItems(items); | 1526 ntp_->SendMostVisitedItems(items); |
1522 if (instant_tab_) | 1527 if (instant_tab_) |
1523 instant_tab_->SendMostVisitedItems(items); | 1528 instant_tab_->SendMostVisitedItems(items); |
1524 content::NotificationService::current()->Notify( | 1529 content::NotificationService::current()->Notify( |
1525 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, | 1530 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, |
1526 content::Source<InstantController>(this), | 1531 content::Source<InstantController>(this), |
1527 content::NotificationService::NoDetails()); | 1532 content::NotificationService::NoDetails()); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1574 // for instance, if the user types 'i' and the suggestion is 'INSTANT', | 1579 // for instance, if the user types 'i' and the suggestion is 'INSTANT', |
1575 // suggest 'nstant'. Otherwise, the user text really isn't a prefix, so | 1580 // suggest 'nstant'. Otherwise, the user text really isn't a prefix, so |
1576 // suggest nothing. | 1581 // suggest nothing. |
1577 // TODO(samarth|jered): revisit this logic. http://crbug.com/196572. | 1582 // TODO(samarth|jered): revisit this logic. http://crbug.com/196572. |
1578 return true; | 1583 return true; |
1579 } | 1584 } |
1580 } | 1585 } |
1581 | 1586 |
1582 return false; | 1587 return false; |
1583 } | 1588 } |
OLD | NEW |