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> |
(...skipping 22 matching lines...) Expand all Loading... |
33 class DownloadRequestHandleInterface; | 33 class DownloadRequestHandleInterface; |
34 | 34 |
35 class CONTENT_EXPORT DownloadManagerImpl : public DownloadManager, | 35 class CONTENT_EXPORT DownloadManagerImpl : public DownloadManager, |
36 private DownloadItemImplDelegate { | 36 private DownloadItemImplDelegate { |
37 public: | 37 public: |
38 typedef base::Callback<void(DownloadItemImpl*)> DownloadItemImplCreated; | 38 typedef base::Callback<void(DownloadItemImpl*)> DownloadItemImplCreated; |
39 | 39 |
40 // Caller guarantees that |net_log| will remain valid | 40 // Caller guarantees that |net_log| will remain valid |
41 // for the lifetime of DownloadManagerImpl (until Shutdown() is called). | 41 // for the lifetime of DownloadManagerImpl (until Shutdown() is called). |
42 DownloadManagerImpl(net::NetLog* net_log, BrowserContext* browser_context); | 42 DownloadManagerImpl(net::NetLog* net_log, BrowserContext* browser_context); |
43 virtual ~DownloadManagerImpl(); | 43 ~DownloadManagerImpl() override; |
44 | 44 |
45 // Implementation functions (not part of the DownloadManager interface). | 45 // Implementation functions (not part of the DownloadManager interface). |
46 | 46 |
47 // Creates a download item for the SavePackage system. | 47 // Creates a download item for the SavePackage system. |
48 // Must be called on the UI thread. Note that the DownloadManager | 48 // Must be called on the UI thread. Note that the DownloadManager |
49 // retains ownership. | 49 // retains ownership. |
50 virtual void CreateSavePackageDownloadItem( | 50 virtual void CreateSavePackageDownloadItem( |
51 const base::FilePath& main_file_path, | 51 const base::FilePath& main_file_path, |
52 const GURL& page_url, | 52 const GURL& page_url, |
53 const std::string& mime_type, | 53 const std::string& mime_type, |
54 scoped_ptr<DownloadRequestHandleInterface> request_handle, | 54 scoped_ptr<DownloadRequestHandleInterface> request_handle, |
55 const DownloadItemImplCreated& item_created); | 55 const DownloadItemImplCreated& item_created); |
56 | 56 |
57 // Notifies DownloadManager about a successful completion of |download_item|. | 57 // Notifies DownloadManager about a successful completion of |download_item|. |
58 void OnSavePackageSuccessfullyFinished(DownloadItem* download_item); | 58 void OnSavePackageSuccessfullyFinished(DownloadItem* download_item); |
59 | 59 |
60 // DownloadManager functions. | 60 // DownloadManager functions. |
61 virtual void SetDelegate(DownloadManagerDelegate* delegate) override; | 61 void SetDelegate(DownloadManagerDelegate* delegate) override; |
62 virtual DownloadManagerDelegate* GetDelegate() const override; | 62 DownloadManagerDelegate* GetDelegate() const override; |
63 virtual void Shutdown() override; | 63 void Shutdown() override; |
64 virtual void GetAllDownloads(DownloadVector* result) override; | 64 void GetAllDownloads(DownloadVector* result) override; |
65 virtual void StartDownload( | 65 void StartDownload( |
66 scoped_ptr<DownloadCreateInfo> info, | 66 scoped_ptr<DownloadCreateInfo> info, |
67 scoped_ptr<ByteStreamReader> stream, | 67 scoped_ptr<ByteStreamReader> stream, |
68 const DownloadUrlParameters::OnStartedCallback& on_started) override; | 68 const DownloadUrlParameters::OnStartedCallback& on_started) override; |
69 virtual int RemoveDownloadsBetween(base::Time remove_begin, | 69 int RemoveDownloadsBetween(base::Time remove_begin, |
70 base::Time remove_end) override; | 70 base::Time remove_end) override; |
71 virtual int RemoveDownloads(base::Time remove_begin) override; | 71 int RemoveDownloads(base::Time remove_begin) override; |
72 virtual int RemoveAllDownloads() override; | 72 int RemoveAllDownloads() override; |
73 virtual void DownloadUrl(scoped_ptr<DownloadUrlParameters> params) override; | 73 void DownloadUrl(scoped_ptr<DownloadUrlParameters> params) override; |
74 virtual void AddObserver(Observer* observer) override; | 74 void AddObserver(Observer* observer) override; |
75 virtual void RemoveObserver(Observer* observer) override; | 75 void RemoveObserver(Observer* observer) override; |
76 virtual content::DownloadItem* CreateDownloadItem( | 76 content::DownloadItem* CreateDownloadItem( |
77 uint32 id, | 77 uint32 id, |
78 const base::FilePath& current_path, | 78 const base::FilePath& current_path, |
79 const base::FilePath& target_path, | 79 const base::FilePath& target_path, |
80 const std::vector<GURL>& url_chain, | 80 const std::vector<GURL>& url_chain, |
81 const GURL& referrer_url, | 81 const GURL& referrer_url, |
82 const std::string& mime_type, | 82 const std::string& mime_type, |
83 const std::string& original_mime_type, | 83 const std::string& original_mime_type, |
84 const base::Time& start_time, | 84 const base::Time& start_time, |
85 const base::Time& end_time, | 85 const base::Time& end_time, |
86 const std::string& etag, | 86 const std::string& etag, |
87 const std::string& last_modified, | 87 const std::string& last_modified, |
88 int64 received_bytes, | 88 int64 received_bytes, |
89 int64 total_bytes, | 89 int64 total_bytes, |
90 content::DownloadItem::DownloadState state, | 90 content::DownloadItem::DownloadState state, |
91 DownloadDangerType danger_type, | 91 DownloadDangerType danger_type, |
92 DownloadInterruptReason interrupt_reason, | 92 DownloadInterruptReason interrupt_reason, |
93 bool opened) override; | 93 bool opened) override; |
94 virtual int InProgressCount() const override; | 94 int InProgressCount() const override; |
95 virtual int NonMaliciousInProgressCount() const override; | 95 int NonMaliciousInProgressCount() const override; |
96 virtual BrowserContext* GetBrowserContext() const override; | 96 BrowserContext* GetBrowserContext() const override; |
97 virtual void CheckForHistoryFilesRemoval() override; | 97 void CheckForHistoryFilesRemoval() override; |
98 virtual DownloadItem* GetDownload(uint32 id) override; | 98 DownloadItem* GetDownload(uint32 id) override; |
99 | 99 |
100 // For testing; specifically, accessed from TestFileErrorInjector. | 100 // For testing; specifically, accessed from TestFileErrorInjector. |
101 void SetDownloadItemFactoryForTesting( | 101 void SetDownloadItemFactoryForTesting( |
102 scoped_ptr<DownloadItemFactory> item_factory); | 102 scoped_ptr<DownloadItemFactory> item_factory); |
103 void SetDownloadFileFactoryForTesting( | 103 void SetDownloadFileFactoryForTesting( |
104 scoped_ptr<DownloadFileFactory> file_factory); | 104 scoped_ptr<DownloadFileFactory> file_factory); |
105 virtual DownloadFileFactory* GetDownloadFileFactoryForTesting(); | 105 virtual DownloadFileFactory* GetDownloadFileFactoryForTesting(); |
106 | 106 |
107 private: | 107 private: |
108 typedef std::set<DownloadItem*> DownloadSet; | 108 typedef std::set<DownloadItem*> DownloadSet; |
(...skipping 28 matching lines...) Expand all Loading... |
137 // be called synchronously. | 137 // be called synchronously. |
138 void GetNextId(const DownloadIdCallback& callback); | 138 void GetNextId(const DownloadIdCallback& callback); |
139 | 139 |
140 // Called with the result of DownloadManagerDelegate::CheckForFileExistence. | 140 // Called with the result of DownloadManagerDelegate::CheckForFileExistence. |
141 // Updates the state of the file and then notifies this update to the file's | 141 // Updates the state of the file and then notifies this update to the file's |
142 // observer. | 142 // observer. |
143 void OnFileExistenceChecked(uint32 download_id, bool result); | 143 void OnFileExistenceChecked(uint32 download_id, bool result); |
144 | 144 |
145 // Overridden from DownloadItemImplDelegate | 145 // Overridden from DownloadItemImplDelegate |
146 // (Note that |GetBrowserContext| are present in both interfaces.) | 146 // (Note that |GetBrowserContext| are present in both interfaces.) |
147 virtual void DetermineDownloadTarget( | 147 void DetermineDownloadTarget(DownloadItemImpl* item, |
148 DownloadItemImpl* item, const DownloadTargetCallback& callback) override; | 148 const DownloadTargetCallback& callback) override; |
149 virtual bool ShouldCompleteDownload( | 149 bool ShouldCompleteDownload(DownloadItemImpl* item, |
150 DownloadItemImpl* item, const base::Closure& complete_callback) override; | 150 const base::Closure& complete_callback) override; |
151 virtual bool ShouldOpenFileBasedOnExtension( | 151 bool ShouldOpenFileBasedOnExtension(const base::FilePath& path) override; |
152 const base::FilePath& path) override; | 152 bool ShouldOpenDownload(DownloadItemImpl* item, |
153 virtual bool ShouldOpenDownload( | 153 const ShouldOpenDownloadCallback& callback) override; |
154 DownloadItemImpl* item, | 154 void CheckForFileRemoval(DownloadItemImpl* download_item) override; |
155 const ShouldOpenDownloadCallback& callback) override; | 155 void ResumeInterruptedDownload( |
156 virtual void CheckForFileRemoval(DownloadItemImpl* download_item) override; | |
157 virtual void ResumeInterruptedDownload( | |
158 scoped_ptr<content::DownloadUrlParameters> params, | 156 scoped_ptr<content::DownloadUrlParameters> params, |
159 uint32 id) override; | 157 uint32 id) override; |
160 virtual void OpenDownload(DownloadItemImpl* download) override; | 158 void OpenDownload(DownloadItemImpl* download) override; |
161 virtual void ShowDownloadInShell(DownloadItemImpl* download) override; | 159 void ShowDownloadInShell(DownloadItemImpl* download) override; |
162 virtual void DownloadRemoved(DownloadItemImpl* download) override; | 160 void DownloadRemoved(DownloadItemImpl* download) override; |
163 | 161 |
164 // Factory for creation of downloads items. | 162 // Factory for creation of downloads items. |
165 scoped_ptr<DownloadItemFactory> item_factory_; | 163 scoped_ptr<DownloadItemFactory> item_factory_; |
166 | 164 |
167 // Factory for the creation of download files. | 165 // Factory for the creation of download files. |
168 scoped_ptr<DownloadFileFactory> file_factory_; | 166 scoped_ptr<DownloadFileFactory> file_factory_; |
169 | 167 |
170 // |downloads_| is the owning set for all downloads known to the | 168 // |downloads_| is the owning set for all downloads known to the |
171 // DownloadManager. This includes downloads started by the user in | 169 // DownloadManager. This includes downloads started by the user in |
172 // this session, downloads initialized from the history system, and | 170 // this session, downloads initialized from the history system, and |
(...skipping 17 matching lines...) Expand all Loading... |
190 net::NetLog* net_log_; | 188 net::NetLog* net_log_; |
191 | 189 |
192 base::WeakPtrFactory<DownloadManagerImpl> weak_factory_; | 190 base::WeakPtrFactory<DownloadManagerImpl> weak_factory_; |
193 | 191 |
194 DISALLOW_COPY_AND_ASSIGN(DownloadManagerImpl); | 192 DISALLOW_COPY_AND_ASSIGN(DownloadManagerImpl); |
195 }; | 193 }; |
196 | 194 |
197 } // namespace content | 195 } // namespace content |
198 | 196 |
199 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ | 197 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_IMPL_H_ |
OLD | NEW |