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 #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" |
11 #include "content/browser/download/download_create_info.h" | 11 #include "content/browser/download/download_create_info.h" |
12 #include "content/browser/download/download_file_impl.h" | 12 #include "content/browser/download/download_file_impl.h" |
13 #include "content/browser/download/download_file_manager.h" | 13 #include "content/browser/download/download_file_manager.h" |
14 #include "content/browser/power_save_blocker.h" | 14 #include "content/browser/power_save_blocker.h" |
15 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" | 15 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 #include "content/public/browser/download_id.h" | 17 #include "content/public/browser/download_id.h" |
18 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
19 | 19 |
| 20 namespace content { |
| 21 class ByteStreamReader; |
| 22 } |
| 23 |
20 namespace { | 24 namespace { |
21 | 25 |
22 DownloadFileManager* GetDownloadFileManager() { | 26 DownloadFileManager* GetDownloadFileManager() { |
23 content::ResourceDispatcherHostImpl* rdh = | 27 content::ResourceDispatcherHostImpl* rdh = |
24 content::ResourceDispatcherHostImpl::Get(); | 28 content::ResourceDispatcherHostImpl::Get(); |
25 DCHECK(rdh != NULL); | 29 DCHECK(rdh != NULL); |
26 return rdh->download_file_manager(); | 30 return rdh->download_file_manager(); |
27 } | 31 } |
28 | 32 |
29 // A class that performs file operations and injects errors. | 33 // A class that performs file operations and injects errors. |
30 class DownloadFileWithErrors: public DownloadFileImpl { | 34 class DownloadFileWithErrors: public DownloadFileImpl { |
31 public: | 35 public: |
32 typedef base::Callback<void(const GURL& url, content::DownloadId id)> | 36 typedef base::Callback<void(const GURL& url, content::DownloadId id)> |
33 ConstructionCallback; | 37 ConstructionCallback; |
34 typedef base::Callback<void(const GURL& url)> DestructionCallback; | 38 typedef base::Callback<void(const GURL& url)> DestructionCallback; |
35 | 39 |
36 DownloadFileWithErrors( | 40 DownloadFileWithErrors( |
37 const DownloadCreateInfo* info, | 41 const DownloadCreateInfo* info, |
| 42 scoped_ptr<content::ByteStreamReader> stream, |
38 DownloadRequestHandleInterface* request_handle, | 43 DownloadRequestHandleInterface* request_handle, |
39 content::DownloadManager* download_manager, | 44 content::DownloadManager* download_manager, |
40 bool calculate_hash, | 45 bool calculate_hash, |
41 const net::BoundNetLog& bound_net_log, | 46 const net::BoundNetLog& bound_net_log, |
42 const content::TestFileErrorInjector::FileErrorInfo& error_info, | 47 const content::TestFileErrorInjector::FileErrorInfo& error_info, |
43 const ConstructionCallback& ctor_callback, | 48 const ConstructionCallback& ctor_callback, |
44 const DestructionCallback& dtor_callback); | 49 const DestructionCallback& dtor_callback); |
45 | 50 |
46 ~DownloadFileWithErrors(); | 51 ~DownloadFileWithErrors(); |
47 | 52 |
(...skipping 18 matching lines...) Expand all Loading... |
66 // Count per operation. 0-based. | 71 // Count per operation. 0-based. |
67 std::map<content::TestFileErrorInjector::FileOperationCode, int> | 72 std::map<content::TestFileErrorInjector::FileOperationCode, int> |
68 operation_counter_; | 73 operation_counter_; |
69 | 74 |
70 // Callback for destruction. | 75 // Callback for destruction. |
71 DestructionCallback destruction_callback_; | 76 DestructionCallback destruction_callback_; |
72 }; | 77 }; |
73 | 78 |
74 DownloadFileWithErrors::DownloadFileWithErrors( | 79 DownloadFileWithErrors::DownloadFileWithErrors( |
75 const DownloadCreateInfo* info, | 80 const DownloadCreateInfo* info, |
| 81 scoped_ptr<content::ByteStreamReader> stream, |
76 DownloadRequestHandleInterface* request_handle, | 82 DownloadRequestHandleInterface* request_handle, |
77 content::DownloadManager* download_manager, | 83 content::DownloadManager* download_manager, |
78 bool calculate_hash, | 84 bool calculate_hash, |
79 const net::BoundNetLog& bound_net_log, | 85 const net::BoundNetLog& bound_net_log, |
80 const content::TestFileErrorInjector::FileErrorInfo& error_info, | 86 const content::TestFileErrorInjector::FileErrorInfo& error_info, |
81 const ConstructionCallback& ctor_callback, | 87 const ConstructionCallback& ctor_callback, |
82 const DestructionCallback& dtor_callback) | 88 const DestructionCallback& dtor_callback) |
83 : DownloadFileImpl(info, | 89 : DownloadFileImpl(info, |
| 90 stream.Pass(), |
84 request_handle, | 91 request_handle, |
85 download_manager, | 92 download_manager, |
86 calculate_hash, | 93 calculate_hash, |
87 scoped_ptr<PowerSaveBlocker>(NULL).Pass(), | 94 scoped_ptr<PowerSaveBlocker>(NULL).Pass(), |
88 bound_net_log), | 95 bound_net_log), |
89 source_url_(info->url()), | 96 source_url_(info->url()), |
90 error_info_(error_info), | 97 error_info_(error_info), |
91 destruction_callback_(dtor_callback) { | 98 destruction_callback_(dtor_callback) { |
92 ctor_callback.Run(source_url_, info->download_id); | 99 ctor_callback.Run(source_url_, info->download_id); |
93 } | 100 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 public: | 157 public: |
151 | 158 |
152 DownloadFileWithErrorsFactory( | 159 DownloadFileWithErrorsFactory( |
153 const DownloadFileWithErrors::ConstructionCallback& ctor_callback, | 160 const DownloadFileWithErrors::ConstructionCallback& ctor_callback, |
154 const DownloadFileWithErrors::DestructionCallback& dtor_callback); | 161 const DownloadFileWithErrors::DestructionCallback& dtor_callback); |
155 virtual ~DownloadFileWithErrorsFactory(); | 162 virtual ~DownloadFileWithErrorsFactory(); |
156 | 163 |
157 // DownloadFileFactory interface. | 164 // DownloadFileFactory interface. |
158 virtual content::DownloadFile* CreateFile( | 165 virtual content::DownloadFile* CreateFile( |
159 DownloadCreateInfo* info, | 166 DownloadCreateInfo* info, |
| 167 scoped_ptr<content::ByteStreamReader> stream, |
160 const DownloadRequestHandle& request_handle, | 168 const DownloadRequestHandle& request_handle, |
161 content::DownloadManager* download_manager, | 169 content::DownloadManager* download_manager, |
162 bool calculate_hash, | 170 bool calculate_hash, |
163 const net::BoundNetLog& bound_net_log); | 171 const net::BoundNetLog& bound_net_log); |
164 | 172 |
165 bool AddError( | 173 bool AddError( |
166 const TestFileErrorInjector::FileErrorInfo& error_info); | 174 const TestFileErrorInjector::FileErrorInfo& error_info); |
167 | 175 |
168 void ClearErrors(); | 176 void ClearErrors(); |
169 | 177 |
(...skipping 11 matching lines...) Expand all Loading... |
181 const DownloadFileWithErrors::DestructionCallback& dtor_callback) | 189 const DownloadFileWithErrors::DestructionCallback& dtor_callback) |
182 : construction_callback_(ctor_callback), | 190 : construction_callback_(ctor_callback), |
183 destruction_callback_(dtor_callback) { | 191 destruction_callback_(dtor_callback) { |
184 } | 192 } |
185 | 193 |
186 DownloadFileWithErrorsFactory::~DownloadFileWithErrorsFactory() { | 194 DownloadFileWithErrorsFactory::~DownloadFileWithErrorsFactory() { |
187 } | 195 } |
188 | 196 |
189 content::DownloadFile* DownloadFileWithErrorsFactory::CreateFile( | 197 content::DownloadFile* DownloadFileWithErrorsFactory::CreateFile( |
190 DownloadCreateInfo* info, | 198 DownloadCreateInfo* info, |
| 199 scoped_ptr<content::ByteStreamReader> stream, |
191 const DownloadRequestHandle& request_handle, | 200 const DownloadRequestHandle& request_handle, |
192 content::DownloadManager* download_manager, | 201 content::DownloadManager* download_manager, |
193 bool calculate_hash, | 202 bool calculate_hash, |
194 const net::BoundNetLog& bound_net_log) { | 203 const net::BoundNetLog& bound_net_log) { |
195 std::string url = info->url().spec(); | 204 std::string url = info->url().spec(); |
196 | 205 |
197 if (injected_errors_.find(url) == injected_errors_.end()) { | 206 if (injected_errors_.find(url) == injected_errors_.end()) { |
198 // Have to create entry, because FileErrorInfo is not a POD type. | 207 // Have to create entry, because FileErrorInfo is not a POD type. |
199 TestFileErrorInjector::FileErrorInfo err_info = { | 208 TestFileErrorInjector::FileErrorInfo err_info = { |
200 url, | 209 url, |
201 TestFileErrorInjector::FILE_OPERATION_INITIALIZE, | 210 TestFileErrorInjector::FILE_OPERATION_INITIALIZE, |
202 -1, | 211 -1, |
203 net::OK | 212 net::OK |
204 }; | 213 }; |
205 injected_errors_[url] = err_info; | 214 injected_errors_[url] = err_info; |
206 } | 215 } |
207 | 216 |
208 return new DownloadFileWithErrors(info, | 217 return new DownloadFileWithErrors(info, |
| 218 stream.Pass(), |
209 new DownloadRequestHandle(request_handle), | 219 new DownloadRequestHandle(request_handle), |
210 download_manager, | 220 download_manager, |
211 calculate_hash, | 221 calculate_hash, |
212 bound_net_log, | 222 bound_net_log, |
213 injected_errors_[url], | 223 injected_errors_[url], |
214 construction_callback_, | 224 construction_callback_, |
215 destruction_callback_); | 225 destruction_callback_); |
216 } | 226 } |
217 | 227 |
218 bool DownloadFileWithErrorsFactory::AddError( | 228 bool DownloadFileWithErrorsFactory::AddError( |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 case FILE_OPERATION_RENAME: | 422 case FILE_OPERATION_RENAME: |
413 return "RENAME"; | 423 return "RENAME"; |
414 default: | 424 default: |
415 break; | 425 break; |
416 } | 426 } |
417 | 427 |
418 return "Unknown"; | 428 return "Unknown"; |
419 } | 429 } |
420 | 430 |
421 } // namespace content | 431 } // namespace content |
OLD | NEW |