Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: content/browser/download/download_file_manager.h

Issue 10392111: Use ByteStream in downloads system to decouple source and sink. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync'd to LKGR. Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 #include "content/public/browser/download_id.h" 54 #include "content/public/browser/download_id.h"
55 #include "content/public/browser/download_interrupt_reasons.h" 55 #include "content/public/browser/download_interrupt_reasons.h"
56 #include "net/base/net_errors.h" 56 #include "net/base/net_errors.h"
57 #include "ui/gfx/native_widget_types.h" 57 #include "ui/gfx/native_widget_types.h"
58 58
59 struct DownloadCreateInfo; 59 struct DownloadCreateInfo;
60 class DownloadRequestHandle; 60 class DownloadRequestHandle;
61 class FilePath; 61 class FilePath;
62 62
63 namespace content { 63 namespace content {
64 class DownloadBuffer; 64 class ByteStreamReader;
65 class DownloadFile; 65 class DownloadFile;
66 class DownloadManager; 66 class DownloadManager;
67 } 67 }
68 68
69 namespace net { 69 namespace net {
70 class BoundNetLog; 70 class BoundNetLog;
71 } 71 }
72 72
73 // Manages all in progress downloads. 73 // Manages all in progress downloads.
74 // Methods are virtual to allow mocks--this class is not intended 74 // Methods are virtual to allow mocks--this class is not intended
75 // to be a base class. 75 // to be a base class.
76 class CONTENT_EXPORT DownloadFileManager 76 class CONTENT_EXPORT DownloadFileManager
77 : public base::RefCountedThreadSafe<DownloadFileManager> { 77 : public base::RefCountedThreadSafe<DownloadFileManager> {
78 public: 78 public:
79 // Callback used with RenameInProgressDownloadFile() and 79 // Callback used with RenameInProgressDownloadFile() and
80 // RenameCompletingDownloadFile(). 80 // RenameCompletingDownloadFile().
81 typedef base::Callback<void(const FilePath&)> RenameCompletionCallback; 81 typedef base::Callback<void(const FilePath&)> RenameCompletionCallback;
82 82
83 class DownloadFileFactory { 83 class DownloadFileFactory {
84 public: 84 public:
85 virtual ~DownloadFileFactory() {} 85 virtual ~DownloadFileFactory() {}
86 86
87 virtual content::DownloadFile* CreateFile( 87 virtual content::DownloadFile* CreateFile(
88 DownloadCreateInfo* info, 88 DownloadCreateInfo* info,
89 scoped_ptr<content::ByteStreamReader> stream,
89 const DownloadRequestHandle& request_handle, 90 const DownloadRequestHandle& request_handle,
90 content::DownloadManager* download_manager, 91 content::DownloadManager* download_manager,
91 bool calculate_hash, 92 bool calculate_hash,
92 const net::BoundNetLog& bound_net_log) = 0; 93 const net::BoundNetLog& bound_net_log) = 0;
93 }; 94 };
94 95
95 // Takes ownership of the factory. 96 // Takes ownership of the factory.
96 // Passing in a NULL for |factory| will cause a default 97 // Passing in a NULL for |factory| will cause a default
97 // |DownloadFileFactory| to be used. 98 // |DownloadFileFactory| to be used.
98 explicit DownloadFileManager(DownloadFileFactory* factory); 99 explicit DownloadFileManager(DownloadFileFactory* factory);
99 100
100 // Called on shutdown on the UI thread. 101 // Called on shutdown on the UI thread.
101 virtual void Shutdown(); 102 virtual void Shutdown();
102 103
103 // Called on UI thread to make DownloadFileManager start the download. 104 // Called on UI thread to make DownloadFileManager start the download.
104 virtual void StartDownload(DownloadCreateInfo* info, 105 virtual void StartDownload(scoped_ptr<DownloadCreateInfo> info,
106 scoped_ptr<content::ByteStreamReader> stream,
105 const DownloadRequestHandle& request_handle); 107 const DownloadRequestHandle& request_handle);
106 108
107 // Handlers for notifications sent from the IO thread and run on the
108 // FILE thread.
109 virtual void UpdateDownload(content::DownloadId global_id,
110 content::DownloadBuffer* buffer);
111
112 // |reason| is the reason for interruption, if one occurs.
113 // |security_info| contains SSL information (cert_id, cert_status,
114 // security_bits, ssl_connection_status), which can be used to
115 // fine-tune the error message. It is empty if the transaction
116 // was not performed securely.
117 virtual void OnResponseCompleted(content::DownloadId global_id,
118 content::DownloadInterruptReason reason,
119 const std::string& security_info);
120
121 // Handlers for notifications sent from the UI thread and run on the 109 // Handlers for notifications sent from the UI thread and run on the
122 // FILE thread. These are both terminal actions with respect to the 110 // FILE thread. These are both terminal actions with respect to the
123 // download file, as far as the DownloadFileManager is concerned -- if 111 // download file, as far as the DownloadFileManager is concerned -- if
124 // anything happens to the download file after they are called, it will 112 // anything happens to the download file after they are called, it will
125 // be ignored. 113 // be ignored.
126 virtual void CancelDownload(content::DownloadId id); 114 virtual void CancelDownload(content::DownloadId id);
127 virtual void CompleteDownload(content::DownloadId id); 115 virtual void CompleteDownload(content::DownloadId id);
128 116
129 // Called on FILE thread by DownloadManager at the beginning of its shutdown. 117 // Called on FILE thread by DownloadManager at the beginning of its shutdown.
130 virtual void OnDownloadManagerShutdown(content::DownloadManager* manager); 118 virtual void OnDownloadManagerShutdown(content::DownloadManager* manager);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 // Timer helpers for updating the UI about the current progress of a download. 167 // Timer helpers for updating the UI about the current progress of a download.
180 void StartUpdateTimer(); 168 void StartUpdateTimer();
181 void StopUpdateTimer(); 169 void StopUpdateTimer();
182 void UpdateInProgressDownloads(); 170 void UpdateInProgressDownloads();
183 171
184 // Clean up helper that runs on the download thread. 172 // Clean up helper that runs on the download thread.
185 void OnShutdown(); 173 void OnShutdown();
186 174
187 // Creates DownloadFile on FILE thread and continues starting the download 175 // Creates DownloadFile on FILE thread and continues starting the download
188 // process. 176 // process.
189 void CreateDownloadFile(DownloadCreateInfo* info, 177 void CreateDownloadFile(scoped_ptr<DownloadCreateInfo> info,
178 scoped_ptr<content::ByteStreamReader> stream,
190 const DownloadRequestHandle& request_handle, 179 const DownloadRequestHandle& request_handle,
191 content::DownloadManager* download_manager, 180 content::DownloadManager* download_manager,
192 bool hash_needed, 181 bool hash_needed,
193 const net::BoundNetLog& bound_net_log); 182 const net::BoundNetLog& bound_net_log);
194 183
195 // Called only on the download thread. 184 // Called only on the download thread.
196 content::DownloadFile* GetDownloadFile(content::DownloadId global_id); 185 content::DownloadFile* GetDownloadFile(content::DownloadId global_id);
197 186
198 // Called only from RenameInProgressDownloadFile and 187 // Called only from RenameInProgressDownloadFile and
199 // RenameCompletingDownloadFile on the FILE thread. 188 // RenameCompletingDownloadFile on the FILE thread.
(...skipping 10 matching lines...) Expand all
210 199
211 // A map of all in progress downloads. It owns the download files. 200 // A map of all in progress downloads. It owns the download files.
212 DownloadFileMap downloads_; 201 DownloadFileMap downloads_;
213 202
214 scoped_ptr<DownloadFileFactory> download_file_factory_; 203 scoped_ptr<DownloadFileFactory> download_file_factory_;
215 204
216 DISALLOW_COPY_AND_ASSIGN(DownloadFileManager); 205 DISALLOW_COPY_AND_ASSIGN(DownloadFileManager);
217 }; 206 };
218 207
219 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_MANAGER_H_ 208 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_MANAGER_H_
OLDNEW
« no previous file with comments | « content/browser/download/download_file_impl.cc ('k') | content/browser/download/download_file_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698