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

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

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