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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/renderer/searchbox/searchbox.h" 5 #include "chrome/renderer/searchbox/searchbox.h"
6 6
7 #include "base/string_number_conversions.h" 7 #include "base/string_number_conversions.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/common/chrome_switches.h" 9 #include "chrome/common/chrome_switches.h"
10 #include "chrome/common/omnibox_focus_state.h" 10 #include "chrome/common/omnibox_focus_state.h"
11 #include "chrome/common/render_messages.h" 11 #include "chrome/common/render_messages.h"
12 #include "chrome/common/url_constants.h" 12 #include "chrome/common/url_constants.h"
13 #include "chrome/renderer/searchbox/searchbox_extension.h" 13 #include "chrome/renderer/searchbox/searchbox_extension.h"
14 #include "content/public/renderer/render_view.h" 14 #include "content/public/renderer/render_view.h"
15 #include "grit/renderer_resources.h" 15 #include "grit/renderer_resources.h"
16 #include "net/base/escape.h" 16 #include "net/base/escape.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
20 #include "ui/base/resource/resource_bundle.h" 20 #include "ui/base/resource/resource_bundle.h"
21 21
22 namespace { 22 namespace {
23 23
24 // Size of the results cache. 24 // Size of the results cache.
25 const size_t kMaxInstantAutocompleteResultItemCacheSize = 100; 25 const size_t kMaxInstantAutocompleteResultItemCacheSize = 100;
26 26
27 // Parses |url| and fills in |id| with the InstantRestrictedID obtained from the
28 // |url|. |render_view_id| is the ID of the associated RenderView.
29 //
30 // Valid |url| forms:
31 // chrome-search://favicon/<view_id>/<restriced_id> or
32 // chrome-search://thumb/<view_id>/<restricted_id>
33 //
34 // If the |url| is valid, returns true and fills in |id| with restricted_id
35 // value. If the |url| is invalid, returns false and |id| is not set.
36 bool GetInstantRestrictedIDFromURL(int render_view_id,
37 const GURL& url,
38 InstantRestrictedID* id) {
39 // Strip leading slash.
40 std::string path = url.path().substr(1);
41
42 // Check that the path is of Most visited item ID form.
43 std::vector<std::string> tokens;
44 if (Tokenize(path, "/", &tokens) != 2)
45 return false;
46
47 int view_id = 0;
48 if (!base::StringToInt(tokens[0], &view_id) || view_id != render_view_id)
49 return false;
50 return base::StringToInt(tokens[1], id);
51 }
52
27 } // namespace 53 } // namespace
28 54
29 SearchBox::SearchBox(content::RenderView* render_view) 55 SearchBox::SearchBox(content::RenderView* render_view)
30 : content::RenderViewObserver(render_view), 56 : content::RenderViewObserver(render_view),
31 content::RenderViewObserverTracker<SearchBox>(render_view), 57 content::RenderViewObserverTracker<SearchBox>(render_view),
32 verbatim_(false), 58 verbatim_(false),
33 query_is_restricted_(false), 59 query_is_restricted_(false),
34 selection_start_(0), 60 selection_start_(0),
35 selection_end_(0), 61 selection_end_(0),
36 start_margin_(0), 62 start_margin_(0),
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 InstantRestrictedID autocomplete_result_id, 174 InstantRestrictedID autocomplete_result_id,
149 InstantAutocompleteResult* result) const { 175 InstantAutocompleteResult* result) const {
150 return autocomplete_results_cache_.GetItemWithRestrictedID( 176 return autocomplete_results_cache_.GetItemWithRestrictedID(
151 autocomplete_result_id, result); 177 autocomplete_result_id, result);
152 } 178 }
153 179
154 const ThemeBackgroundInfo& SearchBox::GetThemeBackgroundInfo() { 180 const ThemeBackgroundInfo& SearchBox::GetThemeBackgroundInfo() {
155 return theme_info_; 181 return theme_info_;
156 } 182 }
157 183
184 bool SearchBox::GenerateThumbnailURLFromTransientURL(const GURL& transient_url,
185 GURL* url) const {
186 InstantRestrictedID rid = 0;
187 if (!GetInstantRestrictedIDFromURL(render_view()->GetRoutingID(),
188 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.
189 return false;
190
191 GURL most_visited_item_url(GetURLForMostVisitedItem(rid));
192 if (most_visited_item_url.is_empty())
193 return false;
194 *url = GURL(base::StringPrintf("chrome-search://thumb/%s",
195 most_visited_item_url.spec().c_str()));
196 return true;
197 }
198
199 bool SearchBox::GenerateFaviconURLFromTransientURL(const GURL& transient_url,
200 GURL* url) const {
201 InstantRestrictedID rid = 0;
202 if (!GetInstantRestrictedIDFromURL(render_view()->GetRoutingID(),
203 transient_url, &rid))
204 return false;
205
206 GURL most_visited_item_url(GetURLForMostVisitedItem(rid));
207 if (most_visited_item_url.is_empty())
208 return false;
209 *url = GURL(base::StringPrintf("chrome-search://favicon/%s",
210 most_visited_item_url.spec().c_str()));
211 return true;
212 }
213
158 bool SearchBox::OnMessageReceived(const IPC::Message& message) { 214 bool SearchBox::OnMessageReceived(const IPC::Message& message) {
159 bool handled = true; 215 bool handled = true;
160 IPC_BEGIN_MESSAGE_MAP(SearchBox, message) 216 IPC_BEGIN_MESSAGE_MAP(SearchBox, message)
161 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxChange, OnChange) 217 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxChange, OnChange)
162 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSubmit, OnSubmit) 218 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSubmit, OnSubmit)
163 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxCancel, OnCancel) 219 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxCancel, OnCancel)
164 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxPopupResize, OnPopupResize) 220 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxPopupResize, OnPopupResize)
165 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxMarginChange, OnMarginChange) 221 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxMarginChange, OnMarginChange)
166 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxBarsHidden, OnBarsHidden) 222 IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxBarsHidden, OnBarsHidden)
167 IPC_MESSAGE_HANDLER(ChromeViewMsg_DetermineIfPageSupportsInstant, 223 IPC_MESSAGE_HANDLER(ChromeViewMsg_DetermineIfPageSupportsInstant,
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 // changes. 454 // changes.
399 } 455 }
400 456
401 void SearchBox::SetQuery(const string16& query, bool verbatim) { 457 void SearchBox::SetQuery(const string16& query, bool verbatim) {
402 query_ = query; 458 query_ = query;
403 verbatim_ = verbatim; 459 verbatim_ = verbatim;
404 query_is_restricted_ = false; 460 query_is_restricted_ = false;
405 } 461 }
406 462
407 void SearchBox::OnMostVisitedChanged( 463 void SearchBox::OnMostVisitedChanged(
408 const std::vector<InstantMostVisitedItemIDPair>& items) { 464 const std::vector<InstantMostVisitedItem>& items) {
409 most_visited_items_cache_.AddItemsWithRestrictedID(items); 465 most_visited_items_cache_.AddItems(items);
410
411 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) { 466 if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
412 extensions_v8::SearchBoxExtension::DispatchMostVisitedChanged( 467 extensions_v8::SearchBoxExtension::DispatchMostVisitedChanged(
413 render_view()->GetWebView()->mainFrame()); 468 render_view()->GetWebView()->mainFrame());
414 } 469 }
415 } 470 }
416 471
417 void SearchBox::GetMostVisitedItems( 472 void SearchBox::GetMostVisitedItems(
418 std::vector<InstantMostVisitedItemIDPair>* items) const { 473 std::vector<InstantMostVisitedItemIDPair>* items) const {
419 return most_visited_items_cache_.GetCurrentItems(items); 474 return most_visited_items_cache_.GetCurrentItems(items);
420 } 475 }
421 476
422 bool SearchBox::GetMostVisitedItemWithID( 477 bool SearchBox::GetMostVisitedItemWithID(
423 InstantRestrictedID most_visited_item_id, 478 InstantRestrictedID most_visited_item_id,
424 InstantMostVisitedItem* item) const { 479 InstantMostVisitedItem* item) const {
425 return most_visited_items_cache_.GetItemWithRestrictedID(most_visited_item_id, 480 return most_visited_items_cache_.GetItemWithRestrictedID(most_visited_item_id,
426 item); 481 item);
427 } 482 }
428 483
429 GURL SearchBox::GetURLForMostVisitedItem(InstantRestrictedID item_id) const { 484 GURL SearchBox::GetURLForMostVisitedItem(InstantRestrictedID item_id) const {
430 InstantMostVisitedItem item; 485 InstantMostVisitedItem item;
431 return GetMostVisitedItemWithID(item_id, &item) ? item.url : GURL(); 486 return GetMostVisitedItemWithID(item_id, &item) ? item.url : GURL();
432 } 487 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698