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

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

Issue 16522: Unbreak unit tests. Revert r7564. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 11 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) 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 class DownloadManager; 55 class DownloadManager;
56 class FilePath;
57 class GURL; 56 class GURL;
58 class MessageLoop; 57 class MessageLoop;
59 class ResourceDispatcherHost; 58 class ResourceDispatcherHost;
60 class URLRequestContext; 59 class URLRequestContext;
61 60
62 // DownloadBuffer -------------------------------------------------------------- 61 // DownloadBuffer --------------------------------------------------------------
63 62
64 // This container is created and populated on the io_thread, and passed to the 63 // 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 64 // 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 65 // many small write messages, each write is appended to the DownloadBuffer while
(...skipping 20 matching lines...) Expand all
87 86
88 bool Initialize(); 87 bool Initialize();
89 88
90 // Write a new chunk of data to the file. Returns true on success. 89 // Write a new chunk of data to the file. Returns true on success.
91 bool AppendDataToFile(const char* data, int data_len); 90 bool AppendDataToFile(const char* data, int data_len);
92 91
93 // Abort the download and automatically close the file. 92 // Abort the download and automatically close the file.
94 void Cancel(); 93 void Cancel();
95 94
96 // Rename the download file. Returns 'true' if the rename was successful. 95 // Rename the download file. Returns 'true' if the rename was successful.
97 bool Rename(const FilePath& full_path); 96 bool Rename(const std::wstring& full_path);
98 97
99 // Accessors. 98 // Accessors.
100 int64 bytes_so_far() const { return bytes_so_far_; } 99 int64 bytes_so_far() const { return bytes_so_far_; }
101 int id() const { return id_; } 100 int id() const { return id_; }
102 FilePath full_path() const { return full_path_; } 101 std::wstring full_path() const { return full_path_; }
103 int render_process_id() const { return render_process_id_; } 102 int render_process_id() const { return render_process_id_; }
104 int render_view_id() const { return render_view_id_; } 103 int render_view_id() const { return render_view_id_; }
105 int request_id() const { return request_id_; } 104 int request_id() const { return request_id_; }
106 bool path_renamed() const { return path_renamed_; } 105 bool path_renamed() const { return path_renamed_; }
107 bool in_progress() const { return file_ != NULL; } 106 bool in_progress() const { return file_ != NULL; }
108 void set_in_progress(bool in_progress) { in_progress_ = in_progress; } 107 void set_in_progress(bool in_progress) { in_progress_ = in_progress; }
109 108
110 private: 109 private:
111 // Open or Close the OS file handle. The file is opened in the constructor 110 // Open or Close the OS file handle. The file is opened in the constructor
112 // based on creation information passed to it, and automatically closed in 111 // based on creation information passed to it, and automatically closed in
(...skipping 13 matching lines...) Expand all
126 int render_view_id_; 125 int render_view_id_;
127 126
128 // Handle for informing the ResourceDispatcherHost of a UI based cancel. 127 // Handle for informing the ResourceDispatcherHost of a UI based cancel.
129 int request_id_; 128 int request_id_;
130 129
131 // Amount of data received up to this point. We may not know in advance how 130 // Amount of data received up to this point. We may not know in advance how
132 // much data to expect since some servers don't provide that information. 131 // much data to expect since some servers don't provide that information.
133 int64 bytes_so_far_; 132 int64 bytes_so_far_;
134 133
135 // Full path to the downloaded file. 134 // Full path to the downloaded file.
136 FilePath full_path_; 135 std::wstring full_path_;
137 136
138 // Whether the download is still using its initial temporary path. 137 // Whether the download is still using its initial temporary path.
139 bool path_renamed_; 138 bool path_renamed_;
140 139
141 // Whether the download is still receiving data. 140 // Whether the download is still receiving data.
142 bool in_progress_; 141 bool in_progress_;
143 142
144 DISALLOW_EVIL_CONSTRUCTORS(DownloadFile); 143 DISALLOW_EVIL_CONSTRUCTORS(DownloadFile);
145 }; 144 };
146 145
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 const GURL& referrer, 185 const GURL& referrer,
187 int render_process_host_id, 186 int render_process_host_id,
188 int render_view_id, 187 int render_view_id,
189 URLRequestContext* request_context); 188 URLRequestContext* request_context);
190 189
191 // Called on the UI thread to remove a download item or manager. 190 // Called on the UI thread to remove a download item or manager.
192 void RemoveDownloadManager(DownloadManager* manager); 191 void RemoveDownloadManager(DownloadManager* manager);
193 void RemoveDownload(int id, DownloadManager* manager); 192 void RemoveDownload(int id, DownloadManager* manager);
194 193
195 // Handler for shell operations sent from the UI to the download thread. 194 // Handler for shell operations sent from the UI to the download thread.
196 void OnShowDownloadInShell(const FilePath& full_path); 195 void OnShowDownloadInShell(const std::wstring full_path);
197 // Handler to open or execute a downloaded file. 196 // Handler to open or execute a downloaded file.
198 void OnOpenDownloadInShell(const FilePath& full_path, 197 void OnOpenDownloadInShell(const std::wstring full_path,
199 const std::wstring& url, HWND parent_window); 198 const std::wstring& url, HWND parent_window);
200 199
201 // The download manager has provided a final name for a download. Sent from 200 // The download manager has provided a final name for a download. Sent from
202 // the UI thread and run on the download thread. 201 // the UI thread and run on the download thread.
203 void OnFinalDownloadName(int id, const FilePath& full_path); 202 void OnFinalDownloadName(int id, const std::wstring& full_path);
204 203
205 // Timer notifications. 204 // Timer notifications.
206 void UpdateInProgressDownloads(); 205 void UpdateInProgressDownloads();
207 206
208 MessageLoop* file_loop() const { return file_loop_; } 207 MessageLoop* file_loop() const { return file_loop_; }
209 208
210 // Called by the download manager to delete non validated dangerous downloads. 209 // Called by the download manager at initialization to ensure the default
211 static void DeleteFile(const FilePath& path); 210 // download directory exists.
211 void CreateDirectory(const std::wstring& directory);
212
213 // Called by the donwload manager to delete non validated dangerous downloads.
214 void DeleteFile(const std::wstring& path);
212 215
213 private: 216 private:
214 // Timer helpers for updating the UI about the current progress of a download. 217 // Timer helpers for updating the UI about the current progress of a download.
215 void StartUpdateTimer(); 218 void StartUpdateTimer();
216 void StopUpdateTimer(); 219 void StopUpdateTimer();
217 220
218 // Clean up helper that runs on the download thread. 221 // Clean up helper that runs on the download thread.
219 void OnShutdown(); 222 void OnShutdown();
220 223
221 // Called only on UI thread to get the DownloadManager for a tab's profile. 224 // Called only on UI thread to get the DownloadManager for a tab's profile.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
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__
OLDNEW
« no previous file with comments | « chrome/browser/automation/automation_provider.cc ('k') | chrome/browser/download/download_file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698