- add sources.
[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/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "components/browser_context_keyed_service/browser_context_keyed_service.h"
13
14 class ChromeDownloadManagerDelegate;
15 class DownloadHistory;
16 class DownloadUIController;
17 class ExtensionDownloadsEventRouter;
18 class Profile;
19
20 namespace content {
21 class DownloadManager;
22 }
23
24 // Owning class for ChromeDownloadManagerDelegate.
25 class DownloadService : public BrowserContextKeyedService {
26  public:
27   explicit DownloadService(Profile* profile);
28   virtual ~DownloadService();
29
30   // Get the download manager delegate, creating it if it doesn't already exist.
31   ChromeDownloadManagerDelegate* GetDownloadManagerDelegate();
32
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();
37
38 #if !defined(OS_ANDROID)
39   ExtensionDownloadsEventRouter* GetExtensionEventRouter() {
40     return extension_event_router_.get();
41   }
42 #endif
43
44   // Has a download manager been created?
45   bool HasCreatedDownloadManager();
46
47   // Number of non-malicious downloads associated with this instance of the
48   // service.
49   int NonMaliciousDownloadCount() const;
50
51   // Number of non-malicious downloads associated with all profiles.
52   static int NonMaliciousDownloadCountAllProfiles();
53
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);
59
60   // Will be called to release references on other services as part
61   // of Profile shutdown.
62   virtual void Shutdown() OVERRIDE;
63
64   // Returns false if at least one extension has disabled the shelf, true
65   // otherwise.
66   bool IsShelfEnabled();
67
68  private:
69   bool download_manager_created_;
70   Profile* profile_;
71
72   // ChromeDownloadManagerDelegate may be the target of callbacks from
73   // the history service/DB thread and must be kept alive for those
74   // callbacks.
75   scoped_refptr<ChromeDownloadManagerDelegate> manager_delegate_;
76
77   scoped_ptr<DownloadHistory> download_history_;
78
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_;
83
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
87   // downloads.
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_;
96 #endif
97
98   DISALLOW_COPY_AND_ASSIGN(DownloadService);
99 };
100
101 #endif  // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SERVICE_H_