File: burn_in_controller.h

package info (click to toggle)
chromium 139.0.7258.127-1~deb13u1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,096 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (101 lines) | stat: -rw-r--r-- 3,995 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// 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.

#ifndef CHROME_BROWSER_ASH_APP_LIST_SEARCH_BURN_IN_CONTROLLER_H_
#define CHROME_BROWSER_ASH_APP_LIST_SEARCH_BURN_IN_CONTROLLER_H_

#include "ash/public/cpp/app_list/app_list_types.h"
#include "base/containers/flat_map.h"
#include "base/functional/callback.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "chrome/browser/ash/app_list/search/types.h"

namespace app_list {

// Manages operations related to the burn-in period. Owned by the
// SearchController.
class BurnInController {
 public:
  using BurnInPeriodElapsedCallback = base::RepeatingCallback<void()>;

  explicit BurnInController(BurnInPeriodElapsedCallback);
  ~BurnInController();

  BurnInController(const BurnInController&) = delete;
  BurnInController& operator=(const BurnInController&) = delete;

  // Called at the beginning of a query search. Initiates the burn-in/ period.
  void Start();

  // Called to stop/interrupt a previous call to Start().
  //
  // Stops the burn-in timer, thereby preventing any now unneeded calls to
  // BurnInPeriodElapsedCallback. Currently, the only use case for this is when
  // a query search is succeeded by a zero-state search.
  void Stop();

  // Called when new result information has become available.
  //
  // Performs house-keeping related to burn-in iteration numbers for categories
  // and individual results. These are later important for sorting purposes in
  // the SearchController - see further documentation below.
  //
  // Triggers the BurnInPeriodElapsedCallback if it is the first time
  // UpdateResults() has been called since the burn-in period has elapsed.
  //
  // Returns true if results are updated before `burn_in_period_`, and false
  // otherwise.
  bool UpdateResults(ResultsMap& results,
                     CategoriesList& categories,
                     ash::AppListSearchResultType result_type);

  const base::flat_map<std::string, int>& ids_to_burn_in_iteration_for_test() {
    return ids_to_burn_in_iteration_;
  }

 private:
  // The time when Start was most recently called.
  base::Time session_start_;

  // Called when the burn-in period has elapsed.
  BurnInPeriodElapsedCallback burn_in_period_elapsed_callback_;

  // The period of time ("burn-in") to wait before publishing a first collection
  // of search results to the model updater.
  const base::TimeDelta burn_in_period_;

  // A timer for the burn-in period. During the burn-in period, results are
  // collected from search providers. Publication of results to the model
  // updater is delayed until the burn-in period has elapsed.
  base::RetainingOneShotTimer burn_in_timer_;

  // Counter for burn-in iterations. Useful for query search only.
  //
  // Zero signifies pre-burn-in state. After burn-in period has elapsed, counter
  // is incremented by one each time SetResults() is called. This burn-in
  // iteration number is used for individual results as well as overall
  // categories.
  //
  // This information is useful because it allows for:
  //
  // (1) Results and categories to be ranked by different rules depending on
  // whether the information arrived pre- or post-burn-in.
  // (2) Sorting stability across multiple post-burn-in updates.
  int burn_in_iteration_counter_ = 0;

  // Store the ID of each result we encounter in a given query, along with the
  // burn-in iteration during which it arrived. This storage is necessary
  // because:
  //
  // Some providers may return more than once, and on each successive return,
  // the previous results are swapped for new ones within SetResults(). Result
  // meta-information we wish to persist across multiple calls to SetResults
  // must therefore be stored separately.
  base::flat_map<std::string, int> ids_to_burn_in_iteration_;
};

}  // namespace app_list

#endif  // CHROME_BROWSER_ASH_APP_LIST_SEARCH_BURN_IN_CONTROLLER_H_