| OLD | NEW |
| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 public: | 79 public: |
| 80 // Callback used with CreateDownloadFile(). |reason| will be | 80 // Callback used with CreateDownloadFile(). |reason| will be |
| 81 // DOWNLOAD_INTERRUPT_REASON_NONE on a successful creation. | 81 // DOWNLOAD_INTERRUPT_REASON_NONE on a successful creation. |
| 82 typedef base::Callback<void(content::DownloadInterruptReason reason)> | 82 typedef base::Callback<void(content::DownloadInterruptReason reason)> |
| 83 CreateDownloadFileCallback; | 83 CreateDownloadFileCallback; |
| 84 | 84 |
| 85 // Callback used with RenameDownloadFile(). | 85 // Callback used with RenameDownloadFile(). |
| 86 typedef content::DownloadFile::RenameCompletionCallback | 86 typedef content::DownloadFile::RenameCompletionCallback |
| 87 RenameCompletionCallback; | 87 RenameCompletionCallback; |
| 88 | 88 |
| 89 // Callback used with CompleteDownload(). |
| 90 typedef content::DownloadFile::DetachCompletionCallback |
| 91 CompleteCompletionCallback; |
| 92 |
| 89 // Takes ownership of the factory. | 93 // Takes ownership of the factory. |
| 90 // Passing in a NULL for |factory| will cause a default | 94 // Passing in a NULL for |factory| will cause a default |
| 91 // |DownloadFileFactory| to be used. | 95 // |DownloadFileFactory| to be used. |
| 92 explicit DownloadFileManager(content::DownloadFileFactory* factory); | 96 explicit DownloadFileManager(content::DownloadFileFactory* factory); |
| 93 | 97 |
| 94 // Create a download file and record it in the download file manager. | 98 // Create a download file and record it in the download file manager. |
| 95 virtual void CreateDownloadFile( | 99 virtual void CreateDownloadFile( |
| 96 scoped_ptr<DownloadCreateInfo> info, | 100 scoped_ptr<DownloadCreateInfo> info, |
| 97 scoped_ptr<content::ByteStreamReader> stream, | 101 scoped_ptr<content::ByteStreamReader> stream, |
| 98 scoped_refptr<content::DownloadManager> download_manager, | 102 scoped_refptr<content::DownloadManager> download_manager, |
| 99 bool hash_needed, | 103 bool hash_needed, |
| 100 const net::BoundNetLog& bound_net_log, | 104 const net::BoundNetLog& bound_net_log, |
| 101 const CreateDownloadFileCallback& callback); | 105 const CreateDownloadFileCallback& callback); |
| 102 | 106 |
| 103 // Called on shutdown on the UI thread. | 107 // Called on shutdown on the UI thread. |
| 104 virtual void Shutdown(); | 108 virtual void Shutdown(); |
| 105 | 109 |
| 106 // Handlers for notifications sent from the UI thread and run on the | 110 // Handlers for notifications sent from the UI thread and run on the |
| 107 // FILE thread. These are both terminal actions with respect to the | 111 // FILE thread. These are both terminal actions with respect to the |
| 108 // download file, as far as the DownloadFileManager is concerned -- if | 112 // download file, as far as the DownloadFileManager is concerned -- if |
| 109 // anything happens to the download file after they are called, it will | 113 // anything happens to the download file after they are called, it will |
| 110 // be ignored. | 114 // be ignored. |
| 111 // We call back to the UI thread in the case of CompleteDownload so that | 115 // We call back to the UI thread in the case of CompleteDownload so that |
| 112 // we know when we can hand the file off to other consumers. | 116 // we know when we can hand the file off to other consumers. |
| 113 virtual void CancelDownload(content::DownloadId id); | 117 virtual void CancelDownload(content::DownloadId id); |
| 114 virtual void CompleteDownload(content::DownloadId id, | 118 virtual void CompleteDownload(content::DownloadId id, |
| 115 const base::Closure& callback); | 119 const CompleteCompletionCallback& callback); |
| 116 | 120 |
| 117 // Called on FILE thread by DownloadManager at the beginning of its shutdown. | 121 // Called on FILE thread by DownloadManager at the beginning of its shutdown. |
| 118 virtual void OnDownloadManagerShutdown(content::DownloadManager* manager); | 122 virtual void OnDownloadManagerShutdown(content::DownloadManager* manager); |
| 119 | 123 |
| 120 // Rename the download file, uniquifying if overwrite was not requested. | 124 // Rename the download file, uniquifying if overwrite was not requested. |
| 121 virtual void RenameDownloadFile( | 125 virtual void RenameDownloadFile( |
| 122 content::DownloadId id, | 126 content::DownloadId id, |
| 123 const FilePath& full_path, | 127 const FilePath& full_path, |
| 124 bool overwrite_existing_file, | 128 bool overwrite_existing_file, |
| 125 const RenameCompletionCallback& callback); | 129 const RenameCompletionCallback& callback); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 | 165 |
| 162 // A map of all in progress downloads. It owns the download files. | 166 // A map of all in progress downloads. It owns the download files. |
| 163 DownloadFileMap downloads_; | 167 DownloadFileMap downloads_; |
| 164 | 168 |
| 165 scoped_ptr<content::DownloadFileFactory> download_file_factory_; | 169 scoped_ptr<content::DownloadFileFactory> download_file_factory_; |
| 166 | 170 |
| 167 DISALLOW_COPY_AND_ASSIGN(DownloadFileManager); | 171 DISALLOW_COPY_AND_ASSIGN(DownloadFileManager); |
| 168 }; | 172 }; |
| 169 | 173 |
| 170 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_MANAGER_H_ | 174 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_MANAGER_H_ |
| OLD | NEW |