File: download_display_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 (142 lines) | stat: -rw-r--r-- 6,052 bytes parent folder | download | duplicates (3)
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright 2021 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_DOWNLOAD_BUBBLE_DOWNLOAD_DISPLAY_CONTROLLER_H_
#define CHROME_BROWSER_DOWNLOAD_BUBBLE_DOWNLOAD_DISPLAY_CONTROLLER_H_

#include "base/memory/raw_ptr.h"
#include "base/power_monitor/power_observer.h"
#include "base/timer/timer.h"
#include "chrome/browser/download/offline_item_model.h"
#include "chrome/browser/ui/download/download_display.h"
#include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
#include "chrome/browser/ui/exclusive_access/fullscreen_observer.h"
#include "components/download/content/public/all_download_item_notifier.h"
#include "components/offline_items_collection/core/offline_content_aggregator.h"
#include "components/offline_items_collection/core/offline_content_provider.h"

struct DownloadBubbleDisplayInfo;
class DownloadBubbleUIController;
class DownloadDisplay;

namespace base {
class TimeDelta;
class OneShotTimer;
}  // namespace base

namespace offline_items_collection {
struct ContentId;
}

// Used to control the DownloadToolbar Button, through the DownloadDisplay
// interface. Supports both regular Download and Offline items. When in the
// future OfflineItems include regular Download on Desktop platforms,
// we can remove AllDownloadItemNotifier::Observer.
// TODO(chlily): Consolidate this with DownloadBubbleUIController.
class DownloadDisplayController : public FullscreenObserver,
                                  public base::PowerSuspendObserver {
 public:
  DownloadDisplayController(DownloadDisplay* display,
                            Browser* browser,
                            DownloadBubbleUIController* bubble_controller);
  DownloadDisplayController(const DownloadDisplayController&) = delete;
  DownloadDisplayController& operator=(const DownloadDisplayController&) =
      delete;
  ~DownloadDisplayController() override;

  // Notifies the controller that the button is pressed. Called by `display_`.
  void OnButtonPressed();

  // Handles the button pressed event. Called by the profile level controller.
  void HandleButtonPressed();

  // Common methods for new downloads or new offline items.
  // These methods are virtual so that they can be overridden for fake
  // controllers in testing.

  // Called from bubble controller when new item(s) are added.
  // |show_animation| specifies whether a small animated arrow should be shown.
  virtual void OnNewItem(bool show_animation);
  // Called from bubble controller when an item is updated, with |is_done|
  // indicating if it was marked done, and with |may_show_details| indicating
  // whether the partial view can be shown. (Whether the partial view is
  // actually shown may depend on the state of the other downloads.)
  virtual void OnUpdatedItem(bool is_done, bool may_show_details);
  // Called from bubble controller when an item is deleted.
  virtual void OnRemovedItem(const ContentId& id);

  // Asks `display_` to hide the toolbar button. Does nothing if the toolbar
  // button is already hidden.
  void HideToolbarButton();
  // Asks `display_` to hide the toolbar button details. Does nothing if the
  // details are already hidden.
  void HideBubble();

  // Start listening to full screen changes. This is separate from the
  // constructor as the exclusive access manager is constructed after
  // BrowserWindow.
  void ListenToFullScreenChanges();

  // FullScreenObserver
  void OnFullscreenStateChanged() override;

  // PowerSuspendObserver
  void OnResume() override;

  // Returns the DownloadDisplay. Should always return a valid display.
  DownloadDisplay* download_display_for_testing() { return display_; }

  void OpenSecuritySubpage(const offline_items_collection::ContentId& id);

 private:
  friend class DownloadDisplayControllerTest;

  // Gets info about all models to display and progress ring info from the
  // update service, then updates the toolbar button state accordingly. Returns
  // the info about all models.
  const DownloadBubbleDisplayInfo& UpdateButtonStateFromUpdateService();

  // Obtains and announces accessible alerts from the update service.
  void HandleAccessibleAlerts();

  // Stops and restarts `icon_disappearance_timer_`. The toolbar button will
  // be hidden after the `interval`.
  void ScheduleToolbarDisappearance(base::TimeDelta interval);
  // Stops and restarts `icon_inactive_timer_`. The toolbar button will
  // be changed to inactive state after the `interval`.
  void ScheduleToolbarInactive(base::TimeDelta interval);

  // Asks `display_` to show the toolbar button. Does nothing if the toolbar
  // button is already showing.
  void ShowToolbarButton();

  // Updates the icon state of the `display_`, including the progress ring.
  void UpdateToolbarButtonState(
      const DownloadBubbleDisplayInfo& info,
      const DownloadDisplay::ProgressInfo& progress_info);

  // Asks `display_` to make the download icon inactive.
  void UpdateDownloadIconToInactive();

  // Decides whether the toolbar button should be shown when it is created.
  virtual void MaybeShowButtonWhenCreated();

  // The pointer is created in ToolbarView and owned by ToolbarView.
  raw_ptr<DownloadDisplay> const display_;
  raw_ptr<Browser> browser_;
  base::ScopedObservation<FullscreenController, FullscreenObserver>
      observation_{this};
  base::OneShotTimer icon_disappearance_timer_;
  base::OneShotTimer icon_inactive_timer_;
  bool fullscreen_notification_shown_ = false;
  bool should_show_details_on_exit_fullscreen_ = false;
  // DownloadDisplayController and DownloadBubbleUIController have the same
  // lifetime. Both are owned, constructed together, and destructed together by
  // DownloadToolbarButtonView. If one is valid, so is the other.
  raw_ptr<DownloadBubbleUIController, DanglingUntriaged> bubble_controller_;

  base::WeakPtrFactory<DownloadDisplayController> weak_factory_{this};
};

#endif  // CHROME_BROWSER_DOWNLOAD_BUBBLE_DOWNLOAD_DISPLAY_CONTROLLER_H_