| 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 25 matching lines...) Expand all Loading... |
| 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& callback, |
| 46 const DownloadItem::ReceivedSlices& received_slices) override; | 46 const DownloadItem::ReceivedSlices& received_slices, |
| 47 bool is_parallelizable) 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, |
| 56 const std::string& client_guid, | 57 const std::string& client_guid, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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& callback, |
| 137 const DownloadItem::ReceivedSlices& received_slices) { | 138 const DownloadItem::ReceivedSlices& received_slices, |
| 139 bool is_parallelizable) { |
| 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 = 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( |
| 149 BrowserThread::UI, FROM_HERE, base::Bind( | 151 BrowserThread::UI, FROM_HERE, base::Bind( |
| 150 callback, error_to_return)); | 152 callback, error_to_return)); |
| 151 return; | 153 return; |
| 152 } | 154 } |
| 153 | 155 |
| 154 // Otherwise, just wrap the return. | 156 // Otherwise, just wrap the return. |
| 155 callback_to_use = base::Bind(&InitializeErrorCallback, callback, | 157 callback_to_use = base::Bind(&InitializeErrorCallback, callback, |
| 156 error_to_return); | 158 error_to_return); |
| 157 } | 159 } |
| 158 | 160 |
| 159 DownloadFileImpl::Initialize(callback_to_use, received_slices); | 161 DownloadFileImpl::Initialize(callback_to_use, received_slices, |
| 162 is_parallelizable); |
| 160 } | 163 } |
| 161 | 164 |
| 162 DownloadInterruptReason DownloadFileWithError::WriteDataToFile( | 165 DownloadInterruptReason DownloadFileWithError::WriteDataToFile( |
| 163 int64_t offset, | 166 int64_t offset, |
| 164 const char* data, | 167 const char* data, |
| 165 size_t data_len) { | 168 size_t data_len) { |
| 166 return ShouldReturnError( | 169 return ShouldReturnError( |
| 167 TestFileErrorInjector::FILE_OPERATION_WRITE, | 170 TestFileErrorInjector::FILE_OPERATION_WRITE, |
| 168 DownloadFileImpl::WriteDataToFile(offset, data, data_len)); | 171 DownloadFileImpl::WriteDataToFile(offset, data, data_len)); |
| 169 } | 172 } |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 case FILE_OPERATION_RENAME_ANNOTATE: | 413 case FILE_OPERATION_RENAME_ANNOTATE: |
| 411 return "RENAME_ANNOTATE"; | 414 return "RENAME_ANNOTATE"; |
| 412 default: | 415 default: |
| 413 break; | 416 break; |
| 414 } | 417 } |
| 415 | 418 |
| 416 return "Unknown"; | 419 return "Unknown"; |
| 417 } | 420 } |
| 418 | 421 |
| 419 } // namespace content | 422 } // namespace content |
| OLD | NEW |