OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SERVICE_H_ |
6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SERVICE_H_ | 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SERVICE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "chrome/browser/profiles/profile_keyed_service.h" | 12 #include "chrome/browser/profiles/profile_keyed_service.h" |
13 | 13 |
14 class ChromeDownloadManagerDelegate; | 14 class ChromeDownloadManagerDelegate; |
15 class DownloadManager; | 15 class DownloadManager; |
16 class Profile; | 16 class Profile; |
| 17 class DownloadIdFactory; |
17 | 18 |
18 // Owning class for DownloadManager (content) and | 19 // Owning class for DownloadManager (content) and |
19 // ChromeDownloadManagerDelegate (chrome) | 20 // ChromeDownloadManagerDelegate (chrome) |
20 class DownloadService : public ProfileKeyedService { | 21 class DownloadService : public ProfileKeyedService { |
21 public: | 22 public: |
22 explicit DownloadService(Profile* profile); | 23 explicit DownloadService(Profile* profile); |
23 virtual ~DownloadService(); | 24 virtual ~DownloadService(); |
24 | 25 |
| 26 DownloadIdFactory* GetDownloadIdFactory() const; |
| 27 |
25 // Get the download manager. Creates the download manager if | 28 // Get the download manager. Creates the download manager if |
26 // it does not already exist. | 29 // it does not already exist. |
27 DownloadManager* GetDownloadManager(); | 30 DownloadManager* GetDownloadManager(); |
28 | 31 |
29 // Has a download manager been created? (By calling above function.) | 32 // Has a download manager been created? (By calling above function.) |
30 bool HasCreatedDownloadManager(); | 33 bool HasCreatedDownloadManager(); |
31 | 34 |
32 // Number of downloads associated with this instance of the service. | 35 // Number of downloads associated with this instance of the service. |
33 int DownloadCount() const; | 36 int DownloadCount() const; |
34 | 37 |
35 // Number of downloads associated with all profiles. | 38 // Number of downloads associated with all profiles. |
36 static int DownloadCountAllProfiles(); | 39 static int DownloadCountAllProfiles(); |
37 | 40 |
38 // Sets the DownloadManagerDelegate associated with this object and | 41 // Sets the DownloadManagerDelegate associated with this object and |
39 // its DownloadManager. Takes ownership of |delegate|, and destroys | 42 // its DownloadManager. Takes ownership of |delegate|, and destroys |
40 // the previous delegate. For testing. | 43 // the previous delegate. For testing. |
41 void SetDownloadManagerDelegateForTesting( | 44 void SetDownloadManagerDelegateForTesting( |
42 ChromeDownloadManagerDelegate* delegate); | 45 ChromeDownloadManagerDelegate* delegate); |
43 | 46 |
44 // Will be called to release references on other services as part | 47 // Will be called to release references on other services as part |
45 // of Profile shutdown. | 48 // of Profile shutdown. |
46 virtual void Shutdown() OVERRIDE; | 49 virtual void Shutdown() OVERRIDE; |
47 | 50 |
48 private: | 51 private: |
| 52 scoped_refptr<DownloadIdFactory> id_factory_; |
| 53 |
49 bool download_manager_created_; | 54 bool download_manager_created_; |
50 Profile* profile_; | 55 Profile* profile_; |
51 | 56 |
52 // Both of these objects are owned by this class. | 57 // Both of these objects are owned by this class. |
53 // DownloadManager is RefCountedThreadSafe because of references | 58 // DownloadManager is RefCountedThreadSafe because of references |
54 // from DownloadFile objects on the FILE thread, and may need to be | 59 // from DownloadFile objects on the FILE thread, and may need to be |
55 // kept alive until those objects are deleted. | 60 // kept alive until those objects are deleted. |
56 // ChromeDownloadManagerDelegate may be the target of callbacks from | 61 // ChromeDownloadManagerDelegate may be the target of callbacks from |
57 // the history service/DB thread and must be kept alive for those | 62 // the history service/DB thread and must be kept alive for those |
58 // callbacks. | 63 // callbacks. |
59 scoped_refptr<DownloadManager> manager_; | 64 scoped_refptr<DownloadManager> manager_; |
60 scoped_refptr<ChromeDownloadManagerDelegate> manager_delegate_; | 65 scoped_refptr<ChromeDownloadManagerDelegate> manager_delegate_; |
61 | 66 |
62 DISALLOW_COPY_AND_ASSIGN(DownloadService); | 67 DISALLOW_COPY_AND_ASSIGN(DownloadService); |
63 }; | 68 }; |
64 | 69 |
65 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SERVICE_H_ | 70 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SERVICE_H_ |
OLD | NEW |