| 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/chromeos/launcher_search_provider/launcher_search_provi
der_service.h" | 5 #include "chrome/browser/chromeos/launcher_search_provider/launcher_search_provi
der_service.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 make_scoped_ptr(new extensions::Event( | 101 make_scoped_ptr(new extensions::Event( |
| 102 extensions::events::LAUNCHER_SEARCH_PROVIDER_ON_OPEN_RESULT, | 102 extensions::events::LAUNCHER_SEARCH_PROVIDER_ON_OPEN_RESULT, |
| 103 api_launcher_search_provider::OnOpenResult::kEventName, | 103 api_launcher_search_provider::OnOpenResult::kEventName, |
| 104 api_launcher_search_provider::OnOpenResult::Create(item_id)))); | 104 api_launcher_search_provider::OnOpenResult::Create(item_id)))); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void Service::SetSearchResults( | 107 void Service::SetSearchResults( |
| 108 const extensions::Extension* extension, | 108 const extensions::Extension* extension, |
| 109 scoped_ptr<ErrorReporter> error_reporter, | 109 scoped_ptr<ErrorReporter> error_reporter, |
| 110 const int query_id, | 110 const int query_id, |
| 111 const std::vector<linked_ptr< | 111 const std::vector<extensions::api::launcher_search_provider::SearchResult>& |
| 112 extensions::api::launcher_search_provider::SearchResult>>& results) { | 112 results) { |
| 113 // If query is not running or query_id is different from current query id, | 113 // If query is not running or query_id is different from current query id, |
| 114 // discard the results. | 114 // discard the results. |
| 115 if (!is_query_running_ || query_id != query_id_) | 115 if (!is_query_running_ || query_id != query_id_) |
| 116 return; | 116 return; |
| 117 | 117 |
| 118 // If |extension| is not in the listener extensions list, ignore it. | 118 // If |extension| is not in the listener extensions list, ignore it. |
| 119 CacheListenerExtensionIds(); | 119 CacheListenerExtensionIds(); |
| 120 if (!ContainsValue(*cached_listener_extension_ids_.get(), extension->id())) | 120 if (!ContainsValue(*cached_listener_extension_ids_.get(), extension->id())) |
| 121 return; | 121 return; |
| 122 | 122 |
| 123 // Set search results to provider. | 123 // Set search results to provider. |
| 124 DCHECK(provider_); | 124 DCHECK(provider_); |
| 125 ScopedVector<app_list::LauncherSearchResult> search_results; | 125 ScopedVector<app_list::LauncherSearchResult> search_results; |
| 126 for (const auto& result : results) { | 126 for (const auto& result : results) { |
| 127 const int relevance = | 127 const int relevance = |
| 128 std::min(kMaxSearchResultScore, std::max(result->relevance, 0)); | 128 std::min(kMaxSearchResultScore, std::max(result.relevance, 0)); |
| 129 const GURL icon_url = | 129 const GURL icon_url = |
| 130 result->icon_url ? GURL(*result->icon_url.get()) : GURL(); | 130 result.icon_url ? GURL(*result.icon_url.get()) : GURL(); |
| 131 | 131 |
| 132 app_list::LauncherSearchResult* search_result = | 132 app_list::LauncherSearchResult* search_result = |
| 133 new app_list::LauncherSearchResult(result->item_id, icon_url, relevance, | 133 new app_list::LauncherSearchResult(result.item_id, icon_url, relevance, |
| 134 profile_, extension, | 134 profile_, extension, |
| 135 error_reporter->Duplicate()); | 135 error_reporter->Duplicate()); |
| 136 search_result->set_title(base::UTF8ToUTF16(result->title)); | 136 search_result->set_title(base::UTF8ToUTF16(result.title)); |
| 137 search_results.push_back(search_result); | 137 search_results.push_back(search_result); |
| 138 } | 138 } |
| 139 provider_->SetSearchResults(extension->id(), std::move(search_results)); | 139 provider_->SetSearchResults(extension->id(), std::move(search_results)); |
| 140 } | 140 } |
| 141 | 141 |
| 142 bool Service::IsQueryRunning() const { | 142 bool Service::IsQueryRunning() const { |
| 143 return is_query_running_; | 143 return is_query_running_; |
| 144 } | 144 } |
| 145 | 145 |
| 146 void Service::OnExtensionLoaded(content::BrowserContext* browser_context, | 146 void Service::OnExtensionLoaded(content::BrowserContext* browser_context, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 170 extension->permissions_data(); | 170 extension->permissions_data(); |
| 171 const bool has_permission = permission_data->HasAPIPermission( | 171 const bool has_permission = permission_data->HasAPIPermission( |
| 172 extensions::APIPermission::kLauncherSearchProvider); | 172 extensions::APIPermission::kLauncherSearchProvider); |
| 173 if (has_permission) | 173 if (has_permission) |
| 174 cached_listener_extension_ids_->insert(extension->id()); | 174 cached_listener_extension_ids_->insert(extension->id()); |
| 175 } | 175 } |
| 176 } | 176 } |
| 177 | 177 |
| 178 } // namespace launcher_search_provider | 178 } // namespace launcher_search_provider |
| 179 } // namespace chromeos | 179 } // namespace chromeos |
| OLD | NEW |