OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 DownloadManager object manages the process of downloading, including | 5 // The DownloadManager object manages the process of downloading, including |
6 // updates to the history system and providing the information for displaying | 6 // updates to the history system and providing the information for displaying |
7 // the downloads view in the Destinations tab. There is one DownloadManager per | 7 // the downloads view in the Destinations tab. There is one DownloadManager per |
8 // active profile in Chrome. | 8 // active profile in Chrome. |
9 // | 9 // |
10 // Download observers: | 10 // Download observers: |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 void ClearLastDownloadPath(); | 180 void ClearLastDownloadPath(); |
181 | 181 |
182 // Registers this file extension for automatic opening upon download | 182 // Registers this file extension for automatic opening upon download |
183 // completion if 'open' is true, or prevents the extension from automatic | 183 // completion if 'open' is true, or prevents the extension from automatic |
184 // opening if 'open' is false. | 184 // opening if 'open' is false. |
185 void OpenFilesBasedOnExtension(const FilePath& path, bool open); | 185 void OpenFilesBasedOnExtension(const FilePath& path, bool open); |
186 | 186 |
187 // Tests if a file type should be opened automatically. | 187 // Tests if a file type should be opened automatically. |
188 bool ShouldOpenFileBasedOnExtension(const FilePath& path) const; | 188 bool ShouldOpenFileBasedOnExtension(const FilePath& path) const; |
189 | 189 |
190 // Tests if we think the server means for this mime_type to be executable. | |
191 static bool IsExecutableMimeType(const std::string& mime_type); | |
192 | |
193 // Tests if a file is considered executable, based on its type. | 190 // Tests if a file is considered executable, based on its type. |
194 bool IsExecutableFile(const FilePath& path) const; | 191 bool IsExecutableFile(const FilePath& path) const; |
195 | 192 |
196 // Tests if a file type is considered executable. | |
197 static bool IsExecutableExtension(const FilePath::StringType& extension); | |
198 | |
199 // Resets the automatic open preference. | 193 // Resets the automatic open preference. |
200 void ResetAutoOpenFiles(); | 194 void ResetAutoOpenFiles(); |
201 | 195 |
202 // Returns true if there are automatic handlers registered for any file | 196 // Returns true if there are automatic handlers registered for any file |
203 // types. | 197 // types. |
204 bool HasAutoOpenFileTypesRegistered() const; | 198 bool HasAutoOpenFileTypesRegistered() const; |
205 | 199 |
206 // Overridden from DownloadHistory::DownloadItemMapper: | 200 // Overridden from DownloadHistory::DownloadItemMapper: |
207 virtual DownloadItem* GetDownloadItemFromDbHandle(int64 db_handle); | 201 virtual DownloadItem* GetDownloadItemFromDbHandle(int64 db_handle); |
208 | 202 |
209 // Overridden from SelectFileDialog::Listener: | 203 // Overridden from SelectFileDialog::Listener: |
210 virtual void FileSelected(const FilePath& path, int index, void* params); | 204 virtual void FileSelected(const FilePath& path, int index, void* params); |
211 virtual void FileSelectionCanceled(void* params); | 205 virtual void FileSelectionCanceled(void* params); |
212 | 206 |
213 // Deletes the specified path on the file thread. | |
214 void DeleteDownload(const FilePath& path); | |
215 | |
216 // Called when the user has validated the download of a dangerous file. | 207 // Called when the user has validated the download of a dangerous file. |
217 void DangerousDownloadValidated(DownloadItem* download); | 208 void DangerousDownloadValidated(DownloadItem* download); |
218 | 209 |
219 // Used to make sure we have a safe file extension and filename for a | |
220 // download. |file_name| can either be just the file name or it can be a | |
221 // full path to a file. | |
222 static void GenerateSafeFileName(const std::string& mime_type, | |
223 FilePath* file_name); | |
224 | |
225 // Create a file name based on the response from the server. | |
226 static void GenerateFileName(const GURL& url, | |
227 const std::string& content_disposition, | |
228 const std::string& referrer_charset, | |
229 const std::string& mime_type, | |
230 FilePath* generated_name); | |
231 | |
232 private: | 210 private: |
233 // This class is used to let an incognito DownloadManager observe changes to | 211 // This class is used to let an incognito DownloadManager observe changes to |
234 // a normal DownloadManager, to propagate ModelChanged() calls from the parent | 212 // a normal DownloadManager, to propagate ModelChanged() calls from the parent |
235 // DownloadManager to the observers of the incognito DownloadManager. | 213 // DownloadManager to the observers of the incognito DownloadManager. |
236 class OtherDownloadManagerObserver : public Observer { | 214 class OtherDownloadManagerObserver : public Observer { |
237 public: | 215 public: |
238 explicit OtherDownloadManagerObserver( | 216 explicit OtherDownloadManagerObserver( |
239 DownloadManager* observing_download_manager); | 217 DownloadManager* observing_download_manager); |
240 virtual ~OtherDownloadManagerObserver(); | 218 virtual ~OtherDownloadManagerObserver(); |
241 | 219 |
(...skipping 11 matching lines...) Expand all Loading... |
253 | 231 |
254 friend class base::RefCountedThreadSafe<DownloadManager>; | 232 friend class base::RefCountedThreadSafe<DownloadManager>; |
255 friend class OtherDownloadManagerObserver; | 233 friend class OtherDownloadManagerObserver; |
256 | 234 |
257 ~DownloadManager(); | 235 ~DownloadManager(); |
258 | 236 |
259 // Opens a download via the Windows shell. | 237 // Opens a download via the Windows shell. |
260 void OpenDownloadInShell(const DownloadItem* download, | 238 void OpenDownloadInShell(const DownloadItem* download, |
261 gfx::NativeView parent_window); | 239 gfx::NativeView parent_window); |
262 | 240 |
263 // Opens downloaded Chrome extension file (*.crx). | |
264 void OpenChromeExtension(const FilePath& full_path, | |
265 const GURL& download_url, | |
266 const GURL& referrer_url, | |
267 const std::string& original_mime_type); | |
268 | |
269 // Shutdown the download manager. This call is needed only after Init. | 241 // Shutdown the download manager. This call is needed only after Init. |
270 void Shutdown(); | 242 void Shutdown(); |
271 | 243 |
272 // Called on the download thread to check whether the suggested file path | 244 // Called on the download thread to check whether the suggested file path |
273 // exists. We don't check if the file exists on the UI thread to avoid UI | 245 // exists. We don't check if the file exists on the UI thread to avoid UI |
274 // stalls from interacting with the file system. | 246 // stalls from interacting with the file system. |
275 void CheckIfSuggestedPathExists(DownloadCreateInfo* info); | 247 void CheckIfSuggestedPathExists(DownloadCreateInfo* info); |
276 | 248 |
277 // Called on the UI thread once the DownloadManager has determined whether the | 249 // Called on the UI thread once the DownloadManager has determined whether the |
278 // suggested file path exists. | 250 // suggested file path exists. |
279 void OnPathExistenceAvailable(DownloadCreateInfo* info); | 251 void OnPathExistenceAvailable(DownloadCreateInfo* info); |
280 | 252 |
281 // Called back after a target path for the file to be downloaded to has been | 253 // Called back after a target path for the file to be downloaded to has been |
282 // determined, either automatically based on the suggested file name, or by | 254 // determined, either automatically based on the suggested file name, or by |
283 // the user in a Save As dialog box. | 255 // the user in a Save As dialog box. |
284 void ContinueStartDownload(DownloadCreateInfo* info, | 256 void ContinueStartDownload(DownloadCreateInfo* info, |
285 const FilePath& target_path); | 257 const FilePath& target_path); |
286 | 258 |
287 // Create an extension based on the file name and mime type. | |
288 static void GenerateExtension(const FilePath& file_name, | |
289 const std::string& mime_type, | |
290 FilePath::StringType* generated_extension); | |
291 | |
292 // Create a file name based on the response from the server. | |
293 static void GenerateFileNameFromInfo(DownloadCreateInfo* info, | |
294 FilePath* generated_name); | |
295 | |
296 // Persist the automatic opening preference. | 259 // Persist the automatic opening preference. |
297 void SaveAutoOpens(); | 260 void SaveAutoOpens(); |
298 | 261 |
299 // Download cancel helper function. | 262 // Download cancel helper function. |
300 void DownloadCancelledInternal(int download_id, | 263 void DownloadCancelledInternal(int download_id, |
301 int render_process_id, | 264 int render_process_id, |
302 int request_id); | 265 int request_id); |
303 | 266 |
304 // Runs the pause on the IO thread. | |
305 static void OnPauseDownloadRequest(ResourceDispatcherHost* rdh, | |
306 int render_process_id, | |
307 int request_id, | |
308 bool pause); | |
309 | |
310 // Performs the last steps required when a download has been completed. | 267 // Performs the last steps required when a download has been completed. |
311 // It is necessary to break down the flow when a download is finished as | 268 // It is necessary to break down the flow when a download is finished as |
312 // dangerous downloads are downloaded to temporary files that need to be | 269 // dangerous downloads are downloaded to temporary files that need to be |
313 // renamed on the file thread first. | 270 // renamed on the file thread first. |
314 // Invoked on the UI thread. | 271 // Invoked on the UI thread. |
315 // Marked virtual for testing. | 272 // Marked virtual for testing. |
316 virtual void ContinueDownloadFinished(DownloadItem* download); | 273 virtual void ContinueDownloadFinished(DownloadItem* download); |
317 | 274 |
318 // Renames a finished dangerous download from its temporary file name to its | 275 // Renames a finished dangerous download from its temporary file name to its |
319 // real file name. | 276 // real file name. |
320 // Invoked on the file thread. | 277 // Invoked on the file thread. |
321 void ProceedWithFinishedDangerousDownload(int64 download_handle, | 278 void ProceedWithFinishedDangerousDownload(int64 download_handle, |
322 const FilePath& path, | 279 const FilePath& path, |
323 const FilePath& original_name); | 280 const FilePath& original_name); |
324 | 281 |
325 // Invoked on the UI thread when a dangerous downloaded file has been renamed. | 282 // Invoked on the UI thread when a dangerous downloaded file has been renamed. |
326 void DangerousDownloadRenamed(int64 download_handle, | 283 void DangerousDownloadRenamed(int64 download_handle, |
327 bool success, | 284 bool success, |
328 const FilePath& new_path, | 285 const FilePath& new_path, |
329 int new_path_uniquifier); | 286 int new_path_uniquifier); |
330 | 287 |
331 // Checks whether a file represents a risk if downloaded. | |
332 bool IsDangerous(const FilePath& file_name); | |
333 | |
334 // Updates the app icon about the overall download progress. | 288 // Updates the app icon about the overall download progress. |
335 // Marked virtual for testing. | 289 // Marked virtual for testing. |
336 virtual void UpdateAppIcon(); | 290 virtual void UpdateAppIcon(); |
337 | 291 |
338 // Changes the paths and file name of the specified |download|, propagating | 292 // Changes the paths and file name of the specified |download|, propagating |
339 // the change to the history system. | 293 // the change to the history system. |
340 void RenameDownload(DownloadItem* download, const FilePath& new_path); | 294 void RenameDownload(DownloadItem* download, const FilePath& new_path); |
341 | 295 |
342 // Inform observers that the model has changed. | 296 // Inform observers that the model has changed. |
343 void NotifyModelChanged(); | 297 void NotifyModelChanged(); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 // The "Save As" dialog box used to ask the user where a file should be | 371 // The "Save As" dialog box used to ask the user where a file should be |
418 // saved. | 372 // saved. |
419 scoped_refptr<SelectFileDialog> select_file_dialog_; | 373 scoped_refptr<SelectFileDialog> select_file_dialog_; |
420 | 374 |
421 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_; | 375 scoped_ptr<OtherDownloadManagerObserver> other_download_manager_observer_; |
422 | 376 |
423 DISALLOW_COPY_AND_ASSIGN(DownloadManager); | 377 DISALLOW_COPY_AND_ASSIGN(DownloadManager); |
424 }; | 378 }; |
425 | 379 |
426 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ | 380 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_MANAGER_H_ |
OLD | NEW |