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

Side by Side Diff: chrome/browser/ui/webui/favicon_source.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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/webui/favicon_source.h" 5 #include "chrome/browser/ui/webui/favicon_source.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "chrome/browser/favicon/favicon_service_factory.h" 10 #include "chrome/browser/favicon/favicon_service_factory.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 75
76 FaviconSource::~FaviconSource() { 76 FaviconSource::~FaviconSource() {
77 } 77 }
78 78
79 std::string FaviconSource::GetSource() const { 79 std::string FaviconSource::GetSource() const {
80 return icon_types_ == chrome::FAVICON ? 80 return icon_types_ == chrome::FAVICON ?
81 chrome::kChromeUIFaviconHost : chrome::kChromeUITouchIconHost; 81 chrome::kChromeUIFaviconHost : chrome::kChromeUITouchIconHost;
82 } 82 }
83 83
84 void FaviconSource::StartDataRequest( 84 void FaviconSource::StartDataRequest(
85 const std::string& raw_path, 85 const std::string& path,
86 int render_process_id, 86 int render_process_id,
87 int render_view_id, 87 int render_view_id,
88 const content::URLDataSource::GotDataCallback& callback) { 88 const content::URLDataSource::GotDataCallback& callback) {
89 FaviconService* favicon_service = 89 FaviconService* favicon_service =
90 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 90 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
91 if (!favicon_service) { 91 if (!favicon_service) {
92 SendDefaultResponse(callback); 92 SendDefaultResponse(callback);
93 return; 93 return;
94 } 94 }
95 95
96 bool is_icon_url = false; 96 bool is_icon_url = false;
97 GURL url; 97 GURL url;
98 int size_in_dip = 16; 98 int size_in_dip = 16;
99 ui::ScaleFactor scale_factor = ui::SCALE_FACTOR_100P; 99 ui::ScaleFactor scale_factor = ui::SCALE_FACTOR_100P;
100 bool success = ParsePath(raw_path, &is_icon_url, &url, &size_in_dip, 100 bool success = ParsePath(path, &is_icon_url, &url, &size_in_dip,
101 &scale_factor); 101 &scale_factor);
102 102
103 if (!success) { 103 if (!success) {
104 SendDefaultResponse(callback); 104 SendDefaultResponse(callback);
105 return; 105 return;
106 } 106 }
107 107
108 if (is_icon_url) { 108 if (is_icon_url) {
109 // TODO(michaelbai): Change GetRawFavicon to support combination of 109 // TODO(michaelbai): Change GetRawFavicon to support combination of
110 // IconType. 110 // IconType.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 return "image/png"; 153 return "image/png";
154 } 154 }
155 155
156 bool FaviconSource::ShouldReplaceExistingSource() const { 156 bool FaviconSource::ShouldReplaceExistingSource() const {
157 // Leave the existing DataSource in place, otherwise we'll drop any pending 157 // Leave the existing DataSource in place, otherwise we'll drop any pending
158 // requests on the floor. 158 // requests on the floor.
159 return false; 159 return false;
160 } 160 }
161 161
162 bool FaviconSource::ShouldServiceRequest(const net::URLRequest* request) const { 162 bool FaviconSource::ShouldServiceRequest(const net::URLRequest* request) const {
163 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) { 163 if (request->url().SchemeIs(chrome::kChromeSearchScheme))
164 return InstantService::IsInstantPath(request->url()) && 164 return InstantIOContext::ShouldServiceRequest(request);
165 InstantIOContext::ShouldServiceRequest(request);
166 }
167 return URLDataSource::ShouldServiceRequest(request); 165 return URLDataSource::ShouldServiceRequest(request);
168 } 166 }
169 167
170 bool FaviconSource::HandleMissingResource(const IconRequest& request) { 168 bool FaviconSource::HandleMissingResource(const IconRequest& request) {
171 // No additional checks to locate the favicon resource in the base 169 // No additional checks to locate the favicon resource in the base
172 // implementation. 170 // implementation.
173 return false; 171 return false;
174 } 172 }
175 173
176 bool FaviconSource::ParsePath(const std::string& raw_path, 174 bool FaviconSource::ParsePath(const std::string& path,
177 bool* is_icon_url, 175 bool* is_icon_url,
178 GURL* url, 176 GURL* url,
179 int* size_in_dip, 177 int* size_in_dip,
180 ui::ScaleFactor* scale_factor) const { 178 ui::ScaleFactor* scale_factor) const {
181 DCHECK_EQ(16, gfx::kFaviconSize); 179 DCHECK_EQ(16, gfx::kFaviconSize);
182 180
183 *is_icon_url = false; 181 *is_icon_url = false;
184 *url = GURL(); 182 *url = GURL();
185 *size_in_dip = 16; 183 *size_in_dip = 16;
186 *scale_factor = ui::SCALE_FACTOR_100P; 184 *scale_factor = ui::SCALE_FACTOR_100P;
187 185
188 if (raw_path.empty()) 186 if (path.empty())
189 return false; 187 return false;
190 188
191 // Translate to regular path if |raw_path| is of the form
192 // chrome-search://favicon/<most_visited_item_id>, where
193 // "most_visited_item_id" is a uint64.
194 std::string path = InstantService::MaybeTranslateInstantPathOnUI(profile_,
195 raw_path);
196 size_t parsed_index = 0; 189 size_t parsed_index = 0;
197 if (HasSubstringAt(path, parsed_index, kLargestParameter)) { 190 if (HasSubstringAt(path, parsed_index, kLargestParameter)) {
198 parsed_index += strlen(kLargestParameter); 191 parsed_index += strlen(kLargestParameter);
199 *size_in_dip = 0; 192 *size_in_dip = 0;
200 } else if (HasSubstringAt(path, parsed_index, kSizeParameter)) { 193 } else if (HasSubstringAt(path, parsed_index, kSizeParameter)) {
201 parsed_index += strlen(kSizeParameter); 194 parsed_index += strlen(kSizeParameter);
202 195
203 size_t slash = path.find("/", parsed_index); 196 size_t slash = path.find("/", parsed_index);
204 if (slash == std::string::npos) 197 if (slash == std::string::npos)
205 return false; 198 return false;
206 199
207 size_t scale_delimiter = path.find("@", parsed_index); 200 size_t scale_delimiter = path.find("@", parsed_index);
208 std::string size_str; 201 std::string size_str;
209 std::string scale_str; 202 std::string scale_str;
210 if (scale_delimiter == std::string::npos) { 203 if (scale_delimiter == std::string::npos) {
211 // Support the legacy size format of 'size/aa/' where 'aa' is the desired 204 // Support the legacy size format of 'size/aa/' where 'aa' is the desired
212 // size in DIP for the sake of not regressing the extensions which use it. 205 // size in DIP for the sake of not regressing the extensions which use it.
213 size_str = path.substr(parsed_index, slash - parsed_index); 206 size_str = path.substr(parsed_index, slash - parsed_index);
214 } else { 207 } else {
215 size_str = path.substr(parsed_index, scale_delimiter - parsed_index); 208 size_str = path.substr(parsed_index, scale_delimiter - parsed_index);
216 scale_str = path.substr(scale_delimiter + 1, 209 scale_str = path.substr(scale_delimiter + 1, slash - scale_delimiter - 1);
217 slash - scale_delimiter - 1);
218 } 210 }
219 211
220 if (!base::StringToInt(size_str, size_in_dip)) 212 if (!base::StringToInt(size_str, size_in_dip))
221 return false; 213 return false;
222 214
223 if (*size_in_dip != 64 && *size_in_dip != 32) { 215 if (*size_in_dip != 64 && *size_in_dip != 32) {
224 // Only 64x64, 32x32 and 16x16 icons are supported. 216 // Only 64x64, 32x32 and 16x16 icons are supported.
225 *size_in_dip = 16; 217 *size_in_dip = 16;
226 } 218 }
227 219
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 297
306 if (!default_favicon) { 298 if (!default_favicon) {
307 ui::ScaleFactor scale_factor = icon_request.scale_factor; 299 ui::ScaleFactor scale_factor = icon_request.scale_factor;
308 default_favicon = ResourceBundle::GetSharedInstance() 300 default_favicon = ResourceBundle::GetSharedInstance()
309 .LoadDataResourceBytesForScale(resource_id, scale_factor); 301 .LoadDataResourceBytesForScale(resource_id, scale_factor);
310 default_favicons_[favicon_index] = default_favicon; 302 default_favicons_[favicon_index] = default_favicon;
311 } 303 }
312 304
313 icon_request.callback.Run(default_favicon); 305 icon_request.callback.Run(default_favicon);
314 } 306 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/favicon_source.h ('k') | chrome/browser/ui/webui/favicon_source_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698