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/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "components/browser_context_keyed_service/browser_context_keyed_service.h"
14 class ChromeDownloadManagerDelegate;
15 class DownloadHistory;
16 class DownloadUIController;
17 class ExtensionDownloadsEventRouter;
21 class DownloadManager;
24 // Owning class for ChromeDownloadManagerDelegate.
25 class DownloadService : public BrowserContextKeyedService {
27 explicit DownloadService(Profile* profile);
28 virtual ~DownloadService();
30 // Get the download manager delegate, creating it if it doesn't already exist.
31 ChromeDownloadManagerDelegate* GetDownloadManagerDelegate();
33 // Get the interface to the history system. Returns NULL if profile is
34 // incognito or if the DownloadManager hasn't been created yet or if there is
35 // no HistoryService for profile.
36 DownloadHistory* GetDownloadHistory();
38 #if !defined(OS_ANDROID)
39 ExtensionDownloadsEventRouter* GetExtensionEventRouter() {
40 return extension_event_router_.get();
44 // Has a download manager been created?
45 bool HasCreatedDownloadManager();
47 // Number of non-malicious downloads associated with this instance of the
49 int NonMaliciousDownloadCount() const;
51 // Number of non-malicious downloads associated with all profiles.
52 static int NonMaliciousDownloadCountAllProfiles();
54 // Sets the DownloadManagerDelegate associated with this object and
55 // its DownloadManager. Takes ownership of |delegate|, and destroys
56 // the previous delegate. For testing.
57 void SetDownloadManagerDelegateForTesting(
58 ChromeDownloadManagerDelegate* delegate);
60 // Will be called to release references on other services as part
61 // of Profile shutdown.
62 virtual void Shutdown() OVERRIDE;
64 // Returns false if at least one extension has disabled the shelf, true
66 bool IsShelfEnabled();
69 bool download_manager_created_;
72 // ChromeDownloadManagerDelegate may be the target of callbacks from
73 // the history service/DB thread and must be kept alive for those
75 scoped_refptr<ChromeDownloadManagerDelegate> manager_delegate_;
77 scoped_ptr<DownloadHistory> download_history_;
79 // The UI controller is responsible for observing the download manager and
80 // notifying the UI of any new downloads. Its lifetime matches that of the
81 // associated download manager.
82 scoped_ptr<DownloadUIController> download_ui_;
84 // On Android, GET downloads are not handled by the DownloadManager.
85 // Once we have extensions on android, we probably need the EventRouter
86 // in ContentViewDownloadDelegate which knows about both GET and POST
88 #if !defined(OS_ANDROID)
89 // The ExtensionDownloadsEventRouter dispatches download creation, change, and
90 // erase events to extensions. Like ChromeDownloadManagerDelegate, it's a
91 // chrome-level concept and its lifetime should match DownloadManager. There
92 // should be a separate EDER for on-record and off-record managers.
93 // There does not appear to be a separate ExtensionSystem for on-record and
94 // off-record profiles, so ExtensionSystem cannot own the EDER.
95 scoped_ptr<ExtensionDownloadsEventRouter> extension_event_router_;
98 DISALLOW_COPY_AND_ASSIGN(DownloadService);
101 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SERVICE_H_