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

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

Issue 2890853002: Downloads: replace BrowserThread::FILE with task scheduler. (Closed)
Patch Set: Add scoped COM initialization to quench a couple of assertion failures. Created 3 years, 5 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
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 <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "content/browser/download/download_file_factory.h" 13 #include "content/browser/download/download_file_factory.h"
14 #include "content/browser/download/download_file_impl.h" 14 #include "content/browser/download/download_file_impl.h"
15 #include "content/browser/download/download_interrupt_reasons_impl.h" 15 #include "content/browser/download/download_interrupt_reasons_impl.h"
16 #include "content/browser/download/download_manager_impl.h" 16 #include "content/browser/download/download_manager_impl.h"
17 #include "content/browser/download/download_task_runner.h"
17 #include "content/browser/loader/resource_dispatcher_host_impl.h" 18 #include "content/browser/loader/resource_dispatcher_host_impl.h"
18 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
19 #include "url/gurl.h" 20 #include "url/gurl.h"
20 21
21 namespace net { 22 namespace net {
22 class NetLogWithSource; 23 class NetLogWithSource;
23 } 24 }
24 25
25 namespace content { 26 namespace content {
26 class ByteStreamReader; 27 class ByteStreamReader;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 const TestFileErrorInjector::FileErrorInfo& error_info, 114 const TestFileErrorInjector::FileErrorInfo& error_info,
114 const base::Closure& ctor_callback, 115 const base::Closure& ctor_callback,
115 const base::Closure& dtor_callback) 116 const base::Closure& dtor_callback)
116 : DownloadFileImpl(std::move(save_info), 117 : DownloadFileImpl(std::move(save_info),
117 default_download_directory, 118 default_download_directory,
118 std::move(byte_stream), 119 std::move(byte_stream),
119 net_log, 120 net_log,
120 observer), 121 observer),
121 error_info_(error_info), 122 error_info_(error_info),
122 destruction_callback_(dtor_callback) { 123 destruction_callback_(dtor_callback) {
123 // DownloadFiles are created on the UI thread and are destroyed on the FILE 124 // DownloadFiles are created on the UI thread and are destroyed on the
124 // thread. Schedule the ConstructionCallback on the FILE thread so that if a 125 // download task runner. Schedule the ConstructionCallback on the
125 // DownloadItem schedules a DownloadFile to be destroyed and creates another 126 // download task runner, so that if a DownloadItem schedules a
126 // one (as happens during download resumption), then the DestructionCallback 127 // DownloadFile to be destroyed and creates another one (as happens during
127 // for the old DownloadFile is run before the ConstructionCallback for the 128 // download resumption), then the DestructionCallback for the old DownloadFile
128 // next DownloadFile. 129 // is run before the ConstructionCallback for the next DownloadFile.
129 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, ctor_callback); 130 GetDownloadTaskRunner()->PostTask(FROM_HERE, ctor_callback);
130 } 131 }
131 132
132 DownloadFileWithError::~DownloadFileWithError() { 133 DownloadFileWithError::~DownloadFileWithError() {
133 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 134 DCHECK(GetDownloadTaskRunner()->RunsTasksInCurrentSequence());
134 destruction_callback_.Run(); 135 destruction_callback_.Run();
135 } 136 }
136 137
137 void DownloadFileWithError::Initialize( 138 void DownloadFileWithError::Initialize(
138 const InitializeCallback& initialize_callback, 139 const InitializeCallback& initialize_callback,
139 const CancelRequestCallback& cancel_request_callback, 140 const CancelRequestCallback& cancel_request_callback,
140 const DownloadItem::ReceivedSlices& received_slices, 141 const DownloadItem::ReceivedSlices& received_slices,
141 bool is_parallelizable) { 142 bool is_parallelizable) {
142 DownloadInterruptReason error_to_return = DOWNLOAD_INTERRUPT_REASON_NONE; 143 DownloadInterruptReason error_to_return = DOWNLOAD_INTERRUPT_REASON_NONE;
143 InitializeCallback callback_to_use = initialize_callback; 144 InitializeCallback callback_to_use = initialize_callback;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 } 293 }
293 294
294 DownloadFileWithErrorFactory::~DownloadFileWithErrorFactory() {} 295 DownloadFileWithErrorFactory::~DownloadFileWithErrorFactory() {}
295 296
296 DownloadFile* DownloadFileWithErrorFactory::CreateFile( 297 DownloadFile* DownloadFileWithErrorFactory::CreateFile(
297 std::unique_ptr<DownloadSaveInfo> save_info, 298 std::unique_ptr<DownloadSaveInfo> save_info,
298 const base::FilePath& default_download_directory, 299 const base::FilePath& default_download_directory,
299 std::unique_ptr<ByteStreamReader> byte_stream, 300 std::unique_ptr<ByteStreamReader> byte_stream,
300 const net::NetLogWithSource& net_log, 301 const net::NetLogWithSource& net_log,
301 base::WeakPtr<DownloadDestinationObserver> observer) { 302 base::WeakPtr<DownloadDestinationObserver> observer) {
302 return new DownloadFileWithError(std::move(save_info), 303 return new DownloadFileWithError(
303 default_download_directory, 304 std::move(save_info), default_download_directory, std::move(byte_stream),
304 std::move(byte_stream), 305 net_log, observer, injected_error_, construction_callback_,
305 net_log, 306 destruction_callback_);
306 observer,
307 injected_error_,
308 construction_callback_,
309 destruction_callback_);
310 } 307 }
311 308
312 bool DownloadFileWithErrorFactory::SetError( 309 bool DownloadFileWithErrorFactory::SetError(
313 TestFileErrorInjector::FileErrorInfo error) { 310 TestFileErrorInjector::FileErrorInfo error) {
314 injected_error_ = std::move(error); 311 injected_error_ = std::move(error);
315 return true; 312 return true;
316 } 313 }
317 314
318 TestFileErrorInjector::TestFileErrorInjector(DownloadManager* download_manager) 315 TestFileErrorInjector::TestFileErrorInjector(DownloadManager* download_manager)
319 : // This code is only used for browser_tests, so a 316 : // This code is only used for browser_tests, so a
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 case FILE_OPERATION_RENAME_ANNOTATE: 411 case FILE_OPERATION_RENAME_ANNOTATE:
415 return "RENAME_ANNOTATE"; 412 return "RENAME_ANNOTATE";
416 default: 413 default:
417 break; 414 break;
418 } 415 }
419 416
420 return "Unknown"; 417 return "Unknown";
421 } 418 }
422 419
423 } // namespace content 420 } // namespace content
OLDNEW
« content/common/quarantine/quarantine_win.cc ('K') | « content/public/test/download_test_observer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698