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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <set> | 10 #include <set> |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 75 |
76 int RemoveDownloadsByURLAndTime( | 76 int RemoveDownloadsByURLAndTime( |
77 const base::Callback<bool(const GURL&)>& url_filter, | 77 const base::Callback<bool(const GURL&)>& url_filter, |
78 base::Time remove_begin, | 78 base::Time remove_begin, |
79 base::Time remove_end) override; | 79 base::Time remove_end) override; |
80 int RemoveAllDownloads() override; | 80 int RemoveAllDownloads() override; |
81 void DownloadUrl(scoped_ptr<DownloadUrlParameters> params) override; | 81 void DownloadUrl(scoped_ptr<DownloadUrlParameters> params) override; |
82 void AddObserver(Observer* observer) override; | 82 void AddObserver(Observer* observer) override; |
83 void RemoveObserver(Observer* observer) override; | 83 void RemoveObserver(Observer* observer) override; |
84 content::DownloadItem* CreateDownloadItem( | 84 content::DownloadItem* CreateDownloadItem( |
| 85 const std::string& guid, |
85 uint32_t id, | 86 uint32_t id, |
86 const base::FilePath& current_path, | 87 const base::FilePath& current_path, |
87 const base::FilePath& target_path, | 88 const base::FilePath& target_path, |
88 const std::vector<GURL>& url_chain, | 89 const std::vector<GURL>& url_chain, |
89 const GURL& referrer_url, | 90 const GURL& referrer_url, |
90 const std::string& mime_type, | 91 const std::string& mime_type, |
91 const std::string& original_mime_type, | 92 const std::string& original_mime_type, |
92 const base::Time& start_time, | 93 const base::Time& start_time, |
93 const base::Time& end_time, | 94 const base::Time& end_time, |
94 const std::string& etag, | 95 const std::string& etag, |
95 const std::string& last_modified, | 96 const std::string& last_modified, |
96 int64_t received_bytes, | 97 int64_t received_bytes, |
97 int64_t total_bytes, | 98 int64_t total_bytes, |
98 content::DownloadItem::DownloadState state, | 99 content::DownloadItem::DownloadState state, |
99 DownloadDangerType danger_type, | 100 DownloadDangerType danger_type, |
100 DownloadInterruptReason interrupt_reason, | 101 DownloadInterruptReason interrupt_reason, |
101 bool opened) override; | 102 bool opened) override; |
102 int InProgressCount() const override; | 103 int InProgressCount() const override; |
103 int NonMaliciousInProgressCount() const override; | 104 int NonMaliciousInProgressCount() const override; |
104 BrowserContext* GetBrowserContext() const override; | 105 BrowserContext* GetBrowserContext() const override; |
105 void CheckForHistoryFilesRemoval() override; | 106 void CheckForHistoryFilesRemoval() override; |
106 DownloadItem* GetDownload(uint32_t id) override; | 107 DownloadItem* GetDownload(uint32_t id) override; |
| 108 DownloadItem* GetDownloadByGuid(const std::string& guid) override; |
107 | 109 |
108 // For testing; specifically, accessed from TestFileErrorInjector. | 110 // For testing; specifically, accessed from TestFileErrorInjector. |
109 void SetDownloadItemFactoryForTesting( | 111 void SetDownloadItemFactoryForTesting( |
110 scoped_ptr<DownloadItemFactory> item_factory); | 112 scoped_ptr<DownloadItemFactory> item_factory); |
111 void SetDownloadFileFactoryForTesting( | 113 void SetDownloadFileFactoryForTesting( |
112 scoped_ptr<DownloadFileFactory> file_factory); | 114 scoped_ptr<DownloadFileFactory> file_factory); |
113 virtual DownloadFileFactory* GetDownloadFileFactoryForTesting(); | 115 virtual DownloadFileFactory* GetDownloadFileFactoryForTesting(); |
114 | 116 |
115 void RemoveUrlDownloader(UrlDownloader* downloader); | 117 void RemoveUrlDownloader(UrlDownloader* downloader); |
116 | 118 |
117 private: | 119 private: |
118 using DownloadSet = std::set<DownloadItem*>; | 120 using DownloadSet = std::set<DownloadItem*>; |
119 using DownloadMap = std::unordered_map<uint32_t, DownloadItemImpl*>; | 121 using DownloadMap = std::unordered_map<uint32_t, DownloadItemImpl*>; |
| 122 using DownloadGuidMap = std::unordered_map<std::string, DownloadItemImpl*>; |
120 using DownloadItemImplVector = std::vector<DownloadItemImpl*>; | 123 using DownloadItemImplVector = std::vector<DownloadItemImpl*>; |
121 using DownloadRemover = base::Callback<bool(const DownloadItemImpl*)>; | 124 using DownloadRemover = base::Callback<bool(const DownloadItemImpl*)>; |
122 | 125 |
123 // For testing. | 126 // For testing. |
124 friend class DownloadManagerTest; | 127 friend class DownloadManagerTest; |
125 friend class DownloadTest; | 128 friend class DownloadTest; |
126 | 129 |
127 void StartDownloadWithId( | 130 void StartDownloadWithId( |
128 scoped_ptr<DownloadCreateInfo> info, | 131 scoped_ptr<DownloadCreateInfo> info, |
129 scoped_ptr<ByteStreamReader> stream, | 132 scoped_ptr<ByteStreamReader> stream, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 // Factory for creation of downloads items. | 182 // Factory for creation of downloads items. |
180 scoped_ptr<DownloadItemFactory> item_factory_; | 183 scoped_ptr<DownloadItemFactory> item_factory_; |
181 | 184 |
182 // Factory for the creation of download files. | 185 // Factory for the creation of download files. |
183 scoped_ptr<DownloadFileFactory> file_factory_; | 186 scoped_ptr<DownloadFileFactory> file_factory_; |
184 | 187 |
185 // |downloads_| is the owning set for all downloads known to the | 188 // |downloads_| is the owning set for all downloads known to the |
186 // DownloadManager. This includes downloads started by the user in | 189 // DownloadManager. This includes downloads started by the user in |
187 // this session, downloads initialized from the history system, and | 190 // this session, downloads initialized from the history system, and |
188 // "save page as" downloads. | 191 // "save page as" downloads. |
| 192 // TODO(asanka): Remove this container in favor of downloads_by_guid_ as a |
| 193 // part of http://crbug.com/593020. |
189 DownloadMap downloads_; | 194 DownloadMap downloads_; |
190 | 195 |
| 196 // Same as the above, but maps from GUID to download item. Note that the |
| 197 // container is case sensitive. Hence the key needs to be normalized to |
| 198 // upper-case when inserting new elements here. Fortunately for us, |
| 199 // DownloadItemImpl already normalizes the string GUID. |
| 200 DownloadGuidMap downloads_by_guid_; |
| 201 |
191 int history_size_; | 202 int history_size_; |
192 | 203 |
193 // True if the download manager has been initialized and requires a shutdown. | 204 // True if the download manager has been initialized and requires a shutdown. |
194 bool shutdown_needed_; | 205 bool shutdown_needed_; |
195 | 206 |
196 // Observers that want to be notified of changes to the set of downloads. | 207 // Observers that want to be notified of changes to the set of downloads. |
197 base::ObserverList<Observer> observers_; | 208 base::ObserverList<Observer> observers_; |
198 | 209 |
199 // The current active browser context. | 210 // The current active browser context. |
200 BrowserContext* browser_context_; | 211 BrowserContext* browser_context_; |
201 | 212 |
202 // Allows an embedder to control behavior. Guaranteed to outlive this object. | 213 // Allows an embedder to control behavior. Guaranteed to outlive this object. |
203 DownloadManagerDelegate* delegate_; | 214 DownloadManagerDelegate* delegate_; |
204 | 215 |
205 net::NetLog* net_log_; | 216 net::NetLog* net_log_; |
206 | 217 |
207 std::vector<scoped_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread>> | 218 std::vector<scoped_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread>> |
208 url_downloaders_; | 219 url_downloaders_; |
209 | 220 |
210 base::WeakPtrFactory<DownloadManagerImpl> weak_factory_; | 221 base::WeakPtrFactory<DownloadManagerImpl> weak_factory_; |
211 | 222 |
212 DISALLOW_COPY_AND_ASSIGN(DownloadManagerImpl); | 223 DISALLOW_COPY_AND_ASSIGN(DownloadManagerImpl); |
213 }; | 224 }; |
214 | 225 |
215 } // namespace content | 226 } // namespace content |
216 | 227 |
217 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ | 228 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ |
OLD | NEW |