1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SERVICE_H_
6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SERVICE_H_
8 #include "base/basictypes.h"
9 #include "base/callback_forward.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "components/keyed_service/core/keyed_service.h"
13 class ChromeDownloadManagerDelegate
;
14 class DownloadHistory
;
15 class DownloadUIController
;
16 class ExtensionDownloadsEventRouter
;
20 class DownloadManager
;
23 namespace extensions
{
24 class ExtensionDownloadsEventRouter
;
27 // Owning class for ChromeDownloadManagerDelegate.
28 class DownloadService
: public KeyedService
{
30 explicit DownloadService(Profile
* profile
);
31 virtual ~DownloadService();
33 // Get the download manager delegate, creating it if it doesn't already exist.
34 ChromeDownloadManagerDelegate
* GetDownloadManagerDelegate();
36 // Get the interface to the history system. Returns NULL if profile is
37 // incognito or if the DownloadManager hasn't been created yet or if there is
38 // no HistoryService for profile. Virtual for testing.
39 virtual DownloadHistory
* GetDownloadHistory();
41 #if defined(ENABLE_EXTENSIONS)
42 extensions::ExtensionDownloadsEventRouter
* GetExtensionEventRouter() {
43 return extension_event_router_
.get();
47 // Has a download manager been created?
48 bool HasCreatedDownloadManager();
50 // Number of non-malicious downloads associated with this instance of the
52 int NonMaliciousDownloadCount() const;
54 // Cancels all in-progress downloads for this profile.
55 void CancelDownloads();
57 // Number of non-malicious downloads associated with all profiles.
58 static int NonMaliciousDownloadCountAllProfiles();
60 // Cancels all in-progress downloads for all profiles.
61 static void CancelAllDownloads();
63 // Sets the DownloadManagerDelegate associated with this object and
64 // its DownloadManager. Takes ownership of |delegate|, and destroys
65 // the previous delegate. For testing.
66 void SetDownloadManagerDelegateForTesting(
67 scoped_ptr
<ChromeDownloadManagerDelegate
> delegate
);
69 // Will be called to release references on other services as part
70 // of Profile shutdown.
71 virtual void Shutdown() OVERRIDE
;
73 // Returns false if at least one extension has disabled the shelf, true
75 bool IsShelfEnabled();
78 bool download_manager_created_
;
81 // ChromeDownloadManagerDelegate may be the target of callbacks from
82 // the history service/DB thread and must be kept alive for those
84 scoped_ptr
<ChromeDownloadManagerDelegate
> manager_delegate_
;
86 scoped_ptr
<DownloadHistory
> download_history_
;
88 // The UI controller is responsible for observing the download manager and
89 // notifying the UI of any new downloads. Its lifetime matches that of the
90 // associated download manager.
91 // Note on destruction order: download_ui_ depends on download_history_ and
92 // should be destroyed before the latter.
93 scoped_ptr
<DownloadUIController
> download_ui_
;
95 // On Android, GET downloads are not handled by the DownloadManager.
96 // Once we have extensions on android, we probably need the EventRouter
97 // in ContentViewDownloadDelegate which knows about both GET and POST
99 #if defined(ENABLE_EXTENSIONS)
100 // The ExtensionDownloadsEventRouter dispatches download creation, change, and
101 // erase events to extensions. Like ChromeDownloadManagerDelegate, it's a
102 // chrome-level concept and its lifetime should match DownloadManager. There
103 // should be a separate EDER for on-record and off-record managers.
104 // There does not appear to be a separate ExtensionSystem for on-record and
105 // off-record profiles, so ExtensionSystem cannot own the EDER.
106 scoped_ptr
<extensions::ExtensionDownloadsEventRouter
> extension_event_router_
;
109 DISALLOW_COPY_AND_ASSIGN(DownloadService
);
112 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SERVICE_H_