Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / download / download_service.h
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.
4
5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SERVICE_H_
6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SERVICE_H_
7
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"
12
13 class ChromeDownloadManagerDelegate;
14 class DownloadHistory;
15 class DownloadUIController;
16 class ExtensionDownloadsEventRouter;
17 class Profile;
18
19 namespace content {
20 class DownloadManager;
21 }
22
23 namespace extensions {
24 class ExtensionDownloadsEventRouter;
25 }
26
27 // Owning class for ChromeDownloadManagerDelegate.
28 class DownloadService : public KeyedService {
29  public:
30   explicit DownloadService(Profile* profile);
31   virtual ~DownloadService();
32
33   // Get the download manager delegate, creating it if it doesn't already exist.
34   ChromeDownloadManagerDelegate* GetDownloadManagerDelegate();
35
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.
39   DownloadHistory* GetDownloadHistory();
40
41 #if !defined(OS_ANDROID)
42   extensions::ExtensionDownloadsEventRouter* GetExtensionEventRouter() {
43     return extension_event_router_.get();
44   }
45 #endif
46
47   // Has a download manager been created?
48   bool HasCreatedDownloadManager();
49
50   // Number of non-malicious downloads associated with this instance of the
51   // service.
52   int NonMaliciousDownloadCount() const;
53
54   // Cancels all in-progress downloads for this profile.
55   void CancelDownloads();
56
57   // Number of non-malicious downloads associated with all profiles.
58   static int NonMaliciousDownloadCountAllProfiles();
59
60   // Cancels all in-progress downloads for all profiles.
61   static void CancelAllDownloads();
62
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);
68
69   // Will be called to release references on other services as part
70   // of Profile shutdown.
71   virtual void Shutdown() OVERRIDE;
72
73   // Returns false if at least one extension has disabled the shelf, true
74   // otherwise.
75   bool IsShelfEnabled();
76
77  private:
78   bool download_manager_created_;
79   Profile* profile_;
80
81   // ChromeDownloadManagerDelegate may be the target of callbacks from
82   // the history service/DB thread and must be kept alive for those
83   // callbacks.
84   scoped_ptr<ChromeDownloadManagerDelegate> manager_delegate_;
85
86   scoped_ptr<DownloadHistory> download_history_;
87
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   scoped_ptr<DownloadUIController> download_ui_;
92
93   // On Android, GET downloads are not handled by the DownloadManager.
94   // Once we have extensions on android, we probably need the EventRouter
95   // in ContentViewDownloadDelegate which knows about both GET and POST
96   // downloads.
97 #if !defined(OS_ANDROID)
98   // The ExtensionDownloadsEventRouter dispatches download creation, change, and
99   // erase events to extensions. Like ChromeDownloadManagerDelegate, it's a
100   // chrome-level concept and its lifetime should match DownloadManager. There
101   // should be a separate EDER for on-record and off-record managers.
102   // There does not appear to be a separate ExtensionSystem for on-record and
103   // off-record profiles, so ExtensionSystem cannot own the EDER.
104   scoped_ptr<extensions::ExtensionDownloadsEventRouter> extension_event_router_;
105 #endif
106
107   DISALLOW_COPY_AND_ASSIGN(DownloadService);
108 };
109
110 #endif  // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SERVICE_H_