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

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: Incorporated Al's comments. 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
« no previous file with comments | « content/public/browser/resource_dispatcher_host.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 scoped_ptr<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 content::DownloadId download_id,
49 const GURL& source_url,
48 const content::TestFileErrorInjector::FileErrorInfo& error_info, 50 const content::TestFileErrorInjector::FileErrorInfo& error_info,
49 const ConstructionCallback& ctor_callback, 51 const ConstructionCallback& ctor_callback,
50 const DestructionCallback& dtor_callback); 52 const DestructionCallback& dtor_callback);
51 53
52 ~DownloadFileWithErrors(); 54 ~DownloadFileWithErrors();
53 55
54 // DownloadFile interface. 56 // DownloadFile interface.
55 virtual content::DownloadInterruptReason Initialize() OVERRIDE; 57 virtual content::DownloadInterruptReason Initialize() OVERRIDE;
56 virtual content::DownloadInterruptReason AppendDataToFile( 58 virtual content::DownloadInterruptReason AppendDataToFile(
57 const char* data, size_t data_len) OVERRIDE; 59 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, 97 content::DownloadInterruptReason original_error,
96 const FilePath& path_result) { 98 const FilePath& path_result) {
97 original_callback.Run( 99 original_callback.Run(
98 overwrite_error, 100 overwrite_error,
99 overwrite_error == content::DOWNLOAD_INTERRUPT_REASON_NONE ? 101 overwrite_error == content::DOWNLOAD_INTERRUPT_REASON_NONE ?
100 path_result : FilePath()); 102 path_result : FilePath());
101 } 103 }
102 104
103 105
104 DownloadFileWithErrors::DownloadFileWithErrors( 106 DownloadFileWithErrors::DownloadFileWithErrors(
105 const DownloadCreateInfo* info, 107 scoped_ptr<DownloadCreateInfo> info,
106 scoped_ptr<content::ByteStreamReader> stream, 108 scoped_ptr<content::ByteStreamReader> stream,
107 DownloadRequestHandleInterface* request_handle, 109 scoped_ptr<DownloadRequestHandleInterface> request_handle,
108 content::DownloadManager* download_manager, 110 content::DownloadManager* download_manager,
109 bool calculate_hash, 111 bool calculate_hash,
110 const net::BoundNetLog& bound_net_log, 112 const net::BoundNetLog& bound_net_log,
113 content::DownloadId download_id,
114 const GURL& source_url,
111 const content::TestFileErrorInjector::FileErrorInfo& error_info, 115 const content::TestFileErrorInjector::FileErrorInfo& error_info,
112 const ConstructionCallback& ctor_callback, 116 const ConstructionCallback& ctor_callback,
113 const DestructionCallback& dtor_callback) 117 const DestructionCallback& dtor_callback)
114 : DownloadFileImpl(info, 118 : DownloadFileImpl(info.Pass(),
115 stream.Pass(), 119 stream.Pass(),
116 request_handle, 120 request_handle.Pass(),
117 download_manager, 121 download_manager,
118 calculate_hash, 122 calculate_hash,
119 scoped_ptr<content::PowerSaveBlocker>(NULL).Pass(), 123 scoped_ptr<content::PowerSaveBlocker>(),
120 bound_net_log), 124 bound_net_log),
121 source_url_(info->url()), 125 source_url_(source_url),
122 error_info_(error_info), 126 error_info_(error_info),
123 destruction_callback_(dtor_callback) { 127 destruction_callback_(dtor_callback) {
124 ctor_callback.Run(source_url_, info->download_id); 128 ctor_callback.Run(source_url_, download_id);
125 } 129 }
126 130
127 DownloadFileWithErrors::~DownloadFileWithErrors() { 131 DownloadFileWithErrors::~DownloadFileWithErrors() {
128 destruction_callback_.Run(source_url_); 132 destruction_callback_.Run(source_url_);
129 } 133 }
130 134
131 content::DownloadInterruptReason DownloadFileWithErrors::Initialize() { 135 content::DownloadInterruptReason DownloadFileWithErrors::Initialize() {
132 return ShouldReturnError( 136 return ShouldReturnError(
133 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE, 137 content::TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
134 DownloadFileImpl::Initialize()); 138 DownloadFileImpl::Initialize());
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 class DownloadFileWithErrorsFactory : public content::DownloadFileFactory { 195 class DownloadFileWithErrorsFactory : public content::DownloadFileFactory {
192 public: 196 public:
193 197
194 DownloadFileWithErrorsFactory( 198 DownloadFileWithErrorsFactory(
195 const DownloadFileWithErrors::ConstructionCallback& ctor_callback, 199 const DownloadFileWithErrors::ConstructionCallback& ctor_callback,
196 const DownloadFileWithErrors::DestructionCallback& dtor_callback); 200 const DownloadFileWithErrors::DestructionCallback& dtor_callback);
197 virtual ~DownloadFileWithErrorsFactory(); 201 virtual ~DownloadFileWithErrorsFactory();
198 202
199 // DownloadFileFactory interface. 203 // DownloadFileFactory interface.
200 virtual DownloadFile* CreateFile( 204 virtual DownloadFile* CreateFile(
201 DownloadCreateInfo* info, 205 scoped_ptr<DownloadCreateInfo> info,
202 scoped_ptr<content::ByteStreamReader> stream, 206 scoped_ptr<content::ByteStreamReader> stream,
203 content::DownloadManager* download_manager, 207 content::DownloadManager* download_manager,
204 bool calculate_hash, 208 bool calculate_hash,
205 const net::BoundNetLog& bound_net_log); 209 const net::BoundNetLog& bound_net_log);
206 210
207 bool AddError( 211 bool AddError(
208 const TestFileErrorInjector::FileErrorInfo& error_info); 212 const TestFileErrorInjector::FileErrorInfo& error_info);
209 213
210 void ClearErrors(); 214 void ClearErrors();
211 215
(...skipping 10 matching lines...) Expand all
222 const DownloadFileWithErrors::ConstructionCallback& ctor_callback, 226 const DownloadFileWithErrors::ConstructionCallback& ctor_callback,
223 const DownloadFileWithErrors::DestructionCallback& dtor_callback) 227 const DownloadFileWithErrors::DestructionCallback& dtor_callback)
224 : construction_callback_(ctor_callback), 228 : construction_callback_(ctor_callback),
225 destruction_callback_(dtor_callback) { 229 destruction_callback_(dtor_callback) {
226 } 230 }
227 231
228 DownloadFileWithErrorsFactory::~DownloadFileWithErrorsFactory() { 232 DownloadFileWithErrorsFactory::~DownloadFileWithErrorsFactory() {
229 } 233 }
230 234
231 content::DownloadFile* DownloadFileWithErrorsFactory::CreateFile( 235 content::DownloadFile* DownloadFileWithErrorsFactory::CreateFile(
232 DownloadCreateInfo* info, 236 scoped_ptr<DownloadCreateInfo> info,
233 scoped_ptr<content::ByteStreamReader> stream, 237 scoped_ptr<content::ByteStreamReader> stream,
234 content::DownloadManager* download_manager, 238 content::DownloadManager* download_manager,
235 bool calculate_hash, 239 bool calculate_hash,
236 const net::BoundNetLog& bound_net_log) { 240 const net::BoundNetLog& bound_net_log) {
237 std::string url = info->url().spec(); 241 GURL url = info->url();
238 242
239 if (injected_errors_.find(url) == injected_errors_.end()) { 243 if (injected_errors_.find(url.spec()) == injected_errors_.end()) {
240 // Have to create entry, because FileErrorInfo is not a POD type. 244 // Have to create entry, because FileErrorInfo is not a POD type.
241 TestFileErrorInjector::FileErrorInfo err_info = { 245 TestFileErrorInjector::FileErrorInfo err_info = {
242 url, 246 url.spec(),
243 TestFileErrorInjector::FILE_OPERATION_INITIALIZE, 247 TestFileErrorInjector::FILE_OPERATION_INITIALIZE,
244 -1, 248 -1,
245 content::DOWNLOAD_INTERRUPT_REASON_NONE 249 content::DOWNLOAD_INTERRUPT_REASON_NONE
246 }; 250 };
247 injected_errors_[url] = err_info; 251 injected_errors_[url.spec()] = err_info;
248 } 252 }
249 253
254 scoped_ptr<DownloadRequestHandleInterface> request_handle(
255 new DownloadRequestHandle(info->request_handle));
256 DownloadId download_id(info->download_id);
257
250 return new DownloadFileWithErrors( 258 return new DownloadFileWithErrors(
251 info, 259 info.Pass(),
252 stream.Pass(), 260 stream.Pass(),
253 new DownloadRequestHandle(info->request_handle), 261 request_handle.Pass(),
254 download_manager, 262 download_manager,
255 calculate_hash, 263 calculate_hash,
256 bound_net_log, 264 bound_net_log,
257 injected_errors_[url], 265 download_id,
266 url,
267 injected_errors_[url.spec()],
258 construction_callback_, 268 construction_callback_,
259 destruction_callback_); 269 destruction_callback_);
260 } 270 }
261 271
262 bool DownloadFileWithErrorsFactory::AddError( 272 bool DownloadFileWithErrorsFactory::AddError(
263 const TestFileErrorInjector::FileErrorInfo& error_info) { 273 const TestFileErrorInjector::FileErrorInfo& error_info) {
264 // Creates an empty entry if necessary. Duplicate entries overwrite. 274 // Creates an empty entry if necessary. Duplicate entries overwrite.
265 injected_errors_[error_info.url] = error_info; 275 injected_errors_[error_info.url] = error_info;
266 276
267 return true; 277 return true;
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 case FILE_OPERATION_RENAME: 466 case FILE_OPERATION_RENAME:
457 return "RENAME"; 467 return "RENAME";
458 default: 468 default:
459 break; 469 break;
460 } 470 }
461 471
462 return "Unknown"; 472 return "Unknown";
463 } 473 }
464 474
465 } // namespace content 475 } // namespace content
OLDNEW
« no previous file with comments | « content/public/browser/resource_dispatcher_host.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698