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

Side by Side Diff: chrome/browser/download/download_file.h

Issue 342020: First of several patches to get rid of MessageLoop caching now that we have C... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 // Objects that handle file operations for downloads, on the download thread. 5 // Objects that handle file operations for downloads, on the download thread.
6 // 6 //
7 // The DownloadFileManager owns a set of DownloadFile objects, each of which 7 // The DownloadFileManager owns a set of DownloadFile objects, each of which
8 // represent one in progress download and performs the disk IO for that 8 // represent one in progress download and performs the disk IO for that
9 // download. The DownloadFileManager itself is a singleton object owned by the 9 // download. The DownloadFileManager itself is a singleton object owned by the
10 // ResourceDispatcherHost. 10 // ResourceDispatcherHost.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 #include "base/ref_counted.h" 53 #include "base/ref_counted.h"
54 #include "base/timer.h" 54 #include "base/timer.h"
55 #include "chrome/browser/power_save_blocker.h" 55 #include "chrome/browser/power_save_blocker.h"
56 #include "googleurl/src/gurl.h" 56 #include "googleurl/src/gurl.h"
57 57
58 namespace net { 58 namespace net {
59 class IOBuffer; 59 class IOBuffer;
60 } 60 }
61 struct DownloadCreateInfo; 61 struct DownloadCreateInfo;
62 class DownloadManager; 62 class DownloadManager;
63 class MessageLoop;
64 class ResourceDispatcherHost; 63 class ResourceDispatcherHost;
65 class URLRequestContextGetter; 64 class URLRequestContextGetter;
66 65
67 // DownloadBuffer -------------------------------------------------------------- 66 // DownloadBuffer --------------------------------------------------------------
68 67
69 // This container is created and populated on the io_thread, and passed to the 68 // This container is created and populated on the io_thread, and passed to the
70 // file_thread for writing. In order to avoid flooding the file_thread with too 69 // file_thread for writing. In order to avoid flooding the file_thread with too
71 // many small write messages, each write is appended to the DownloadBuffer while 70 // many small write messages, each write is appended to the DownloadBuffer while
72 // waiting for the task to run on the file_thread. Access to the write buffers 71 // waiting for the task to run on the file_thread. Access to the write buffers
73 // is synchronized via the lock. Each entry in 'contents' represents one data 72 // is synchronized via the lock. Each entry in 'contents' represents one data
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 DISALLOW_COPY_AND_ASSIGN(DownloadFile); 160 DISALLOW_COPY_AND_ASSIGN(DownloadFile);
162 }; 161 };
163 162
164 163
165 // DownloadFileManager --------------------------------------------------------- 164 // DownloadFileManager ---------------------------------------------------------
166 165
167 // Manages all in progress downloads. 166 // Manages all in progress downloads.
168 class DownloadFileManager 167 class DownloadFileManager
169 : public base::RefCountedThreadSafe<DownloadFileManager> { 168 : public base::RefCountedThreadSafe<DownloadFileManager> {
170 public: 169 public:
171 DownloadFileManager(MessageLoop* ui_loop, ResourceDispatcherHost* rdh); 170 DownloadFileManager(ResourceDispatcherHost* rdh);
172 ~DownloadFileManager(); 171 ~DownloadFileManager();
173 172
174 // Lifetime management functions, called on the UI thread. 173 // Called on shutdown on the UI thread.
175 void Initialize();
176 void Shutdown(); 174 void Shutdown();
177 175
178 // Called on the IO thread 176 // Called on the IO thread
179 int GetNextId(); 177 int GetNextId();
180 178
181 // Handlers for notifications sent from the IO thread and run on the 179 // Handlers for notifications sent from the IO thread and run on the
182 // download thread. 180 // download thread.
183 void StartDownload(DownloadCreateInfo* info); 181 void StartDownload(DownloadCreateInfo* info);
184 void UpdateDownload(int id, DownloadBuffer* buffer); 182 void UpdateDownload(int id, DownloadBuffer* buffer);
185 void CancelDownload(int id); 183 void CancelDownload(int id);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 #endif 223 #endif
226 224
227 // The download manager has provided a final name for a download. Sent from 225 // The download manager has provided a final name for a download. Sent from
228 // the UI thread and run on the download thread. 226 // the UI thread and run on the download thread.
229 void OnFinalDownloadName(int id, const FilePath& full_path, 227 void OnFinalDownloadName(int id, const FilePath& full_path,
230 DownloadManager* download_manager); 228 DownloadManager* download_manager);
231 229
232 // Timer notifications. 230 // Timer notifications.
233 void UpdateInProgressDownloads(); 231 void UpdateInProgressDownloads();
234 232
235 MessageLoop* file_loop() const { return file_loop_; }
236
237 // Called by the download manager to delete non validated dangerous downloads. 233 // Called by the download manager to delete non validated dangerous downloads.
238 static void DeleteFile(const FilePath& path); 234 static void DeleteFile(const FilePath& path);
239 235
240 private: 236 private:
241 // Timer helpers for updating the UI about the current progress of a download. 237 // Timer helpers for updating the UI about the current progress of a download.
242 void StartUpdateTimer(); 238 void StartUpdateTimer();
243 void StopUpdateTimer(); 239 void StopUpdateTimer();
244 240
245 // Clean up helper that runs on the download thread. 241 // Clean up helper that runs on the download thread.
246 void OnShutdown(); 242 void OnShutdown();
(...skipping 12 matching lines...) Expand all
259 // Unique ID for each DownloadFile. 255 // Unique ID for each DownloadFile.
260 int next_id_; 256 int next_id_;
261 257
262 // A map of all in progress downloads. 258 // A map of all in progress downloads.
263 typedef base::hash_map<int, DownloadFile*> DownloadFileMap; 259 typedef base::hash_map<int, DownloadFile*> DownloadFileMap;
264 DownloadFileMap downloads_; 260 DownloadFileMap downloads_;
265 261
266 // Throttle updates to the UI thread. 262 // Throttle updates to the UI thread.
267 base::RepeatingTimer<DownloadFileManager> update_timer_; 263 base::RepeatingTimer<DownloadFileManager> update_timer_;
268 264
269 // The MessageLoop that the DownloadManagers live on.
270 MessageLoop* ui_loop_;
271
272 // The MessageLoop that the this objects primarily operates on.
273 MessageLoop* file_loop_;
274
275 // Used only for DCHECKs!
276 MessageLoop* io_loop_;
277
278 ResourceDispatcherHost* resource_dispatcher_host_; 265 ResourceDispatcherHost* resource_dispatcher_host_;
279 266
280 // Tracking which DownloadManager to send data to, called only on UI thread. 267 // Tracking which DownloadManager to send data to, called only on UI thread.
281 // DownloadManagerMap maps download IDs to their DownloadManager. 268 // DownloadManagerMap maps download IDs to their DownloadManager.
282 typedef base::hash_map<int, DownloadManager*> DownloadManagerMap; 269 typedef base::hash_map<int, DownloadManager*> DownloadManagerMap;
283 DownloadManagerMap managers_; 270 DownloadManagerMap managers_;
284 271
285 // RequestMap maps a DownloadManager to all in-progress download IDs. 272 // RequestMap maps a DownloadManager to all in-progress download IDs.
286 // Called only on the UI thread. 273 // Called only on the UI thread.
287 typedef base::hash_set<int> DownloadRequests; 274 typedef base::hash_set<int> DownloadRequests;
288 typedef std::map<DownloadManager*, DownloadRequests> RequestMap; 275 typedef std::map<DownloadManager*, DownloadRequests> RequestMap;
289 RequestMap requests_; 276 RequestMap requests_;
290 277
291 // Used for progress updates on the UI thread, mapping download->id() to bytes 278 // Used for progress updates on the UI thread, mapping download->id() to bytes
292 // received so far. Written to by the file thread and read by the UI thread. 279 // received so far. Written to by the file thread and read by the UI thread.
293 typedef base::hash_map<int, int64> ProgressMap; 280 typedef base::hash_map<int, int64> ProgressMap;
294 ProgressMap ui_progress_; 281 ProgressMap ui_progress_;
295 Lock progress_lock_; 282 Lock progress_lock_;
296 283
297 DISALLOW_COPY_AND_ASSIGN(DownloadFileManager); 284 DISALLOW_COPY_AND_ASSIGN(DownloadFileManager);
298 }; 285 };
299 286
300 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ 287 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698