chromium/ash/webui/personalization_app/search/search.mojom

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module ash.personalization_app.mojom;

import "mojo/public/mojom/base/string16.mojom";

// Enum of available concepts to search for in personalization app. This is used
// in metrics, do not re-use any values. If any value is added, please update
// enums.xml PersonalizationSearchConceptId.
enum SearchConceptId {
    kPersonalization = 0,
    kChangeWallpaper = 100,
    kTimeOfDayWallpaper = 101,
    kChangeDeviceAccountImage = 200,
    kAmbientMode = 300,
    kAmbientModeChooseSource = 301,
    kAmbientModeTurnOff = 302,
    kAmbientModeGooglePhotos = 303,
    kAmbientModeArtGallery = 304,
    kAmbientModeTurnOn = 305,
    kAmbientModeTimeOfDay = 306,
    kDarkMode = 400,
    kDarkModeSchedule = 401,
    kDarkModeTurnOff = 402,
    kDarkModeTurnOn = 403,
    kDynamicColor = 404,
    kKeyboardBacklight = 500,
};

// A result to display in launcher search that represents a personalization
// feature or page.
struct SearchResult {
    // The id of the search concept that generated this search result. Note that
    // multiple results with a different |text| can have the same
    // |search_concept_id|, as some SearchResults can be found with alternate
    // search text (eg "Dark Mode" and "Dark Theme").
    SearchConceptId search_concept_id;

    // The display text of the search result.
    mojo_base.mojom.String16 text;

    // The relative url, including query parameters, to open when the search
    // result is selected.
    string relative_url;

    // The score of the search result for ranking purposes.
    double relevance_score;
};

// Used to observe changes to search results.
interface SearchResultsObserver {
  // Called when one or more search results has changed.
  // This may happen when certain preferences are set by sync or schedule, ie
  // search results for dark mode may change if dark mode is changed in the
  // background due to auto dark mode schedule.
  OnSearchResultsChanged();
};

// Handles search queries and may respond with Personalization results.
interface SearchHandler {
    // Run a search from user input and reply with a list of results. Returns
    // empty list on error or no relevant results.
    Search(mojo_base.mojom.String16 query, uint32 max_num_results) => (
        array<SearchResult> results);

    // Set an observer for search results. To stop observing, close the
    // connection.
    AddObserver(pending_remote<SearchResultsObserver> observer);
};