Index: chrome/browser/ui/app_list/search/suggestions/suggestions_result.cc |
diff --git a/chrome/browser/ui/app_list/search/suggestions/suggestions_result.cc b/chrome/browser/ui/app_list/search/suggestions/suggestions_result.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ed587077a10fbfc211735e9fbfcfced9190d8622 |
--- /dev/null |
+++ b/chrome/browser/ui/app_list/search/suggestions/suggestions_result.cc |
@@ -0,0 +1,76 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/app_list/search/suggestions/suggestions_result.h" |
+ |
+#include "base/strings/utf_string_conversions.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/ui/app_list/search/search_util.h" |
+#include "third_party/skia/include/core/SkBitmap.h" |
+#include "ui/base/page_transition_types.h" |
+#include "ui/gfx/image/image_skia.h" |
+#include "url/gurl.h" |
+ |
+namespace app_list { |
+ |
+SuggestionsResult::SuggestionsResult( |
+ Profile* profile, |
+ AppListControllerDelegate* list_controller, |
+ suggestions::SuggestionsService* suggestions_service, |
+ const suggestions::ChromeSuggestion suggestion, |
+ int index) |
+ : profile_(profile), |
+ list_controller_(list_controller), |
+ suggestions_service_(suggestions_service), |
+ suggestion_(suggestion), |
+ index_(index), |
+ weak_ptr_factory_(this) { |
+ set_id(suggestion_.url()); |
+ set_title(base::UTF8ToUTF16(suggestion_.title())); |
+ set_display_type(DISPLAY_TILE); |
+ |
+ // The index of the suggestion is an indication of its relevance. |
+ if (index_) |
+ set_relevance(1.0 / index_); |
+ |
+ UpdateIcon(); |
+} |
+ |
+SuggestionsResult::~SuggestionsResult() {} |
+ |
+void SuggestionsResult::Open(int event_flags) { |
+ RecordHistogram(SUGGESTIONS_SEARCH_RESULT); |
+ list_controller_->OpenURL(profile_, |
+ GURL(suggestion_.url()), |
+ ui::PageTransition::PAGE_TRANSITION_LINK, |
+ ui::DispositionFromEventFlags(event_flags)); |
+} |
+ |
+scoped_ptr<SearchResult> SuggestionsResult::Duplicate() { |
+ return scoped_ptr<SearchResult>(new SuggestionsResult( |
+ profile_, list_controller_, suggestions_service_, suggestion_, index_)); |
+} |
+ |
+void SuggestionsResult::UpdateIcon() { |
+ if (suggestions_service_) { |
+ suggestions_service_->GetPageThumbnail( |
+ GURL(suggestion_.url()), |
+ base::Bind(&SuggestionsResult::OnSuggestionsThumbnailAvailable, |
+ weak_ptr_factory_.GetWeakPtr())); |
+ } |
+} |
+ |
+void SuggestionsResult::OnSuggestionsThumbnailAvailable( |
+ const GURL& url, |
+ const SkBitmap* bitmap) { |
+ if (bitmap) { |
+ SetIcon(gfx::ImageSkia::CreateFrom1xBitmap(*bitmap)); |
+ } else { |
+ // There is no image for this suggestion. Disable being shown on the start |
+ // screen. |
+ set_display_type(DISPLAY_LIST); |
+ } |
+} |
+ |
+} // namespace app_list |