| 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 base::WeakPtr<DownloadDestinationObserver> observer, | 37 base::WeakPtr<DownloadDestinationObserver> observer, |
| 38 const TestFileErrorInjector::FileErrorInfo& error_info, | 38 const TestFileErrorInjector::FileErrorInfo& error_info, |
| 39 const base::Closure& ctor_callback, | 39 const base::Closure& ctor_callback, |
| 40 const base::Closure& dtor_callback); | 40 const base::Closure& dtor_callback); |
| 41 | 41 |
| 42 ~DownloadFileWithError() override; | 42 ~DownloadFileWithError() override; |
| 43 | 43 |
| 44 void Initialize(const InitializeCallback& callback) override; | 44 void Initialize(const InitializeCallback& callback) override; |
| 45 | 45 |
| 46 // DownloadFile interface. | 46 // DownloadFile interface. |
| 47 DownloadInterruptReason AppendDataToFile(const char* data, | 47 DownloadInterruptReason WriteDataToFile(int64_t offset, |
| 48 size_t data_len) override; | 48 const char* data, |
| 49 size_t data_len) override; |
| 50 |
| 49 void RenameAndUniquify(const base::FilePath& full_path, | 51 void RenameAndUniquify(const base::FilePath& full_path, |
| 50 const RenameCompletionCallback& callback) override; | 52 const RenameCompletionCallback& callback) override; |
| 51 void RenameAndAnnotate(const base::FilePath& full_path, | 53 void RenameAndAnnotate(const base::FilePath& full_path, |
| 52 const std::string& client_guid, | 54 const std::string& client_guid, |
| 53 const GURL& source_url, | 55 const GURL& source_url, |
| 54 const GURL& referrer_url, | 56 const GURL& referrer_url, |
| 55 const RenameCompletionCallback& callback) override; | 57 const RenameCompletionCallback& callback) override; |
| 56 | 58 |
| 57 private: | 59 private: |
| 58 // Error generating helper. | 60 // Error generating helper. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 std::unique_ptr<ByteStreamReader> byte_stream, | 106 std::unique_ptr<ByteStreamReader> byte_stream, |
| 105 const net::NetLogWithSource& net_log, | 107 const net::NetLogWithSource& net_log, |
| 106 base::WeakPtr<DownloadDestinationObserver> observer, | 108 base::WeakPtr<DownloadDestinationObserver> observer, |
| 107 const TestFileErrorInjector::FileErrorInfo& error_info, | 109 const TestFileErrorInjector::FileErrorInfo& error_info, |
| 108 const base::Closure& ctor_callback, | 110 const base::Closure& ctor_callback, |
| 109 const base::Closure& dtor_callback) | 111 const base::Closure& dtor_callback) |
| 110 : DownloadFileImpl(std::move(save_info), | 112 : DownloadFileImpl(std::move(save_info), |
| 111 default_download_directory, | 113 default_download_directory, |
| 112 std::move(byte_stream), | 114 std::move(byte_stream), |
| 113 net_log, | 115 net_log, |
| 116 false, /* is_sparse_file */ |
| 114 observer), | 117 observer), |
| 115 error_info_(error_info), | 118 error_info_(error_info), |
| 116 destruction_callback_(dtor_callback) { | 119 destruction_callback_(dtor_callback) { |
| 117 // DownloadFiles are created on the UI thread and are destroyed on the FILE | 120 // DownloadFiles are created on the UI thread and are destroyed on the FILE |
| 118 // thread. Schedule the ConstructionCallback on the FILE thread so that if a | 121 // thread. Schedule the ConstructionCallback on the FILE thread so that if a |
| 119 // DownloadItem schedules a DownloadFile to be destroyed and creates another | 122 // DownloadItem schedules a DownloadFile to be destroyed and creates another |
| 120 // one (as happens during download resumption), then the DestructionCallback | 123 // one (as happens during download resumption), then the DestructionCallback |
| 121 // for the old DownloadFile is run before the ConstructionCallback for the | 124 // for the old DownloadFile is run before the ConstructionCallback for the |
| 122 // next DownloadFile. | 125 // next DownloadFile. |
| 123 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, ctor_callback); | 126 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, ctor_callback); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 147 } | 150 } |
| 148 | 151 |
| 149 // Otherwise, just wrap the return. | 152 // Otherwise, just wrap the return. |
| 150 callback_to_use = base::Bind(&InitializeErrorCallback, callback, | 153 callback_to_use = base::Bind(&InitializeErrorCallback, callback, |
| 151 error_to_return); | 154 error_to_return); |
| 152 } | 155 } |
| 153 | 156 |
| 154 DownloadFileImpl::Initialize(callback_to_use); | 157 DownloadFileImpl::Initialize(callback_to_use); |
| 155 } | 158 } |
| 156 | 159 |
| 157 DownloadInterruptReason DownloadFileWithError::AppendDataToFile( | 160 DownloadInterruptReason DownloadFileWithError::WriteDataToFile( |
| 158 const char* data, size_t data_len) { | 161 int64_t offset, |
| 162 const char* data, |
| 163 size_t data_len) { |
| 159 return ShouldReturnError( | 164 return ShouldReturnError( |
| 160 TestFileErrorInjector::FILE_OPERATION_WRITE, | 165 TestFileErrorInjector::FILE_OPERATION_WRITE, |
| 161 DownloadFileImpl::AppendDataToFile(data, data_len)); | 166 DownloadFileImpl::WriteDataToFile(offset, data, data_len)); |
| 162 } | 167 } |
| 163 | 168 |
| 164 void DownloadFileWithError::RenameAndUniquify( | 169 void DownloadFileWithError::RenameAndUniquify( |
| 165 const base::FilePath& full_path, | 170 const base::FilePath& full_path, |
| 166 const RenameCompletionCallback& callback) { | 171 const RenameCompletionCallback& callback) { |
| 167 DownloadInterruptReason error_to_return = DOWNLOAD_INTERRUPT_REASON_NONE; | 172 DownloadInterruptReason error_to_return = DOWNLOAD_INTERRUPT_REASON_NONE; |
| 168 RenameCompletionCallback callback_to_use = callback; | 173 RenameCompletionCallback callback_to_use = callback; |
| 169 | 174 |
| 170 // Replace callback if the error needs to be overwritten. | 175 // Replace callback if the error needs to be overwritten. |
| 171 if (OverwriteError( | 176 if (OverwriteError( |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 case FILE_OPERATION_RENAME_ANNOTATE: | 408 case FILE_OPERATION_RENAME_ANNOTATE: |
| 404 return "RENAME_ANNOTATE"; | 409 return "RENAME_ANNOTATE"; |
| 405 default: | 410 default: |
| 406 break; | 411 break; |
| 407 } | 412 } |
| 408 | 413 |
| 409 return "Unknown"; | 414 return "Unknown"; |
| 410 } | 415 } |
| 411 | 416 |
| 412 } // namespace content | 417 } // namespace content |
| OLD | NEW |