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

Unified Diff: chrome/renderer/searchbox/searchbox.cc

Issue 15907006: Rip out browser-side RID caching for most visited items. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/searchbox/searchbox.cc
diff --git a/chrome/renderer/searchbox/searchbox.cc b/chrome/renderer/searchbox/searchbox.cc
index 4aa93c34843229e4c3e01c57c83285162c96ddc3..439508cf451d0a55d2cda522630a7e51d0260310 100644
--- a/chrome/renderer/searchbox/searchbox.cc
+++ b/chrome/renderer/searchbox/searchbox.cc
@@ -24,6 +24,32 @@ namespace {
// Size of the results cache.
const size_t kMaxInstantAutocompleteResultItemCacheSize = 100;
+// Parses |url| and fills in |id| with the InstantRestrictedID obtained from the
+// |url|. |render_view_id| is the ID of the associated RenderView.
+//
+// Valid |url| forms:
+// chrome-search://favicon/<view_id>/<restriced_id> or
+// chrome-search://thumb/<view_id>/<restricted_id>
+//
+// If the |url| is valid, returns true and fills in |id| with restricted_id
+// value. If the |url| is invalid, returns false and |id| is not set.
+bool GetInstantRestrictedIDFromURL(int render_view_id,
+ const GURL& url,
+ InstantRestrictedID* id) {
+ // Strip leading slash.
+ std::string path = url.path().substr(1);
+
+ // Check that the path is of Most visited item ID form.
+ std::vector<std::string> tokens;
+ if (Tokenize(path, "/", &tokens) != 2)
+ return false;
+
+ int view_id = 0;
+ if (!base::StringToInt(tokens[0], &view_id) || view_id != render_view_id)
+ return false;
+ return base::StringToInt(tokens[1], id);
+}
+
} // namespace
SearchBox::SearchBox(content::RenderView* render_view)
@@ -155,6 +181,36 @@ const ThemeBackgroundInfo& SearchBox::GetThemeBackgroundInfo() {
return theme_info_;
}
+bool SearchBox::GenerateThumbnailURLFromTransientURL(const GURL& transient_url,
+ GURL* url) const {
+ InstantRestrictedID rid = 0;
+ if (!GetInstantRestrictedIDFromURL(render_view()->GetRoutingID(),
+ transient_url, &rid))
palmer 2013/06/05 17:50:54 Nit: curly braces, here and on line 202
kmadhusu 2013/06/05 18:40:39 Done.
+ return false;
+
+ GURL most_visited_item_url(GetURLForMostVisitedItem(rid));
+ if (most_visited_item_url.is_empty())
+ return false;
+ *url = GURL(base::StringPrintf("chrome-search://thumb/%s",
+ most_visited_item_url.spec().c_str()));
+ return true;
+}
+
+bool SearchBox::GenerateFaviconURLFromTransientURL(const GURL& transient_url,
+ GURL* url) const {
+ InstantRestrictedID rid = 0;
+ if (!GetInstantRestrictedIDFromURL(render_view()->GetRoutingID(),
+ transient_url, &rid))
+ return false;
+
+ GURL most_visited_item_url(GetURLForMostVisitedItem(rid));
+ if (most_visited_item_url.is_empty())
+ return false;
+ *url = GURL(base::StringPrintf("chrome-search://favicon/%s",
+ most_visited_item_url.spec().c_str()));
+ return true;
+}
+
bool SearchBox::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(SearchBox, message)
@@ -405,9 +461,8 @@ void SearchBox::SetQuery(const string16& query, bool verbatim) {
}
void SearchBox::OnMostVisitedChanged(
- const std::vector<InstantMostVisitedItemIDPair>& items) {
- most_visited_items_cache_.AddItemsWithRestrictedID(items);
-
+ const std::vector<InstantMostVisitedItem>& items) {
+ most_visited_items_cache_.AddItems(items);
if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
extensions_v8::SearchBoxExtension::DispatchMostVisitedChanged(
render_view()->GetWebView()->mainFrame());

Powered by Google App Engine
This is Rietveld 408576698