Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / download / download_service.h
blob72b0de09574675574f7446dfc00ce256a0b801a7
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/browser_context_keyed_service/browser_context_keyed_service.h"
13 class ChromeDownloadManagerDelegate;
14 class DownloadHistory;
15 class DownloadUIController;
16 class ExtensionDownloadsEventRouter;
17 class Profile;
19 namespace content {
20 class DownloadManager;
23 // Owning class for ChromeDownloadManagerDelegate.
24 class DownloadService : public BrowserContextKeyedService {
25 public:
26 explicit DownloadService(Profile* profile);
27 virtual ~DownloadService();
29 // Get the download manager delegate, creating it if it doesn't already exist.
30 ChromeDownloadManagerDelegate* GetDownloadManagerDelegate();
32 // Get the interface to the history system. Returns NULL if profile is
33 // incognito or if the DownloadManager hasn't been created yet or if there is
34 // no HistoryService for profile.
35 DownloadHistory* GetDownloadHistory();
37 #if !defined(OS_ANDROID)
38 ExtensionDownloadsEventRouter* GetExtensionEventRouter() {
39 return extension_event_router_.get();
41 #endif
43 // Has a download manager been created?
44 bool HasCreatedDownloadManager();
46 // Number of non-malicious downloads associated with this instance of the
47 // service.
48 int NonMaliciousDownloadCount() const;
50 // Number of non-malicious downloads associated with all profiles.
51 static int NonMaliciousDownloadCountAllProfiles();
53 // Cancels all in-progress downloads.
54 static void CancelAllDownloads();
56 // Sets the DownloadManagerDelegate associated with this object and
57 // its DownloadManager. Takes ownership of |delegate|, and destroys
58 // the previous delegate. For testing.
59 void SetDownloadManagerDelegateForTesting(
60 scoped_ptr<ChromeDownloadManagerDelegate> delegate);
62 // Will be called to release references on other services as part
63 // of Profile shutdown.
64 virtual void Shutdown() OVERRIDE;
66 // Returns false if at least one extension has disabled the shelf, true
67 // otherwise.
68 bool IsShelfEnabled();
70 private:
71 bool download_manager_created_;
72 Profile* profile_;
74 // ChromeDownloadManagerDelegate may be the target of callbacks from
75 // the history service/DB thread and must be kept alive for those
76 // callbacks.
77 scoped_ptr<ChromeDownloadManagerDelegate> manager_delegate_;
79 scoped_ptr<DownloadHistory> download_history_;
81 // The UI controller is responsible for observing the download manager and
82 // notifying the UI of any new downloads. Its lifetime matches that of the
83 // associated download manager.
84 scoped_ptr<DownloadUIController> download_ui_;
86 // On Android, GET downloads are not handled by the DownloadManager.
87 // Once we have extensions on android, we probably need the EventRouter
88 // in ContentViewDownloadDelegate which knows about both GET and POST
89 // downloads.
90 #if !defined(OS_ANDROID)
91 // The ExtensionDownloadsEventRouter dispatches download creation, change, and
92 // erase events to extensions. Like ChromeDownloadManagerDelegate, it's a
93 // chrome-level concept and its lifetime should match DownloadManager. There
94 // should be a separate EDER for on-record and off-record managers.
95 // There does not appear to be a separate ExtensionSystem for on-record and
96 // off-record profiles, so ExtensionSystem cannot own the EDER.
97 scoped_ptr<ExtensionDownloadsEventRouter> extension_event_router_;
98 #endif
100 DISALLOW_COPY_AND_ASSIGN(DownloadService);
103 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SERVICE_H_