Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: chrome/browser/chromeos/launcher_search_provider/service.cc

Issue 1140873002: Change queryId of launcherSearchProvider API to integer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove old TODO. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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.
58 event_router->DispatchEventToExtension( 57 event_router->DispatchEventToExtension(
59 extension_id, 58 extension_id,
60 make_scoped_ptr(new extensions::Event( 59 make_scoped_ptr(new extensions::Event(
61 api_launcher_search_provider::OnQueryStarted::kEventName, 60 api_launcher_search_provider::OnQueryStarted::kEventName,
62 api_launcher_search_provider::OnQueryStarted::Create( 61 api_launcher_search_provider::OnQueryStarted::Create(
63 std::to_string(query_id_), query, max_result)))); 62 query_id_, query, max_result))));
64 } 63 }
65 } 64 }
66 65
67 void Service::OnQueryEnded() { 66 void Service::OnQueryEnded() {
68 DCHECK(is_query_running_); 67 DCHECK(is_query_running_);
69 provider_ = nullptr; 68 provider_ = nullptr;
70 69
71 extensions::EventRouter* event_router = 70 extensions::EventRouter* event_router =
72 extensions::EventRouter::Get(profile_); 71 extensions::EventRouter::Get(profile_);
73 72
74 std::set<ExtensionId> extension_ids = GetListenerExtensionIds(); 73 std::set<ExtensionId> extension_ids = GetListenerExtensionIds();
75 for (const ExtensionId extension_id : extension_ids) { 74 for (const ExtensionId extension_id : extension_ids) {
76 event_router->DispatchEventToExtension( 75 event_router->DispatchEventToExtension(
77 extension_id, 76 extension_id,
78 make_scoped_ptr(new extensions::Event( 77 make_scoped_ptr(new extensions::Event(
79 api_launcher_search_provider::OnQueryEnded::kEventName, 78 api_launcher_search_provider::OnQueryEnded::kEventName,
80 api_launcher_search_provider::OnQueryEnded::Create( 79 api_launcher_search_provider::OnQueryEnded::Create(query_id_))));
81 std::to_string(query_id_)))));
82 } 80 }
83 81
84 is_query_running_ = false; 82 is_query_running_ = false;
85 } 83 }
86 84
87 void Service::OnOpenResult(const ExtensionId& extension_id, 85 void Service::OnOpenResult(const ExtensionId& extension_id,
88 const std::string& item_id) { 86 const std::string& item_id) {
89 CHECK(ContainsValue(GetListenerExtensionIds(), extension_id)); 87 CHECK(ContainsValue(GetListenerExtensionIds(), extension_id));
90 88
91 extensions::EventRouter* event_router = 89 extensions::EventRouter* event_router =
92 extensions::EventRouter::Get(profile_); 90 extensions::EventRouter::Get(profile_);
93 event_router->DispatchEventToExtension( 91 event_router->DispatchEventToExtension(
94 extension_id, 92 extension_id,
95 make_scoped_ptr(new extensions::Event( 93 make_scoped_ptr(new extensions::Event(
96 api_launcher_search_provider::OnOpenResult::kEventName, 94 api_launcher_search_provider::OnOpenResult::kEventName,
97 api_launcher_search_provider::OnOpenResult::Create(item_id)))); 95 api_launcher_search_provider::OnOpenResult::Create(item_id))));
98 } 96 }
99 97
100 void Service::SetSearchResults( 98 void Service::SetSearchResults(
101 const extensions::Extension* extension, 99 const extensions::Extension* extension,
102 scoped_ptr<ErrorReporter> error_reporter, 100 scoped_ptr<ErrorReporter> error_reporter,
103 const std::string& query_id, 101 const int query_id,
104 const std::vector<linked_ptr< 102 const std::vector<linked_ptr<
105 extensions::api::launcher_search_provider::SearchResult>>& results) { 103 extensions::api::launcher_search_provider::SearchResult>>& results) {
106 // If query is not running or query_id is different from current query id, 104 // If query is not running or query_id is different from current query id,
107 // discard the results. 105 // discard the results.
108 if (!is_query_running_ || query_id != std::to_string(query_id_)) 106 if (!is_query_running_ || query_id != query_id_)
109 return; 107 return;
110 108
111 // If |extension| is not in the listener extensions list, ignore it. 109 // If |extension| is not in the listener extensions list, ignore it.
112 if (!ContainsValue(GetListenerExtensionIds(), extension->id())) 110 if (!ContainsValue(GetListenerExtensionIds(), extension->id()))
113 return; 111 return;
114 112
115 // Set search results to provider. 113 // Set search results to provider.
116 DCHECK(provider_); 114 DCHECK(provider_);
117 ScopedVector<app_list::LauncherSearchResult> search_results; 115 ScopedVector<app_list::LauncherSearchResult> search_results;
118 for (const auto& result : results) { 116 for (const auto& result : results) {
(...skipping 28 matching lines...) Expand all
147 extensions::APIPermission::kLauncherSearchProvider); 145 extensions::APIPermission::kLauncherSearchProvider);
148 if (has_permission) 146 if (has_permission)
149 extension_ids.insert(extension->id()); 147 extension_ids.insert(extension->id());
150 } 148 }
151 149
152 return extension_ids; 150 return extension_ids;
153 } 151 }
154 152
155 } // namespace launcher_search_provider 153 } // namespace launcher_search_provider
156 } // namespace chromeos 154 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/launcher_search_provider/service.h ('k') | chrome/common/extensions/api/launcher_search_provider.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698