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

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

Issue 1750943002: [Downloads] Stop keying TestFileErrorInjector off of URLs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
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 <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/callback.h"
10 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "content/browser/download/download_file_factory.h" 13 #include "content/browser/download/download_file_factory.h"
13 #include "content/browser/download/download_file_impl.h" 14 #include "content/browser/download/download_file_impl.h"
14 #include "content/browser/download/download_interrupt_reasons_impl.h" 15 #include "content/browser/download/download_interrupt_reasons_impl.h"
15 #include "content/browser/download/download_manager_impl.h" 16 #include "content/browser/download/download_manager_impl.h"
16 #include "content/browser/loader/resource_dispatcher_host_impl.h" 17 #include "content/browser/loader/resource_dispatcher_host_impl.h"
17 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
18 #include "url/gurl.h" 19 #include "url/gurl.h"
19 20
20 namespace content { 21 namespace content {
21 class ByteStreamReader; 22 class ByteStreamReader;
22 23
23 namespace { 24 namespace {
24 25
25 // A class that performs file operations and injects errors. 26 // A class that performs file operations and injects errors.
26 class DownloadFileWithErrors: public DownloadFileImpl { 27 class DownloadFileWithErrors: public DownloadFileImpl {
27 public: 28 public:
28 typedef base::Callback<void(const GURL& url)> ConstructionCallback;
29 typedef base::Callback<void(const GURL& url)> DestructionCallback;
30
31 DownloadFileWithErrors(const DownloadSaveInfo& save_info, 29 DownloadFileWithErrors(const DownloadSaveInfo& save_info,
32 const base::FilePath& default_download_directory, 30 const base::FilePath& default_download_directory,
33 const GURL& url, 31 const GURL& url,
34 const GURL& referrer_url, 32 const GURL& referrer_url,
35 bool calculate_hash, 33 bool calculate_hash,
36 base::File file, 34 base::File file,
37 scoped_ptr<ByteStreamReader> byte_stream, 35 scoped_ptr<ByteStreamReader> byte_stream,
38 const net::BoundNetLog& bound_net_log, 36 const net::BoundNetLog& bound_net_log,
39 base::WeakPtr<DownloadDestinationObserver> observer, 37 base::WeakPtr<DownloadDestinationObserver> observer,
40 const TestFileErrorInjector::FileErrorInfo& error_info, 38 const TestFileErrorInjector::FileErrorInfo& error_info,
41 const ConstructionCallback& ctor_callback, 39 const base::Closure& ctor_callback,
42 const DestructionCallback& dtor_callback); 40 const base::Closure& dtor_callback);
43 41
44 ~DownloadFileWithErrors() override; 42 ~DownloadFileWithErrors() override;
45 43
46 void Initialize(const InitializeCallback& callback) override; 44 void Initialize(const InitializeCallback& callback) override;
47 45
48 // DownloadFile interface. 46 // DownloadFile interface.
49 DownloadInterruptReason AppendDataToFile(const char* data, 47 DownloadInterruptReason AppendDataToFile(const char* data,
50 size_t data_len) override; 48 size_t data_len) override;
51 void RenameAndUniquify(const base::FilePath& full_path, 49 void RenameAndUniquify(const base::FilePath& full_path,
52 const RenameCompletionCallback& callback) override; 50 const RenameCompletionCallback& callback) override;
53 void RenameAndAnnotate(const base::FilePath& full_path, 51 void RenameAndAnnotate(const base::FilePath& full_path,
54 const RenameCompletionCallback& callback) override; 52 const RenameCompletionCallback& callback) override;
55 53
56 private: 54 private:
57 // Error generating helper. 55 // Error generating helper.
58 DownloadInterruptReason ShouldReturnError( 56 DownloadInterruptReason ShouldReturnError(
59 TestFileErrorInjector::FileOperationCode code, 57 TestFileErrorInjector::FileOperationCode code,
60 DownloadInterruptReason original_error); 58 DownloadInterruptReason original_error);
61 59
62 // Determine whether to overwrite an operation with the given code 60 // Determine whether to overwrite an operation with the given code
63 // with a substitute error; if returns true, |*original_error| is 61 // with a substitute error; if returns true, |*original_error| is
64 // written with the error to use for overwriting. 62 // written with the error to use for overwriting.
65 // NOTE: This routine changes state; specifically, it increases the 63 // NOTE: This routine changes state; specifically, it increases the
66 // operations counts for the specified code. It should only be called 64 // operations counts for the specified code. It should only be called
67 // once per operation. 65 // once per operation.
68 bool OverwriteError( 66 bool OverwriteError(
69 TestFileErrorInjector::FileOperationCode code, 67 TestFileErrorInjector::FileOperationCode code,
70 DownloadInterruptReason* output_error); 68 DownloadInterruptReason* output_error);
71 69
72 // Source URL for the file being downloaded.
73 GURL source_url_;
74
75 // Our injected error. Only one per file. 70 // Our injected error. Only one per file.
76 TestFileErrorInjector::FileErrorInfo error_info_; 71 TestFileErrorInjector::FileErrorInfo error_info_;
77 72
78 // Count per operation. 0-based. 73 // Count per operation. 0-based.
79 std::map<TestFileErrorInjector::FileOperationCode, int> operation_counter_; 74 std::map<TestFileErrorInjector::FileOperationCode, int> operation_counter_;
80 75
81 // Callback for destruction. 76 // Callback for destruction.
82 DestructionCallback destruction_callback_; 77 base::Closure destruction_callback_;
83 }; 78 };
84 79
85 static void InitializeErrorCallback( 80 static void InitializeErrorCallback(
86 const DownloadFile::InitializeCallback original_callback, 81 const DownloadFile::InitializeCallback original_callback,
87 DownloadInterruptReason overwrite_error, 82 DownloadInterruptReason overwrite_error,
88 DownloadInterruptReason original_error) { 83 DownloadInterruptReason original_error) {
89 original_callback.Run(overwrite_error); 84 original_callback.Run(overwrite_error);
90 } 85 }
91 86
92 static void RenameErrorCallback( 87 static void RenameErrorCallback(
(...skipping 11 matching lines...) Expand all
104 const DownloadSaveInfo& save_info, 99 const DownloadSaveInfo& save_info,
105 const base::FilePath& default_download_directory, 100 const base::FilePath& default_download_directory,
106 const GURL& url, 101 const GURL& url,
107 const GURL& referrer_url, 102 const GURL& referrer_url,
108 bool calculate_hash, 103 bool calculate_hash,
109 base::File file, 104 base::File file,
110 scoped_ptr<ByteStreamReader> byte_stream, 105 scoped_ptr<ByteStreamReader> byte_stream,
111 const net::BoundNetLog& bound_net_log, 106 const net::BoundNetLog& bound_net_log,
112 base::WeakPtr<DownloadDestinationObserver> observer, 107 base::WeakPtr<DownloadDestinationObserver> observer,
113 const TestFileErrorInjector::FileErrorInfo& error_info, 108 const TestFileErrorInjector::FileErrorInfo& error_info,
114 const ConstructionCallback& ctor_callback, 109 const base::Closure& ctor_callback,
115 const DestructionCallback& dtor_callback) 110 const base::Closure& dtor_callback)
116 : DownloadFileImpl(save_info, 111 : DownloadFileImpl(save_info,
117 default_download_directory, 112 default_download_directory,
118 url, 113 url,
119 referrer_url, 114 referrer_url,
120 calculate_hash, 115 calculate_hash,
121 std::move(file), 116 std::move(file),
122 std::move(byte_stream), 117 std::move(byte_stream),
123 bound_net_log, 118 bound_net_log,
124 observer), 119 observer),
125 source_url_(url),
126 error_info_(error_info), 120 error_info_(error_info),
127 destruction_callback_(dtor_callback) { 121 destruction_callback_(dtor_callback) {
128 // DownloadFiles are created on the UI thread and are destroyed on the FILE 122 // DownloadFiles are created on the UI thread and are destroyed on the FILE
129 // thread. Schedule the ConstructionCallback on the FILE thread so that if a 123 // thread. Schedule the ConstructionCallback on the FILE thread so that if a
130 // DownloadItem schedules a DownloadFile to be destroyed and creates another 124 // DownloadItem schedules a DownloadFile to be destroyed and creates another
131 // one (as happens during download resumption), then the DestructionCallback 125 // one (as happens during download resumption), then the DestructionCallback
132 // for the old DownloadFile is run before the ConstructionCallback for the 126 // for the old DownloadFile is run before the ConstructionCallback for the
133 // next DownloadFile. 127 // next DownloadFile.
134 BrowserThread::PostTask( 128 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, ctor_callback);
135 BrowserThread::FILE,
136 FROM_HERE,
137 base::Bind(ctor_callback, source_url_));
138 } 129 }
139 130
140 DownloadFileWithErrors::~DownloadFileWithErrors() { 131 DownloadFileWithErrors::~DownloadFileWithErrors() {
141 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 132 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
142 destruction_callback_.Run(source_url_); 133 destruction_callback_.Run();
143 } 134 }
144 135
145 void DownloadFileWithErrors::Initialize( 136 void DownloadFileWithErrors::Initialize(
146 const InitializeCallback& callback) { 137 const InitializeCallback& callback) {
147 DownloadInterruptReason error_to_return = DOWNLOAD_INTERRUPT_REASON_NONE; 138 DownloadInterruptReason error_to_return = DOWNLOAD_INTERRUPT_REASON_NONE;
148 InitializeCallback callback_to_use = callback; 139 InitializeCallback callback_to_use = callback;
149 140
150 // Replace callback if the error needs to be overwritten. 141 // Replace callback if the error needs to be overwritten.
151 if (OverwriteError( 142 if (OverwriteError(
152 TestFileErrorInjector::FILE_OPERATION_INITIALIZE, 143 TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 DownloadInterruptReason output_error = original_error; 241 DownloadInterruptReason output_error = original_error;
251 OverwriteError(code, &output_error); 242 OverwriteError(code, &output_error);
252 return output_error; 243 return output_error;
253 } 244 }
254 245
255 } // namespace 246 } // namespace
256 247
257 // A factory for constructing DownloadFiles that inject errors. 248 // A factory for constructing DownloadFiles that inject errors.
258 class DownloadFileWithErrorsFactory : public DownloadFileFactory { 249 class DownloadFileWithErrorsFactory : public DownloadFileFactory {
259 public: 250 public:
260 DownloadFileWithErrorsFactory( 251 DownloadFileWithErrorsFactory(const base::Closure& ctor_callback,
261 const DownloadFileWithErrors::ConstructionCallback& ctor_callback, 252 const base::Closure& dtor_callback);
262 const DownloadFileWithErrors::DestructionCallback& dtor_callback);
263 ~DownloadFileWithErrorsFactory() override; 253 ~DownloadFileWithErrorsFactory() override;
264 254
265 // DownloadFileFactory interface. 255 // DownloadFileFactory interface.
266 DownloadFile* CreateFile( 256 DownloadFile* CreateFile(
267 const DownloadSaveInfo& save_info, 257 const DownloadSaveInfo& save_info,
268 const base::FilePath& default_download_directory, 258 const base::FilePath& default_download_directory,
269 const GURL& url, 259 const GURL& url,
270 const GURL& referrer_url, 260 const GURL& referrer_url,
271 bool calculate_hash, 261 bool calculate_hash,
272 base::File file, 262 base::File file,
273 scoped_ptr<ByteStreamReader> byte_stream, 263 scoped_ptr<ByteStreamReader> byte_stream,
274 const net::BoundNetLog& bound_net_log, 264 const net::BoundNetLog& bound_net_log,
275 base::WeakPtr<DownloadDestinationObserver> observer) override; 265 base::WeakPtr<DownloadDestinationObserver> observer) override;
276 266
277 bool AddError( 267 bool SetErrorQueue(TestFileErrorInjector::ErrorQueue errors);
278 const TestFileErrorInjector::FileErrorInfo& error_info);
279
280 void ClearErrors();
281 268
282 private: 269 private:
283 // Our injected error list, mapped by URL. One per file. 270 // Our injected error list, mapped by URL. One per file.
284 TestFileErrorInjector::ErrorMap injected_errors_; 271 TestFileErrorInjector::ErrorQueue injected_errors_;
285 272
286 // Callback for creation and destruction. 273 // Callback for creation and destruction.
287 DownloadFileWithErrors::ConstructionCallback construction_callback_; 274 base::Closure construction_callback_;
288 DownloadFileWithErrors::DestructionCallback destruction_callback_; 275 base::Closure destruction_callback_;
289 }; 276 };
290 277
291 DownloadFileWithErrorsFactory::DownloadFileWithErrorsFactory( 278 DownloadFileWithErrorsFactory::DownloadFileWithErrorsFactory(
292 const DownloadFileWithErrors::ConstructionCallback& ctor_callback, 279 const base::Closure& ctor_callback,
293 const DownloadFileWithErrors::DestructionCallback& dtor_callback) 280 const base::Closure& dtor_callback)
294 : construction_callback_(ctor_callback), 281 : construction_callback_(ctor_callback),
295 destruction_callback_(dtor_callback) { 282 destruction_callback_(dtor_callback) {}
296 }
297 283
298 DownloadFileWithErrorsFactory::~DownloadFileWithErrorsFactory() { 284 DownloadFileWithErrorsFactory::~DownloadFileWithErrorsFactory() {
299 } 285 }
300 286
301 DownloadFile* DownloadFileWithErrorsFactory::CreateFile( 287 DownloadFile* DownloadFileWithErrorsFactory::CreateFile(
302 const DownloadSaveInfo& save_info, 288 const DownloadSaveInfo& save_info,
303 const base::FilePath& default_download_directory, 289 const base::FilePath& default_download_directory,
304 const GURL& url, 290 const GURL& url,
305 const GURL& referrer_url, 291 const GURL& referrer_url,
306 bool calculate_hash, 292 bool calculate_hash,
307 base::File file, 293 base::File file,
308 scoped_ptr<ByteStreamReader> byte_stream, 294 scoped_ptr<ByteStreamReader> byte_stream,
309 const net::BoundNetLog& bound_net_log, 295 const net::BoundNetLog& bound_net_log,
310 base::WeakPtr<DownloadDestinationObserver> observer) { 296 base::WeakPtr<DownloadDestinationObserver> observer) {
311 if (injected_errors_.find(url.spec()) == injected_errors_.end()) { 297 static TestFileErrorInjector::FileErrorInfo kNoOpErrorInfo = {
312 // Have to create entry, because FileErrorInfo is not a POD type. 298 TestFileErrorInjector::FILE_OPERATION_INITIALIZE, -1,
313 TestFileErrorInjector::FileErrorInfo err_info = { 299 DOWNLOAD_INTERRUPT_REASON_NONE};
314 url.spec(), 300 TestFileErrorInjector::FileErrorInfo err_info =
315 TestFileErrorInjector::FILE_OPERATION_INITIALIZE, 301 injected_errors_.empty() ? kNoOpErrorInfo : injected_errors_.front();
svaldez 2016/03/01 18:01:49 I might be misunderstanding the code, but don't yo
asanka 2016/03/01 18:58:49 Indeed. None of the tests depend on that, which ma
316 -1,
317 DOWNLOAD_INTERRUPT_REASON_NONE
318 };
319 injected_errors_[url.spec()] = err_info;
320 }
321 302
322 return new DownloadFileWithErrors( 303 return new DownloadFileWithErrors(
323 save_info, default_download_directory, url, referrer_url, calculate_hash, 304 save_info, default_download_directory, url, referrer_url, calculate_hash,
324 std::move(file), std::move(byte_stream), bound_net_log, observer, 305 std::move(file), std::move(byte_stream), bound_net_log, observer,
325 injected_errors_[url.spec()], construction_callback_, 306 err_info, construction_callback_, destruction_callback_);
326 destruction_callback_);
327 } 307 }
328 308
329 bool DownloadFileWithErrorsFactory::AddError( 309 bool DownloadFileWithErrorsFactory::SetErrorQueue(
330 const TestFileErrorInjector::FileErrorInfo& error_info) { 310 TestFileErrorInjector::ErrorQueue errors) {
331 // Creates an empty entry if necessary. Duplicate entries overwrite. 311 injected_errors_ = std::move(errors);
332 injected_errors_[error_info.url] = error_info;
333
334 return true; 312 return true;
335 } 313 }
336 314
337 void DownloadFileWithErrorsFactory::ClearErrors() { 315 TestFileErrorInjector::TestFileErrorInjector(DownloadManager* download_manager)
338 injected_errors_.clear(); 316 : // This code is only used for browser_tests, so a
339 }
340
341 TestFileErrorInjector::TestFileErrorInjector(
342 DownloadManager* download_manager)
343 : created_factory_(NULL),
344 // This code is only used for browser_tests, so a
345 // DownloadManager is always a DownloadManagerImpl. 317 // DownloadManager is always a DownloadManagerImpl.
asanka 2016/03/01 16:11:38 This is .. special. I'm going to move ownership of
346 download_manager_(static_cast<DownloadManagerImpl*>(download_manager)) { 318 download_manager_(static_cast<DownloadManagerImpl*>(download_manager)) {
347 // Record the value of the pointer, for later validation. 319 // Record the value of the pointer, for later validation.
348 created_factory_ = 320 created_factory_ =
349 new DownloadFileWithErrorsFactory( 321 new DownloadFileWithErrorsFactory(
350 base::Bind(&TestFileErrorInjector::RecordDownloadFileConstruction, 322 base::Bind(&TestFileErrorInjector::RecordDownloadFileConstruction,
351 this), 323 this),
352 base::Bind(&TestFileErrorInjector::RecordDownloadFileDestruction, 324 base::Bind(&TestFileErrorInjector::RecordDownloadFileDestruction,
353 this)); 325 this));
354 326
355 // We will transfer ownership of the factory to the download manager. 327 // We will transfer ownership of the factory to the download manager.
356 scoped_ptr<DownloadFileFactory> download_file_factory( 328 scoped_ptr<DownloadFileFactory> download_file_factory(
357 created_factory_); 329 created_factory_);
358 330
359 download_manager_->SetDownloadFileFactoryForTesting( 331 download_manager_->SetDownloadFileFactoryForTesting(
360 std::move(download_file_factory)); 332 std::move(download_file_factory));
361 } 333 }
362 334
363 TestFileErrorInjector::~TestFileErrorInjector() { 335 TestFileErrorInjector::~TestFileErrorInjector() {
364 } 336 }
365 337
366 bool TestFileErrorInjector::AddError(const FileErrorInfo& error_info) { 338 bool TestFileErrorInjector::AddError(const FileErrorInfo& error_info) {
367 DCHECK_CURRENTLY_ON(BrowserThread::UI); 339 DCHECK_CURRENTLY_ON(BrowserThread::UI);
368 DCHECK_LE(0, error_info.operation_instance); 340 DCHECK_LE(0, error_info.operation_instance);
369 DCHECK(injected_errors_.find(error_info.url) == injected_errors_.end());
370 341
371 // Creates an empty entry if necessary. 342 // Creates an empty entry if necessary.
372 injected_errors_[error_info.url] = error_info; 343 injected_errors_.push_back(error_info);
373 344
374 return true; 345 return true;
375 } 346 }
376 347
377 void TestFileErrorInjector::ClearErrors() { 348 void TestFileErrorInjector::ClearErrors() {
378 DCHECK_CURRENTLY_ON(BrowserThread::UI); 349 DCHECK_CURRENTLY_ON(BrowserThread::UI);
379 injected_errors_.clear(); 350 injected_errors_.clear();
380 } 351 }
381 352
382 bool TestFileErrorInjector::InjectErrors() { 353 bool TestFileErrorInjector::InjectErrors() {
383 DCHECK_CURRENTLY_ON(BrowserThread::UI); 354 DCHECK_CURRENTLY_ON(BrowserThread::UI);
384 355
385 ClearFoundFiles(); 356 ClearTotalFileCount();
386 357
387 DCHECK_EQ(static_cast<DownloadFileFactory*>(created_factory_), 358 DCHECK_EQ(static_cast<DownloadFileFactory*>(created_factory_),
388 download_manager_->GetDownloadFileFactoryForTesting()); 359 download_manager_->GetDownloadFileFactoryForTesting());
389 360
390 created_factory_->ClearErrors(); 361 created_factory_->SetErrorQueue(std::move(injected_errors_));
391
392 for (ErrorMap::const_iterator it = injected_errors_.begin();
393 it != injected_errors_.end(); ++it)
394 created_factory_->AddError(it->second);
395
396 return true; 362 return true;
397 } 363 }
398 364
399 size_t TestFileErrorInjector::CurrentFileCount() const { 365 size_t TestFileErrorInjector::CurrentFileCount() const {
400 DCHECK_CURRENTLY_ON(BrowserThread::UI); 366 DCHECK_CURRENTLY_ON(BrowserThread::UI);
401 return files_.size(); 367 return active_file_count_;
402 } 368 }
403 369
404 size_t TestFileErrorInjector::TotalFileCount() const { 370 size_t TestFileErrorInjector::TotalFileCount() const {
405 DCHECK_CURRENTLY_ON(BrowserThread::UI); 371 DCHECK_CURRENTLY_ON(BrowserThread::UI);
406 return found_files_.size(); 372 return total_file_count_;
407 } 373 }
408 374
409 375 void TestFileErrorInjector::ClearTotalFileCount() {
410 bool TestFileErrorInjector::HadFile(const GURL& url) const { 376 total_file_count_ = 0;
411 DCHECK_CURRENTLY_ON(BrowserThread::UI);
412
413 return (found_files_.find(url) != found_files_.end());
414 } 377 }
415 378
416 void TestFileErrorInjector::ClearFoundFiles() { 379 void TestFileErrorInjector::DownloadFileCreated() {
417 found_files_.clear(); 380 DCHECK_CURRENTLY_ON(BrowserThread::UI);
381 ++active_file_count_;
382 ++total_file_count_;
418 } 383 }
419 384
420 void TestFileErrorInjector::DownloadFileCreated(GURL url) { 385 void TestFileErrorInjector::DestroyingDownloadFile() {
421 DCHECK_CURRENTLY_ON(BrowserThread::UI); 386 DCHECK_CURRENTLY_ON(BrowserThread::UI);
422 DCHECK(files_.find(url) == files_.end()); 387 --active_file_count_;
423
424 files_.insert(url);
425 found_files_.insert(url);
426 } 388 }
427 389
428 void TestFileErrorInjector::DestroyingDownloadFile(GURL url) { 390 void TestFileErrorInjector::RecordDownloadFileConstruction() {
429 DCHECK_CURRENTLY_ON(BrowserThread::UI); 391 BrowserThread::PostTask(
430 DCHECK(files_.find(url) != files_.end()); 392 BrowserThread::UI, FROM_HERE,
431 393 base::Bind(&TestFileErrorInjector::DownloadFileCreated, this));
432 files_.erase(url);
433 } 394 }
434 395
435 void TestFileErrorInjector::RecordDownloadFileConstruction(const GURL& url) { 396 void TestFileErrorInjector::RecordDownloadFileDestruction() {
436 BrowserThread::PostTask( 397 BrowserThread::PostTask(
437 BrowserThread::UI, 398 BrowserThread::UI, FROM_HERE,
438 FROM_HERE, 399 base::Bind(&TestFileErrorInjector::DestroyingDownloadFile, this));
439 base::Bind(&TestFileErrorInjector::DownloadFileCreated, this, url));
440 }
441
442 void TestFileErrorInjector::RecordDownloadFileDestruction(const GURL& url) {
443 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
444 base::Bind(&TestFileErrorInjector::DestroyingDownloadFile, this, url));
445 } 400 }
446 401
447 // static 402 // static
448 scoped_refptr<TestFileErrorInjector> TestFileErrorInjector::Create( 403 scoped_refptr<TestFileErrorInjector> TestFileErrorInjector::Create(
449 DownloadManager* download_manager) { 404 DownloadManager* download_manager) {
450 static bool visited = false; 405 static bool visited = false;
451 DCHECK(!visited); // Only allowed to be called once. 406 DCHECK(!visited); // Only allowed to be called once.
452 visited = true; 407 visited = true;
453 408
454 scoped_refptr<TestFileErrorInjector> single_injector( 409 scoped_refptr<TestFileErrorInjector> single_injector(
(...skipping 14 matching lines...) Expand all
469 case FILE_OPERATION_RENAME_ANNOTATE: 424 case FILE_OPERATION_RENAME_ANNOTATE:
470 return "RENAME_ANNOTATE"; 425 return "RENAME_ANNOTATE";
471 default: 426 default:
472 break; 427 break;
473 } 428 }
474 429
475 return "Unknown"; 430 return "Unknown";
476 } 431 }
477 432
478 } // namespace content 433 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698