File: apps_collections_controller.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 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 (111 lines) | stat: -rw-r--r-- 3,953 bytes parent folder | download | duplicates (6)
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
102
103
104
105
106
107
108
109
110
111
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_APP_LIST_APPS_COLLECTIONS_CONTROLLER_H_
#define ASH_APP_LIST_APPS_COLLECTIONS_CONTROLLER_H_

#include <string>

#include "ash/ash_export.h"
#include "ash/public/cpp/app_list/app_list_types.h"
#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"

namespace ash {

class AppListClient;

// Controller responsible for the Apps Collections feature tutorial view.
class ASH_EXPORT AppsCollectionsController {
 public:
  using ReorderCallback = base::RepeatingCallback<void(AppListSortOrder)>;
  // The different ways a user can dismiss the Apps Collections. Used for
  // logging, do not change the order of this enum.
  enum class DismissReason {
    // User sorted apps in the app list.
    kSorting = 0,
    // User clicked the exit button in the tutorial view nudge.
    kExitNudge = 1,
    kMaxValue = kExitNudge,
  };

  // The experimental arm that the user belong into for metrics purposes.
  enum class ExperimentalArm {
    // The default value for the experimental arm. Represents that the user was
    // not separated into an experimental arm yet.
    kDefaultValue = -1,
    // For users that are considered out of the AppsCollections experiment.
    kControl = 0,
    // For users that are considered as part of the AppsCollections experiment
    // but are treated as the control group for metric analysis.
    kCounterfactual = 1,
    // For users that are considered as part of the AppsCollections experiment
    // and are shown the AppsCollections.
    kEnabled = 2,
    // For users that are considered as part of the AppsCollections experiment
    // and are not shown the AppsCollections but the AppsGrid in a different
    // default order.
    kModifiedOrder = 3,
    kMaxValue = kModifiedOrder,
  };

  AppsCollectionsController();
  AppsCollectionsController(const AppsCollectionsController&) = delete;
  AppsCollectionsController& operator=(const AppsCollectionsController&) =
      delete;
  ~AppsCollectionsController();

  // Returns the singleton instance owned by AppListController.
  // NOTE: Exists if and only if the Apps Collection feature is enabled.
  static AppsCollectionsController* Get();

  // Fetch the experimental arm this user belongs into the AppsCollections
  // experiment.
  ExperimentalArm GetUserExperimentalArm();
  std::string GetUserExperimentalArmAsHistogramSuffix();

  // Whether the AppsCollection page should be presented by default when opening
  // the bubble, instead of the Apps page.
  bool ShouldShowAppsCollection();
  void CalculateExperimentalArm();

  // Signal that the user has dismissed the AppsCollection page.
  void SetAppsCollectionDismissed(DismissReason reason);

  // Signal that the user has reorderes the Apps page.
  void SetAppsReordered();

  void SetClient(AppListClient* client);

  // Invoked when the user attempts to sort apps from the AppsCollection page.
  void RequestAppReorder(AppListSortOrder order);

  void SetReorderCallback(ReorderCallback callback);

  void ForceAppsCollectionsForTesting(bool force);

 private:
  // Store the experimental arm for this user as a profile perf.
  void MaybeRecordUserExperimentStatePref(ExperimentalArm arm);

  // The client which facilitates communication between Ash and the browser.
  raw_ptr<AppListClient> client_;

  // A local flag that stores whether the apps collections view was dismissed
  // during this session.
  bool apps_collections_was_dissmissed_ = false;

  // A local flag that stores whether the app list was reordered during this
  // session.
  bool app_list_was_reordered_ = false;

  bool force_apps_collections_ = false;

  // A callback invoked when the nudge on this page is removed/dismissed.
  ReorderCallback reorder_callback_;
};

}  // namespace ash

#endif  // ASH_APP_LIST_APPS_COLLECTIONS_CONTROLLER_H_