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

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: Rebase 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
« no previous file with comments | « chrome/renderer/searchbox/searchbox.h ('k') | chrome/renderer/searchbox/searchbox_extension.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/searchbox/searchbox.cc
diff --git a/chrome/renderer/searchbox/searchbox.cc b/chrome/renderer/searchbox/searchbox.cc
index c7e13621472eb6dc11a96367af6f5ae41e47a7a8..8e1121c5a801fd3f8a7239813beecdff2c66d631 100644
--- a/chrome/renderer/searchbox/searchbox.cc
+++ b/chrome/renderer/searchbox/searchbox.cc
@@ -4,7 +4,10 @@
#include "chrome/renderer/searchbox/searchbox.h"
+#include <string>
+
#include "base/string_number_conversions.h"
+#include "base/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/omnibox_focus_state.h"
@@ -12,6 +15,7 @@
#include "chrome/common/url_constants.h"
#include "chrome/renderer/searchbox/searchbox_extension.h"
#include "content/public/renderer/render_view.h"
+#include "googleurl/src/gurl.h"
#include "grit/renderer_resources.h"
#include "net/base/escape.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
@@ -26,6 +30,36 @@ const size_t kMaxInstantAutocompleteResultItemCacheSize = 100;
} // namespace
+namespace internal { // for testing
+
+// 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>/<restricted_id>
+// 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 path.
+ 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 internal
+
SearchBox::SearchBox(content::RenderView* render_view)
: content::RenderViewObserver(render_view),
content::RenderViewObserverTracker<SearchBox>(render_view),
@@ -155,6 +189,38 @@ const ThemeBackgroundInfo& SearchBox::GetThemeBackgroundInfo() {
return theme_info_;
}
+bool SearchBox::GenerateThumbnailURLFromTransientURL(const GURL& transient_url,
+ GURL* url) const {
+ InstantRestrictedID rid = 0;
+ if (!internal::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://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 (!internal::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)
@@ -407,9 +473,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());
« no previous file with comments | « chrome/renderer/searchbox/searchbox.h ('k') | chrome/renderer/searchbox/searchbox_extension.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698