Commit 7867e6f2 authored by tby's avatar tby Committed by Commit Bot

Make providers report their type on update, and add hook to controller

This is CL #2 for integration testing. It uses the new ResultType method
to allow search providers to report _which_ provider is returning
results on an update to the SearchController.

The SearchController has also had a callback hook added, which is passed
the updated result type on each call. This hook can be used by a browser
test to control a run loop that stops when the desired set of providers
have returned.

See the CL description in crrev.com/c/2214736 for more details on the
implementation plan for integration tests.

Bug: 1086713
Change-Id: Iedd8e7ce6824dc6c90623837342456db26494069
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2217945Reviewed-by: default avatarThanh Nguyen <thanhdng@chromium.org>
Commit-Queue: Tony Yeoman <tby@chromium.org>
Cr-Commit-Position: refs/heads/master@{#774536}
parent 4e6f2275
...@@ -5,13 +5,11 @@ ...@@ -5,13 +5,11 @@
#include "chrome/browser/ui/app_list/search/search_controller.h" #include "chrome/browser/ui/app_list/search/search_controller.h"
#include <algorithm> #include <algorithm>
#include <memory>
#include <utility>
#include <vector>
#include "ash/public/cpp/app_list/app_list_config.h" #include "ash/public/cpp/app_list/app_list_config.h"
#include "ash/public/cpp/app_list/app_list_features.h" #include "ash/public/cpp/app_list/app_list_features.h"
#include "ash/public/cpp/app_list/app_list_metrics.h" #include "ash/public/cpp/app_list/app_list_metrics.h"
#include "ash/public/cpp/app_list/app_list_types.h"
#include "ash/public/cpp/tablet_mode.h" #include "ash/public/cpp/tablet_mode.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
...@@ -144,11 +142,19 @@ size_t SearchController::AddGroup(size_t max_results, ...@@ -144,11 +142,19 @@ size_t SearchController::AddGroup(size_t max_results,
void SearchController::AddProvider(size_t group_id, void SearchController::AddProvider(size_t group_id,
std::unique_ptr<SearchProvider> provider) { std::unique_ptr<SearchProvider> provider) {
provider->set_result_changed_callback( provider->set_result_changed_callback(
base::Bind(&SearchController::OnResultsChanged, base::Unretained(this))); base::Bind(&SearchController::OnResultsChangedWithType,
base::Unretained(this), provider->ResultType()));
mixer_->AddProviderToGroup(group_id, provider.get()); mixer_->AddProviderToGroup(group_id, provider.get());
providers_.emplace_back(std::move(provider)); providers_.emplace_back(std::move(provider));
} }
void SearchController::OnResultsChangedWithType(
ash::AppListSearchResultType result_type) {
OnResultsChanged();
if (results_changed_callback_)
results_changed_callback_.Run(result_type);
}
void SearchController::OnResultsChanged() { void SearchController::OnResultsChanged() {
if (dispatching_query_) if (dispatching_query_)
return; return;
......
...@@ -9,8 +9,10 @@ ...@@ -9,8 +9,10 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility>
#include <vector> #include <vector>
#include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "chrome/browser/ui/app_list/search/mixer.h" #include "chrome/browser/ui/app_list/search/mixer.h"
...@@ -23,6 +25,7 @@ class Profile; ...@@ -23,6 +25,7 @@ class Profile;
namespace ash { namespace ash {
class AppListNotifier; class AppListNotifier;
enum class AppListSearchResultType;
} }
namespace app_list { namespace app_list {
...@@ -36,6 +39,9 @@ enum class RankingItemType; ...@@ -36,6 +39,9 @@ enum class RankingItemType;
// results to the given SearchResults UI model. // results to the given SearchResults UI model.
class SearchController { class SearchController {
public: public:
using ResultsChangedCallback =
base::RepeatingCallback<void(ash::AppListSearchResultType)>;
SearchController(AppListModelUpdater* model_updater, SearchController(AppListModelUpdater* model_updater,
AppListControllerDelegate* list_controller, AppListControllerDelegate* list_controller,
ash::AppListNotifier* notifier, ash::AppListNotifier* notifier,
...@@ -78,9 +84,16 @@ class SearchController { ...@@ -78,9 +84,16 @@ class SearchController {
const ash::SearchResultIdWithPositionIndices& results, const ash::SearchResultIdWithPositionIndices& results,
int launched_index); int launched_index);
void set_results_changed_callback_for_test(ResultsChangedCallback callback) {
results_changed_callback_ = std::move(callback);
}
private: private:
// Invoked when the search results are changed. // Invoked when the search results are changed. Providers should use the one
// argument version, and pass the primary type of result produced by the
// invoking search provider.
void OnResultsChanged(); void OnResultsChanged();
void OnResultsChangedWithType(ash::AppListSearchResultType result_type);
Profile* profile_; Profile* profile_;
...@@ -96,6 +109,9 @@ class SearchController { ...@@ -96,6 +109,9 @@ class SearchController {
// recording. // recording.
std::string last_launched_app_id_; std::string last_launched_app_id_;
// If set, called when OnResultsChanged is invoked.
ResultsChangedCallback results_changed_callback_;
std::unique_ptr<Mixer> mixer_; std::unique_ptr<Mixer> mixer_;
std::unique_ptr<SearchMetricsObserver> metrics_observer_; std::unique_ptr<SearchMetricsObserver> metrics_observer_;
using Providers = std::vector<std::unique_ptr<SearchProvider>>; using Providers = std::vector<std::unique_ptr<SearchProvider>>;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment