OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/app_list/search/suggestions/suggestions_result.h" |
| 6 |
| 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/app_list/search/search_util.h" |
| 10 #include "third_party/skia/include/core/SkBitmap.h" |
| 11 #include "ui/base/page_transition_types.h" |
| 12 #include "ui/gfx/image/image_skia.h" |
| 13 #include "url/gurl.h" |
| 14 |
| 15 namespace app_list { |
| 16 |
| 17 SuggestionsResult::SuggestionsResult( |
| 18 Profile* profile, |
| 19 AppListControllerDelegate* list_controller, |
| 20 suggestions::SuggestionsService* suggestions_service, |
| 21 const suggestions::ChromeSuggestion suggestion, |
| 22 int index) |
| 23 : profile_(profile), |
| 24 list_controller_(list_controller), |
| 25 suggestions_service_(suggestions_service), |
| 26 suggestion_(suggestion), |
| 27 index_(index), |
| 28 weak_ptr_factory_(this) { |
| 29 set_id(suggestion_.url()); |
| 30 set_title(base::UTF8ToUTF16(suggestion_.title())); |
| 31 set_display_type(DISPLAY_TILE); |
| 32 |
| 33 // The index of the suggestion is an indication of its relevance. |
| 34 if (index_) |
| 35 set_relevance(1.0 / index_); |
| 36 |
| 37 UpdateIcon(); |
| 38 } |
| 39 |
| 40 SuggestionsResult::~SuggestionsResult() {} |
| 41 |
| 42 void SuggestionsResult::Open(int event_flags) { |
| 43 RecordHistogram(SUGGESTIONS_SEARCH_RESULT); |
| 44 list_controller_->OpenURL(profile_, |
| 45 GURL(suggestion_.url()), |
| 46 ui::PageTransition::PAGE_TRANSITION_LINK, |
| 47 ui::DispositionFromEventFlags(event_flags)); |
| 48 } |
| 49 |
| 50 scoped_ptr<SearchResult> SuggestionsResult::Duplicate() { |
| 51 return scoped_ptr<SearchResult>(new SuggestionsResult( |
| 52 profile_, list_controller_, suggestions_service_, suggestion_, index_)); |
| 53 } |
| 54 |
| 55 void SuggestionsResult::UpdateIcon() { |
| 56 if (suggestions_service_) { |
| 57 suggestions_service_->GetPageThumbnail( |
| 58 GURL(suggestion_.url()), |
| 59 base::Bind(&SuggestionsResult::OnSuggestionsThumbnailAvailable, |
| 60 weak_ptr_factory_.GetWeakPtr())); |
| 61 } |
| 62 } |
| 63 |
| 64 void SuggestionsResult::OnSuggestionsThumbnailAvailable( |
| 65 const GURL& url, |
| 66 const SkBitmap* bitmap) { |
| 67 if (bitmap) { |
| 68 SetIcon(gfx::ImageSkia::CreateFrom1xBitmap(*bitmap)); |
| 69 } else { |
| 70 // There is no image for this suggestion. Disable being shown on the start |
| 71 // screen. |
| 72 set_display_type(DISPLAY_LIST); |
| 73 } |
| 74 } |
| 75 |
| 76 } // namespace app_list |
OLD | NEW |