| 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 #include "content/public/test/test_file_error_injector.h" | 5 #include "content/public/test/test_file_error_injector.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 const base::FilePath& default_download_directory, | 35 const base::FilePath& default_download_directory, |
| 36 std::unique_ptr<ByteStreamReader> byte_stream, | 36 std::unique_ptr<ByteStreamReader> byte_stream, |
| 37 const net::NetLogWithSource& net_log, | 37 const net::NetLogWithSource& net_log, |
| 38 base::WeakPtr<DownloadDestinationObserver> observer, | 38 base::WeakPtr<DownloadDestinationObserver> observer, |
| 39 const TestFileErrorInjector::FileErrorInfo& error_info, | 39 const TestFileErrorInjector::FileErrorInfo& error_info, |
| 40 const base::Closure& ctor_callback, | 40 const base::Closure& ctor_callback, |
| 41 const base::Closure& dtor_callback); | 41 const base::Closure& dtor_callback); |
| 42 | 42 |
| 43 ~DownloadFileWithError() override; | 43 ~DownloadFileWithError() override; |
| 44 | 44 |
| 45 void Initialize(const InitializeCallback& callback, | 45 void Initialize(const InitializeCallback& initialize_callback, |
| 46 const CancelRequestCallback& cancel_request_callback, |
| 46 const DownloadItem::ReceivedSlices& received_slices) override; | 47 const DownloadItem::ReceivedSlices& received_slices) override; |
| 47 | 48 |
| 48 // DownloadFile interface. | 49 // DownloadFile interface. |
| 49 DownloadInterruptReason WriteDataToFile(int64_t offset, | 50 DownloadInterruptReason WriteDataToFile(int64_t offset, |
| 50 const char* data, | 51 const char* data, |
| 51 size_t data_len) override; | 52 size_t data_len) override; |
| 52 | 53 |
| 53 void RenameAndUniquify(const base::FilePath& full_path, | 54 void RenameAndUniquify(const base::FilePath& full_path, |
| 54 const RenameCompletionCallback& callback) override; | 55 const RenameCompletionCallback& callback) override; |
| 55 void RenameAndAnnotate(const base::FilePath& full_path, | 56 void RenameAndAnnotate(const base::FilePath& full_path, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 // next DownloadFile. | 127 // next DownloadFile. |
| 127 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, ctor_callback); | 128 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, ctor_callback); |
| 128 } | 129 } |
| 129 | 130 |
| 130 DownloadFileWithError::~DownloadFileWithError() { | 131 DownloadFileWithError::~DownloadFileWithError() { |
| 131 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 132 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 132 destruction_callback_.Run(); | 133 destruction_callback_.Run(); |
| 133 } | 134 } |
| 134 | 135 |
| 135 void DownloadFileWithError::Initialize( | 136 void DownloadFileWithError::Initialize( |
| 136 const InitializeCallback& callback, | 137 const InitializeCallback& initialize_callback, |
| 138 const CancelRequestCallback& cancel_request_callback, |
| 137 const DownloadItem::ReceivedSlices& received_slices) { | 139 const DownloadItem::ReceivedSlices& received_slices) { |
| 138 DownloadInterruptReason error_to_return = DOWNLOAD_INTERRUPT_REASON_NONE; | 140 DownloadInterruptReason error_to_return = DOWNLOAD_INTERRUPT_REASON_NONE; |
| 139 InitializeCallback callback_to_use = callback; | 141 InitializeCallback callback_to_use = initialize_callback; |
| 140 | 142 |
| 141 // Replace callback if the error needs to be overwritten. | 143 // Replace callback if the error needs to be overwritten. |
| 142 if (OverwriteError( | 144 if (OverwriteError( |
| 143 TestFileErrorInjector::FILE_OPERATION_INITIALIZE, | 145 TestFileErrorInjector::FILE_OPERATION_INITIALIZE, |
| 144 &error_to_return)) { | 146 &error_to_return)) { |
| 145 if (DOWNLOAD_INTERRUPT_REASON_NONE != error_to_return) { | 147 if (DOWNLOAD_INTERRUPT_REASON_NONE != error_to_return) { |
| 146 // Don't execute a, probably successful, Initialize; just | 148 // Don't execute a, probably successful, Initialize; just |
| 147 // return the error. | 149 // return the error. |
| 148 BrowserThread::PostTask( | 150 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 149 BrowserThread::UI, FROM_HERE, base::Bind( | 151 base::Bind(initialize_callback, error_to_return)); |
| 150 callback, error_to_return)); | |
| 151 return; | 152 return; |
| 152 } | 153 } |
| 153 | 154 |
| 154 // Otherwise, just wrap the return. | 155 // Otherwise, just wrap the return. |
| 155 callback_to_use = base::Bind(&InitializeErrorCallback, callback, | 156 callback_to_use = base::Bind(&InitializeErrorCallback, initialize_callback, |
| 156 error_to_return); | 157 error_to_return); |
| 157 } | 158 } |
| 158 | 159 |
| 159 DownloadFileImpl::Initialize(callback_to_use, received_slices); | 160 DownloadFileImpl::Initialize(callback_to_use, cancel_request_callback, |
| 161 received_slices); |
| 160 } | 162 } |
| 161 | 163 |
| 162 DownloadInterruptReason DownloadFileWithError::WriteDataToFile( | 164 DownloadInterruptReason DownloadFileWithError::WriteDataToFile( |
| 163 int64_t offset, | 165 int64_t offset, |
| 164 const char* data, | 166 const char* data, |
| 165 size_t data_len) { | 167 size_t data_len) { |
| 166 return ShouldReturnError( | 168 return ShouldReturnError( |
| 167 TestFileErrorInjector::FILE_OPERATION_WRITE, | 169 TestFileErrorInjector::FILE_OPERATION_WRITE, |
| 168 DownloadFileImpl::WriteDataToFile(offset, data, data_len)); | 170 DownloadFileImpl::WriteDataToFile(offset, data, data_len)); |
| 169 } | 171 } |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 case FILE_OPERATION_RENAME_ANNOTATE: | 412 case FILE_OPERATION_RENAME_ANNOTATE: |
| 411 return "RENAME_ANNOTATE"; | 413 return "RENAME_ANNOTATE"; |
| 412 default: | 414 default: |
| 413 break; | 415 break; |
| 414 } | 416 } |
| 415 | 417 |
| 416 return "Unknown"; | 418 return "Unknown"; |
| 417 } | 419 } |
| 418 | 420 |
| 419 } // namespace content | 421 } // namespace content |
| OLD | NEW |