| 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 26 matching lines...) Expand all Loading... |
| 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& initialize_callback, | 45 void Initialize(const InitializeCallback& initialize_callback, |
| 46 const CancelRequestCallback& cancel_request_callback, | 46 const CancelRequestCallback& cancel_request_callback, |
| 47 const DownloadItem::ReceivedSlices& received_slices) override; | 47 const DownloadItem::ReceivedSlices& received_slices, |
| 48 bool is_parallelizable) override; |
| 48 | 49 |
| 49 // DownloadFile interface. | 50 // DownloadFile interface. |
| 50 DownloadInterruptReason WriteDataToFile(int64_t offset, | 51 DownloadInterruptReason WriteDataToFile(int64_t offset, |
| 51 const char* data, | 52 const char* data, |
| 52 size_t data_len) override; | 53 size_t data_len) override; |
| 53 | 54 |
| 54 void RenameAndUniquify(const base::FilePath& full_path, | 55 void RenameAndUniquify(const base::FilePath& full_path, |
| 55 const RenameCompletionCallback& callback) override; | 56 const RenameCompletionCallback& callback) override; |
| 56 void RenameAndAnnotate(const base::FilePath& full_path, | 57 void RenameAndAnnotate(const base::FilePath& full_path, |
| 57 const std::string& client_guid, | 58 const std::string& client_guid, |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 } | 130 } |
| 130 | 131 |
| 131 DownloadFileWithError::~DownloadFileWithError() { | 132 DownloadFileWithError::~DownloadFileWithError() { |
| 132 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 133 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 133 destruction_callback_.Run(); | 134 destruction_callback_.Run(); |
| 134 } | 135 } |
| 135 | 136 |
| 136 void DownloadFileWithError::Initialize( | 137 void DownloadFileWithError::Initialize( |
| 137 const InitializeCallback& initialize_callback, | 138 const InitializeCallback& initialize_callback, |
| 138 const CancelRequestCallback& cancel_request_callback, | 139 const CancelRequestCallback& cancel_request_callback, |
| 139 const DownloadItem::ReceivedSlices& received_slices) { | 140 const DownloadItem::ReceivedSlices& received_slices, |
| 141 bool is_parallelizable) { |
| 140 DownloadInterruptReason error_to_return = DOWNLOAD_INTERRUPT_REASON_NONE; | 142 DownloadInterruptReason error_to_return = DOWNLOAD_INTERRUPT_REASON_NONE; |
| 141 InitializeCallback callback_to_use = initialize_callback; | 143 InitializeCallback callback_to_use = initialize_callback; |
| 142 | 144 |
| 143 // Replace callback if the error needs to be overwritten. | 145 // Replace callback if the error needs to be overwritten. |
| 144 if (OverwriteError( | 146 if (OverwriteError( |
| 145 TestFileErrorInjector::FILE_OPERATION_INITIALIZE, | 147 TestFileErrorInjector::FILE_OPERATION_INITIALIZE, |
| 146 &error_to_return)) { | 148 &error_to_return)) { |
| 147 if (DOWNLOAD_INTERRUPT_REASON_NONE != error_to_return) { | 149 if (DOWNLOAD_INTERRUPT_REASON_NONE != error_to_return) { |
| 148 // Don't execute a, probably successful, Initialize; just | 150 // Don't execute a, probably successful, Initialize; just |
| 149 // return the error. | 151 // return the error. |
| 150 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 152 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 151 base::Bind(initialize_callback, error_to_return)); | 153 base::Bind(initialize_callback, error_to_return)); |
| 152 return; | 154 return; |
| 153 } | 155 } |
| 154 | 156 |
| 155 // Otherwise, just wrap the return. | 157 // Otherwise, just wrap the return. |
| 156 callback_to_use = base::Bind(&InitializeErrorCallback, initialize_callback, | 158 callback_to_use = base::Bind(&InitializeErrorCallback, initialize_callback, |
| 157 error_to_return); | 159 error_to_return); |
| 158 } | 160 } |
| 159 | 161 |
| 160 DownloadFileImpl::Initialize(callback_to_use, cancel_request_callback, | 162 DownloadFileImpl::Initialize(callback_to_use, cancel_request_callback, |
| 161 received_slices); | 163 received_slices, is_parallelizable); |
| 162 } | 164 } |
| 163 | 165 |
| 164 DownloadInterruptReason DownloadFileWithError::WriteDataToFile( | 166 DownloadInterruptReason DownloadFileWithError::WriteDataToFile( |
| 165 int64_t offset, | 167 int64_t offset, |
| 166 const char* data, | 168 const char* data, |
| 167 size_t data_len) { | 169 size_t data_len) { |
| 168 return ShouldReturnError( | 170 return ShouldReturnError( |
| 169 TestFileErrorInjector::FILE_OPERATION_WRITE, | 171 TestFileErrorInjector::FILE_OPERATION_WRITE, |
| 170 DownloadFileImpl::WriteDataToFile(offset, data, data_len)); | 172 DownloadFileImpl::WriteDataToFile(offset, data, data_len)); |
| 171 } | 173 } |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 case FILE_OPERATION_RENAME_ANNOTATE: | 414 case FILE_OPERATION_RENAME_ANNOTATE: |
| 413 return "RENAME_ANNOTATE"; | 415 return "RENAME_ANNOTATE"; |
| 414 default: | 416 default: |
| 415 break; | 417 break; |
| 416 } | 418 } |
| 417 | 419 |
| 418 return "Unknown"; | 420 return "Unknown"; |
| 419 } | 421 } |
| 420 | 422 |
| 421 } // namespace content | 423 } // namespace content |
| OLD | NEW |