Chromium Code Reviews| 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..c1bb86595c11f050bbd748053063c63aeaa2fd76 |
| --- /dev/null |
| +++ b/chrome/browser/ui/app_list/search/suggestions/suggestions_result.cc |
| @@ -0,0 +1,73 @@ |
| +// 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/app_list_controller_delegate.h" |
| +#include "chrome/browser/ui/app_list/search/search_util.h" |
| +#include "components/suggestions/suggestions_service.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_); |
|
calamity
2014/12/05 04:01:58
label public_relevance:
I think that you should be
Mathieu
2014/12/05 20:14:32
Done.
|
| + |
| + 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)); |
|
calamity
2014/12/05 04:01:58
So this type of result is a URL suggestion? If so,
Mathieu
2014/12/05 20:14:32
Done.
|
| +} |
| + |
| +scoped_ptr<SearchResult> SuggestionsResult::Duplicate() { |
| + return scoped_ptr<SearchResult>(new SuggestionsResult( |
| + profile_, list_controller_, suggestions_service_, suggestion_, index_)); |
|
calamity
2014/12/05 04:01:58
If you went through with #public_relevance, you'd
Mathieu
2014/12/05 20:14:32
Done.
|
| +} |
| + |
| +void SuggestionsResult::UpdateIcon() { |
| + if (suggestions_service_) { |
| + suggestions_service_->GetPageThumbnail( |
| + GURL(suggestion_.url()), |
| + base::Bind(&SuggestionsResult::OnSuggestionsThumbnailAvailable, |
| + weak_ptr_factory_.GetWeakPtr())); |
| + } |
|
calamity
2014/12/05 04:01:58
Hmm. Does this mean that a blank suggestion will f
Mathieu
2014/12/05 20:14:32
We actually heavily cache images to disk, and so i
calamity
2014/12/10 01:47:42
Sweet.
|
| +} |
| + |
| +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); |
|
calamity
2014/12/05 04:01:58
Consider adding a DISPLAY_NONE to SearchResult.
Mathieu
2014/12/05 20:14:32
Done.
|
| + } |
| +} |
| + |
| +} // namespace app_list |