Commit 424f3065 authored by Kyle Horimoto's avatar Kyle Horimoto Committed by Commit Bot

[CrOS Settings] Add fields to SearchResult Mojo struct

(1) Added relevance score, which indicates how well the result matches
    the user's query.
(2) Added settings page hierarchy, an array of strings to be used for
    breadcrumbs. The implementation adds dummy values for this field and
    has a TODO to implement them properly.

These changes are required by the Launcher UI code and unblock their
team's development.

Bug: 1059099
Change-Id: I46e9a6ca3bad830446eb0d415d368b4fb750b335
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2153271Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#760194}
parent ff058c2b
...@@ -41,6 +41,8 @@ function fakeSettingsSearchHandlerSearch(query) { ...@@ -41,6 +41,8 @@ function fakeSettingsSearchHandlerSearch(query) {
}, },
urlPathWithParameters: resultArr[1], urlPathWithParameters: resultArr[1],
icon: resultArr[2], icon: resultArr[2],
relevanceScore: 0.5,
settingsPageHierarchy: [],
}); });
} }
......
...@@ -21,6 +21,19 @@ struct SearchResult { ...@@ -21,6 +21,19 @@ struct SearchResult {
// Icon to display for the search result. // Icon to display for the search result.
SearchResultIcon icon; SearchResultIcon icon;
// Relevance score, in the range [0, 1]. A score of 1 indicates a perfect
// string match.
double relevance_score;
// List of names of the sections/subpages for this result, which may contain
// names of sections and/or subpages. Names are all localized String16s, ready
// to be displayed directly (e.g., as breadcrumbs).
//
// Example 1 - Wi-Fi subpage: ["Settings", "Network", "Wi-Fi"]
// Example 2 - External storage: ["Settings", "Device", "Storage management",
// "External storage preferences"]
array<mojo_base.mojom.String16> settings_page_hierarchy;
}; };
// Provides settings search results. Implemented in the browser process; // Provides settings search results. Implemented in the browser process;
......
...@@ -5,9 +5,11 @@ ...@@ -5,9 +5,11 @@
#include "chrome/browser/ui/webui/settings/chromeos/search/search_handler.h" #include "chrome/browser/ui/webui/settings/chromeos/search/search_handler.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/webui/settings/chromeos/os_settings_localized_strings_provider.h" #include "chrome/browser/ui/webui/settings/chromeos/os_settings_localized_strings_provider.h"
#include "chrome/browser/ui/webui/settings/chromeos/search/search_concept.h" #include "chrome/browser/ui/webui/settings/chromeos/search/search_concept.h"
#include "chrome/browser/ui/webui/settings/chromeos/search/search_result_icon.mojom.h" #include "chrome/browser/ui/webui/settings/chromeos/search/search_result_icon.mojom.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/services/local_search_service/local_search_service_impl.h" #include "chrome/services/local_search_service/local_search_service_impl.h"
#include "chrome/services/local_search_service/public/mojom/types.mojom.h" #include "chrome/services/local_search_service/public/mojom/types.mojom.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
...@@ -18,6 +20,15 @@ namespace { ...@@ -18,6 +20,15 @@ namespace {
const int32_t kLocalSearchServiceMaxResults = 10; const int32_t kLocalSearchServiceMaxResults = 10;
// TODO(https://crbug.com/1071700): Delete this function.
std::vector<base::string16> GenerateDummySettingsHierarchy(
const char* url_path_with_parameters) {
std::vector<base::string16> hierarchy;
hierarchy.push_back(l10n_util::GetStringUTF16(IDS_INTERNAL_APP_SETTINGS));
hierarchy.push_back(base::ASCIIToUTF16(url_path_with_parameters));
return hierarchy;
}
} // namespace } // namespace
// static // static
...@@ -92,9 +103,12 @@ mojom::SearchResultPtr SearchHandler::ResultToSearchResult( ...@@ -92,9 +103,12 @@ mojom::SearchResultPtr SearchHandler::ResultToSearchResult(
if (!concept) if (!concept)
return nullptr; return nullptr;
return mojom::SearchResult::New(l10n_util::GetStringUTF16(message_id), // TODO(https://crbug.com/1071700): Generate real hierarchy instead of using
concept->url_path_with_parameters, // GenerateDummySettingsHierarchy().
concept->icon); return mojom::SearchResult::New(
l10n_util::GetStringUTF16(message_id), concept->url_path_with_parameters,
concept->icon, result.score,
GenerateDummySettingsHierarchy(concept->url_path_with_parameters));
} }
void SearchHandler::Shutdown() { void SearchHandler::Shutdown() {
......
...@@ -5,6 +5,12 @@ ...@@ -5,6 +5,12 @@
/** @fileoverview Runs tests for the OS settings search box. */ /** @fileoverview Runs tests for the OS settings search box. */
suite('OSSettingsSearchBox', () => { suite('OSSettingsSearchBox', () => {
/** @const {number} */
const DEFAULT_RELEVANCE_SCORE = 0.5;
/** @const {!Array<mojoBase.mojom.String16>} */
const DEFAULT_PAGE_HIERARCHY = [];
/** @type {?OsToolbar} */ /** @type {?OsToolbar} */
let toolbar; let toolbar;
...@@ -57,6 +63,8 @@ suite('OSSettingsSearchBox', () => { ...@@ -57,6 +63,8 @@ suite('OSSettingsSearchBox', () => {
}, },
urlPathWithParameters: urlPathWithParameters, urlPathWithParameters: urlPathWithParameters,
icon: icon ? icon : chromeos.settings.mojom.SearchResultIcon.MIN_VALUE, icon: icon ? icon : chromeos.settings.mojom.SearchResultIcon.MIN_VALUE,
relevanceScore: DEFAULT_RELEVANCE_SCORE,
settingsPageHierarchy: DEFAULT_PAGE_HIERARCHY,
}); });
} }
......
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