Chromium Code Reviews| 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 #ifndef CONTENT_PUBLIC_TEST_TEST_FILE_ERROR_INJECTOR_H_ | 5 #ifndef CONTENT_PUBLIC_TEST_TEST_FILE_ERROR_INJECTOR_H_ |
| 6 #define CONTENT_PUBLIC_TEST_TEST_FILE_ERROR_INJECTOR_H_ | 6 #define CONTENT_PUBLIC_TEST_TEST_FILE_ERROR_INJECTOR_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 DownloadInterruptReason error; // Error to inject. | 67 DownloadInterruptReason error; // Error to inject. |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 typedef std::map<std::string, FileErrorInfo> ErrorMap; | 70 typedef std::map<std::string, FileErrorInfo> ErrorMap; |
| 71 | 71 |
| 72 // Creates an instance. May only be called once. | 72 // Creates an instance. May only be called once. |
| 73 // Lives until all callbacks (in the implementation) are complete and the | 73 // Lives until all callbacks (in the implementation) are complete and the |
| 74 // creator goes out of scope. | 74 // creator goes out of scope. |
| 75 // TODO(rdsmith): Allow multiple calls for different download managers. | 75 // TODO(rdsmith): Allow multiple calls for different download managers. |
| 76 static scoped_refptr<TestFileErrorInjector> Create( | 76 static scoped_refptr<TestFileErrorInjector> Create( |
| 77 scoped_refptr<DownloadManager> download_manager); | 77 DownloadManager* download_manager); |
| 78 | 78 |
| 79 // Adds an error. | 79 // Adds an error. |
| 80 // Must be called before |InjectErrors()| for a particular download file. | 80 // Must be called before |InjectErrors()| for a particular download file. |
| 81 // It is an error to call |AddError()| more than once for the same file | 81 // It is an error to call |AddError()| more than once for the same file |
| 82 // (URL), unless you call |ClearErrors()| in between them. | 82 // (URL), unless you call |ClearErrors()| in between them. |
| 83 bool AddError(const FileErrorInfo& error_info); | 83 bool AddError(const FileErrorInfo& error_info); |
| 84 | 84 |
| 85 // Clears all errors. | 85 // Clears all errors. |
| 86 // Only affects files created after the next call to InjectErrors(). | 86 // Only affects files created after the next call to InjectErrors(). |
| 87 void ClearErrors(); | 87 void ClearErrors(); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 105 // Resets the found file list. | 105 // Resets the found file list. |
| 106 void ClearFoundFiles(); | 106 void ClearFoundFiles(); |
| 107 | 107 |
| 108 static std::string DebugString(FileOperationCode code); | 108 static std::string DebugString(FileOperationCode code); |
| 109 | 109 |
| 110 private: | 110 private: |
| 111 friend class base::RefCountedThreadSafe<TestFileErrorInjector>; | 111 friend class base::RefCountedThreadSafe<TestFileErrorInjector>; |
| 112 | 112 |
| 113 typedef std::set<GURL> FileSet; | 113 typedef std::set<GURL> FileSet; |
| 114 | 114 |
| 115 TestFileErrorInjector( | 115 TestFileErrorInjector(DownloadManager* download_manager); |
|
sky
2013/05/23 21:55:53
explicit
| |
| 116 scoped_refptr<DownloadManager> download_manager); | |
| 117 | 116 |
| 118 virtual ~TestFileErrorInjector(); | 117 virtual ~TestFileErrorInjector(); |
| 119 | 118 |
| 120 // Callbacks from the download file, to record lifetimes. | 119 // Callbacks from the download file, to record lifetimes. |
| 121 // These may be called on any thread. | 120 // These may be called on any thread. |
| 122 void RecordDownloadFileConstruction(const GURL& url); | 121 void RecordDownloadFileConstruction(const GURL& url); |
| 123 void RecordDownloadFileDestruction(const GURL& url); | 122 void RecordDownloadFileDestruction(const GURL& url); |
| 124 | 123 |
| 125 // These run on the UI thread. | 124 // These run on the UI thread. |
| 126 void DownloadFileCreated(GURL url); | 125 void DownloadFileCreated(GURL url); |
| 127 void DestroyingDownloadFile(GURL url); | 126 void DestroyingDownloadFile(GURL url); |
| 128 | 127 |
| 129 // All the data is used on the UI thread. | 128 // All the data is used on the UI thread. |
| 130 // Our injected error list, mapped by URL. One per file. | 129 // Our injected error list, mapped by URL. One per file. |
| 131 ErrorMap injected_errors_; | 130 ErrorMap injected_errors_; |
| 132 | 131 |
| 133 // Keep track of active DownloadFiles. | 132 // Keep track of active DownloadFiles. |
| 134 FileSet files_; | 133 FileSet files_; |
| 135 | 134 |
| 136 // Keep track of found DownloadFiles. | 135 // Keep track of found DownloadFiles. |
| 137 FileSet found_files_; | 136 FileSet found_files_; |
| 138 | 137 |
| 139 // The factory we created. May outlive this class. | 138 // The factory we created. May outlive this class. |
| 140 DownloadFileWithErrorsFactory* created_factory_; | 139 DownloadFileWithErrorsFactory* created_factory_; |
| 141 | 140 |
| 142 // The download manager we set the factory on. | 141 // The download manager we set the factory on. |
| 143 scoped_refptr<DownloadManagerImpl> download_manager_; | 142 DownloadManagerImpl* download_manager_; |
| 144 | 143 |
| 145 DISALLOW_COPY_AND_ASSIGN(TestFileErrorInjector); | 144 DISALLOW_COPY_AND_ASSIGN(TestFileErrorInjector); |
| 146 }; | 145 }; |
| 147 | 146 |
| 148 } // namespace content | 147 } // namespace content |
| 149 | 148 |
| 150 #endif // CONTENT_PUBLIC_TEST_TEST_FILE_ERROR_INJECTOR_H_ | 149 #endif // CONTENT_PUBLIC_TEST_TEST_FILE_ERROR_INJECTOR_H_ |
| OLD | NEW |