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

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

Issue 14593012: BrowserContext should simply own DownloadManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 7 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 <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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 injected_errors_[error_info.url] = error_info; 331 injected_errors_[error_info.url] = error_info;
332 332
333 return true; 333 return true;
334 } 334 }
335 335
336 void DownloadFileWithErrorsFactory::ClearErrors() { 336 void DownloadFileWithErrorsFactory::ClearErrors() {
337 injected_errors_.clear(); 337 injected_errors_.clear();
338 } 338 }
339 339
340 TestFileErrorInjector::TestFileErrorInjector( 340 TestFileErrorInjector::TestFileErrorInjector(
341 scoped_refptr<DownloadManager> download_manager) 341 DownloadManager* download_manager)
342 : created_factory_(NULL), 342 : created_factory_(NULL),
343 // This code is only used for browser_tests, so a 343 // This code is only used for browser_tests, so a
344 // DownloadManager is always a DownloadManagerImpl. 344 // DownloadManager is always a DownloadManagerImpl.
345 download_manager_( 345 download_manager_(static_cast<DownloadManagerImpl*>(download_manager)) {
346 static_cast<DownloadManagerImpl*>(download_manager.get())) {
347 // Record the value of the pointer, for later validation. 346 // Record the value of the pointer, for later validation.
348 created_factory_ = 347 created_factory_ =
349 new DownloadFileWithErrorsFactory( 348 new DownloadFileWithErrorsFactory(
350 base::Bind(&TestFileErrorInjector::RecordDownloadFileConstruction, 349 base::Bind(&TestFileErrorInjector::RecordDownloadFileConstruction,
351 this), 350 this),
352 base::Bind(&TestFileErrorInjector::RecordDownloadFileDestruction, 351 base::Bind(&TestFileErrorInjector::RecordDownloadFileDestruction,
353 this)); 352 this));
354 353
355 // We will transfer ownership of the factory to the download manager. 354 // We will transfer ownership of the factory to the download manager.
356 scoped_ptr<DownloadFileFactory> download_file_factory( 355 scoped_ptr<DownloadFileFactory> download_file_factory(
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 base::Bind(&TestFileErrorInjector::DownloadFileCreated, this, url)); 438 base::Bind(&TestFileErrorInjector::DownloadFileCreated, this, url));
440 } 439 }
441 440
442 void TestFileErrorInjector::RecordDownloadFileDestruction(const GURL& url) { 441 void TestFileErrorInjector::RecordDownloadFileDestruction(const GURL& url) {
443 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 442 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
444 base::Bind(&TestFileErrorInjector::DestroyingDownloadFile, this, url)); 443 base::Bind(&TestFileErrorInjector::DestroyingDownloadFile, this, url));
445 } 444 }
446 445
447 // static 446 // static
448 scoped_refptr<TestFileErrorInjector> TestFileErrorInjector::Create( 447 scoped_refptr<TestFileErrorInjector> TestFileErrorInjector::Create(
449 scoped_refptr<DownloadManager> download_manager) { 448 DownloadManager* download_manager) {
450 static bool visited = false; 449 static bool visited = false;
451 DCHECK(!visited); // Only allowed to be called once. 450 DCHECK(!visited); // Only allowed to be called once.
452 visited = true; 451 visited = true;
453 452
454 scoped_refptr<TestFileErrorInjector> single_injector( 453 scoped_refptr<TestFileErrorInjector> single_injector(
455 new TestFileErrorInjector(download_manager)); 454 new TestFileErrorInjector(download_manager));
456 455
457 return single_injector; 456 return single_injector;
458 } 457 }
459 458
460 // static 459 // static
461 std::string TestFileErrorInjector::DebugString(FileOperationCode code) { 460 std::string TestFileErrorInjector::DebugString(FileOperationCode code) {
462 switch (code) { 461 switch (code) {
463 case FILE_OPERATION_INITIALIZE: 462 case FILE_OPERATION_INITIALIZE:
464 return "INITIALIZE"; 463 return "INITIALIZE";
465 case FILE_OPERATION_WRITE: 464 case FILE_OPERATION_WRITE:
466 return "WRITE"; 465 return "WRITE";
467 case FILE_OPERATION_RENAME_UNIQUIFY: 466 case FILE_OPERATION_RENAME_UNIQUIFY:
468 return "RENAME_UNIQUIFY"; 467 return "RENAME_UNIQUIFY";
469 case FILE_OPERATION_RENAME_ANNOTATE: 468 case FILE_OPERATION_RENAME_ANNOTATE:
470 return "RENAME_ANNOTATE"; 469 return "RENAME_ANNOTATE";
471 default: 470 default:
472 break; 471 break;
473 } 472 }
474 473
475 return "Unknown"; 474 return "Unknown";
476 } 475 }
477 476
478 } // namespace content 477 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698