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

Unified Diff: content/public/test/test_file_error_injector.h

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, 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 side-by-side diff with in-line comments
Download patch
Index: content/public/test/test_file_error_injector.h
diff --git a/content/public/test/test_file_error_injector.h b/content/public/test/test_file_error_injector.h
index f3ab979b68e9905f4d65ee195ac4e872d2d5208e..a84f5f4ef9d950bd81a46aefd4fb6e2425c3cefa 100644
--- a/content/public/test/test_file_error_injector.h
+++ b/content/public/test/test_file_error_injector.h
@@ -7,8 +7,7 @@
#include <stddef.h>
-#include <map>
-#include <set>
+#include <deque>
#include <string>
#include "base/macros.h"
@@ -29,12 +28,10 @@ class DownloadManagerImpl;
// All errors for a download must be injected before it starts.
// This class needs to be |RefCountedThreadSafe| because the implementation
// is referenced by other classes that live past the time when the user is
-// nominally done with it. These classes are internal to content/.
+// nominally done with it.
//
-// NOTE: No more than one download with the same URL can be in progress at
-// the same time. You can have multiple simultaneous downloads as long as the
-// URLs are different, as the URLs are used as keys to get information about
-// the download.
+// Each error is injected to a single DownloadFile in the order in which the
+// error was added to the TestFileErrorInjector.
//
// Example:
//
@@ -48,9 +45,8 @@ class DownloadManagerImpl;
// injector->AddError(b);
// injector->InjectErrors();
//
-// download_manager->DownloadUrl(url1, ...);
-// download_manager->DownloadUrl(url2, ...);
-// ... wait for downloads to finish or get an injected error ...
+// download_manager->DownloadUrl(url1, ...); // Will be interrupted due to |a|.
+// download_manager->DownloadUrl(url2, ...); // Will be interrupted due to |b|.
class TestFileErrorInjector
: public base::RefCountedThreadSafe<TestFileErrorInjector> {
public:
@@ -63,13 +59,12 @@ class TestFileErrorInjector
// Structure that encapsulates the information needed to inject a file error.
struct FileErrorInfo {
- std::string url; // Full URL of the download. Identifies the download.
FileOperationCode code; // Operation to affect.
int operation_instance; // 0-based count of operation calls, for each code.
DownloadInterruptReason error; // Error to inject.
};
- typedef std::map<std::string, FileErrorInfo> ErrorMap;
+ using ErrorQueue = std::deque<FileErrorInfo>;
// Creates an instance. May only be called once.
// Lives until all callbacks (in the implementation) are complete and the
@@ -80,8 +75,6 @@ class TestFileErrorInjector
// Adds an error.
// Must be called before |InjectErrors()| for a particular download file.
- // It is an error to call |AddError()| more than once for the same file
- // (URL), unless you call |ClearErrors()| in between them.
bool AddError(const FileErrorInfo& error_info);
// Clears all errors.
@@ -101,47 +94,42 @@ class TestFileErrorInjector
// last call to |ClearFoundFiles()|).
size_t TotalFileCount() const;
- // Returns whether or not a file matching |url| has been created.
- bool HadFile(const GURL& url) const;
-
// Resets the found file list.
- void ClearFoundFiles();
+ void ClearTotalFileCount();
static std::string DebugString(FileOperationCode code);
private:
friend class base::RefCountedThreadSafe<TestFileErrorInjector>;
- typedef std::set<GURL> FileSet;
-
explicit TestFileErrorInjector(DownloadManager* download_manager);
virtual ~TestFileErrorInjector();
// Callbacks from the download file, to record lifetimes.
// These may be called on any thread.
- void RecordDownloadFileConstruction(const GURL& url);
- void RecordDownloadFileDestruction(const GURL& url);
+ void RecordDownloadFileConstruction();
+ void RecordDownloadFileDestruction();
// These run on the UI thread.
- void DownloadFileCreated(GURL url);
- void DestroyingDownloadFile(GURL url);
+ void DownloadFileCreated();
+ void DestroyingDownloadFile();
// All the data is used on the UI thread.
- // Our injected error list, mapped by URL. One per file.
- ErrorMap injected_errors_;
+ // Our injected error queue. One per file.
+ ErrorQueue injected_errors_;
svaldez 2016/03/01 18:01:49 Possibly assert on empty upon destruction?
asanka 2016/03/01 18:58:49 Now a no-op.
// Keep track of active DownloadFiles.
- FileSet files_;
+ size_t active_file_count_ = 0;
// Keep track of found DownloadFiles.
- FileSet found_files_;
+ size_t total_file_count_ = 0;
- // The factory we created. May outlive this class.
- DownloadFileWithErrorsFactory* created_factory_;
+ // The factory we created. May outlive this class.
+ DownloadFileWithErrorsFactory* created_factory_ = nullptr;
// The download manager we set the factory on.
- DownloadManagerImpl* download_manager_;
+ DownloadManagerImpl* download_manager_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(TestFileErrorInjector);
};

Powered by Google App Engine
This is Rietveld 408576698