Index: chrome/browser/ui/app_list/search/playstore/playstore_search_provider.cc |
diff --git a/chrome/browser/ui/app_list/search/playstore/playstore_search_provider.cc b/chrome/browser/ui/app_list/search/playstore/playstore_search_provider.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7013879a8f2984b765651a2bc1a692b9db189013 |
--- /dev/null |
+++ b/chrome/browser/ui/app_list/search/playstore/playstore_search_provider.cc |
@@ -0,0 +1,61 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/app_list/search/playstore/playstore_search_provider.h" |
+ |
+#include <utility> |
+ |
+#include "base/strings/utf_string_conversions.h" |
+#include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" |
+#include "chrome/browser/ui/app_list/search/playstore/playstore_search_result.h" |
+#include "components/arc/arc_bridge_service.h" |
+#include "components/arc/arc_service_manager.h" |
+ |
+namespace app_list { |
+ |
+PlayStoreSearchProvider::PlayStoreSearchProvider( |
+ int max_results, |
+ Profile* profile, |
+ AppListControllerDelegate* list_controller) |
+ : max_results_(max_results), |
+ profile_(profile), |
+ list_controller_(list_controller), |
+ weak_ptr_factory_(this) {} |
+ |
+PlayStoreSearchProvider::~PlayStoreSearchProvider() = default; |
+ |
+void PlayStoreSearchProvider::Start(bool is_voice_query, |
+ const base::string16& query) { |
+ // TODO(crbug.com/736027): should search for voice? |
+ arc::mojom::AppInstance* app_instance = |
+ arc::ArcServiceManager::Get() |
+ ? ARC_GET_INSTANCE_FOR_METHOD( |
+ arc::ArcServiceManager::Get()->arc_bridge_service()->app(), |
+ GetRecentAndSuggestedAppsFromPlayStore) |
+ : nullptr; |
+ |
+ if (app_instance == nullptr) |
+ return; |
+ |
+ ClearResults(); |
+ app_instance->GetRecentAndSuggestedAppsFromPlayStore( |
+ UTF16ToUTF8(query), max_results_, |
+ base::Bind(&PlayStoreSearchProvider::OnResults, |
+ weak_ptr_factory_.GetWeakPtr())); |
+} |
+ |
+void PlayStoreSearchProvider::Stop() {} |
+ |
+void PlayStoreSearchProvider::OnResults( |
+ std::vector<arc::mojom::AppDiscoveryResultPtr> results) { |
+ for (auto& result : results) { |
+ Add(base::MakeUnique<PlayStoreSearchResult>( |
+ result->launch_intent_uri, result->install_intent_uri, result->label, |
+ result->is_instant_app, result->is_recent, result->publisher_name, |
+ result->formatted_price, result->review_score, result->icon_png_data, |
+ profile_, list_controller_)); |
+ } |
+} |
+ |
+} // namespace app_list |