| 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 // This file contains download browser tests that are known to be runnable | 5 // This file contains download browser tests that are known to be runnable |
| 6 // in a pure content context. Over time tests should be migrated here. | 6 // in a pure content context. Over time tests should be migrated here. |
| 7 | 7 |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 // Wraps DownloadFileImpl::Rename and intercepts the return callback, | 90 // Wraps DownloadFileImpl::Rename and intercepts the return callback, |
| 91 // storing it in the factory that produced this object for later | 91 // storing it in the factory that produced this object for later |
| 92 // retrieval. | 92 // retrieval. |
| 93 virtual void Rename(const FilePath& full_path, | 93 virtual void Rename(const FilePath& full_path, |
| 94 bool overwrite_existing_file, | 94 bool overwrite_existing_file, |
| 95 const RenameCompletionCallback& callback) OVERRIDE; | 95 const RenameCompletionCallback& callback) OVERRIDE; |
| 96 | 96 |
| 97 // Wraps DownloadFileImpl::Detach and intercepts the return callback, | 97 // Wraps DownloadFileImpl::Detach and intercepts the return callback, |
| 98 // storing it in the factory that produced this object for later | 98 // storing it in the factory that produced this object for later |
| 99 // retrieval. | 99 // retrieval. |
| 100 virtual void Detach(base::Closure callback) OVERRIDE; | 100 virtual void Detach(const DetachCompletionCallback& callback) OVERRIDE; |
| 101 | 101 |
| 102 private: | 102 private: |
| 103 static void RenameCallbackWrapper( | 103 static void RenameCallbackWrapper( |
| 104 DownloadFileWithDelayFactory* factory, | 104 DownloadFileWithDelayFactory* factory, |
| 105 const RenameCompletionCallback& original_callback, | 105 const RenameCompletionCallback& original_callback, |
| 106 DownloadInterruptReason reason, | 106 DownloadInterruptReason reason, |
| 107 const FilePath& path); | 107 const FilePath& path); |
| 108 | 108 |
| 109 static void DetachCallbackWrapper( | 109 static void DetachCallbackWrapper( |
| 110 DownloadFileWithDelayFactory* factory, | 110 DownloadFileWithDelayFactory* factory, |
| 111 const base::Closure& original_callback); | 111 const DetachCompletionCallback& original_callback, |
| 112 DownloadInterruptReason interrupt_reason); |
| 112 | 113 |
| 113 // This variable may only be read on the FILE thread, and may only be | 114 // This variable may only be read on the FILE thread, and may only be |
| 114 // indirected through (e.g. methods on DownloadFileWithDelayFactory called) | 115 // indirected through (e.g. methods on DownloadFileWithDelayFactory called) |
| 115 // on the UI thread. This is because after construction, | 116 // on the UI thread. This is because after construction, |
| 116 // DownloadFileWithDelay lives on the file thread, but | 117 // DownloadFileWithDelay lives on the file thread, but |
| 117 // DownloadFileWithDelayFactory is purely a UI thread object. | 118 // DownloadFileWithDelayFactory is purely a UI thread object. |
| 118 base::WeakPtr<DownloadFileWithDelayFactory> owner_; | 119 base::WeakPtr<DownloadFileWithDelayFactory> owner_; |
| 119 | 120 |
| 120 DISALLOW_COPY_AND_ASSIGN(DownloadFileWithDelay); | 121 DISALLOW_COPY_AND_ASSIGN(DownloadFileWithDelay); |
| 121 }; | 122 }; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 void DownloadFileWithDelay::Rename(const FilePath& full_path, | 180 void DownloadFileWithDelay::Rename(const FilePath& full_path, |
| 180 bool overwrite_existing_file, | 181 bool overwrite_existing_file, |
| 181 const RenameCompletionCallback& callback) { | 182 const RenameCompletionCallback& callback) { |
| 182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 183 DownloadFileImpl::Rename( | 184 DownloadFileImpl::Rename( |
| 184 full_path, overwrite_existing_file, | 185 full_path, overwrite_existing_file, |
| 185 base::Bind(DownloadFileWithDelay::RenameCallbackWrapper, | 186 base::Bind(DownloadFileWithDelay::RenameCallbackWrapper, |
| 186 owner_, callback)); | 187 owner_, callback)); |
| 187 } | 188 } |
| 188 | 189 |
| 189 void DownloadFileWithDelay::Detach(base::Closure callback) { | 190 void DownloadFileWithDelay::Detach(const DetachCompletionCallback& callback) { |
| 190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 191 DownloadFileImpl::Detach( | 192 DownloadFileImpl::Detach( |
| 192 base::Bind(DownloadFileWithDelay::DetachCallbackWrapper, | 193 base::Bind(DownloadFileWithDelay::DetachCallbackWrapper, |
| 193 owner_, callback)); | 194 owner_, callback)); |
| 194 } | 195 } |
| 195 | 196 |
| 196 // static | 197 // static |
| 197 void DownloadFileWithDelay::RenameCallbackWrapper( | 198 void DownloadFileWithDelay::RenameCallbackWrapper( |
| 198 DownloadFileWithDelayFactory* factory, | 199 DownloadFileWithDelayFactory* factory, |
| 199 const RenameCompletionCallback& original_callback, | 200 const RenameCompletionCallback& original_callback, |
| 200 DownloadInterruptReason reason, | 201 DownloadInterruptReason reason, |
| 201 const FilePath& path) { | 202 const FilePath& path) { |
| 202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 203 factory->AddRenameCallback(base::Bind(original_callback, reason, path)); | 204 factory->AddRenameCallback(base::Bind(original_callback, reason, path)); |
| 204 } | 205 } |
| 205 | 206 |
| 206 // static | 207 // static |
| 207 void DownloadFileWithDelay::DetachCallbackWrapper( | 208 void DownloadFileWithDelay::DetachCallbackWrapper( |
| 208 DownloadFileWithDelayFactory* factory, | 209 DownloadFileWithDelayFactory* factory, |
| 209 const base::Closure& original_callback) { | 210 const DetachCompletionCallback& original_callback, |
| 211 DownloadInterruptReason interrupt_reason) { |
| 210 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 212 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 211 factory->AddDetachCallback(original_callback); | 213 factory->AddDetachCallback(base::Bind(original_callback, interrupt_reason)); |
| 212 } | 214 } |
| 213 | 215 |
| 214 DownloadFileWithDelayFactory::DownloadFileWithDelayFactory() | 216 DownloadFileWithDelayFactory::DownloadFileWithDelayFactory() |
| 215 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 217 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 216 waiting_(false) {} | 218 waiting_(false) {} |
| 217 DownloadFileWithDelayFactory::~DownloadFileWithDelayFactory() {} | 219 DownloadFileWithDelayFactory::~DownloadFileWithDelayFactory() {} |
| 218 | 220 |
| 219 DownloadFile* DownloadFileWithDelayFactory::CreateFile( | 221 DownloadFile* DownloadFileWithDelayFactory::CreateFile( |
| 220 scoped_ptr<DownloadSaveInfo> save_info, | 222 scoped_ptr<DownloadSaveInfo> save_info, |
| 221 const FilePath& default_download_directory, | 223 const FilePath& default_download_directory, |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 // Shutdown the download manager. Mostly this is confirming a lack of | 765 // Shutdown the download manager. Mostly this is confirming a lack of |
| 764 // crashes. | 766 // crashes. |
| 765 DownloadManagerForShell(shell())->Shutdown(); | 767 DownloadManagerForShell(shell())->Shutdown(); |
| 766 | 768 |
| 767 // Run the detach callback; shouldn't cause any problems. | 769 // Run the detach callback; shouldn't cause any problems. |
| 768 callbacks[0].Run(); | 770 callbacks[0].Run(); |
| 769 callbacks.clear(); | 771 callbacks.clear(); |
| 770 } | 772 } |
| 771 | 773 |
| 772 } // namespace content | 774 } // namespace content |
| OLD | NEW |