File: download_shelf.h

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (107 lines) | stat: -rw-r--r-- 3,550 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
// Copyright 2012 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_DOWNLOAD_SHELF_H_
#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_H_

#include <optional>

#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/download/download_ui_model.h"

class Browser;
class Profile;

namespace base {
class TimeDelta;
}  // namespace base

namespace offline_items_collection {
struct ContentId;
struct OfflineItem;
}  // namespace offline_items_collection

namespace views {
class View;
}

// This is an abstract base class for platform specific download shelf
// implementations.
class DownloadShelf {
 public:
  DownloadShelf(Browser* browser, Profile* profile);
  DownloadShelf(const DownloadShelf&) = delete;
  DownloadShelf& operator=(const DownloadShelf&) = delete;
  virtual ~DownloadShelf();

  // The browser view needs to know when we are going away to properly return
  // the resize corner size to WebKit so that we don't draw on top of it.
  // This returns the showing state of our animation which is set to true at
  // the beginning Show and false at the beginning of a Hide.
  virtual bool IsShowing() const = 0;

  // Returns whether the download shelf is showing the close animation.
  virtual bool IsClosing() const = 0;

  // A new download has started. Add it to our shelf and show the download
  // started animation.
  //
  // Some downloads are removed from the shelf on completion (See
  // DownloadItemModel::ShouldRemoveFromShelfWhenComplete()). These transient
  // downloads are added to the shelf after a delay. If the download completes
  // before the delay duration, it will not be added to the shelf at all.
  void AddDownload(DownloadUIModel::DownloadUIModelPtr download);

  // Opens the shelf.
  void Open();

  // Closes the shelf.
  void Close();

  // Closes the shelf and prevents it from reopening until Unhide() is called.
  void Hide();

  // Allows the shelf to open after a previous call to Hide().  Opens the shelf
  // if, had Hide() not been called, it would currently be open.
  void Unhide();

  Browser* browser() { return browser_; }
  virtual views::View* GetView() = 0;
  bool is_hidden() const { return is_hidden_; }

 protected:
  virtual void DoShowDownload(DownloadUIModel::DownloadUIModelPtr download) = 0;
  virtual void DoOpen() = 0;
  virtual void DoClose() = 0;
  virtual void DoHide() = 0;
  virtual void DoUnhide() = 0;

  // Time delay to wait before adding a transient download to the shelf.
  // Protected virtual for testing.
  virtual base::TimeDelta GetTransientDownloadShowDelay() const;

  Profile* profile() { return profile_; }

 private:
  // Shows the download on the shelf immediately. Also displays the download
  // started animation if necessary.
  void ShowDownload(DownloadUIModel::DownloadUIModelPtr download);

  // Similar to ShowDownload() but refers to the download using an ID.
  void ShowDownloadById(const offline_items_collection::ContentId& id);

  // Callback used by ShowDownloadById() to trigger ShowDownload() once |item|
  // has been fetched.
  void OnGetDownloadDoneForOfflineItem(
      const std::optional<offline_items_collection::OfflineItem>& item);

  const raw_ptr<Browser> browser_;
  const raw_ptr<Profile> profile_;
  bool should_show_on_unhide_ = false;
  bool is_hidden_ = false;
  base::WeakPtrFactory<DownloadShelf> weak_ptr_factory_{this};
};

#endif  // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_H_