| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 56 |
| 57 extensions::EventRouter* event_router = | 57 extensions::EventRouter* event_router = |
| 58 extensions::EventRouter::Get(profile_); | 58 extensions::EventRouter::Get(profile_); |
| 59 | 59 |
| 60 CacheListenerExtensionIds(); | 60 CacheListenerExtensionIds(); |
| 61 for (const ExtensionId extension_id : *cached_listener_extension_ids_.get()) { | 61 for (const ExtensionId extension_id : *cached_listener_extension_ids_.get()) { |
| 62 // Convert query_id_ to string here since queryId is defined as string in | 62 // Convert query_id_ to string here since queryId is defined as string in |
| 63 // javascript side API while we use uint32_t internally to generate it. | 63 // javascript side API while we use uint32_t internally to generate it. |
| 64 event_router->DispatchEventToExtension( | 64 event_router->DispatchEventToExtension( |
| 65 extension_id, | 65 extension_id, |
| 66 base::WrapUnique(new extensions::Event( | 66 base::MakeUnique<extensions::Event>( |
| 67 extensions::events::LAUNCHER_SEARCH_PROVIDER_ON_QUERY_STARTED, | 67 extensions::events::LAUNCHER_SEARCH_PROVIDER_ON_QUERY_STARTED, |
| 68 api_launcher_search_provider::OnQueryStarted::kEventName, | 68 api_launcher_search_provider::OnQueryStarted::kEventName, |
| 69 api_launcher_search_provider::OnQueryStarted::Create( | 69 api_launcher_search_provider::OnQueryStarted::Create( |
| 70 query_id_, query, max_result)))); | 70 query_id_, query, max_result))); |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 void Service::OnQueryEnded() { | 74 void Service::OnQueryEnded() { |
| 75 DCHECK(is_query_running_); | 75 DCHECK(is_query_running_); |
| 76 provider_ = nullptr; | 76 provider_ = nullptr; |
| 77 | 77 |
| 78 extensions::EventRouter* event_router = | 78 extensions::EventRouter* event_router = |
| 79 extensions::EventRouter::Get(profile_); | 79 extensions::EventRouter::Get(profile_); |
| 80 | 80 |
| 81 CacheListenerExtensionIds(); | 81 CacheListenerExtensionIds(); |
| 82 for (const ExtensionId extension_id : *cached_listener_extension_ids_.get()) { | 82 for (const ExtensionId extension_id : *cached_listener_extension_ids_.get()) { |
| 83 event_router->DispatchEventToExtension( | 83 event_router->DispatchEventToExtension( |
| 84 extension_id, | 84 extension_id, |
| 85 base::WrapUnique(new extensions::Event( | 85 base::MakeUnique<extensions::Event>( |
| 86 extensions::events::LAUNCHER_SEARCH_PROVIDER_ON_QUERY_ENDED, | 86 extensions::events::LAUNCHER_SEARCH_PROVIDER_ON_QUERY_ENDED, |
| 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( | 97 CHECK( |
| 98 base::ContainsValue(*cached_listener_extension_ids_.get(), extension_id)); | 98 base::ContainsValue(*cached_listener_extension_ids_.get(), extension_id)); |
| 99 | 99 |
| 100 extensions::EventRouter* event_router = | 100 extensions::EventRouter* event_router = |
| 101 extensions::EventRouter::Get(profile_); | 101 extensions::EventRouter::Get(profile_); |
| 102 event_router->DispatchEventToExtension( | 102 event_router->DispatchEventToExtension( |
| 103 extension_id, | 103 extension_id, |
| 104 base::WrapUnique(new extensions::Event( | 104 base::MakeUnique<extensions::Event>( |
| 105 extensions::events::LAUNCHER_SEARCH_PROVIDER_ON_OPEN_RESULT, | 105 extensions::events::LAUNCHER_SEARCH_PROVIDER_ON_OPEN_RESULT, |
| 106 api_launcher_search_provider::OnOpenResult::kEventName, | 106 api_launcher_search_provider::OnOpenResult::kEventName, |
| 107 api_launcher_search_provider::OnOpenResult::Create(item_id)))); | 107 api_launcher_search_provider::OnOpenResult::Create(item_id))); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void Service::SetSearchResults( | 110 void Service::SetSearchResults( |
| 111 const extensions::Extension* extension, | 111 const extensions::Extension* extension, |
| 112 std::unique_ptr<ErrorReporter> error_reporter, | 112 std::unique_ptr<ErrorReporter> error_reporter, |
| 113 const int query_id, | 113 const int query_id, |
| 114 const std::vector<extensions::api::launcher_search_provider::SearchResult>& | 114 const std::vector<extensions::api::launcher_search_provider::SearchResult>& |
| 115 results) { | 115 results) { |
| 116 // 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, |
| 117 // discard the results. | 117 // discard the results. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 extension->permissions_data(); | 175 extension->permissions_data(); |
| 176 const bool has_permission = permission_data->HasAPIPermission( | 176 const bool has_permission = permission_data->HasAPIPermission( |
| 177 extensions::APIPermission::kLauncherSearchProvider); | 177 extensions::APIPermission::kLauncherSearchProvider); |
| 178 if (has_permission) | 178 if (has_permission) |
| 179 cached_listener_extension_ids_->insert(extension->id()); | 179 cached_listener_extension_ids_->insert(extension->id()); |
| 180 } | 180 } |
| 181 } | 181 } |
| 182 | 182 |
| 183 } // namespace launcher_search_provider | 183 } // namespace launcher_search_provider |
| 184 } // namespace chromeos | 184 } // namespace chromeos |
| OLD | NEW |