| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "chrome/browser/profiles/profile_keyed_service.h" | 14 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 15 | 15 |
| 16 class ChromeDownloadManagerDelegate; | 16 class ChromeDownloadManagerDelegate; |
| 17 class Profile; | 17 class Profile; |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| 20 class DownloadManager; | 20 class DownloadManager; |
| 21 class DownloadManagerDelegate; |
| 21 } | 22 } |
| 22 | 23 |
| 23 // Owning class for DownloadManager (content) and | 24 // Owning class for ChromeDownloadManagerDelegate. |
| 24 // ChromeDownloadManagerDelegate (chrome) | |
| 25 class DownloadService : public ProfileKeyedService { | 25 class DownloadService : public ProfileKeyedService { |
| 26 public: | 26 public: |
| 27 explicit DownloadService(Profile* profile); | 27 explicit DownloadService(Profile* profile); |
| 28 virtual ~DownloadService(); | 28 virtual ~DownloadService(); |
| 29 | 29 |
| 30 // Register a callback to be called whenever the DownloadManager is created. | 30 // Register a callback to be called whenever the DownloadManager is created. |
| 31 typedef base::Callback<void(content::DownloadManager*)> | 31 typedef base::Callback<void(content::DownloadManager*)> |
| 32 OnManagerCreatedCallback; | 32 OnManagerCreatedCallback; |
| 33 void OnManagerCreated(const OnManagerCreatedCallback& cb); | 33 void OnManagerCreated(const OnManagerCreatedCallback& cb); |
| 34 | 34 |
| 35 // Get the download manager. Creates the download manager if | 35 // Get the download manager delegate, creating it if it doesn't already exist. |
| 36 // it does not already exist. | 36 content::DownloadManagerDelegate* GetDownloadManagerDelegate(); |
| 37 content::DownloadManager* GetDownloadManager(); | |
| 38 | 37 |
| 39 // Has a download manager been created? (By calling above function.) | 38 // Has a download manager been created? |
| 40 bool HasCreatedDownloadManager(); | 39 bool HasCreatedDownloadManager(); |
| 41 | 40 |
| 42 // Number of downloads associated with this instance of the service. | 41 // Number of downloads associated with this instance of the service. |
| 43 int DownloadCount() const; | 42 int DownloadCount() const; |
| 44 | 43 |
| 45 // Number of downloads associated with all profiles. | 44 // Number of downloads associated with all profiles. |
| 46 static int DownloadCountAllProfiles(); | 45 static int DownloadCountAllProfiles(); |
| 47 | 46 |
| 48 // Sets the DownloadManagerDelegate associated with this object and | 47 // Sets the DownloadManagerDelegate associated with this object and |
| 49 // its DownloadManager. Takes ownership of |delegate|, and destroys | 48 // its DownloadManager. Takes ownership of |delegate|, and destroys |
| 50 // the previous delegate. For testing. | 49 // the previous delegate. For testing. |
| 51 void SetDownloadManagerDelegateForTesting( | 50 void SetDownloadManagerDelegateForTesting( |
| 52 ChromeDownloadManagerDelegate* delegate); | 51 ChromeDownloadManagerDelegate* delegate); |
| 53 | 52 |
| 54 // Will be called to release references on other services as part | 53 // Will be called to release references on other services as part |
| 55 // of Profile shutdown. | 54 // of Profile shutdown. |
| 56 virtual void Shutdown() OVERRIDE; | 55 virtual void Shutdown() OVERRIDE; |
| 57 | 56 |
| 58 private: | 57 private: |
| 59 bool download_manager_created_; | 58 bool download_manager_created_; |
| 60 Profile* profile_; | 59 Profile* profile_; |
| 61 | 60 |
| 62 // Both of these objects are owned by this class. | |
| 63 // DownloadManager is RefCountedThreadSafe because of references | |
| 64 // from DownloadFile objects on the FILE thread, and may need to be | |
| 65 // kept alive until those objects are deleted. | |
| 66 // ChromeDownloadManagerDelegate may be the target of callbacks from | 61 // ChromeDownloadManagerDelegate may be the target of callbacks from |
| 67 // 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 |
| 68 // callbacks. | 63 // callbacks. |
| 69 scoped_refptr<content::DownloadManager> manager_; | |
| 70 scoped_refptr<ChromeDownloadManagerDelegate> manager_delegate_; | 64 scoped_refptr<ChromeDownloadManagerDelegate> manager_delegate_; |
| 71 | 65 |
| 72 std::vector<OnManagerCreatedCallback> on_manager_created_callbacks_; | 66 std::vector<OnManagerCreatedCallback> on_manager_created_callbacks_; |
| 73 | 67 |
| 74 DISALLOW_COPY_AND_ASSIGN(DownloadService); | 68 DISALLOW_COPY_AND_ASSIGN(DownloadService); |
| 75 }; | 69 }; |
| 76 | 70 |
| 77 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SERVICE_H_ | 71 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SERVICE_H_ |
| OLD | NEW |