OLD | NEW |
| (Empty) |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SERVICE_IMPL_H_ | |
6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SERVICE_IMPL_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "base/callback_forward.h" | |
11 #include "base/macros.h" | |
12 #include "chrome/browser/download/download_service.h" | |
13 #include "components/keyed_service/core/keyed_service.h" | |
14 #include "extensions/features/features.h" | |
15 | |
16 class ChromeDownloadManagerDelegate; | |
17 class DownloadHistory; | |
18 class DownloadUIController; | |
19 class ExtensionDownloadsEventRouter; | |
20 class Profile; | |
21 | |
22 namespace content { | |
23 class DownloadManager; | |
24 } | |
25 | |
26 namespace extensions { | |
27 class ExtensionDownloadsEventRouter; | |
28 } | |
29 | |
30 // Owning class for ChromeDownloadManagerDelegate. | |
31 class DownloadServiceImpl : public DownloadService { | |
32 public: | |
33 explicit DownloadServiceImpl(Profile* profile); | |
34 ~DownloadServiceImpl() override; | |
35 | |
36 // DownloadService | |
37 ChromeDownloadManagerDelegate* GetDownloadManagerDelegate() override; | |
38 DownloadHistory* GetDownloadHistory() override; | |
39 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
40 extensions::ExtensionDownloadsEventRouter* GetExtensionEventRouter() override; | |
41 #endif | |
42 bool HasCreatedDownloadManager() override; | |
43 int NonMaliciousDownloadCount() const override; | |
44 void CancelDownloads() override; | |
45 void SetDownloadManagerDelegateForTesting( | |
46 std::unique_ptr<ChromeDownloadManagerDelegate> delegate) override; | |
47 bool IsShelfEnabled() override; | |
48 | |
49 // KeyedService | |
50 void Shutdown() override; | |
51 | |
52 private: | |
53 bool download_manager_created_; | |
54 Profile* profile_; | |
55 | |
56 // ChromeDownloadManagerDelegate may be the target of callbacks from | |
57 // the history service/DB thread and must be kept alive for those | |
58 // callbacks. | |
59 std::unique_ptr<ChromeDownloadManagerDelegate> manager_delegate_; | |
60 | |
61 std::unique_ptr<DownloadHistory> download_history_; | |
62 | |
63 // The UI controller is responsible for observing the download manager and | |
64 // notifying the UI of any new downloads. Its lifetime matches that of the | |
65 // associated download manager. | |
66 // Note on destruction order: download_ui_ depends on download_history_ and | |
67 // should be destroyed before the latter. | |
68 std::unique_ptr<DownloadUIController> download_ui_; | |
69 | |
70 // On Android, GET downloads are not handled by the DownloadManager. | |
71 // Once we have extensions on android, we probably need the EventRouter | |
72 // in ContentViewDownloadDelegate which knows about both GET and POST | |
73 // downloads. | |
74 #if BUILDFLAG(ENABLE_EXTENSIONS) | |
75 // The ExtensionDownloadsEventRouter dispatches download creation, change, and | |
76 // erase events to extensions. Like ChromeDownloadManagerDelegate, it's a | |
77 // chrome-level concept and its lifetime should match DownloadManager. There | |
78 // should be a separate EDER for on-record and off-record managers. | |
79 // There does not appear to be a separate ExtensionSystem for on-record and | |
80 // off-record profiles, so ExtensionSystem cannot own the EDER. | |
81 std::unique_ptr<extensions::ExtensionDownloadsEventRouter> | |
82 extension_event_router_; | |
83 #endif | |
84 | |
85 DISALLOW_COPY_AND_ASSIGN(DownloadServiceImpl); | |
86 }; | |
87 | |
88 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SERVICE_IMPL_H_ | |
OLD | NEW |