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

Side by Side Diff: chrome/browser/ui/webui/favicon_source.cc

Issue 11885021: Don't derive from ChromeURLDataManager::DataSource, and instead have these classes implement a dele… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: nits Created 7 years, 11 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 "chrome/browser/favicon/favicon_service_factory.h" 9 #include "chrome/browser/favicon/favicon_service_factory.h"
10 #include "chrome/browser/history/top_sites.h" 10 #include "chrome/browser/history/top_sites.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
12 #include "chrome/browser/ui/webui/web_ui_util.h" 13 #include "chrome/browser/ui/webui/web_ui_util.h"
13 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
14 #include "grit/locale_settings.h" 15 #include "grit/locale_settings.h"
15 #include "grit/ui_resources.h" 16 #include "grit/ui_resources.h"
16 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/layout.h" 18 #include "ui/base/layout.h"
18 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
19 20
20 FaviconSource::FaviconSource(Profile* profile, IconType type) 21 FaviconSource::FaviconSource(Profile* profile, IconType type)
21 : DataSource(type == FAVICON ? chrome::kChromeUIFaviconHost : 22 : profile_(profile->GetOriginalProfile()),
22 chrome::kChromeUITouchIconHost, 23 icon_types_(type == FAVICON ? history::FAVICON :
23 MessageLoop::current()) { 24 history::TOUCH_PRECOMPOSED_ICON | history::TOUCH_ICON |
24 Init(profile, type); 25 history::FAVICON) {
25 }
26
27 FaviconSource::FaviconSource(Profile* profile,
28 IconType type,
29 const std::string& source_name)
30 : DataSource(source_name, MessageLoop::current()) {
31 Init(profile, type);
32 } 26 }
33 27
34 FaviconSource::~FaviconSource() { 28 FaviconSource::~FaviconSource() {
35 } 29 }
36 30
37 void FaviconSource::Init(Profile* profile, IconType type) { 31 std::string FaviconSource::GetSource() {
38 profile_ = profile->GetOriginalProfile(); 32 return icon_types_ == history::FAVICON ?
39 icon_types_ = type == FAVICON ? history::FAVICON : 33 chrome::kChromeUIFaviconHost : chrome::kChromeUITouchIconHost;
40 history::TOUCH_PRECOMPOSED_ICON | history::TOUCH_ICON |
41 history::FAVICON;
42 } 34 }
43 35
44 void FaviconSource::StartDataRequest(const std::string& path, 36 void FaviconSource::StartDataRequest(const std::string& path,
45 bool is_incognito, 37 bool is_incognito,
46 int request_id) { 38 int request_id) {
47 FaviconService* favicon_service = 39 FaviconService* favicon_service =
48 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 40 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
49 if (!favicon_service || path.empty()) { 41 if (!favicon_service || path.empty()) {
50 SendDefaultResponse(IconRequest(request_id, 42 SendDefaultResponse(IconRequest(request_id,
51 "", 43 "",
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 url = GURL(originalUrl).GetOrigin(); 108 url = GURL(originalUrl).GetOrigin();
117 } else { 109 } else {
118 url = GURL(path); 110 url = GURL(path);
119 } 111 }
120 } 112 }
121 113
122 // Intercept requests for prepopulated pages. 114 // Intercept requests for prepopulated pages.
123 for (size_t i = 0; i < arraysize(history::kPrepopulatedPages); i++) { 115 for (size_t i = 0; i < arraysize(history::kPrepopulatedPages); i++) {
124 if (url.spec() == 116 if (url.spec() ==
125 l10n_util::GetStringUTF8(history::kPrepopulatedPages[i].url_id)) { 117 l10n_util::GetStringUTF8(history::kPrepopulatedPages[i].url_id)) {
126 SendResponse(request_id, 118 url_data_source()->SendResponse(request_id,
127 ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( 119 ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale(
128 history::kPrepopulatedPages[i].favicon_id, 120 history::kPrepopulatedPages[i].favicon_id,
129 scale_factor)); 121 scale_factor));
130 return; 122 return;
131 } 123 }
132 } 124 }
133 125
134 favicon_service->GetRawFaviconForURL( 126 favicon_service->GetRawFaviconForURL(
135 FaviconService::FaviconForURLParams( 127 FaviconService::FaviconForURLParams(
136 profile_, url, icon_types_, size_in_dip), 128 profile_, url, icon_types_, size_in_dip),
(...skipping 24 matching lines...) Expand all
161 // No additional checks to locate the favicon resource in the base 153 // No additional checks to locate the favicon resource in the base
162 // implementation. 154 // implementation.
163 return false; 155 return false;
164 } 156 }
165 157
166 void FaviconSource::OnFaviconDataAvailable( 158 void FaviconSource::OnFaviconDataAvailable(
167 const IconRequest& request, 159 const IconRequest& request,
168 const history::FaviconBitmapResult& bitmap_result) { 160 const history::FaviconBitmapResult& bitmap_result) {
169 if (bitmap_result.is_valid()) { 161 if (bitmap_result.is_valid()) {
170 // Forward the data along to the networking system. 162 // Forward the data along to the networking system.
171 SendResponse(request.request_id, bitmap_result.bitmap_data); 163 url_data_source()->SendResponse(
164 request.request_id, bitmap_result.bitmap_data);
172 } else if (!HandleMissingResource(request)) { 165 } else if (!HandleMissingResource(request)) {
173 SendDefaultResponse(request); 166 SendDefaultResponse(request);
174 } 167 }
175 } 168 }
176 169
177 void FaviconSource::SendDefaultResponse(const IconRequest& icon_request) { 170 void FaviconSource::SendDefaultResponse(const IconRequest& icon_request) {
178 int favicon_index; 171 int favicon_index;
179 int resource_id; 172 int resource_id;
180 switch (icon_request.size_in_dip) { 173 switch (icon_request.size_in_dip) {
181 case 64: 174 case 64:
(...skipping 11 matching lines...) Expand all
193 } 186 }
194 base::RefCountedMemory* default_favicon = default_favicons_[favicon_index]; 187 base::RefCountedMemory* default_favicon = default_favicons_[favicon_index];
195 188
196 if (!default_favicon) { 189 if (!default_favicon) {
197 ui::ScaleFactor scale_factor = icon_request.scale_factor; 190 ui::ScaleFactor scale_factor = icon_request.scale_factor;
198 default_favicon = ResourceBundle::GetSharedInstance() 191 default_favicon = ResourceBundle::GetSharedInstance()
199 .LoadDataResourceBytesForScale(resource_id, scale_factor); 192 .LoadDataResourceBytesForScale(resource_id, scale_factor);
200 default_favicons_[favicon_index] = default_favicon; 193 default_favicons_[favicon_index] = default_favicon;
201 } 194 }
202 195
203 SendResponse(icon_request.request_id, default_favicon); 196 url_data_source()->SendResponse(icon_request.request_id, default_favicon);
204 } 197 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698