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 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
935 base::Time::Now().ToInternalValue(), info)); | 932 base::Time::Now().ToInternalValue(), info)); |
936 static const size_t kMaxDebugEventSize = 2000; | 933 static const size_t kMaxDebugEventSize = 2000; |
937 if (debug_events_.size() > kMaxDebugEventSize) | 934 if (debug_events_.size() > kMaxDebugEventSize) |
938 debug_events_.pop_back(); | 935 debug_events_.pop_back(); |
939 } | 936 } |
940 | 937 |
941 void InstantController::ClearDebugEvents() { | 938 void InstantController::ClearDebugEvents() { |
942 debug_events_.clear(); | 939 debug_events_.clear(); |
943 } | 940 } |
944 | 941 |
945 void InstantController::DeleteMostVisitedItem(uint64 most_visited_item_id) { | 942 void InstantController::DeleteMostVisitedItem( |
| 943 InstantRestrictedID most_visited_item_id) { |
946 history::TopSites* top_sites = browser_->profile()->GetTopSites(); | 944 history::TopSites* top_sites = browser_->profile()->GetTopSites(); |
947 if (!top_sites) | 945 if (!top_sites) |
948 return; | 946 return; |
949 | 947 |
950 GURL url; | 948 GURL url; |
951 if (GetURLForMostVisitedItemId(browser_->profile(), | 949 if (GetURLForMostVisitedItemID(browser_->profile(), |
952 most_visited_item_id, &url)) | 950 most_visited_item_id, &url)) |
953 top_sites->AddBlacklistedURL(url); | 951 top_sites->AddBlacklistedURL(url); |
954 } | 952 } |
955 | 953 |
956 void InstantController::UndoMostVisitedDeletion(uint64 most_visited_item_id) { | 954 void InstantController::UndoMostVisitedDeletion( |
| 955 InstantRestrictedID most_visited_item_id) { |
957 history::TopSites* top_sites = browser_->profile()->GetTopSites(); | 956 history::TopSites* top_sites = browser_->profile()->GetTopSites(); |
958 if (!top_sites) | 957 if (!top_sites) |
959 return; | 958 return; |
960 | 959 |
961 GURL url; | 960 GURL url; |
962 if (GetURLForMostVisitedItemId(browser_->profile(), | 961 if (GetURLForMostVisitedItemID(browser_->profile(), |
963 most_visited_item_id, &url)) | 962 most_visited_item_id, &url)) |
964 top_sites->RemoveBlacklistedURL(url); | 963 top_sites->RemoveBlacklistedURL(url); |
965 } | 964 } |
966 | 965 |
967 void InstantController::UndoAllMostVisitedDeletions() { | 966 void InstantController::UndoAllMostVisitedDeletions() { |
968 history::TopSites* top_sites = browser_->profile()->GetTopSites(); | 967 history::TopSites* top_sites = browser_->profile()->GetTopSites(); |
969 if (!top_sites) | 968 if (!top_sites) |
970 return; | 969 return; |
971 | 970 |
972 top_sites->ClearBlacklistedURLs(); | 971 top_sites->ClearBlacklistedURLs(); |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1510 history::TopSites* top_sites = browser_->profile()->GetTopSites(); | 1509 history::TopSites* top_sites = browser_->profile()->GetTopSites(); |
1511 if (top_sites) { | 1510 if (top_sites) { |
1512 top_sites->GetMostVisitedURLs( | 1511 top_sites->GetMostVisitedURLs( |
1513 base::Bind(&InstantController::OnMostVisitedItemsReceived, | 1512 base::Bind(&InstantController::OnMostVisitedItemsReceived, |
1514 weak_ptr_factory_.GetWeakPtr())); | 1513 weak_ptr_factory_.GetWeakPtr())); |
1515 } | 1514 } |
1516 } | 1515 } |
1517 | 1516 |
1518 void InstantController::OnMostVisitedItemsReceived( | 1517 void InstantController::OnMostVisitedItemsReceived( |
1519 const history::MostVisitedURLList& data) { | 1518 const history::MostVisitedURLList& data) { |
| 1519 InstantService* instant_service = |
| 1520 InstantServiceFactory::GetForProfile(browser_->profile()); |
| 1521 if (!instant_service) |
| 1522 return; |
| 1523 |
1520 std::vector<InstantMostVisitedItem> most_visited_items; | 1524 std::vector<InstantMostVisitedItem> most_visited_items; |
1521 for (size_t i = 0; i < data.size(); i++) { | 1525 for (size_t i = 0; i < data.size(); i++) { |
1522 const history::MostVisitedURL& url = data[i]; | 1526 const history::MostVisitedURL& url = data[i]; |
1523 | |
1524 InstantMostVisitedItem item; | 1527 InstantMostVisitedItem item; |
1525 item.most_visited_item_id = GetMostVisitedItemIDForURL(browser_->profile(), | |
1526 url.url); | |
1527 item.url = url.url; | 1528 item.url = url.url; |
1528 item.title = url.title; | 1529 item.title = url.title; |
1529 | |
1530 most_visited_items.push_back(item); | 1530 most_visited_items.push_back(item); |
1531 } | 1531 } |
1532 SendMostVisitedItems(most_visited_items); | 1532 |
| 1533 instant_service->AddMostVisitedItems(most_visited_items); |
| 1534 |
| 1535 std::vector<InstantMostVisitedItemIDPair> items_with_ids; |
| 1536 instant_service->GetCurrentMostVisitedItems(&items_with_ids); |
| 1537 SendMostVisitedItems(items_with_ids); |
1533 } | 1538 } |
1534 | 1539 |
1535 void InstantController::SendMostVisitedItems( | 1540 void InstantController::SendMostVisitedItems( |
1536 const std::vector<InstantMostVisitedItem>& items) { | 1541 const std::vector<InstantMostVisitedItemIDPair>& items) { |
1537 if (overlay_) | 1542 if (overlay_) |
1538 overlay_->SendMostVisitedItems(items); | 1543 overlay_->SendMostVisitedItems(items); |
1539 if (ntp_) | 1544 if (ntp_) |
1540 ntp_->SendMostVisitedItems(items); | 1545 ntp_->SendMostVisitedItems(items); |
1541 if (instant_tab_) | 1546 if (instant_tab_) |
1542 instant_tab_->SendMostVisitedItems(items); | 1547 instant_tab_->SendMostVisitedItems(items); |
1543 content::NotificationService::current()->Notify( | 1548 content::NotificationService::current()->Notify( |
1544 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, | 1549 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, |
1545 content::Source<InstantController>(this), | 1550 content::Source<InstantController>(this), |
1546 content::NotificationService::NoDetails()); | 1551 content::NotificationService::NoDetails()); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1593 // for instance, if the user types 'i' and the suggestion is 'INSTANT', | 1598 // for instance, if the user types 'i' and the suggestion is 'INSTANT', |
1594 // suggest 'nstant'. Otherwise, the user text really isn't a prefix, so | 1599 // suggest 'nstant'. Otherwise, the user text really isn't a prefix, so |
1595 // suggest nothing. | 1600 // suggest nothing. |
1596 // TODO(samarth|jered): revisit this logic. http://crbug.com/196572. | 1601 // TODO(samarth|jered): revisit this logic. http://crbug.com/196572. |
1597 return true; | 1602 return true; |
1598 } | 1603 } |
1599 } | 1604 } |
1600 | 1605 |
1601 return false; | 1606 return false; |
1602 } | 1607 } |
OLD | NEW |