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_file_factory.h" | 11 #include "content/browser/download/download_file_factory.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_interrupt_reasons_impl.h" | 13 #include "content/browser/download/download_interrupt_reasons_impl.h" |
14 #include "content/browser/download/download_manager_impl.h" | 14 #include "content/browser/download/download_manager_impl.h" |
15 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 15 #include "content/browser/loader/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_interrupt_reasons.h" |
17 #include "content/public/browser/power_save_blocker.h" | 18 #include "content/public/browser/power_save_blocker.h" |
18 #include "url/gurl.h" | 19 #include "url/gurl.h" |
19 | 20 |
20 namespace content { | 21 namespace content { |
| 22 template <typename StatusType> |
21 class ByteStreamReader; | 23 class ByteStreamReader; |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
25 // A class that performs file operations and injects errors. | 27 // A class that performs file operations and injects errors. |
26 class DownloadFileWithErrors: public DownloadFileImpl { | 28 class DownloadFileWithErrors: public DownloadFileImpl { |
27 public: | 29 public: |
28 typedef base::Callback<void(const GURL& url)> ConstructionCallback; | 30 typedef base::Callback<void(const GURL& url)> ConstructionCallback; |
29 typedef base::Callback<void(const GURL& url)> DestructionCallback; | 31 typedef base::Callback<void(const GURL& url)> DestructionCallback; |
30 | 32 |
31 DownloadFileWithErrors( | 33 DownloadFileWithErrors( |
32 scoped_ptr<DownloadSaveInfo> save_info, | 34 scoped_ptr<DownloadSaveInfo> save_info, |
33 const base::FilePath& default_download_directory, | 35 const base::FilePath& default_download_directory, |
34 const GURL& url, | 36 const GURL& url, |
35 const GURL& referrer_url, | 37 const GURL& referrer_url, |
36 bool calculate_hash, | 38 bool calculate_hash, |
37 scoped_ptr<ByteStreamReader> stream, | 39 scoped_ptr<ByteStreamReader<DownloadInterruptReason> > stream, |
38 const net::BoundNetLog& bound_net_log, | 40 const net::BoundNetLog& bound_net_log, |
39 scoped_ptr<PowerSaveBlocker> power_save_blocker, | 41 scoped_ptr<PowerSaveBlocker> power_save_blocker, |
40 base::WeakPtr<DownloadDestinationObserver> observer, | 42 base::WeakPtr<DownloadDestinationObserver> observer, |
41 const TestFileErrorInjector::FileErrorInfo& error_info, | 43 const TestFileErrorInjector::FileErrorInfo& error_info, |
42 const ConstructionCallback& ctor_callback, | 44 const ConstructionCallback& ctor_callback, |
43 const DestructionCallback& dtor_callback); | 45 const DestructionCallback& dtor_callback); |
44 | 46 |
45 virtual ~DownloadFileWithErrors(); | 47 virtual ~DownloadFileWithErrors(); |
46 | 48 |
47 virtual void Initialize(const InitializeCallback& callback) OVERRIDE; | 49 virtual void Initialize(const InitializeCallback& callback) OVERRIDE; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 overwrite_error == DOWNLOAD_INTERRUPT_REASON_NONE ? | 104 overwrite_error == DOWNLOAD_INTERRUPT_REASON_NONE ? |
103 path_result : base::FilePath()); | 105 path_result : base::FilePath()); |
104 } | 106 } |
105 | 107 |
106 DownloadFileWithErrors::DownloadFileWithErrors( | 108 DownloadFileWithErrors::DownloadFileWithErrors( |
107 scoped_ptr<DownloadSaveInfo> save_info, | 109 scoped_ptr<DownloadSaveInfo> save_info, |
108 const base::FilePath& default_download_directory, | 110 const base::FilePath& default_download_directory, |
109 const GURL& url, | 111 const GURL& url, |
110 const GURL& referrer_url, | 112 const GURL& referrer_url, |
111 bool calculate_hash, | 113 bool calculate_hash, |
112 scoped_ptr<ByteStreamReader> stream, | 114 scoped_ptr<ByteStreamReader<DownloadInterruptReason> > stream, |
113 const net::BoundNetLog& bound_net_log, | 115 const net::BoundNetLog& bound_net_log, |
114 scoped_ptr<PowerSaveBlocker> power_save_blocker, | 116 scoped_ptr<PowerSaveBlocker> power_save_blocker, |
115 base::WeakPtr<DownloadDestinationObserver> observer, | 117 base::WeakPtr<DownloadDestinationObserver> observer, |
116 const TestFileErrorInjector::FileErrorInfo& error_info, | 118 const TestFileErrorInjector::FileErrorInfo& error_info, |
117 const ConstructionCallback& ctor_callback, | 119 const ConstructionCallback& ctor_callback, |
118 const DestructionCallback& dtor_callback) | 120 const DestructionCallback& dtor_callback) |
119 : DownloadFileImpl( | 121 : DownloadFileImpl( |
120 save_info.Pass(), default_download_directory, url, referrer_url, | 122 save_info.Pass(), default_download_directory, url, referrer_url, |
121 calculate_hash, stream.Pass(), bound_net_log, | 123 calculate_hash, stream.Pass(), bound_net_log, |
122 power_save_blocker.Pass(), observer), | 124 power_save_blocker.Pass(), observer), |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 const DownloadFileWithErrors::DestructionCallback& dtor_callback); | 262 const DownloadFileWithErrors::DestructionCallback& dtor_callback); |
261 virtual ~DownloadFileWithErrorsFactory(); | 263 virtual ~DownloadFileWithErrorsFactory(); |
262 | 264 |
263 // DownloadFileFactory interface. | 265 // DownloadFileFactory interface. |
264 virtual DownloadFile* CreateFile( | 266 virtual DownloadFile* CreateFile( |
265 scoped_ptr<DownloadSaveInfo> save_info, | 267 scoped_ptr<DownloadSaveInfo> save_info, |
266 const base::FilePath& default_download_directory, | 268 const base::FilePath& default_download_directory, |
267 const GURL& url, | 269 const GURL& url, |
268 const GURL& referrer_url, | 270 const GURL& referrer_url, |
269 bool calculate_hash, | 271 bool calculate_hash, |
270 scoped_ptr<ByteStreamReader> stream, | 272 scoped_ptr<ByteStreamReader<DownloadInterruptReason> > stream, |
271 const net::BoundNetLog& bound_net_log, | 273 const net::BoundNetLog& bound_net_log, |
272 base::WeakPtr<DownloadDestinationObserver> observer) OVERRIDE; | 274 base::WeakPtr<DownloadDestinationObserver> observer) OVERRIDE; |
273 | 275 |
274 bool AddError( | 276 bool AddError( |
275 const TestFileErrorInjector::FileErrorInfo& error_info); | 277 const TestFileErrorInjector::FileErrorInfo& error_info); |
276 | 278 |
277 void ClearErrors(); | 279 void ClearErrors(); |
278 | 280 |
279 private: | 281 private: |
280 // Our injected error list, mapped by URL. One per file. | 282 // Our injected error list, mapped by URL. One per file. |
(...skipping 13 matching lines...) Expand all Loading... |
294 | 296 |
295 DownloadFileWithErrorsFactory::~DownloadFileWithErrorsFactory() { | 297 DownloadFileWithErrorsFactory::~DownloadFileWithErrorsFactory() { |
296 } | 298 } |
297 | 299 |
298 DownloadFile* DownloadFileWithErrorsFactory::CreateFile( | 300 DownloadFile* DownloadFileWithErrorsFactory::CreateFile( |
299 scoped_ptr<DownloadSaveInfo> save_info, | 301 scoped_ptr<DownloadSaveInfo> save_info, |
300 const base::FilePath& default_download_directory, | 302 const base::FilePath& default_download_directory, |
301 const GURL& url, | 303 const GURL& url, |
302 const GURL& referrer_url, | 304 const GURL& referrer_url, |
303 bool calculate_hash, | 305 bool calculate_hash, |
304 scoped_ptr<ByteStreamReader> stream, | 306 scoped_ptr<ByteStreamReader<DownloadInterruptReason> > stream, |
305 const net::BoundNetLog& bound_net_log, | 307 const net::BoundNetLog& bound_net_log, |
306 base::WeakPtr<DownloadDestinationObserver> observer) { | 308 base::WeakPtr<DownloadDestinationObserver> observer) { |
307 if (injected_errors_.find(url.spec()) == injected_errors_.end()) { | 309 if (injected_errors_.find(url.spec()) == injected_errors_.end()) { |
308 // Have to create entry, because FileErrorInfo is not a POD type. | 310 // Have to create entry, because FileErrorInfo is not a POD type. |
309 TestFileErrorInjector::FileErrorInfo err_info = { | 311 TestFileErrorInjector::FileErrorInfo err_info = { |
310 url.spec(), | 312 url.spec(), |
311 TestFileErrorInjector::FILE_OPERATION_INITIALIZE, | 313 TestFileErrorInjector::FILE_OPERATION_INITIALIZE, |
312 -1, | 314 -1, |
313 DOWNLOAD_INTERRUPT_REASON_NONE | 315 DOWNLOAD_INTERRUPT_REASON_NONE |
314 }; | 316 }; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 case FILE_OPERATION_RENAME_ANNOTATE: | 480 case FILE_OPERATION_RENAME_ANNOTATE: |
479 return "RENAME_ANNOTATE"; | 481 return "RENAME_ANNOTATE"; |
480 default: | 482 default: |
481 break; | 483 break; |
482 } | 484 } |
483 | 485 |
484 return "Unknown"; | 486 return "Unknown"; |
485 } | 487 } |
486 | 488 |
487 } // namespace content | 489 } // namespace content |
OLD | NEW |