Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Side by Side Diff: content/public/test/test_file_error_injector.cc

Issue 12286020: Replace FilePath with base::FilePath. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/public/test/test_browser_context.cc ('k') | content/public/test/test_launcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <vector> 7 #include <vector>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 12 matching lines...) Expand all
23 namespace { 23 namespace {
24 24
25 // A class that performs file operations and injects errors. 25 // A class that performs file operations and injects errors.
26 class DownloadFileWithErrors: public DownloadFileImpl { 26 class DownloadFileWithErrors: public DownloadFileImpl {
27 public: 27 public:
28 typedef base::Callback<void(const GURL& url)> ConstructionCallback; 28 typedef base::Callback<void(const GURL& url)> ConstructionCallback;
29 typedef base::Callback<void(const GURL& url)> DestructionCallback; 29 typedef base::Callback<void(const GURL& url)> DestructionCallback;
30 30
31 DownloadFileWithErrors( 31 DownloadFileWithErrors(
32 scoped_ptr<DownloadSaveInfo> save_info, 32 scoped_ptr<DownloadSaveInfo> save_info,
33 const FilePath& default_download_directory, 33 const base::FilePath& default_download_directory,
34 const GURL& url, 34 const GURL& url,
35 const GURL& referrer_url, 35 const GURL& referrer_url,
36 bool calculate_hash, 36 bool calculate_hash,
37 scoped_ptr<ByteStreamReader> stream, 37 scoped_ptr<ByteStreamReader> stream,
38 const net::BoundNetLog& bound_net_log, 38 const net::BoundNetLog& bound_net_log,
39 scoped_ptr<PowerSaveBlocker> power_save_blocker, 39 scoped_ptr<PowerSaveBlocker> power_save_blocker,
40 base::WeakPtr<DownloadDestinationObserver> observer, 40 base::WeakPtr<DownloadDestinationObserver> observer,
41 const TestFileErrorInjector::FileErrorInfo& error_info, 41 const TestFileErrorInjector::FileErrorInfo& error_info,
42 const ConstructionCallback& ctor_callback, 42 const ConstructionCallback& ctor_callback,
43 const DestructionCallback& dtor_callback); 43 const DestructionCallback& dtor_callback);
44 44
45 virtual ~DownloadFileWithErrors(); 45 virtual ~DownloadFileWithErrors();
46 46
47 virtual void Initialize(const InitializeCallback& callback) OVERRIDE; 47 virtual void Initialize(const InitializeCallback& callback) OVERRIDE;
48 48
49 // DownloadFile interface. 49 // DownloadFile interface.
50 virtual DownloadInterruptReason AppendDataToFile( 50 virtual DownloadInterruptReason AppendDataToFile(
51 const char* data, size_t data_len) OVERRIDE; 51 const char* data, size_t data_len) OVERRIDE;
52 virtual void RenameAndUniquify( 52 virtual void RenameAndUniquify(
53 const FilePath& full_path, 53 const base::FilePath& full_path,
54 const RenameCompletionCallback& callback) OVERRIDE; 54 const RenameCompletionCallback& callback) OVERRIDE;
55 virtual void RenameAndAnnotate( 55 virtual void RenameAndAnnotate(
56 const FilePath& full_path, 56 const base::FilePath& full_path,
57 const RenameCompletionCallback& callback) OVERRIDE; 57 const RenameCompletionCallback& callback) OVERRIDE;
58 58
59 private: 59 private:
60 // Error generating helper. 60 // Error generating helper.
61 DownloadInterruptReason ShouldReturnError( 61 DownloadInterruptReason ShouldReturnError(
62 TestFileErrorInjector::FileOperationCode code, 62 TestFileErrorInjector::FileOperationCode code,
63 DownloadInterruptReason original_error); 63 DownloadInterruptReason original_error);
64 64
65 // Determine whether to overwrite an operation with the given code 65 // Determine whether to overwrite an operation with the given code
66 // with a substitute error; if returns true, |*original_error| is 66 // with a substitute error; if returns true, |*original_error| is
(...skipping 22 matching lines...) Expand all
89 const DownloadFile::InitializeCallback original_callback, 89 const DownloadFile::InitializeCallback original_callback,
90 DownloadInterruptReason overwrite_error, 90 DownloadInterruptReason overwrite_error,
91 DownloadInterruptReason original_error) { 91 DownloadInterruptReason original_error) {
92 original_callback.Run(overwrite_error); 92 original_callback.Run(overwrite_error);
93 } 93 }
94 94
95 static void RenameErrorCallback( 95 static void RenameErrorCallback(
96 const DownloadFile::RenameCompletionCallback original_callback, 96 const DownloadFile::RenameCompletionCallback original_callback,
97 DownloadInterruptReason overwrite_error, 97 DownloadInterruptReason overwrite_error,
98 DownloadInterruptReason original_error, 98 DownloadInterruptReason original_error,
99 const FilePath& path_result) { 99 const base::FilePath& path_result) {
100 original_callback.Run( 100 original_callback.Run(
101 overwrite_error, 101 overwrite_error,
102 overwrite_error == DOWNLOAD_INTERRUPT_REASON_NONE ? 102 overwrite_error == DOWNLOAD_INTERRUPT_REASON_NONE ?
103 path_result : FilePath()); 103 path_result : base::FilePath());
104 } 104 }
105 105
106 DownloadFileWithErrors::DownloadFileWithErrors( 106 DownloadFileWithErrors::DownloadFileWithErrors(
107 scoped_ptr<DownloadSaveInfo> save_info, 107 scoped_ptr<DownloadSaveInfo> save_info,
108 const FilePath& default_download_directory, 108 const base::FilePath& default_download_directory,
109 const GURL& url, 109 const GURL& url,
110 const GURL& referrer_url, 110 const GURL& referrer_url,
111 bool calculate_hash, 111 bool calculate_hash,
112 scoped_ptr<ByteStreamReader> stream, 112 scoped_ptr<ByteStreamReader> stream,
113 const net::BoundNetLog& bound_net_log, 113 const net::BoundNetLog& bound_net_log,
114 scoped_ptr<PowerSaveBlocker> power_save_blocker, 114 scoped_ptr<PowerSaveBlocker> power_save_blocker,
115 base::WeakPtr<DownloadDestinationObserver> observer, 115 base::WeakPtr<DownloadDestinationObserver> observer,
116 const TestFileErrorInjector::FileErrorInfo& error_info, 116 const TestFileErrorInjector::FileErrorInfo& error_info,
117 const ConstructionCallback& ctor_callback, 117 const ConstructionCallback& ctor_callback,
118 const DestructionCallback& dtor_callback) 118 const DestructionCallback& dtor_callback)
(...skipping 28 matching lines...) Expand all
147 } 147 }
148 148
149 DownloadInterruptReason DownloadFileWithErrors::AppendDataToFile( 149 DownloadInterruptReason DownloadFileWithErrors::AppendDataToFile(
150 const char* data, size_t data_len) { 150 const char* data, size_t data_len) {
151 return ShouldReturnError( 151 return ShouldReturnError(
152 TestFileErrorInjector::FILE_OPERATION_WRITE, 152 TestFileErrorInjector::FILE_OPERATION_WRITE,
153 DownloadFileImpl::AppendDataToFile(data, data_len)); 153 DownloadFileImpl::AppendDataToFile(data, data_len));
154 } 154 }
155 155
156 void DownloadFileWithErrors::RenameAndUniquify( 156 void DownloadFileWithErrors::RenameAndUniquify(
157 const FilePath& full_path, 157 const base::FilePath& full_path,
158 const RenameCompletionCallback& callback) { 158 const RenameCompletionCallback& callback) {
159 DownloadInterruptReason error_to_return = DOWNLOAD_INTERRUPT_REASON_NONE; 159 DownloadInterruptReason error_to_return = DOWNLOAD_INTERRUPT_REASON_NONE;
160 RenameCompletionCallback callback_to_use = callback; 160 RenameCompletionCallback callback_to_use = callback;
161 161
162 // Replace callback if the error needs to be overwritten. 162 // Replace callback if the error needs to be overwritten.
163 if (OverwriteError( 163 if (OverwriteError(
164 TestFileErrorInjector::FILE_OPERATION_RENAME_UNIQUIFY, 164 TestFileErrorInjector::FILE_OPERATION_RENAME_UNIQUIFY,
165 &error_to_return)) { 165 &error_to_return)) {
166 callback_to_use = base::Bind(&RenameErrorCallback, callback, 166 callback_to_use = base::Bind(&RenameErrorCallback, callback,
167 error_to_return); 167 error_to_return);
168 } 168 }
169 169
170 DownloadFileImpl::RenameAndUniquify(full_path, callback_to_use); 170 DownloadFileImpl::RenameAndUniquify(full_path, callback_to_use);
171 } 171 }
172 172
173 void DownloadFileWithErrors::RenameAndAnnotate( 173 void DownloadFileWithErrors::RenameAndAnnotate(
174 const FilePath& full_path, 174 const base::FilePath& full_path,
175 const RenameCompletionCallback& callback) { 175 const RenameCompletionCallback& callback) {
176 DownloadInterruptReason error_to_return = DOWNLOAD_INTERRUPT_REASON_NONE; 176 DownloadInterruptReason error_to_return = DOWNLOAD_INTERRUPT_REASON_NONE;
177 RenameCompletionCallback callback_to_use = callback; 177 RenameCompletionCallback callback_to_use = callback;
178 178
179 // Replace callback if the error needs to be overwritten. 179 // Replace callback if the error needs to be overwritten.
180 if (OverwriteError( 180 if (OverwriteError(
181 TestFileErrorInjector::FILE_OPERATION_RENAME_ANNOTATE, 181 TestFileErrorInjector::FILE_OPERATION_RENAME_ANNOTATE,
182 &error_to_return)) { 182 &error_to_return)) {
183 callback_to_use = base::Bind(&RenameErrorCallback, callback, 183 callback_to_use = base::Bind(&RenameErrorCallback, callback,
184 error_to_return); 184 error_to_return);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 class DownloadFileWithErrorsFactory : public DownloadFileFactory { 216 class DownloadFileWithErrorsFactory : public DownloadFileFactory {
217 public: 217 public:
218 DownloadFileWithErrorsFactory( 218 DownloadFileWithErrorsFactory(
219 const DownloadFileWithErrors::ConstructionCallback& ctor_callback, 219 const DownloadFileWithErrors::ConstructionCallback& ctor_callback,
220 const DownloadFileWithErrors::DestructionCallback& dtor_callback); 220 const DownloadFileWithErrors::DestructionCallback& dtor_callback);
221 virtual ~DownloadFileWithErrorsFactory(); 221 virtual ~DownloadFileWithErrorsFactory();
222 222
223 // DownloadFileFactory interface. 223 // DownloadFileFactory interface.
224 virtual DownloadFile* CreateFile( 224 virtual DownloadFile* CreateFile(
225 scoped_ptr<DownloadSaveInfo> save_info, 225 scoped_ptr<DownloadSaveInfo> save_info,
226 const FilePath& default_download_directory, 226 const base::FilePath& default_download_directory,
227 const GURL& url, 227 const GURL& url,
228 const GURL& referrer_url, 228 const GURL& referrer_url,
229 bool calculate_hash, 229 bool calculate_hash,
230 scoped_ptr<ByteStreamReader> stream, 230 scoped_ptr<ByteStreamReader> stream,
231 const net::BoundNetLog& bound_net_log, 231 const net::BoundNetLog& bound_net_log,
232 base::WeakPtr<DownloadDestinationObserver> observer) OVERRIDE; 232 base::WeakPtr<DownloadDestinationObserver> observer) OVERRIDE;
233 233
234 bool AddError( 234 bool AddError(
235 const TestFileErrorInjector::FileErrorInfo& error_info); 235 const TestFileErrorInjector::FileErrorInfo& error_info);
236 236
(...skipping 13 matching lines...) Expand all
250 const DownloadFileWithErrors::DestructionCallback& dtor_callback) 250 const DownloadFileWithErrors::DestructionCallback& dtor_callback)
251 : construction_callback_(ctor_callback), 251 : construction_callback_(ctor_callback),
252 destruction_callback_(dtor_callback) { 252 destruction_callback_(dtor_callback) {
253 } 253 }
254 254
255 DownloadFileWithErrorsFactory::~DownloadFileWithErrorsFactory() { 255 DownloadFileWithErrorsFactory::~DownloadFileWithErrorsFactory() {
256 } 256 }
257 257
258 DownloadFile* DownloadFileWithErrorsFactory::CreateFile( 258 DownloadFile* DownloadFileWithErrorsFactory::CreateFile(
259 scoped_ptr<DownloadSaveInfo> save_info, 259 scoped_ptr<DownloadSaveInfo> save_info,
260 const FilePath& default_download_directory, 260 const base::FilePath& default_download_directory,
261 const GURL& url, 261 const GURL& url,
262 const GURL& referrer_url, 262 const GURL& referrer_url,
263 bool calculate_hash, 263 bool calculate_hash,
264 scoped_ptr<ByteStreamReader> stream, 264 scoped_ptr<ByteStreamReader> stream,
265 const net::BoundNetLog& bound_net_log, 265 const net::BoundNetLog& bound_net_log,
266 base::WeakPtr<DownloadDestinationObserver> observer) { 266 base::WeakPtr<DownloadDestinationObserver> observer) {
267 if (injected_errors_.find(url.spec()) == injected_errors_.end()) { 267 if (injected_errors_.find(url.spec()) == injected_errors_.end()) {
268 // Have to create entry, because FileErrorInfo is not a POD type. 268 // Have to create entry, because FileErrorInfo is not a POD type.
269 TestFileErrorInjector::FileErrorInfo err_info = { 269 TestFileErrorInjector::FileErrorInfo err_info = {
270 url.spec(), 270 url.spec(),
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 case FILE_OPERATION_RENAME_ANNOTATE: 439 case FILE_OPERATION_RENAME_ANNOTATE:
440 return "RENAME_ANNOTATE"; 440 return "RENAME_ANNOTATE";
441 default: 441 default:
442 break; 442 break;
443 } 443 }
444 444
445 return "Unknown"; 445 return "Unknown";
446 } 446 }
447 447
448 } // namespace content 448 } // namespace content
OLDNEW
« no previous file with comments | « content/public/test/test_browser_context.cc ('k') | content/public/test/test_launcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698