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

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

Issue 10873022: Revert 152904 - Moving FaviconService to a ProfileKeyedService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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"
10 #include "chrome/browser/history/top_sites.h" 9 #include "chrome/browser/history/top_sites.h"
11 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/common/url_constants.h" 11 #include "chrome/common/url_constants.h"
13 #include "grit/locale_settings.h" 12 #include "grit/locale_settings.h"
14 #include "grit/ui_resources.h" 13 #include "grit/ui_resources.h"
15 #include "ui/base/l10n/l10n_util.h" 14 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/layout.h" 15 #include "ui/base/layout.h"
17 #include "ui/base/resource/resource_bundle.h" 16 #include "ui/base/resource/resource_bundle.h"
18 17
19 FaviconSource::FaviconSource(Profile* profile, IconType type) 18 FaviconSource::FaviconSource(Profile* profile, IconType type)
(...skipping 17 matching lines...) Expand all
37 profile_ = profile->GetOriginalProfile(); 36 profile_ = profile->GetOriginalProfile();
38 icon_types_ = type == FAVICON ? history::FAVICON : 37 icon_types_ = type == FAVICON ? history::FAVICON :
39 history::TOUCH_PRECOMPOSED_ICON | history::TOUCH_ICON | 38 history::TOUCH_PRECOMPOSED_ICON | history::TOUCH_ICON |
40 history::FAVICON; 39 history::FAVICON;
41 } 40 }
42 41
43 void FaviconSource::StartDataRequest(const std::string& path, 42 void FaviconSource::StartDataRequest(const std::string& path,
44 bool is_incognito, 43 bool is_incognito,
45 int request_id) { 44 int request_id) {
46 FaviconService* favicon_service = 45 FaviconService* favicon_service =
47 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 46 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS);
48 if (!favicon_service || path.empty()) { 47 if (!favicon_service || path.empty()) {
49 SendDefaultResponse(request_id); 48 SendDefaultResponse(request_id);
50 return; 49 return;
51 } 50 }
52 51
53 FaviconService::Handle handle; 52 FaviconService::Handle handle;
54 if (path.size() > 8 && path.substr(0, 8) == "iconurl/") { 53 if (path.size() > 8 && path.substr(0, 8) == "iconurl/") {
55 // TODO : Change GetFavicon to support combination of IconType. 54 // TODO : Change GetFavicon to support combination of IconType.
56 handle = favicon_service->GetFavicon( 55 handle = favicon_service->GetFavicon(
57 GURL(path.substr(8)), 56 GURL(path.substr(8)),
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 SendResponse(request_id, 98 SendResponse(request_id,
100 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( 99 ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
101 history::kPrepopulatedPages[i].favicon_id, 100 history::kPrepopulatedPages[i].favicon_id,
102 ui::SCALE_FACTOR_100P)); 101 ui::SCALE_FACTOR_100P));
103 return; 102 return;
104 } 103 }
105 } 104 }
106 105
107 // TODO(estade): fetch the requested size. 106 // TODO(estade): fetch the requested size.
108 handle = favicon_service->GetFaviconForURL( 107 handle = favicon_service->GetFaviconForURL(
109 profile_,
110 url, 108 url,
111 icon_types_, 109 icon_types_,
112 &cancelable_consumer_, 110 &cancelable_consumer_,
113 base::Bind(&FaviconSource::OnFaviconDataAvailable, 111 base::Bind(&FaviconSource::OnFaviconDataAvailable,
114 base::Unretained(this))); 112 base::Unretained(this)));
115 } 113 }
116 114
117 // Attach the ChromeURLDataManager request ID to the history request. 115 // Attach the ChromeURLDataManager request ID to the history request.
118 cancelable_consumer_.SetClientData(favicon_service, handle, request_id); 116 cancelable_consumer_.SetClientData(favicon_service, handle, request_id);
119 } 117 }
120 118
121 std::string FaviconSource::GetMimeType(const std::string&) const { 119 std::string FaviconSource::GetMimeType(const std::string&) const {
122 // We need to explicitly return a mime type, otherwise if the user tries to 120 // We need to explicitly return a mime type, otherwise if the user tries to
123 // drag the image they get no extension. 121 // drag the image they get no extension.
124 return "image/png"; 122 return "image/png";
125 } 123 }
126 124
127 bool FaviconSource::ShouldReplaceExistingSource() const { 125 bool FaviconSource::ShouldReplaceExistingSource() const {
128 // Leave the existing DataSource in place, otherwise we'll drop any pending 126 // Leave the existing DataSource in place, otherwise we'll drop any pending
129 // requests on the floor. 127 // requests on the floor.
130 return false; 128 return false;
131 } 129 }
132 130
133 void FaviconSource::OnFaviconDataAvailable( 131 void FaviconSource::OnFaviconDataAvailable(
134 FaviconService::Handle request_handle, 132 FaviconService::Handle request_handle,
135 history::FaviconData favicon) { 133 history::FaviconData favicon) {
136 FaviconService* favicon_service = 134 FaviconService* favicon_service =
137 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); 135 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS);
138 int request_id = cancelable_consumer_.GetClientData(favicon_service, 136 int request_id = cancelable_consumer_.GetClientData(favicon_service,
139 request_handle); 137 request_handle);
140 138
141 if (favicon.is_valid()) { 139 if (favicon.is_valid()) {
142 // Forward the data along to the networking system. 140 // Forward the data along to the networking system.
143 SendResponse(request_id, favicon.image_data); 141 SendResponse(request_id, favicon.image_data);
144 } else { 142 } else {
145 SendDefaultResponse(request_id); 143 SendDefaultResponse(request_id);
146 } 144 }
147 } 145 }
(...skipping 12 matching lines...) Expand all
160 default_favicon_ = 158 default_favicon_ =
161 ResourceBundle::GetSharedInstance().LoadDataResourceBytes( 159 ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
162 IDR_DEFAULT_FAVICON, ui::SCALE_FACTOR_100P); 160 IDR_DEFAULT_FAVICON, ui::SCALE_FACTOR_100P);
163 } 161 }
164 bytes = default_favicon_; 162 bytes = default_favicon_;
165 } 163 }
166 request_size_map_.erase(request_id); 164 request_size_map_.erase(request_id);
167 165
168 SendResponse(request_id, bytes); 166 SendResponse(request_id, bytes);
169 } 167 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/extensions/extension_icon_source.cc ('k') | chrome/browser/ui/webui/ntp/android/bookmarks_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698