| OLD | NEW |
| 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/extensions/extension_icon_source.h" | 5 #include "chrome/browser/ui/webui/extensions/extension_icon_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/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 12 #include "base/string_split.h" | 12 #include "base/string_split.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
| 16 #include "chrome/browser/extensions/extension_prefs.h" | 16 #include "chrome/browser/extensions/extension_prefs.h" |
| 17 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
| 18 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
| 20 #include "chrome/common/extensions/extension_constants.h" | 21 #include "chrome/common/extensions/extension_constants.h" |
| 21 #include "chrome/common/extensions/extension_resource.h" | 22 #include "chrome/common/extensions/extension_resource.h" |
| 22 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| 23 #include "googleurl/src/gurl.h" | 24 #include "googleurl/src/gurl.h" |
| 24 #include "grit/component_extension_resources_map.h" | 25 #include "grit/component_extension_resources_map.h" |
| 25 #include "grit/theme_resources.h" | 26 #include "grit/theme_resources.h" |
| 26 #include "skia/ext/image_operations.h" | 27 #include "skia/ext/image_operations.h" |
| 27 #include "ui/base/layout.h" | 28 #include "ui/base/layout.h" |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 ExtensionIconRequest* request = GetData(request_id); | 198 ExtensionIconRequest* request = GetData(request_id); |
| 198 tracker_map_[next_tracker_id_++] = request_id; | 199 tracker_map_[next_tracker_id_++] = request_id; |
| 199 tracker_->LoadImage(request->extension, | 200 tracker_->LoadImage(request->extension, |
| 200 icon, | 201 icon, |
| 201 gfx::Size(request->size, request->size), | 202 gfx::Size(request->size, request->size), |
| 202 ImageLoadingTracker::DONT_CACHE); | 203 ImageLoadingTracker::DONT_CACHE); |
| 203 } | 204 } |
| 204 | 205 |
| 205 void ExtensionIconSource::LoadFaviconImage(int request_id) { | 206 void ExtensionIconSource::LoadFaviconImage(int request_id) { |
| 206 FaviconService* favicon_service = | 207 FaviconService* favicon_service = |
| 207 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); | 208 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 208 // Fall back to the default icons if the service isn't available. | 209 // Fall back to the default icons if the service isn't available. |
| 209 if (favicon_service == NULL) { | 210 if (favicon_service == NULL) { |
| 210 LoadDefaultImage(request_id); | 211 LoadDefaultImage(request_id); |
| 211 return; | 212 return; |
| 212 } | 213 } |
| 213 | 214 |
| 214 GURL favicon_url = GetData(request_id)->extension->GetFullLaunchURL(); | 215 GURL favicon_url = GetData(request_id)->extension->GetFullLaunchURL(); |
| 215 FaviconService::Handle handle = favicon_service->GetFaviconForURL( | 216 FaviconService::Handle handle = favicon_service->GetFaviconForURL( |
| 217 profile_, |
| 216 favicon_url, | 218 favicon_url, |
| 217 history::FAVICON, | 219 history::FAVICON, |
| 218 &cancelable_consumer_, | 220 &cancelable_consumer_, |
| 219 base::Bind(&ExtensionIconSource::OnFaviconDataAvailable, | 221 base::Bind(&ExtensionIconSource::OnFaviconDataAvailable, |
| 220 base::Unretained(this))); | 222 base::Unretained(this))); |
| 221 cancelable_consumer_.SetClientData(favicon_service, handle, request_id); | 223 cancelable_consumer_.SetClientData(favicon_service, handle, request_id); |
| 222 } | 224 } |
| 223 | 225 |
| 224 void ExtensionIconSource::OnFaviconDataAvailable( | 226 void ExtensionIconSource::OnFaviconDataAvailable( |
| 225 FaviconService::Handle request_handle, | 227 FaviconService::Handle request_handle, |
| 226 history::FaviconData favicon) { | 228 history::FaviconData favicon) { |
| 227 int request_id = cancelable_consumer_.GetClientData( | 229 int request_id = cancelable_consumer_.GetClientData( |
| 228 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS), request_handle); | 230 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS), |
| 231 request_handle); |
| 229 ExtensionIconRequest* request = GetData(request_id); | 232 ExtensionIconRequest* request = GetData(request_id); |
| 230 | 233 |
| 231 // Fallback to the default icon if there wasn't a favicon. | 234 // Fallback to the default icon if there wasn't a favicon. |
| 232 if (!favicon.is_valid()) { | 235 if (!favicon.is_valid()) { |
| 233 LoadDefaultImage(request_id); | 236 LoadDefaultImage(request_id); |
| 234 return; | 237 return; |
| 235 } | 238 } |
| 236 | 239 |
| 237 if (!request->grayscale) { | 240 if (!request->grayscale) { |
| 238 // If we don't need a grayscale image, then we can bypass FinalizeImage | 241 // If we don't need a grayscale image, then we can bypass FinalizeImage |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 | 342 |
| 340 void ExtensionIconSource::ClearData(int request_id) { | 343 void ExtensionIconSource::ClearData(int request_id) { |
| 341 std::map<int, ExtensionIconRequest*>::iterator i = | 344 std::map<int, ExtensionIconRequest*>::iterator i = |
| 342 request_map_.find(request_id); | 345 request_map_.find(request_id); |
| 343 if (i == request_map_.end()) | 346 if (i == request_map_.end()) |
| 344 return; | 347 return; |
| 345 | 348 |
| 346 delete i->second; | 349 delete i->second; |
| 347 request_map_.erase(i); | 350 request_map_.erase(i); |
| 348 } | 351 } |
| OLD | NEW |