File: download_core_service_impl.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 (101 lines) | stat: -rw-r--r-- 3,712 bytes parent folder | download | duplicates (4)
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 2015 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_CORE_SERVICE_IMPL_H_
#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_CORE_SERVICE_IMPL_H_

#include <memory>

#include "base/memory/raw_ptr.h"
#include "build/build_config.h"
#include "chrome/browser/download/download_core_service.h"
#include "components/keyed_service/core/keyed_service.h"
#include "extensions/buildflags/buildflags.h"

#if !BUILDFLAG(IS_ANDROID)
#include "chrome/browser/download/download_shelf_controller.h"
#endif

class ChromeDownloadManagerDelegate;
class DownloadHistory;
class DownloadUIController;
class Profile;

namespace content {
class DownloadManager;
}

namespace extensions {
class ExtensionDownloadsEventRouter;
}

// Owning class for ChromeDownloadManagerDelegate.
class DownloadCoreServiceImpl : public DownloadCoreService {
 public:
  explicit DownloadCoreServiceImpl(Profile* profile);

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

  ~DownloadCoreServiceImpl() override;

  // DownloadCoreService
  ChromeDownloadManagerDelegate* GetDownloadManagerDelegate() override;
  DownloadHistory* GetDownloadHistory() override;
#if BUILDFLAG(ENABLE_EXTENSIONS)
  extensions::ExtensionDownloadsEventRouter* GetExtensionEventRouter() override;
#endif
  bool HasCreatedDownloadManager() override;
  int BlockingShutdownCount() const override;
  void CancelDownloads(
      DownloadCoreService::CancelDownloadsTrigger trigger) override;
  void SetDownloadManagerDelegateForTesting(
      std::unique_ptr<ChromeDownloadManagerDelegate> delegate) override;
  bool IsDownloadUiEnabled() override;
  DownloadUIController* GetDownloadUIController() override;
  void SetDownloadHistoryForTesting(
      std::unique_ptr<DownloadHistory> download_history) override;

  // KeyedService
  void Shutdown() override;

 private:
  bool download_manager_created_;
  raw_ptr<Profile> profile_;

  // ChromeDownloadManagerDelegate may be the target of callbacks from
  // the history service/DB thread and must be kept alive for those
  // callbacks.
  std::unique_ptr<ChromeDownloadManagerDelegate> manager_delegate_;

  std::unique_ptr<DownloadHistory> download_history_;

  // The UI controller is responsible for observing the download manager and
  // notifying the UI of any new downloads. Its lifetime matches that of the
  // associated download manager.
  // Note on destruction order: download_ui_ depends on download_history_ and
  // should be destroyed before the latter.
  std::unique_ptr<DownloadUIController> download_ui_;

#if !BUILDFLAG(IS_ANDROID)
  std::unique_ptr<DownloadShelfController> download_shelf_controller_;
#endif

// On Android, GET downloads are not handled by the DownloadManager.
// Once we have extensions on android, we probably need the EventRouter
// in ContentViewDownloadDelegate which knows about both GET and POST
// downloads.
#if BUILDFLAG(ENABLE_EXTENSIONS)
  // The ExtensionDownloadsEventRouter dispatches download creation, change, and
  // erase events to extensions. Like ChromeDownloadManagerDelegate, it's a
  // chrome-level concept and its lifetime should match DownloadManager. There
  // should be a separate EDER for on-record and off-record managers.
  // There does not appear to be a separate ExtensionSystem for on-record and
  // off-record profiles, so ExtensionSystem cannot own the EDER.
  std::unique_ptr<extensions::ExtensionDownloadsEventRouter>
      extension_event_router_;
#endif
};

#endif  // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_CORE_SERVICE_IMPL_H_