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

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

Issue 11028131: Shift passage of FileStream in downloads system to be by scoped_ptr<>. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed blank line. Created 8 years, 2 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 | Annotate | Revision Log
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 21 matching lines...) Expand all
32 } 32 }
33 33
34 // A class that performs file operations and injects errors. 34 // A class that performs file operations and injects errors.
35 class DownloadFileWithErrors: public DownloadFileImpl { 35 class DownloadFileWithErrors: public DownloadFileImpl {
36 public: 36 public:
37 typedef base::Callback<void(const GURL& url, content::DownloadId id)> 37 typedef base::Callback<void(const GURL& url, content::DownloadId id)>
38 ConstructionCallback; 38 ConstructionCallback;
39 typedef base::Callback<void(const GURL& url)> DestructionCallback; 39 typedef base::Callback<void(const GURL& url)> DestructionCallback;
40 40
41 DownloadFileWithErrors( 41 DownloadFileWithErrors(
42 const DownloadCreateInfo* info, 42 scoped_ptr<DownloadCreateInfo> info,
43 scoped_ptr<content::ByteStreamReader> stream, 43 scoped_ptr<content::ByteStreamReader> stream,
44 DownloadRequestHandleInterface* request_handle, 44 DownloadRequestHandleInterface* request_handle,
45 content::DownloadManager* download_manager, 45 content::DownloadManager* download_manager,
46 bool calculate_hash, 46 bool calculate_hash,
47 const net::BoundNetLog& bound_net_log, 47 const net::BoundNetLog& bound_net_log,
48 const GURL& source_url,
48 const content::TestFileErrorInjector::FileErrorInfo& error_info, 49 const content::TestFileErrorInjector::FileErrorInfo& error_info,
49 const ConstructionCallback& ctor_callback, 50 const ConstructionCallback& ctor_callback,
50 const DestructionCallback& dtor_callback); 51 const DestructionCallback& dtor_callback);
51 52
52 ~DownloadFileWithErrors(); 53 ~DownloadFileWithErrors();
53 54
54 // DownloadFile interface. 55 // DownloadFile interface.
55 virtual content::DownloadInterruptReason Initialize() OVERRIDE; 56 virtual content::DownloadInterruptReason Initialize() OVERRIDE;
56 virtual content::DownloadInterruptReason AppendDataToFile( 57 virtual content::DownloadInterruptReason AppendDataToFile(
57 const char* data, size_t data_len) OVERRIDE; 58 const char* data, size_t data_len) OVERRIDE;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 content::DownloadInterruptReason original_error, 96 content::DownloadInterruptReason original_error,
96 const FilePath& path_result) { 97 const FilePath& path_result) {
97 original_callback.Run( 98 original_callback.Run(
98 overwrite_error, 99 overwrite_error,
99 overwrite_error == content::DOWNLOAD_INTERRUPT_REASON_NONE ? 100 overwrite_error == content::DOWNLOAD_INTERRUPT_REASON_NONE ?
100 path_result : FilePath()); 101 path_result : FilePath());
101 } 102 }
102 103
103 104
104 DownloadFileWithErrors::DownloadFileWithErrors( 105 DownloadFileWithErrors::DownloadFileWithErrors(
105 const DownloadCreateInfo* info, 106 scoped_ptr<DownloadCreateInfo> info,
106 scoped_ptr<content::ByteStreamReader> stream, 107 scoped_ptr<content::ByteStreamReader> stream,
107 DownloadRequestHandleInterface* request_handle, 108 DownloadRequestHandleInterface* request_handle,
108 content::DownloadManager* download_manager, 109 content::DownloadManager* download_manager,
109 bool calculate_hash, 110 bool calculate_hash,
110 const net::BoundNetLog& bound_net_log, 111 const net::BoundNetLog& bound_net_log,
112 const GURL& source_url,
111 const content::TestFileErrorInjector::FileErrorInfo& error_info, 113 const content::TestFileErrorInjector::FileErrorInfo& error_info,
112 const ConstructionCallback& ctor_callback, 114 const ConstructionCallback& ctor_callback,
113 const DestructionCallback& dtor_callback) 115 const DestructionCallback& dtor_callback)
114 : DownloadFileImpl(info, 116 : DownloadFileImpl(info.Pass(),
115 stream.Pass(), 117 stream.Pass(),
116 request_handle, 118 request_handle,
117 download_manager, 119 download_manager,
118 calculate_hash, 120 calculate_hash,
119 scoped_ptr<content::PowerSaveBlocker>(NULL).Pass(), 121 scoped_ptr<content::PowerSaveBlocker>(NULL).Pass(),
120 bound_net_log), 122 bound_net_log),
121 source_url_(info->url()), 123 source_url_(source_url),
122 error_info_(error_info), 124 error_info_(error_info),
123 destruction_callback_(dtor_callback) { 125 destruction_callback_(dtor_callback) {
124 ctor_callback.Run(source_url_, info->download_id); 126 ctor_callback.Run(source_url_, info->download_id);
125 } 127 }
126 128
127 DownloadFileWithErrors::~DownloadFileWithErrors() { 129 DownloadFileWithErrors::~DownloadFileWithErrors() {
128 destruction_callback_.Run(source_url_); 130 destruction_callback_.Run(source_url_);
129 } 131 }
130 132
131 content::DownloadInterruptReason DownloadFileWithErrors::Initialize() { 133 content::DownloadInterruptReason DownloadFileWithErrors::Initialize() {
132 return ShouldReturnError( 134 return ShouldReturnError(
133 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE, 135 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 class DownloadFileWithErrorsFactory : public content::DownloadFileFactory { 193 class DownloadFileWithErrorsFactory : public content::DownloadFileFactory {
192 public: 194 public:
193 195
194 DownloadFileWithErrorsFactory( 196 DownloadFileWithErrorsFactory(
195 const DownloadFileWithErrors::ConstructionCallback& ctor_callback, 197 const DownloadFileWithErrors::ConstructionCallback& ctor_callback,
196 const DownloadFileWithErrors::DestructionCallback& dtor_callback); 198 const DownloadFileWithErrors::DestructionCallback& dtor_callback);
197 virtual ~DownloadFileWithErrorsFactory(); 199 virtual ~DownloadFileWithErrorsFactory();
198 200
199 // DownloadFileFactory interface. 201 // DownloadFileFactory interface.
200 virtual DownloadFile* CreateFile( 202 virtual DownloadFile* CreateFile(
201 DownloadCreateInfo* info, 203 scoped_ptr<DownloadCreateInfo> info,
202 scoped_ptr<content::ByteStreamReader> stream, 204 scoped_ptr<content::ByteStreamReader> stream,
203 content::DownloadManager* download_manager, 205 content::DownloadManager* download_manager,
204 bool calculate_hash, 206 bool calculate_hash,
205 const net::BoundNetLog& bound_net_log); 207 const net::BoundNetLog& bound_net_log);
206 208
207 bool AddError( 209 bool AddError(
208 const TestFileErrorInjector::FileErrorInfo& error_info); 210 const TestFileErrorInjector::FileErrorInfo& error_info);
209 211
210 void ClearErrors(); 212 void ClearErrors();
211 213
(...skipping 10 matching lines...) Expand all
222 const DownloadFileWithErrors::ConstructionCallback& ctor_callback, 224 const DownloadFileWithErrors::ConstructionCallback& ctor_callback,
223 const DownloadFileWithErrors::DestructionCallback& dtor_callback) 225 const DownloadFileWithErrors::DestructionCallback& dtor_callback)
224 : construction_callback_(ctor_callback), 226 : construction_callback_(ctor_callback),
225 destruction_callback_(dtor_callback) { 227 destruction_callback_(dtor_callback) {
226 } 228 }
227 229
228 DownloadFileWithErrorsFactory::~DownloadFileWithErrorsFactory() { 230 DownloadFileWithErrorsFactory::~DownloadFileWithErrorsFactory() {
229 } 231 }
230 232
231 content::DownloadFile* DownloadFileWithErrorsFactory::CreateFile( 233 content::DownloadFile* DownloadFileWithErrorsFactory::CreateFile(
232 DownloadCreateInfo* info, 234 scoped_ptr<DownloadCreateInfo> info,
233 scoped_ptr<content::ByteStreamReader> stream, 235 scoped_ptr<content::ByteStreamReader> stream,
234 content::DownloadManager* download_manager, 236 content::DownloadManager* download_manager,
235 bool calculate_hash, 237 bool calculate_hash,
236 const net::BoundNetLog& bound_net_log) { 238 const net::BoundNetLog& bound_net_log) {
237 std::string url = info->url().spec(); 239 GURL url = info->url();
238 240
239 if (injected_errors_.find(url) == injected_errors_.end()) { 241 if (injected_errors_.find(url.spec()) == injected_errors_.end()) {
240 // Have to create entry, because FileErrorInfo is not a POD type. 242 // Have to create entry, because FileErrorInfo is not a POD type.
241 TestFileErrorInjector::FileErrorInfo err_info = { 243 TestFileErrorInjector::FileErrorInfo err_info = {
242 url, 244 url.spec(),
243 TestFileErrorInjector::FILE_OPERATION_INITIALIZE, 245 TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
244 -1, 246 -1,
245 content::DOWNLOAD_INTERRUPT_REASON_NONE 247 content::DOWNLOAD_INTERRUPT_REASON_NONE
246 }; 248 };
247 injected_errors_[url] = err_info; 249 injected_errors_[url.spec()] = err_info;
248 } 250 }
249 251
252 DownloadRequestHandle* request_handle(
253 new DownloadRequestHandle(info->request_handle));
254
250 return new DownloadFileWithErrors( 255 return new DownloadFileWithErrors(
251 info, 256 info.Pass(),
252 stream.Pass(), 257 stream.Pass(),
253 new DownloadRequestHandle(info->request_handle), 258 request_handle, // Takes ownership.
benjhayden 2012/10/11 19:41:12 Again, this comment belongs in DFWE, not here.
Randy Smith (Not in Mondays) 2012/10/15 18:56:32 Moot because of your other suggestion, but if I we
254 download_manager, 259 download_manager,
255 calculate_hash, 260 calculate_hash,
256 bound_net_log, 261 bound_net_log,
257 injected_errors_[url], 262 url,
263 injected_errors_[url.spec()],
258 construction_callback_, 264 construction_callback_,
259 destruction_callback_); 265 destruction_callback_);
260 } 266 }
261 267
262 bool DownloadFileWithErrorsFactory::AddError( 268 bool DownloadFileWithErrorsFactory::AddError(
263 const TestFileErrorInjector::FileErrorInfo& error_info) { 269 const TestFileErrorInjector::FileErrorInfo& error_info) {
264 // Creates an empty entry if necessary. Duplicate entries overwrite. 270 // Creates an empty entry if necessary. Duplicate entries overwrite.
265 injected_errors_[error_info.url] = error_info; 271 injected_errors_[error_info.url] = error_info;
266 272
267 return true; 273 return true;
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 case FILE_OPERATION_RENAME: 462 case FILE_OPERATION_RENAME:
457 return "RENAME"; 463 return "RENAME";
458 default: 464 default:
459 break; 465 break;
460 } 466 }
461 467
462 return "Unknown"; 468 return "Unknown";
463 } 469 }
464 470
465 } // namespace content 471 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698