| 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 CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ |
| 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ | 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/callback_forward.h" |
| 12 #include "base/containers/hash_tables.h" | 13 #include "base/containers/hash_tables.h" |
| 13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 16 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
| 17 #include "base/sequenced_task_runner_helpers.h" | 18 #include "base/sequenced_task_runner_helpers.h" |
| 18 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
| 19 #include "content/browser/download/download_item_impl_delegate.h" | 20 #include "content/browser/download/download_item_impl_delegate.h" |
| 20 #include "content/common/content_export.h" | 21 #include "content/common/content_export.h" |
| 21 #include "content/public/browser/download_manager.h" | 22 #include "content/public/browser/download_manager.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 | 60 |
| 60 // DownloadManager functions. | 61 // DownloadManager functions. |
| 61 void SetDelegate(DownloadManagerDelegate* delegate) override; | 62 void SetDelegate(DownloadManagerDelegate* delegate) override; |
| 62 DownloadManagerDelegate* GetDelegate() const override; | 63 DownloadManagerDelegate* GetDelegate() const override; |
| 63 void Shutdown() override; | 64 void Shutdown() override; |
| 64 void GetAllDownloads(DownloadVector* result) override; | 65 void GetAllDownloads(DownloadVector* result) override; |
| 65 void StartDownload( | 66 void StartDownload( |
| 66 scoped_ptr<DownloadCreateInfo> info, | 67 scoped_ptr<DownloadCreateInfo> info, |
| 67 scoped_ptr<ByteStreamReader> stream, | 68 scoped_ptr<ByteStreamReader> stream, |
| 68 const DownloadUrlParameters::OnStartedCallback& on_started) override; | 69 const DownloadUrlParameters::OnStartedCallback& on_started) override; |
| 70 |
| 71 int RemoveDownloadsByOriginAndTime(const url::Origin& origin, |
| 72 base::Time remove_begin, |
| 73 base::Time remove_end) override; |
| 69 int RemoveDownloadsBetween(base::Time remove_begin, | 74 int RemoveDownloadsBetween(base::Time remove_begin, |
| 70 base::Time remove_end) override; | 75 base::Time remove_end) override; |
| 71 int RemoveDownloads(base::Time remove_begin) override; | 76 int RemoveDownloads(base::Time remove_begin) override; |
| 72 int RemoveAllDownloads() override; | 77 int RemoveAllDownloads() override; |
| 73 void DownloadUrl(scoped_ptr<DownloadUrlParameters> params) override; | 78 void DownloadUrl(scoped_ptr<DownloadUrlParameters> params) override; |
| 74 void AddObserver(Observer* observer) override; | 79 void AddObserver(Observer* observer) override; |
| 75 void RemoveObserver(Observer* observer) override; | 80 void RemoveObserver(Observer* observer) override; |
| 76 content::DownloadItem* CreateDownloadItem( | 81 content::DownloadItem* CreateDownloadItem( |
| 77 uint32 id, | 82 uint32 id, |
| 78 const base::FilePath& current_path, | 83 const base::FilePath& current_path, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 101 void SetDownloadItemFactoryForTesting( | 106 void SetDownloadItemFactoryForTesting( |
| 102 scoped_ptr<DownloadItemFactory> item_factory); | 107 scoped_ptr<DownloadItemFactory> item_factory); |
| 103 void SetDownloadFileFactoryForTesting( | 108 void SetDownloadFileFactoryForTesting( |
| 104 scoped_ptr<DownloadFileFactory> file_factory); | 109 scoped_ptr<DownloadFileFactory> file_factory); |
| 105 virtual DownloadFileFactory* GetDownloadFileFactoryForTesting(); | 110 virtual DownloadFileFactory* GetDownloadFileFactoryForTesting(); |
| 106 | 111 |
| 107 private: | 112 private: |
| 108 typedef std::set<DownloadItem*> DownloadSet; | 113 typedef std::set<DownloadItem*> DownloadSet; |
| 109 typedef base::hash_map<uint32, DownloadItemImpl*> DownloadMap; | 114 typedef base::hash_map<uint32, DownloadItemImpl*> DownloadMap; |
| 110 typedef std::vector<DownloadItemImpl*> DownloadItemImplVector; | 115 typedef std::vector<DownloadItemImpl*> DownloadItemImplVector; |
| 116 typedef base::Callback<bool(const DownloadItemImpl*)> DownloadRemover; |
| 111 | 117 |
| 112 // For testing. | 118 // For testing. |
| 113 friend class DownloadManagerTest; | 119 friend class DownloadManagerTest; |
| 114 friend class DownloadTest; | 120 friend class DownloadTest; |
| 115 | 121 |
| 116 void StartDownloadWithId( | 122 void StartDownloadWithId( |
| 117 scoped_ptr<DownloadCreateInfo> info, | 123 scoped_ptr<DownloadCreateInfo> info, |
| 118 scoped_ptr<ByteStreamReader> stream, | 124 scoped_ptr<ByteStreamReader> stream, |
| 119 const DownloadUrlParameters::OnStartedCallback& on_started, | 125 const DownloadUrlParameters::OnStartedCallback& on_started, |
| 120 bool new_download, | 126 bool new_download, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 135 | 141 |
| 136 // Get next download id. |callback| is called on the UI thread and may | 142 // Get next download id. |callback| is called on the UI thread and may |
| 137 // be called synchronously. | 143 // be called synchronously. |
| 138 void GetNextId(const DownloadIdCallback& callback); | 144 void GetNextId(const DownloadIdCallback& callback); |
| 139 | 145 |
| 140 // Called with the result of DownloadManagerDelegate::CheckForFileExistence. | 146 // Called with the result of DownloadManagerDelegate::CheckForFileExistence. |
| 141 // Updates the state of the file and then notifies this update to the file's | 147 // Updates the state of the file and then notifies this update to the file's |
| 142 // observer. | 148 // observer. |
| 143 void OnFileExistenceChecked(uint32 download_id, bool result); | 149 void OnFileExistenceChecked(uint32 download_id, bool result); |
| 144 | 150 |
| 151 // Remove all downloads for which |remover| returns true. |
| 152 int RemoveDownloads(const DownloadRemover& remover); |
| 153 |
| 145 // Overridden from DownloadItemImplDelegate | 154 // Overridden from DownloadItemImplDelegate |
| 146 // (Note that |GetBrowserContext| are present in both interfaces.) | 155 // (Note that |GetBrowserContext| are present in both interfaces.) |
| 147 void DetermineDownloadTarget(DownloadItemImpl* item, | 156 void DetermineDownloadTarget(DownloadItemImpl* item, |
| 148 const DownloadTargetCallback& callback) override; | 157 const DownloadTargetCallback& callback) override; |
| 149 bool ShouldCompleteDownload(DownloadItemImpl* item, | 158 bool ShouldCompleteDownload(DownloadItemImpl* item, |
| 150 const base::Closure& complete_callback) override; | 159 const base::Closure& complete_callback) override; |
| 151 bool ShouldOpenFileBasedOnExtension(const base::FilePath& path) override; | 160 bool ShouldOpenFileBasedOnExtension(const base::FilePath& path) override; |
| 152 bool ShouldOpenDownload(DownloadItemImpl* item, | 161 bool ShouldOpenDownload(DownloadItemImpl* item, |
| 153 const ShouldOpenDownloadCallback& callback) override; | 162 const ShouldOpenDownloadCallback& callback) override; |
| 154 void CheckForFileRemoval(DownloadItemImpl* download_item) override; | 163 void CheckForFileRemoval(DownloadItemImpl* download_item) override; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 net::NetLog* net_log_; | 197 net::NetLog* net_log_; |
| 189 | 198 |
| 190 base::WeakPtrFactory<DownloadManagerImpl> weak_factory_; | 199 base::WeakPtrFactory<DownloadManagerImpl> weak_factory_; |
| 191 | 200 |
| 192 DISALLOW_COPY_AND_ASSIGN(DownloadManagerImpl); | 201 DISALLOW_COPY_AND_ASSIGN(DownloadManagerImpl); |
| 193 }; | 202 }; |
| 194 | 203 |
| 195 } // namespace content | 204 } // namespace content |
| 196 | 205 |
| 197 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ | 206 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ |
| OLD | NEW |