OLD | NEW |
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 #include <vector> | 45 #include <vector> |
46 | 46 |
47 #include "base/basictypes.h" | 47 #include "base/basictypes.h" |
48 #include "base/hash_tables.h" | 48 #include "base/hash_tables.h" |
49 #include "base/lock.h" | 49 #include "base/lock.h" |
50 #include "base/ref_counted.h" | 50 #include "base/ref_counted.h" |
51 #include "base/thread.h" | 51 #include "base/thread.h" |
52 #include "base/timer.h" | 52 #include "base/timer.h" |
53 #include "chrome/browser/history/download_types.h" | 53 #include "chrome/browser/history/download_types.h" |
54 | 54 |
| 55 namespace net { |
| 56 class IOBuffer; |
| 57 } |
55 class DownloadManager; | 58 class DownloadManager; |
56 class FilePath; | 59 class FilePath; |
57 class GURL; | 60 class GURL; |
58 class MessageLoop; | 61 class MessageLoop; |
59 class ResourceDispatcherHost; | 62 class ResourceDispatcherHost; |
60 class URLRequestContext; | 63 class URLRequestContext; |
61 | 64 |
62 // DownloadBuffer -------------------------------------------------------------- | 65 // DownloadBuffer -------------------------------------------------------------- |
63 | 66 |
64 // This container is created and populated on the io_thread, and passed to the | 67 // This container is created and populated on the io_thread, and passed to the |
65 // file_thread for writing. In order to avoid flooding the file_thread with too | 68 // file_thread for writing. In order to avoid flooding the file_thread with too |
66 // many small write messages, each write is appended to the DownloadBuffer while | 69 // many small write messages, each write is appended to the DownloadBuffer while |
67 // waiting for the task to run on the file_thread. Access to the write buffers | 70 // waiting for the task to run on the file_thread. Access to the write buffers |
68 // is synchronized via the lock. Each entry in 'contents' represents one data | 71 // is synchronized via the lock. Each entry in 'contents' represents one data |
69 // buffer and its size in bytes. | 72 // buffer and its size in bytes. |
70 | 73 |
71 struct DownloadBuffer { | 74 struct DownloadBuffer { |
72 Lock lock; | 75 Lock lock; |
73 typedef std::pair<char *, int> Contents; | 76 typedef std::pair<net::IOBuffer*, int> Contents; |
74 std::vector<Contents> contents; | 77 std::vector<Contents> contents; |
75 }; | 78 }; |
76 | 79 |
77 // DownloadFile ---------------------------------------------------------------- | 80 // DownloadFile ---------------------------------------------------------------- |
78 | 81 |
79 // These objects live exclusively on the download thread and handle the writing | 82 // These objects live exclusively on the download thread and handle the writing |
80 // operations for one download. These objects live only for the duration that | 83 // operations for one download. These objects live only for the duration that |
81 // the download is 'in progress': once the download has been completed or | 84 // the download is 'in progress': once the download has been completed or |
82 // cancelled, the DownloadFile is destroyed. | 85 // cancelled, the DownloadFile is destroyed. |
83 class DownloadFile { | 86 class DownloadFile { |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 // Used for progress updates on the UI thread, mapping download->id() to bytes | 267 // Used for progress updates on the UI thread, mapping download->id() to bytes |
265 // received so far. Written to by the file thread and read by the UI thread. | 268 // received so far. Written to by the file thread and read by the UI thread. |
266 typedef base::hash_map<int, int64> ProgressMap; | 269 typedef base::hash_map<int, int64> ProgressMap; |
267 ProgressMap ui_progress_; | 270 ProgressMap ui_progress_; |
268 Lock progress_lock_; | 271 Lock progress_lock_; |
269 | 272 |
270 DISALLOW_EVIL_CONSTRUCTORS(DownloadFileManager); | 273 DISALLOW_EVIL_CONSTRUCTORS(DownloadFileManager); |
271 }; | 274 }; |
272 | 275 |
273 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H__ | 276 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H__ |
OLD | NEW |