Commit a061d48a authored by tby's avatar tby Committed by Commit Bot

[Launcher settings] Query SearchHandler for results.

Link the OS settings search provider with the settings SearchHandler,
by querying it for results on each search. These results:

- Set their metadata from the returned SearchResultPtr.
- Launch the settings app via
  chrome::SettingsWindowManager::ShowOSSettings.

Bug: 1068851
Change-Id: I2f7236fcec3401c14f54934dee03302c3fbf7ce4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2147132Reviewed-by: default avatarJia Meng <jiameng@chromium.org>
Reviewed-by: default avatarRachel Wong <wrong@chromium.org>
Commit-Queue: Tony Yeoman <tby@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759566}
parent ea1fe107
...@@ -4,11 +4,19 @@ ...@@ -4,11 +4,19 @@
#include "chrome/browser/ui/app_list/search/os_settings_provider.h" #include "chrome/browser/ui/app_list/search/os_settings_provider.h"
#include <memory>
#include <string> #include <string>
#include "ash/public/cpp/app_list/app_list_features.h" #include "ash/public/cpp/app_list/app_list_features.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/settings_window_manager_chromeos.h"
#include "chrome/browser/ui/webui/settings/chromeos/search/search.mojom.h"
#include "chrome/browser/ui/webui/settings/chromeos/search/search_handler.h"
#include "chrome/browser/ui/webui/settings/chromeos/search/search_handler_factory.h"
#include "url/gurl.h"
namespace app_list { namespace app_list {
namespace { namespace {
...@@ -17,26 +25,65 @@ constexpr char kOsSettingsResultPrefix[] = "os-settings://"; ...@@ -17,26 +25,65 @@ constexpr char kOsSettingsResultPrefix[] = "os-settings://";
} // namespace } // namespace
OsSettingsResult::OsSettingsResult(float relevance, Profile* profile) OsSettingsResult::OsSettingsResult(
: profile_(profile) { Profile* profile,
DCHECK(profile_); const chromeos::settings::mojom::SearchResultPtr& result)
set_id(kOsSettingsResultPrefix); : profile_(profile), url_path_(result->url_path_with_parameters) {
// TODO(crbug.com/1068851): Results need a useful relevance score and details
// text. Once this is available in the SearchResultPtr, set the metadata here.
set_id(kOsSettingsResultPrefix + url_path_);
set_relevance(8.0f);
SetTitle(result->result_text);
SetResultType(ResultType::kOsSettings);
SetDisplayType(DisplayType::kList);
// TODO(crbug.com/1068851): Set the icon for the result.
} }
OsSettingsResult::~OsSettingsResult() = default; OsSettingsResult::~OsSettingsResult() = default;
void OsSettingsResult::Open(int event_flags) {} void OsSettingsResult::Open(int event_flags) {
chrome::SettingsWindowManager::GetInstance()->ShowOSSettings(profile_,
url_path_);
}
ash::SearchResultType OsSettingsResult::GetSearchResultType() const { ash::SearchResultType OsSettingsResult::GetSearchResultType() const {
return ash::OS_SETTINGS; return ash::OS_SETTINGS;
} }
OsSettingsProvider::OsSettingsProvider(Profile* profile) : profile_(profile) { OsSettingsProvider::OsSettingsProvider(Profile* profile)
: profile_(profile),
search_handler_(
chromeos::settings::SearchHandlerFactory::GetForProfile(profile)) {
DCHECK(profile_); DCHECK(profile_);
DCHECK(search_handler_);
} }
OsSettingsProvider::~OsSettingsProvider() = default; OsSettingsProvider::~OsSettingsProvider() = default;
void OsSettingsProvider::Start(const base::string16& query) {} void OsSettingsProvider::Start(const base::string16& query) {
// This provider does not handle zero-state.
if (query.empty())
return;
// Invalidate weak pointers to cancel existing searches.
weak_factory_.InvalidateWeakPtrs();
// TODO(crbug.com/1068851): There are currently only a handful of settings
// returned from the backend. Once the search service has finished integration
// into settings, verify we see all results here, and that opening works
// correctly for the new URLs.
search_handler_->Search(query,
base::BindOnce(&OsSettingsProvider::OnSearchReturned,
weak_factory_.GetWeakPtr()));
}
void OsSettingsProvider::OnSearchReturned(
std::vector<chromeos::settings::mojom::SearchResultPtr> results) {
SearchProvider::Results search_results;
for (const auto& result : results) {
search_results.emplace_back(
std::make_unique<OsSettingsResult>(profile_, result));
}
SwapResults(&search_results);
}
} // namespace app_list } // namespace app_list
...@@ -5,38 +5,46 @@ ...@@ -5,38 +5,46 @@
#ifndef CHROME_BROWSER_UI_APP_LIST_SEARCH_OS_SETTINGS_PROVIDER_H_ #ifndef CHROME_BROWSER_UI_APP_LIST_SEARCH_OS_SETTINGS_PROVIDER_H_
#define CHROME_BROWSER_UI_APP_LIST_SEARCH_OS_SETTINGS_PROVIDER_H_ #define CHROME_BROWSER_UI_APP_LIST_SEARCH_OS_SETTINGS_PROVIDER_H_
#include <string>
#include <vector>
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/app_list/search/chrome_search_result.h" #include "chrome/browser/ui/app_list/search/chrome_search_result.h"
#include "chrome/browser/ui/app_list/search/search_provider.h" #include "chrome/browser/ui/app_list/search/search_provider.h"
#include "chrome/browser/ui/webui/settings/chromeos/search/search.mojom.h"
class Profile; class Profile;
namespace chromeos {
namespace settings {
class SearchHandler;
}
} // namespace chromeos
namespace app_list { namespace app_list {
// Search results for OS settings. // Search results for OS settings.
// TODO(crbug.com/1068851): This is still a WIP, and needs to integrate with the
// settings backend.
class OsSettingsResult : public ChromeSearchResult { class OsSettingsResult : public ChromeSearchResult {
public: public:
OsSettingsResult(float relevance, Profile* profile); OsSettingsResult(Profile* profile,
const chromeos::settings::mojom::SearchResultPtr& result);
~OsSettingsResult() override; ~OsSettingsResult() override;
OsSettingsResult(const OsSettingsResult&) = delete; OsSettingsResult(const OsSettingsResult&) = delete;
OsSettingsResult& operator=(const OsSettingsResult&) = delete; OsSettingsResult& operator=(const OsSettingsResult&) = delete;
// ChromeSearchResult overrides: // ChromeSearchResult:
void Open(int event_flags) override; void Open(int event_flags) override;
ash::SearchResultType GetSearchResultType() const override; ash::SearchResultType GetSearchResultType() const override;
private: private:
Profile* const profile_; Profile* profile_;
const std::string url_path_;
}; };
// Provider results for OS settings based on a search query. No results are // Provider results for OS settings based on a search query. No results are
// provided for zero-state. // provided for zero-state.
// TODO(crbug.com/1068851): This is still a WIP, and needs to integrate with the
// settings backend.
class OsSettingsProvider : public SearchProvider { class OsSettingsProvider : public SearchProvider {
public: public:
explicit OsSettingsProvider(Profile* profile); explicit OsSettingsProvider(Profile* profile);
...@@ -45,10 +53,17 @@ class OsSettingsProvider : public SearchProvider { ...@@ -45,10 +53,17 @@ class OsSettingsProvider : public SearchProvider {
OsSettingsProvider(const OsSettingsProvider&) = delete; OsSettingsProvider(const OsSettingsProvider&) = delete;
OsSettingsProvider& operator=(const OsSettingsProvider&) = delete; OsSettingsProvider& operator=(const OsSettingsProvider&) = delete;
// SearchProvider:
void Start(const base::string16& query) override; void Start(const base::string16& query) override;
private: private:
void OnSearchReturned(
std::vector<chromeos::settings::mojom::SearchResultPtr> results);
Profile* const profile_; Profile* const profile_;
chromeos::settings::SearchHandler* const search_handler_;
base::WeakPtrFactory<OsSettingsProvider> weak_factory_{this};
}; };
} // namespace app_list } // namespace app_list
......
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