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 // The DownloadFileManager owns a set of DownloadFile objects, each of which | 5 // The DownloadFileManager owns a set of DownloadFile objects, each of which |
6 // represent one in progress download and performs the disk IO for that | 6 // represent one in progress download and performs the disk IO for that |
7 // download. The DownloadFileManager itself is a singleton object owned by the | 7 // download. The DownloadFileManager itself is a singleton object owned by the |
8 // ResourceDispatcherHostImpl. | 8 // ResourceDispatcherHostImpl. |
9 // | 9 // |
10 // The DownloadFileManager uses the file_thread for performing file write | 10 // The DownloadFileManager uses the file_thread for performing file write |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 #include "content/public/browser/download_id.h" | 53 #include "content/public/browser/download_id.h" |
54 #include "content/public/browser/download_interrupt_reasons.h" | 54 #include "content/public/browser/download_interrupt_reasons.h" |
55 #include "net/base/net_errors.h" | 55 #include "net/base/net_errors.h" |
56 #include "ui/gfx/native_widget_types.h" | 56 #include "ui/gfx/native_widget_types.h" |
57 | 57 |
58 struct DownloadCreateInfo; | 58 struct DownloadCreateInfo; |
59 class DownloadRequestHandle; | 59 class DownloadRequestHandle; |
60 class FilePath; | 60 class FilePath; |
61 | 61 |
62 namespace content { | 62 namespace content { |
63 class DownloadBuffer; | 63 class ByteStreamOutput; |
64 class DownloadFile; | 64 class DownloadFile; |
65 class DownloadManager; | 65 class DownloadManager; |
66 } | 66 } |
67 | 67 |
68 namespace net { | 68 namespace net { |
69 class BoundNetLog; | 69 class BoundNetLog; |
70 } | 70 } |
71 | 71 |
72 // Manages all in progress downloads. | 72 // Manages all in progress downloads. |
73 class CONTENT_EXPORT DownloadFileManager | 73 class CONTENT_EXPORT DownloadFileManager |
74 : public base::RefCountedThreadSafe<DownloadFileManager> { | 74 : public base::RefCountedThreadSafe<DownloadFileManager> { |
75 public: | 75 public: |
76 class DownloadFileFactory { | 76 class DownloadFileFactory { |
77 public: | 77 public: |
78 virtual ~DownloadFileFactory() {} | 78 virtual ~DownloadFileFactory() {} |
79 | 79 |
80 virtual content::DownloadFile* CreateFile( | 80 virtual content::DownloadFile* CreateFile( |
81 DownloadCreateInfo* info, | 81 DownloadCreateInfo* info, |
| 82 scoped_ptr<content::ByteStreamOutput> pipe, |
82 const DownloadRequestHandle& request_handle, | 83 const DownloadRequestHandle& request_handle, |
83 content::DownloadManager* download_manager, | 84 content::DownloadManager* download_manager, |
84 bool calculate_hash, | 85 bool calculate_hash, |
85 const net::BoundNetLog& bound_net_log) = 0; | 86 const net::BoundNetLog& bound_net_log) = 0; |
86 }; | 87 }; |
87 | 88 |
88 // Takes ownership of the factory. | 89 // Takes ownership of the factory. |
89 // Passing in a NULL for |factory| will cause a default | 90 // Passing in a NULL for |factory| will cause a default |
90 // |DownloadFileFactory| to be used. | 91 // |DownloadFileFactory| to be used. |
91 explicit DownloadFileManager(DownloadFileFactory* factory); | 92 explicit DownloadFileManager(DownloadFileFactory* factory); |
92 | 93 |
93 // Called on shutdown on the UI thread. | 94 // Called on shutdown on the UI thread. |
94 void Shutdown(); | 95 void Shutdown(); |
95 | 96 |
96 // Called on UI thread to make DownloadFileManager start the download. | 97 // Called on UI thread to make DownloadFileManager start the download. |
97 void StartDownload(DownloadCreateInfo* info, | 98 void StartDownload(scoped_ptr<DownloadCreateInfo> info, |
| 99 scoped_ptr<content::ByteStreamOutput> pipe, |
98 const DownloadRequestHandle& request_handle); | 100 const DownloadRequestHandle& request_handle); |
99 | 101 |
100 // Handlers for notifications sent from the IO thread and run on the | |
101 // FILE thread. | |
102 void UpdateDownload(content::DownloadId global_id, | |
103 content::DownloadBuffer* buffer); | |
104 | |
105 // |reason| is the reason for interruption, if one occurs. | |
106 // |security_info| contains SSL information (cert_id, cert_status, | |
107 // security_bits, ssl_connection_status), which can be used to | |
108 // fine-tune the error message. It is empty if the transaction | |
109 // was not performed securely. | |
110 void OnResponseCompleted(content::DownloadId global_id, | |
111 content::DownloadInterruptReason reason, | |
112 const std::string& security_info); | |
113 | |
114 // Handlers for notifications sent from the UI thread and run on the | 102 // Handlers for notifications sent from the UI thread and run on the |
115 // FILE thread. These are both terminal actions with respect to the | 103 // FILE thread. These are both terminal actions with respect to the |
116 // download file, as far as the DownloadFileManager is concerned -- if | 104 // download file, as far as the DownloadFileManager is concerned -- if |
117 // anything happens to the download file after they are called, it will | 105 // anything happens to the download file after they are called, it will |
118 // be ignored. | 106 // be ignored. |
119 void CancelDownload(content::DownloadId id); | 107 void CancelDownload(content::DownloadId id); |
120 void CompleteDownload(content::DownloadId id); | 108 void CompleteDownload(content::DownloadId id); |
121 | 109 |
122 // Called on FILE thread by DownloadManager at the beginning of its shutdown. | 110 // Called on FILE thread by DownloadManager at the beginning of its shutdown. |
123 void OnDownloadManagerShutdown(content::DownloadManager* manager); | 111 void OnDownloadManagerShutdown(content::DownloadManager* manager); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 // Timer helpers for updating the UI about the current progress of a download. | 149 // Timer helpers for updating the UI about the current progress of a download. |
162 void StartUpdateTimer(); | 150 void StartUpdateTimer(); |
163 void StopUpdateTimer(); | 151 void StopUpdateTimer(); |
164 void UpdateInProgressDownloads(); | 152 void UpdateInProgressDownloads(); |
165 | 153 |
166 // Clean up helper that runs on the download thread. | 154 // Clean up helper that runs on the download thread. |
167 void OnShutdown(); | 155 void OnShutdown(); |
168 | 156 |
169 // Creates DownloadFile on FILE thread and continues starting the download | 157 // Creates DownloadFile on FILE thread and continues starting the download |
170 // process. | 158 // process. |
171 void CreateDownloadFile(DownloadCreateInfo* info, | 159 void CreateDownloadFile(scoped_ptr<DownloadCreateInfo> info, |
| 160 scoped_ptr<content::ByteStreamOutput> pipe, |
172 const DownloadRequestHandle& request_handle, | 161 const DownloadRequestHandle& request_handle, |
173 content::DownloadManager* download_manager, | 162 content::DownloadManager* download_manager, |
174 bool hash_needed, | 163 bool hash_needed, |
175 const net::BoundNetLog& bound_net_log); | 164 const net::BoundNetLog& bound_net_log); |
176 | 165 |
177 // Called only on the download thread. | 166 // Called only on the download thread. |
178 content::DownloadFile* GetDownloadFile(content::DownloadId global_id); | 167 content::DownloadFile* GetDownloadFile(content::DownloadId global_id); |
179 | 168 |
180 // Called only from RenameInProgressDownloadFile and | 169 // Called only from RenameInProgressDownloadFile and |
181 // RenameCompletingDownloadFile on the FILE thread. | 170 // RenameCompletingDownloadFile on the FILE thread. |
(...skipping 10 matching lines...) Expand all Loading... |
192 | 181 |
193 // A map of all in progress downloads. It owns the download files. | 182 // A map of all in progress downloads. It owns the download files. |
194 DownloadFileMap downloads_; | 183 DownloadFileMap downloads_; |
195 | 184 |
196 scoped_ptr<DownloadFileFactory> download_file_factory_; | 185 scoped_ptr<DownloadFileFactory> download_file_factory_; |
197 | 186 |
198 DISALLOW_COPY_AND_ASSIGN(DownloadFileManager); | 187 DISALLOW_COPY_AND_ASSIGN(DownloadFileManager); |
199 }; | 188 }; |
200 | 189 |
201 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_MANAGER_H_ | 190 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_MANAGER_H_ |
OLD | NEW |