File: shelf_spinner_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 (120 lines) | stat: -rw-r--r-- 4,333 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
112
113
114
115
116
117
118
119
120
// Copyright 2018 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_UI_ASH_SHELF_SHELF_SPINNER_CONTROLLER_H_
#define CHROME_BROWSER_UI_ASH_SHELF_SHELF_SPINNER_CONTROLLER_H_

#include <stdint.h>

#include <map>
#include <memory>
#include <string>
#include <utility>

#include "ash/public/cpp/shelf_model_observer.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "components/account_id/account_id.h"

class ShelfSpinnerItemController;
class ChromeShelfController;
class Profile;

namespace ash {
class ShelfItemDelegate;
}  // namespace ash

namespace gfx {
class ImageSkia;
}  // namespace gfx

// ShelfSpinnerController displays visual feedback that the application the user
// has just activated will not be immediately available, as it is for example
// waiting for ARC or Crostini to be ready.
class ShelfSpinnerController : public ash::ShelfModelObserver {
 public:
  // ShelfSpinnerData holds the information used to draw the spinner, including
  // animating the spinner after it has been dismissed.
  class ShelfSpinnerData;

  explicit ShelfSpinnerController(ChromeShelfController* owner);

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

  ~ShelfSpinnerController() override;

  bool HasApp(const std::string& app_id) const;

  base::TimeDelta GetActiveTime(const std::string& app_id) const;

  // Adds a spinner to the shelf unless the app is already running.
  void AddSpinnerToShelf(
      const std::string& app_id,
      std::unique_ptr<ShelfSpinnerItemController> controller);

  // Applies spinning effect if requested app is handled by spinner controller.
  void MaybeApplySpinningEffect(const std::string& app_id,
                                gfx::ImageSkia* image);

  // Finishes spinning on an icon. If an icon is pinned it will be kept on the
  // shelf as a shortcut, otherwise it will be removed without storing the
  // delegate.
  void CloseSpinner(const std::string& app_id);

  // Closes all Crostini spinner shelf items.
  // This should be avoided when possible.
  void CloseCrostiniSpinners();

  Profile* OwnerProfile();

  // Hide all the spinners associated with the old user, and restore to the
  // shelf any spinners associated with the new active user. Called by
  // ChromeShelfController when the active user is changed.
  void ActiveUserChanged(const AccountId& account_id);

  // ash::ShelfModelObserver:
  void ShelfItemDelegateChanged(const ash::ShelfID& id,
                                ash::ShelfItemDelegate* old_delegate,
                                ash::ShelfItemDelegate* delegate) override;

 private:
  // Defines mapping of a shelf app id to a corresponding controller's data.
  // Shelf app id is optional mapping (for example, Play Store to ARC Host
  // Support).
  using AppControllerMap = std::map<std::string, ShelfSpinnerData>;
  // Defines a mapping from account id to (app id, ShelfSpinnerItemController)
  // for spinners that are not currently on the shelf. Taking ownership of these
  // delegates allows us to reuse them if we need to add the spinner back on to
  // the shelf.
  using HiddenAppControllerMap = std::multimap<
      AccountId,
      std::pair<std::string, std::unique_ptr<ShelfSpinnerItemController>>>;

  void UpdateApps();
  void UpdateShelfItemIcon(const std::string& app_id);
  void RegisterNextUpdate();
  // Removes the spinner with id |app_id| from |app_controller_map_| and returns
  // true if it was present, false otherwise.
  bool RemoveSpinnerFromControllerMap(const std::string& app_id);

  // Removes a spinner from the shelf and stores the delegate for later
  // restoration. Used when the user switches from one profile to another.
  void HideSpinner(const std::string& app_id);

  // Unowned pointers.
  raw_ptr<ChromeShelfController> owner_;

  AccountId current_account_id_;

  AppControllerMap app_controller_map_;

  HiddenAppControllerMap hidden_app_controller_map_;

  // Always keep this the last member of this class.
  base::WeakPtrFactory<ShelfSpinnerController> weak_ptr_factory_{this};
};

#endif  // CHROME_BROWSER_UI_ASH_SHELF_SHELF_SPINNER_CONTROLLER_H_