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 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 api_launcher_search_provider::OnQueryEnded::kEventName, | 87 api_launcher_search_provider::OnQueryEnded::kEventName, |
88 api_launcher_search_provider::OnQueryEnded::Create(query_id_)))); | 88 api_launcher_search_provider::OnQueryEnded::Create(query_id_)))); |
89 } | 89 } |
90 | 90 |
91 is_query_running_ = false; | 91 is_query_running_ = false; |
92 } | 92 } |
93 | 93 |
94 void Service::OnOpenResult(const ExtensionId& extension_id, | 94 void Service::OnOpenResult(const ExtensionId& extension_id, |
95 const std::string& item_id) { | 95 const std::string& item_id) { |
96 CacheListenerExtensionIds(); | 96 CacheListenerExtensionIds(); |
97 CHECK(ContainsValue(*cached_listener_extension_ids_.get(), extension_id)); | 97 CHECK( |
| 98 base::ContainsValue(*cached_listener_extension_ids_.get(), extension_id)); |
98 | 99 |
99 extensions::EventRouter* event_router = | 100 extensions::EventRouter* event_router = |
100 extensions::EventRouter::Get(profile_); | 101 extensions::EventRouter::Get(profile_); |
101 event_router->DispatchEventToExtension( | 102 event_router->DispatchEventToExtension( |
102 extension_id, | 103 extension_id, |
103 base::WrapUnique(new extensions::Event( | 104 base::WrapUnique(new extensions::Event( |
104 extensions::events::LAUNCHER_SEARCH_PROVIDER_ON_OPEN_RESULT, | 105 extensions::events::LAUNCHER_SEARCH_PROVIDER_ON_OPEN_RESULT, |
105 api_launcher_search_provider::OnOpenResult::kEventName, | 106 api_launcher_search_provider::OnOpenResult::kEventName, |
106 api_launcher_search_provider::OnOpenResult::Create(item_id)))); | 107 api_launcher_search_provider::OnOpenResult::Create(item_id)))); |
107 } | 108 } |
108 | 109 |
109 void Service::SetSearchResults( | 110 void Service::SetSearchResults( |
110 const extensions::Extension* extension, | 111 const extensions::Extension* extension, |
111 std::unique_ptr<ErrorReporter> error_reporter, | 112 std::unique_ptr<ErrorReporter> error_reporter, |
112 const int query_id, | 113 const int query_id, |
113 const std::vector<extensions::api::launcher_search_provider::SearchResult>& | 114 const std::vector<extensions::api::launcher_search_provider::SearchResult>& |
114 results) { | 115 results) { |
115 // If query is not running or query_id is different from current query id, | 116 // If query is not running or query_id is different from current query id, |
116 // discard the results. | 117 // discard the results. |
117 if (!is_query_running_ || query_id != query_id_) | 118 if (!is_query_running_ || query_id != query_id_) |
118 return; | 119 return; |
119 | 120 |
120 // If |extension| is not in the listener extensions list, ignore it. | 121 // If |extension| is not in the listener extensions list, ignore it. |
121 CacheListenerExtensionIds(); | 122 CacheListenerExtensionIds(); |
122 if (!ContainsValue(*cached_listener_extension_ids_.get(), extension->id())) | 123 if (!base::ContainsValue(*cached_listener_extension_ids_.get(), |
| 124 extension->id())) { |
123 return; | 125 return; |
| 126 } |
124 | 127 |
125 // Set search results to provider. | 128 // Set search results to provider. |
126 DCHECK(provider_); | 129 DCHECK(provider_); |
127 ScopedVector<app_list::LauncherSearchResult> search_results; | 130 ScopedVector<app_list::LauncherSearchResult> search_results; |
128 for (const auto& result : results) { | 131 for (const auto& result : results) { |
129 const int relevance = | 132 const int relevance = |
130 std::min(kMaxSearchResultScore, std::max(result.relevance, 0)); | 133 std::min(kMaxSearchResultScore, std::max(result.relevance, 0)); |
131 const GURL icon_url = | 134 const GURL icon_url = |
132 result.icon_url ? GURL(*result.icon_url.get()) : GURL(); | 135 result.icon_url ? GURL(*result.icon_url.get()) : GURL(); |
133 | 136 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 extension->permissions_data(); | 175 extension->permissions_data(); |
173 const bool has_permission = permission_data->HasAPIPermission( | 176 const bool has_permission = permission_data->HasAPIPermission( |
174 extensions::APIPermission::kLauncherSearchProvider); | 177 extensions::APIPermission::kLauncherSearchProvider); |
175 if (has_permission) | 178 if (has_permission) |
176 cached_listener_extension_ids_->insert(extension->id()); | 179 cached_listener_extension_ids_->insert(extension->id()); |
177 } | 180 } |
178 } | 181 } |
179 | 182 |
180 } // namespace launcher_search_provider | 183 } // namespace launcher_search_provider |
181 } // namespace chromeos | 184 } // namespace chromeos |
OLD | NEW |