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

Side by Side Diff: content/browser/download/download_job.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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/browser/download/download_job.h" 5 #include "content/browser/download/download_job.h"
6 6
7 #include "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "content/browser/download/download_item_impl.h" 8 #include "content/browser/download/download_item_impl.h"
9 #include "content/browser/download/download_task_runner.h"
9 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
10 #include "content/public/browser/web_contents.h" 11 #include "content/public/browser/web_contents.h"
11 12
12 namespace content { 13 namespace content {
13 14
14 DownloadJob::DownloadJob( 15 DownloadJob::DownloadJob(
15 DownloadItemImpl* download_item, 16 DownloadItemImpl* download_item,
16 std::unique_ptr<DownloadRequestHandleInterface> request_handle) 17 std::unique_ptr<DownloadRequestHandleInterface> request_handle)
17 : download_item_(download_item), 18 : download_item_(download_item),
18 request_handle_(std::move(request_handle)), 19 request_handle_(std::move(request_handle)),
(...skipping 22 matching lines...) Expand all
41 request_handle_->ResumeRequest(); 42 request_handle_->ResumeRequest();
42 } 43 }
43 44
44 WebContents* DownloadJob::GetWebContents() const { 45 WebContents* DownloadJob::GetWebContents() const {
45 return request_handle_ ? request_handle_->GetWebContents() : nullptr; 46 return request_handle_ ? request_handle_->GetWebContents() : nullptr;
46 } 47 }
47 48
48 void DownloadJob::Start(DownloadFile* download_file_, 49 void DownloadJob::Start(DownloadFile* download_file_,
49 const DownloadFile::InitializeCallback& callback, 50 const DownloadFile::InitializeCallback& callback,
50 const DownloadItem::ReceivedSlices& received_slices) { 51 const DownloadItem::ReceivedSlices& received_slices) {
51 BrowserThread::PostTask( 52 GetDownloadTaskRunner()->PostTask(
52 BrowserThread::FILE, FROM_HERE, 53 FROM_HERE,
53 base::Bind(&DownloadFile::Initialize, 54 base::Bind(&DownloadFile::Initialize,
54 // Safe because we control download file lifetime. 55 // Safe because we control download file lifetime.
55 base::Unretained(download_file_), 56 base::Unretained(download_file_),
56 base::Bind(&DownloadJob::OnDownloadFileInitialized, 57 base::Bind(&DownloadJob::OnDownloadFileInitialized,
57 weak_ptr_factory_.GetWeakPtr(), callback), 58 weak_ptr_factory_.GetWeakPtr(), callback),
58 base::Bind(&DownloadJob::CancelRequestWithOffset, 59 base::Bind(&DownloadJob::CancelRequestWithOffset,
59 weak_ptr_factory_.GetWeakPtr()), 60 weak_ptr_factory_.GetWeakPtr()),
60 received_slices, IsParallelizable())); 61 received_slices, IsParallelizable()));
61 } 62 }
62 63
63 void DownloadJob::OnDownloadFileInitialized( 64 void DownloadJob::OnDownloadFileInitialized(
64 const DownloadFile::InitializeCallback& callback, 65 const DownloadFile::InitializeCallback& callback,
65 DownloadInterruptReason result) { 66 DownloadInterruptReason result) {
66 callback.Run(result); 67 callback.Run(result);
67 } 68 }
68 69
69 bool DownloadJob::AddByteStream(std::unique_ptr<ByteStreamReader> stream_reader, 70 bool DownloadJob::AddByteStream(std::unique_ptr<ByteStreamReader> stream_reader,
70 int64_t offset, 71 int64_t offset,
71 int64_t length) { 72 int64_t length) {
72 DCHECK_CURRENTLY_ON(BrowserThread::UI); 73 DCHECK_CURRENTLY_ON(BrowserThread::UI);
73 DownloadFile* download_file = download_item_->download_file_.get(); 74 DownloadFile* download_file = download_item_->download_file_.get();
74 if (!download_file) 75 if (!download_file)
75 return false; 76 return false;
76 77
77 // download_file_ is owned by download_item_ on the UI thread and is always 78 // download_file_ is owned by download_item_ on the UI thread and is always
78 // deleted on the FILE thread after download_file_ is nulled out. 79 // deleted on the download task runner after download_file_ is nulled out.
79 // So it's safe to use base::Unretained here. 80 // So it's safe to use base::Unretained here.
80 BrowserThread::PostTask( 81 GetDownloadTaskRunner()->PostTask(
81 BrowserThread::FILE, FROM_HERE, 82 FROM_HERE,
82 base::Bind(&DownloadFile::AddByteStream, base::Unretained(download_file), 83 base::Bind(&DownloadFile::AddByteStream, base::Unretained(download_file),
83 base::Passed(&stream_reader), offset, length)); 84 base::Passed(&stream_reader), offset, length));
84 return true; 85 return true;
85 } 86 }
86 87
87 void DownloadJob::CancelRequestWithOffset(int64_t offset) { 88 void DownloadJob::CancelRequestWithOffset(int64_t offset) {
88 NOTREACHED(); 89 NOTREACHED();
89 } 90 }
90 91
91 bool DownloadJob::IsParallelizable() const { 92 bool DownloadJob::IsParallelizable() const {
92 return false; 93 return false;
93 } 94 }
94 95
95 bool DownloadJob::IsSavePackageDownload() const { 96 bool DownloadJob::IsSavePackageDownload() const {
96 return false; 97 return false;
97 } 98 }
98 99
99 } // namespace content 100 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698