| 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 12 matching lines...) Expand all Loading... |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace content { | 25 namespace content { |
| 26 class ByteStreamReader; | 26 class ByteStreamReader; |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 // A class that performs file operations and injects errors. | 30 // A class that performs file operations and injects errors. |
| 31 class DownloadFileWithError: public DownloadFileImpl { | 31 class DownloadFileWithError: public DownloadFileImpl { |
| 32 public: | 32 public: |
| 33 DownloadFileWithError(std::unique_ptr<DownloadSaveInfo> save_info, | 33 DownloadFileWithError( |
| 34 const base::FilePath& default_download_directory, | 34 std::unique_ptr<DownloadSaveInfo> save_info, |
| 35 std::unique_ptr<ByteStreamReader> byte_stream, | 35 const base::FilePath& default_download_directory, |
| 36 const net::NetLogWithSource& net_log, | 36 std::unique_ptr<ByteStreamReader> byte_stream, |
| 37 base::WeakPtr<DownloadDestinationObserver> observer, | 37 const std::vector<DownloadItem::ReceivedSlice>& received_slices, |
| 38 const TestFileErrorInjector::FileErrorInfo& error_info, | 38 const net::NetLogWithSource& net_log, |
| 39 const base::Closure& ctor_callback, | 39 base::WeakPtr<DownloadDestinationObserver> observer, |
| 40 const base::Closure& dtor_callback); | 40 const TestFileErrorInjector::FileErrorInfo& error_info, |
| 41 const base::Closure& ctor_callback, |
| 42 const base::Closure& dtor_callback); |
| 41 | 43 |
| 42 ~DownloadFileWithError() override; | 44 ~DownloadFileWithError() override; |
| 43 | 45 |
| 44 void Initialize(const InitializeCallback& callback) override; | 46 void Initialize(const InitializeCallback& callback) override; |
| 45 | 47 |
| 46 // DownloadFile interface. | 48 // DownloadFile interface. |
| 47 DownloadInterruptReason WriteDataToFile(int64_t offset, | 49 DownloadInterruptReason WriteDataToFile(int64_t offset, |
| 48 const char* data, | 50 const char* data, |
| 49 size_t data_len) override; | 51 size_t data_len) override; |
| 50 | 52 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 original_callback.Run( | 99 original_callback.Run( |
| 98 overwrite_error, | 100 overwrite_error, |
| 99 overwrite_error == DOWNLOAD_INTERRUPT_REASON_NONE ? | 101 overwrite_error == DOWNLOAD_INTERRUPT_REASON_NONE ? |
| 100 path_result : base::FilePath()); | 102 path_result : base::FilePath()); |
| 101 } | 103 } |
| 102 | 104 |
| 103 DownloadFileWithError::DownloadFileWithError( | 105 DownloadFileWithError::DownloadFileWithError( |
| 104 std::unique_ptr<DownloadSaveInfo> save_info, | 106 std::unique_ptr<DownloadSaveInfo> save_info, |
| 105 const base::FilePath& default_download_directory, | 107 const base::FilePath& default_download_directory, |
| 106 std::unique_ptr<ByteStreamReader> byte_stream, | 108 std::unique_ptr<ByteStreamReader> byte_stream, |
| 109 const std::vector<DownloadItem::ReceivedSlice>& received_slices, |
| 107 const net::NetLogWithSource& net_log, | 110 const net::NetLogWithSource& net_log, |
| 108 base::WeakPtr<DownloadDestinationObserver> observer, | 111 base::WeakPtr<DownloadDestinationObserver> observer, |
| 109 const TestFileErrorInjector::FileErrorInfo& error_info, | 112 const TestFileErrorInjector::FileErrorInfo& error_info, |
| 110 const base::Closure& ctor_callback, | 113 const base::Closure& ctor_callback, |
| 111 const base::Closure& dtor_callback) | 114 const base::Closure& dtor_callback) |
| 112 : DownloadFileImpl(std::move(save_info), | 115 : DownloadFileImpl(std::move(save_info), |
| 113 default_download_directory, | 116 default_download_directory, |
| 114 std::move(byte_stream), | 117 std::move(byte_stream), |
| 118 received_slices, |
| 115 net_log, | 119 net_log, |
| 116 false, /* is_sparse_file */ | 120 false, /* is_sparse_file */ |
| 117 observer), | 121 observer), |
| 118 error_info_(error_info), | 122 error_info_(error_info), |
| 119 destruction_callback_(dtor_callback) { | 123 destruction_callback_(dtor_callback) { |
| 120 // DownloadFiles are created on the UI thread and are destroyed on the FILE | 124 // DownloadFiles are created on the UI thread and are destroyed on the FILE |
| 121 // thread. Schedule the ConstructionCallback on the FILE thread so that if a | 125 // thread. Schedule the ConstructionCallback on the FILE thread so that if a |
| 122 // DownloadItem schedules a DownloadFile to be destroyed and creates another | 126 // DownloadItem schedules a DownloadFile to be destroyed and creates another |
| 123 // one (as happens during download resumption), then the DestructionCallback | 127 // one (as happens during download resumption), then the DestructionCallback |
| 124 // for the old DownloadFile is run before the ConstructionCallback for the | 128 // for the old DownloadFile is run before the ConstructionCallback for the |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 public: | 258 public: |
| 255 DownloadFileWithErrorFactory(const base::Closure& ctor_callback, | 259 DownloadFileWithErrorFactory(const base::Closure& ctor_callback, |
| 256 const base::Closure& dtor_callback); | 260 const base::Closure& dtor_callback); |
| 257 ~DownloadFileWithErrorFactory() override; | 261 ~DownloadFileWithErrorFactory() override; |
| 258 | 262 |
| 259 // DownloadFileFactory interface. | 263 // DownloadFileFactory interface. |
| 260 DownloadFile* CreateFile( | 264 DownloadFile* CreateFile( |
| 261 std::unique_ptr<DownloadSaveInfo> save_info, | 265 std::unique_ptr<DownloadSaveInfo> save_info, |
| 262 const base::FilePath& default_download_directory, | 266 const base::FilePath& default_download_directory, |
| 263 std::unique_ptr<ByteStreamReader> byte_stream, | 267 std::unique_ptr<ByteStreamReader> byte_stream, |
| 268 const std::vector<DownloadItem::ReceivedSlice>& received_slices, |
| 264 const net::NetLogWithSource& net_log, | 269 const net::NetLogWithSource& net_log, |
| 265 base::WeakPtr<DownloadDestinationObserver> observer) override; | 270 base::WeakPtr<DownloadDestinationObserver> observer) override; |
| 266 | 271 |
| 267 bool SetError(TestFileErrorInjector::FileErrorInfo error); | 272 bool SetError(TestFileErrorInjector::FileErrorInfo error); |
| 268 | 273 |
| 269 private: | 274 private: |
| 270 // Our injected error. | 275 // Our injected error. |
| 271 TestFileErrorInjector::FileErrorInfo injected_error_; | 276 TestFileErrorInjector::FileErrorInfo injected_error_; |
| 272 | 277 |
| 273 // Callback for creation and destruction. | 278 // Callback for creation and destruction. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 284 injected_error_.error = DOWNLOAD_INTERRUPT_REASON_NONE; | 289 injected_error_.error = DOWNLOAD_INTERRUPT_REASON_NONE; |
| 285 injected_error_.operation_instance = -1; | 290 injected_error_.operation_instance = -1; |
| 286 } | 291 } |
| 287 | 292 |
| 288 DownloadFileWithErrorFactory::~DownloadFileWithErrorFactory() {} | 293 DownloadFileWithErrorFactory::~DownloadFileWithErrorFactory() {} |
| 289 | 294 |
| 290 DownloadFile* DownloadFileWithErrorFactory::CreateFile( | 295 DownloadFile* DownloadFileWithErrorFactory::CreateFile( |
| 291 std::unique_ptr<DownloadSaveInfo> save_info, | 296 std::unique_ptr<DownloadSaveInfo> save_info, |
| 292 const base::FilePath& default_download_directory, | 297 const base::FilePath& default_download_directory, |
| 293 std::unique_ptr<ByteStreamReader> byte_stream, | 298 std::unique_ptr<ByteStreamReader> byte_stream, |
| 299 const std::vector<DownloadItem::ReceivedSlice>& received_slices, |
| 294 const net::NetLogWithSource& net_log, | 300 const net::NetLogWithSource& net_log, |
| 295 base::WeakPtr<DownloadDestinationObserver> observer) { | 301 base::WeakPtr<DownloadDestinationObserver> observer) { |
| 296 return new DownloadFileWithError(std::move(save_info), | 302 return new DownloadFileWithError(std::move(save_info), |
| 297 default_download_directory, | 303 default_download_directory, |
| 298 std::move(byte_stream), | 304 std::move(byte_stream), |
| 305 received_slices, |
| 299 net_log, | 306 net_log, |
| 300 observer, | 307 observer, |
| 301 injected_error_, | 308 injected_error_, |
| 302 construction_callback_, | 309 construction_callback_, |
| 303 destruction_callback_); | 310 destruction_callback_); |
| 304 } | 311 } |
| 305 | 312 |
| 306 bool DownloadFileWithErrorFactory::SetError( | 313 bool DownloadFileWithErrorFactory::SetError( |
| 307 TestFileErrorInjector::FileErrorInfo error) { | 314 TestFileErrorInjector::FileErrorInfo error) { |
| 308 injected_error_ = std::move(error); | 315 injected_error_ = std::move(error); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 case FILE_OPERATION_RENAME_ANNOTATE: | 415 case FILE_OPERATION_RENAME_ANNOTATE: |
| 409 return "RENAME_ANNOTATE"; | 416 return "RENAME_ANNOTATE"; |
| 410 default: | 417 default: |
| 411 break; | 418 break; |
| 412 } | 419 } |
| 413 | 420 |
| 414 return "Unknown"; | 421 return "Unknown"; |
| 415 } | 422 } |
| 416 | 423 |
| 417 } // namespace content | 424 } // namespace content |
| OLD | NEW |