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

Unified Diff: chrome/browser/ui/app_list/search/suggestions/url_suggestion_result.cc

Issue 795863002: [AppList] Use local favicons/icons with URLSuggestionResult (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed nits Created 6 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/app_list/search/suggestions/url_suggestion_result.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/app_list/search/suggestions/url_suggestion_result.cc
diff --git a/chrome/browser/ui/app_list/search/suggestions/url_suggestion_result.cc b/chrome/browser/ui/app_list/search/suggestions/url_suggestion_result.cc
index ffcb92947e68ec410823cfe016dee4ed62eeaf38..c4edc118729911ad5752acd8aae1f3e803b33992 100644
--- a/chrome/browser/ui/app_list/search/suggestions/url_suggestion_result.cc
+++ b/chrome/browser/ui/app_list/search/suggestions/url_suggestion_result.cc
@@ -5,12 +5,17 @@
#include "chrome/browser/ui/app_list/search/suggestions/url_suggestion_result.h"
#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/favicon/favicon_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
#include "chrome/browser/ui/app_list/search/search_util.h"
+#include "components/favicon_base/favicon_callback.h"
+#include "components/favicon_base/favicon_types.h"
#include "components/suggestions/suggestions_service.h"
#include "third_party/skia/include/core/SkBitmap.h"
+#include "ui/app_list/app_list_constants.h"
#include "ui/base/page_transition_types.h"
+#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/image/image_skia.h"
#include "url/gurl.h"
@@ -18,12 +23,15 @@ namespace app_list {
URLSuggestionResult::URLSuggestionResult(
Profile* profile, AppListControllerDelegate* list_controller,
+ FaviconService* favicon_service,
suggestions::SuggestionsService* suggestions_service,
const suggestions::ChromeSuggestion& suggestion)
: profile_(profile),
list_controller_(list_controller),
+ favicon_service_(favicon_service),
suggestions_service_(suggestions_service),
suggestion_(suggestion),
+ cancelable_task_tracker_(new base::CancelableTaskTracker()),
weak_ptr_factory_(this) {
set_id(suggestion_.url());
set_title(base::UTF8ToUTF16(suggestion_.title()));
@@ -43,17 +51,52 @@ void URLSuggestionResult::Open(int event_flags) {
scoped_ptr<SearchResult> URLSuggestionResult::Duplicate() {
URLSuggestionResult* new_result = new URLSuggestionResult(
- profile_, list_controller_, suggestions_service_, suggestion_);
+ profile_, list_controller_, favicon_service_, suggestions_service_,
+ suggestion_);
new_result->set_relevance(relevance());
return scoped_ptr<SearchResult>(new_result);
}
void URLSuggestionResult::UpdateIcon() {
- if (suggestions_service_) {
- suggestions_service_->GetPageThumbnail(
- GURL(suggestion_.url()),
- base::Bind(&URLSuggestionResult::OnSuggestionsThumbnailAvailable,
- weak_ptr_factory_.GetWeakPtr()));
+ std::vector<int> icon_types;
+ icon_types.push_back(favicon_base::IconType::FAVICON);
+ icon_types.push_back(favicon_base::IconType::TOUCH_ICON);
+ icon_types.push_back(favicon_base::IconType::TOUCH_PRECOMPOSED_ICON);
+
+ if (favicon_service_) {
+ // NOTE: Favicons with size < kMinimumDesiredSizePixels are still returned.
+ favicon_service_->GetLargestRawFaviconForPageURL(
+ GURL(suggestion_.url()), icon_types, kTileIconSize,
+ base::Bind(&URLSuggestionResult::OnDidGetIcon, base::Unretained(this)),
+ cancelable_task_tracker_.get());
+ }
+}
+
+void URLSuggestionResult::OnDidGetIcon(
+ const favicon_base::FaviconRawBitmapResult& bitmap_result) {
+ if (!bitmap_result.is_valid()) {
+ if (suggestions_service_) {
+ suggestions_service_->GetPageThumbnail(
+ GURL(suggestion_.url()),
+ base::Bind(&URLSuggestionResult::OnSuggestionsThumbnailAvailable,
+ weak_ptr_factory_.GetWeakPtr()));
+ } else {
+ set_display_type(DISPLAY_NONE);
+ }
+ return;
+ }
+
+ // |bitmap_result| is valid.
+ SkBitmap bitmap;
+ if (gfx::PNGCodec::Decode(bitmap_result.bitmap_data->front(),
+ bitmap_result.bitmap_data->size(), &bitmap)) {
+ gfx::ImageSkia image_skia;
+ // TODO(mathp): Support hidpi displays by building an ImageSkia with as many
+ // representations as possible?
+ image_skia.AddRepresentation(gfx::ImageSkiaRep(bitmap, 1.0f));
+ SetIcon(image_skia);
+ } else {
+ set_display_type(DISPLAY_NONE);
}
}
« no previous file with comments | « chrome/browser/ui/app_list/search/suggestions/url_suggestion_result.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698