| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/app_list/search/launcher_search/launcher_search_resu
lt.h" | 5 #include "chrome/browser/ui/app_list/search/launcher_search/launcher_search_resu
lt.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/chromeos/launcher_search_provider/launcher_search_provi
der_service.h" | 11 #include "chrome/browser/chromeos/launcher_search_provider/launcher_search_provi
der_service.h" |
| 11 #include "chrome/browser/ui/app_list/search/launcher_search/launcher_search_icon
_image_loader_impl.h" | 12 #include "chrome/browser/ui/app_list/search/launcher_search/launcher_search_icon
_image_loader_impl.h" |
| 12 #include "chrome/browser/ui/app_list/search/search_util.h" | 13 #include "chrome/browser/ui/app_list/search/search_util.h" |
| 13 | 14 |
| 14 using chromeos::launcher_search_provider::Service; | 15 using chromeos::launcher_search_provider::Service; |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 const char kResultIdDelimiter = ':'; | 19 const char kResultIdDelimiter = ':'; |
| 19 | 20 |
| 20 } // namespace | 21 } // namespace |
| 21 | 22 |
| 22 namespace app_list { | 23 namespace app_list { |
| 23 | 24 |
| 24 LauncherSearchResult::LauncherSearchResult( | 25 LauncherSearchResult::LauncherSearchResult( |
| 25 const std::string& item_id, | 26 const std::string& item_id, |
| 26 const GURL& icon_url, | 27 const GURL& icon_url, |
| 27 const int discrete_value_relevance, | 28 const int discrete_value_relevance, |
| 28 Profile* profile, | 29 Profile* profile, |
| 29 const extensions::Extension* extension, | 30 const extensions::Extension* extension, |
| 30 scoped_ptr<chromeos::launcher_search_provider::ErrorReporter> | 31 std::unique_ptr<chromeos::launcher_search_provider::ErrorReporter> |
| 31 error_reporter) | 32 error_reporter) |
| 32 : item_id_(item_id), | 33 : item_id_(item_id), |
| 33 discrete_value_relevance_(discrete_value_relevance), | 34 discrete_value_relevance_(discrete_value_relevance), |
| 34 profile_(profile), | 35 profile_(profile), |
| 35 extension_(extension) { | 36 extension_(extension) { |
| 36 DCHECK_GE(discrete_value_relevance, 0); | 37 DCHECK_GE(discrete_value_relevance, 0); |
| 37 DCHECK_LE(discrete_value_relevance, | 38 DCHECK_LE(discrete_value_relevance, |
| 38 chromeos::launcher_search_provider::kMaxSearchResultScore); | 39 chromeos::launcher_search_provider::kMaxSearchResultScore); |
| 39 | 40 |
| 40 icon_image_loader_.reset(new LauncherSearchIconImageLoaderImpl( | 41 icon_image_loader_.reset(new LauncherSearchIconImageLoaderImpl( |
| 41 icon_url, profile, extension, GetPreferredIconDimension(), | 42 icon_url, profile, extension, GetPreferredIconDimension(), |
| 42 std::move(error_reporter))); | 43 std::move(error_reporter))); |
| 43 icon_image_loader_->LoadResources(); | 44 icon_image_loader_->LoadResources(); |
| 44 | 45 |
| 45 Initialize(); | 46 Initialize(); |
| 46 } | 47 } |
| 47 | 48 |
| 48 LauncherSearchResult::~LauncherSearchResult() { | 49 LauncherSearchResult::~LauncherSearchResult() { |
| 49 if (icon_image_loader_ != nullptr) | 50 if (icon_image_loader_ != nullptr) |
| 50 icon_image_loader_->RemoveObserver(this); | 51 icon_image_loader_->RemoveObserver(this); |
| 51 } | 52 } |
| 52 | 53 |
| 53 scoped_ptr<SearchResult> LauncherSearchResult::Duplicate() const { | 54 std::unique_ptr<SearchResult> LauncherSearchResult::Duplicate() const { |
| 54 LauncherSearchResult* duplicated_result = | 55 LauncherSearchResult* duplicated_result = |
| 55 new LauncherSearchResult(item_id_, discrete_value_relevance_, profile_, | 56 new LauncherSearchResult(item_id_, discrete_value_relevance_, profile_, |
| 56 extension_, icon_image_loader_); | 57 extension_, icon_image_loader_); |
| 57 duplicated_result->set_title(title()); | 58 duplicated_result->set_title(title()); |
| 58 return make_scoped_ptr(duplicated_result); | 59 return base::WrapUnique(duplicated_result); |
| 59 } | 60 } |
| 60 | 61 |
| 61 void LauncherSearchResult::Open(int event_flags) { | 62 void LauncherSearchResult::Open(int event_flags) { |
| 62 RecordHistogram(LAUNCHER_SEARCH_PROVIDER_RESULT); | 63 RecordHistogram(LAUNCHER_SEARCH_PROVIDER_RESULT); |
| 63 | 64 |
| 64 Service* service = Service::Get(profile_); | 65 Service* service = Service::Get(profile_); |
| 65 service->OnOpenResult(extension_->id(), item_id_); | 66 service->OnOpenResult(extension_->id(), item_id_); |
| 66 } | 67 } |
| 67 | 68 |
| 68 void LauncherSearchResult::OnIconImageChanged( | 69 void LauncherSearchResult::OnIconImageChanged( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 | 104 |
| 104 SetIcon(icon_image_loader_->GetIconImage()); | 105 SetIcon(icon_image_loader_->GetIconImage()); |
| 105 SetBadgeIcon(icon_image_loader_->GetBadgeIconImage()); | 106 SetBadgeIcon(icon_image_loader_->GetBadgeIconImage()); |
| 106 } | 107 } |
| 107 | 108 |
| 108 std::string LauncherSearchResult::GetSearchResultId() { | 109 std::string LauncherSearchResult::GetSearchResultId() { |
| 109 return extension_->id() + kResultIdDelimiter + item_id_; | 110 return extension_->id() + kResultIdDelimiter + item_id_; |
| 110 } | 111 } |
| 111 | 112 |
| 112 } // namespace app_list | 113 } // namespace app_list |
| OLD | NEW |