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 // Sets the DownloadManagerDelegate associated with this object and | 35 // Sets the DownloadManagerDelegate associated with this object and |
33 // its DownloadManager. Takes ownership of |delegate|, and destroys | 36 // its DownloadManager. Takes ownership of |delegate|, and destroys |
34 // the previous delegate. For testing. | 37 // the previous delegate. For testing. |
35 void SetDownloadManagerDelegateForTesting( | 38 void SetDownloadManagerDelegateForTesting( |
36 ChromeDownloadManagerDelegate* delegate); | 39 ChromeDownloadManagerDelegate* delegate); |
37 | 40 |
38 // Will be called to release references on other services as part | 41 // Will be called to release references on other services as part |
39 // of Profile shutdown. | 42 // of Profile shutdown. |
40 virtual void Shutdown() OVERRIDE; | 43 virtual void Shutdown() OVERRIDE; |
41 | 44 |
42 private: | 45 private: |
| 46 scoped_refptr<DownloadIdFactory> id_factory_; |
| 47 |
43 bool download_manager_created_; | 48 bool download_manager_created_; |
44 Profile* profile_; | 49 Profile* profile_; |
45 | 50 |
46 // Both of these objects are owned by this class. | 51 // Both of these objects are owned by this class. |
47 // DownloadManager is RefCountedThreadSafe because of references | 52 // DownloadManager is RefCountedThreadSafe because of references |
48 // from DownloadFile objects on the FILE thread, and may need to be | 53 // from DownloadFile objects on the FILE thread, and may need to be |
49 // kept alive until those objects are deleted. | 54 // kept alive until those objects are deleted. |
50 // ChromeDownloadManagerDelegate may be the target of callbacks from | 55 // ChromeDownloadManagerDelegate may be the target of callbacks from |
51 // the history service/DB thread and must be kept alive for those | 56 // the history service/DB thread and must be kept alive for those |
52 // callbacks. | 57 // callbacks. |
53 scoped_refptr<DownloadManager> manager_; | 58 scoped_refptr<DownloadManager> manager_; |
54 scoped_refptr<ChromeDownloadManagerDelegate> manager_delegate_; | 59 scoped_refptr<ChromeDownloadManagerDelegate> manager_delegate_; |
55 | 60 |
56 DISALLOW_COPY_AND_ASSIGN(DownloadService); | 61 DISALLOW_COPY_AND_ASSIGN(DownloadService); |
57 }; | 62 }; |
58 | 63 |
59 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SERVICE_H_ | 64 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SERVICE_H_ |
OLD | NEW |