Chromium Code Reviews| 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/service.h" | 5 #include "chrome/browser/chromeos/launcher_search_provider/service.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_vector.h" | 7 #include "base/memory/scoped_vector.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/chromeos/launcher_search_provider/service_factory.h" | 9 #include "chrome/browser/chromeos/launcher_search_provider/service_factory.h" |
| 10 #include "chrome/browser/ui/app_list/search/launcher_search/launcher_search_prov ider.h" | 10 #include "chrome/browser/ui/app_list/search/launcher_search/launcher_search_prov ider.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 | 47 |
| 48 ++query_id_; | 48 ++query_id_; |
| 49 | 49 |
| 50 extensions::EventRouter* event_router = | 50 extensions::EventRouter* event_router = |
| 51 extensions::EventRouter::Get(profile_); | 51 extensions::EventRouter::Get(profile_); |
| 52 | 52 |
| 53 std::set<ExtensionId> extension_ids = GetListenerExtensionIds(); | 53 std::set<ExtensionId> extension_ids = GetListenerExtensionIds(); |
| 54 for (const ExtensionId extension_id : extension_ids) { | 54 for (const ExtensionId extension_id : extension_ids) { |
| 55 // Convert query_id_ to string here since queryId is defined as string in | 55 // Convert query_id_ to string here since queryId is defined as string in |
| 56 // javascript side API while we use uint32 internally to generate it. | 56 // javascript side API while we use uint32 internally to generate it. |
| 57 // TODO(yawano): Consider if we can change it to integer at javascript side. | 57 // TODO(yawano): Consider if we can change it to integer at javascript side. |
|
Matt Giuca
2015/05/14 00:56:07
Remove this comment.
yawano
2015/05/14 04:08:45
Thank you! I forgot to remove this.
| |
| 58 event_router->DispatchEventToExtension( | 58 event_router->DispatchEventToExtension( |
| 59 extension_id, | 59 extension_id, |
| 60 make_scoped_ptr(new extensions::Event( | 60 make_scoped_ptr(new extensions::Event( |
| 61 api_launcher_search_provider::OnQueryStarted::kEventName, | 61 api_launcher_search_provider::OnQueryStarted::kEventName, |
| 62 api_launcher_search_provider::OnQueryStarted::Create( | 62 api_launcher_search_provider::OnQueryStarted::Create( |
| 63 std::to_string(query_id_), query, max_result)))); | 63 query_id_, query, max_result)))); |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 | 66 |
| 67 void Service::OnQueryEnded() { | 67 void Service::OnQueryEnded() { |
| 68 DCHECK(is_query_running_); | 68 DCHECK(is_query_running_); |
| 69 provider_ = nullptr; | 69 provider_ = nullptr; |
| 70 | 70 |
| 71 extensions::EventRouter* event_router = | 71 extensions::EventRouter* event_router = |
| 72 extensions::EventRouter::Get(profile_); | 72 extensions::EventRouter::Get(profile_); |
| 73 | 73 |
| 74 std::set<ExtensionId> extension_ids = GetListenerExtensionIds(); | 74 std::set<ExtensionId> extension_ids = GetListenerExtensionIds(); |
| 75 for (const ExtensionId extension_id : extension_ids) { | 75 for (const ExtensionId extension_id : extension_ids) { |
| 76 event_router->DispatchEventToExtension( | 76 event_router->DispatchEventToExtension( |
| 77 extension_id, | 77 extension_id, |
| 78 make_scoped_ptr(new extensions::Event( | 78 make_scoped_ptr(new extensions::Event( |
| 79 api_launcher_search_provider::OnQueryEnded::kEventName, | 79 api_launcher_search_provider::OnQueryEnded::kEventName, |
| 80 api_launcher_search_provider::OnQueryEnded::Create( | 80 api_launcher_search_provider::OnQueryEnded::Create(query_id_)))); |
| 81 std::to_string(query_id_))))); | |
| 82 } | 81 } |
| 83 | 82 |
| 84 is_query_running_ = false; | 83 is_query_running_ = false; |
| 85 } | 84 } |
| 86 | 85 |
| 87 void Service::OnOpenResult(const ExtensionId& extension_id, | 86 void Service::OnOpenResult(const ExtensionId& extension_id, |
| 88 const std::string& item_id) { | 87 const std::string& item_id) { |
| 89 CHECK(ContainsValue(GetListenerExtensionIds(), extension_id)); | 88 CHECK(ContainsValue(GetListenerExtensionIds(), extension_id)); |
| 90 | 89 |
| 91 extensions::EventRouter* event_router = | 90 extensions::EventRouter* event_router = |
| 92 extensions::EventRouter::Get(profile_); | 91 extensions::EventRouter::Get(profile_); |
| 93 event_router->DispatchEventToExtension( | 92 event_router->DispatchEventToExtension( |
| 94 extension_id, | 93 extension_id, |
| 95 make_scoped_ptr(new extensions::Event( | 94 make_scoped_ptr(new extensions::Event( |
| 96 api_launcher_search_provider::OnOpenResult::kEventName, | 95 api_launcher_search_provider::OnOpenResult::kEventName, |
| 97 api_launcher_search_provider::OnOpenResult::Create(item_id)))); | 96 api_launcher_search_provider::OnOpenResult::Create(item_id)))); |
| 98 } | 97 } |
| 99 | 98 |
| 100 void Service::SetSearchResults( | 99 void Service::SetSearchResults( |
| 101 const extensions::Extension* extension, | 100 const extensions::Extension* extension, |
| 102 scoped_ptr<ErrorReporter> error_reporter, | 101 scoped_ptr<ErrorReporter> error_reporter, |
| 103 const std::string& query_id, | 102 const int query_id, |
| 104 const std::vector<linked_ptr< | 103 const std::vector<linked_ptr< |
| 105 extensions::api::launcher_search_provider::SearchResult>>& results) { | 104 extensions::api::launcher_search_provider::SearchResult>>& results) { |
| 106 // If query is not running or query_id is different from current query id, | 105 // If query is not running or query_id is different from current query id, |
| 107 // discard the results. | 106 // discard the results. |
| 108 if (!is_query_running_ || query_id != std::to_string(query_id_)) | 107 if (!is_query_running_ || query_id != query_id_) |
| 109 return; | 108 return; |
| 110 | 109 |
| 111 // If |extension| is not in the listener extensions list, ignore it. | 110 // If |extension| is not in the listener extensions list, ignore it. |
| 112 if (!ContainsValue(GetListenerExtensionIds(), extension->id())) | 111 if (!ContainsValue(GetListenerExtensionIds(), extension->id())) |
| 113 return; | 112 return; |
| 114 | 113 |
| 115 // Set search results to provider. | 114 // Set search results to provider. |
| 116 DCHECK(provider_); | 115 DCHECK(provider_); |
| 117 ScopedVector<app_list::LauncherSearchResult> search_results; | 116 ScopedVector<app_list::LauncherSearchResult> search_results; |
| 118 for (const auto& result : results) { | 117 for (const auto& result : results) { |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 147 extensions::APIPermission::kLauncherSearchProvider); | 146 extensions::APIPermission::kLauncherSearchProvider); |
| 148 if (has_permission) | 147 if (has_permission) |
| 149 extension_ids.insert(extension->id()); | 148 extension_ids.insert(extension->id()); |
| 150 } | 149 } |
| 151 | 150 |
| 152 return extension_ids; | 151 return extension_ids; |
| 153 } | 152 } |
| 154 | 153 |
| 155 } // namespace launcher_search_provider | 154 } // namespace launcher_search_provider |
| 156 } // namespace chromeos | 155 } // namespace chromeos |
| OLD | NEW |