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

Side by Side Diff: net/url_request/url_request_simple_job.cc

Issue 2679583004: Use TaskScheduler instead of WorkerPool in url_request_simple_job.cc. (Closed)
Patch Set: private last Created 3 years, 10 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 "net/url_request/url_request_simple_job.h" 5 #include "net/url_request/url_request_simple_job.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/memory/ref_counted_memory.h" 12 #include "base/memory/ref_counted_memory.h"
13 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
14 #include "base/task_scheduler/post_task.h"
14 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
15 #include "base/threading/worker_pool.h" 16 #include "base/threading/worker_pool.h"
16 #include "net/base/io_buffer.h" 17 #include "net/base/io_buffer.h"
17 #include "net/base/net_errors.h" 18 #include "net/base/net_errors.h"
18 #include "net/http/http_request_headers.h" 19 #include "net/http/http_request_headers.h"
19 #include "net/http/http_util.h" 20 #include "net/http/http_util.h"
20 #include "net/url_request/url_request_status.h" 21 #include "net/url_request/url_request_status.h"
21 22
22 namespace net { 23 namespace net {
23 24
24 namespace { 25 namespace {
25 26
26 void CopyData(const scoped_refptr<IOBuffer>& buf, 27 void CopyData(const scoped_refptr<IOBuffer>& buf,
27 int buf_size, 28 int buf_size,
28 const scoped_refptr<base::RefCountedMemory>& data, 29 const scoped_refptr<base::RefCountedMemory>& data,
29 int64_t data_offset) { 30 int64_t data_offset) {
30 memcpy(buf->data(), data->front() + data_offset, buf_size); 31 memcpy(buf->data(), data->front() + data_offset, buf_size);
31 } 32 }
32 33
33 } // namespace 34 } // namespace
34 35
35 URLRequestSimpleJob::URLRequestSimpleJob(URLRequest* request, 36 URLRequestSimpleJob::URLRequestSimpleJob(URLRequest* request,
36 NetworkDelegate* network_delegate) 37 NetworkDelegate* network_delegate)
37 : URLRangeRequestJob(request, network_delegate), 38 : URLRangeRequestJob(request, network_delegate),
38 next_data_offset_(0), 39 next_data_offset_(0),
39 task_runner_(base::WorkerPool::GetTaskRunner(false)),
40 weak_factory_(this) { 40 weak_factory_(this) {
41 } 41 }
42 42
43 void URLRequestSimpleJob::Start() { 43 void URLRequestSimpleJob::Start() {
44 // Start reading asynchronously so that all error reporting and data 44 // Start reading asynchronously so that all error reporting and data
45 // callbacks happen as they would for network requests. 45 // callbacks happen as they would for network requests.
46 base::ThreadTaskRunnerHandle::Get()->PostTask( 46 base::ThreadTaskRunnerHandle::Get()->PostTask(
47 FROM_HERE, 47 FROM_HERE,
48 base::Bind(&URLRequestSimpleJob::StartAsync, weak_factory_.GetWeakPtr())); 48 base::Bind(&URLRequestSimpleJob::StartAsync, weak_factory_.GetWeakPtr()));
49 } 49 }
(...skipping 14 matching lines...) Expand all
64 } 64 }
65 65
66 URLRequestSimpleJob::~URLRequestSimpleJob() {} 66 URLRequestSimpleJob::~URLRequestSimpleJob() {}
67 67
68 int URLRequestSimpleJob::ReadRawData(IOBuffer* buf, int buf_size) { 68 int URLRequestSimpleJob::ReadRawData(IOBuffer* buf, int buf_size) {
69 buf_size = std::min(static_cast<int64_t>(buf_size), 69 buf_size = std::min(static_cast<int64_t>(buf_size),
70 byte_range_.last_byte_position() - next_data_offset_ + 1); 70 byte_range_.last_byte_position() - next_data_offset_ + 1);
71 if (buf_size == 0) 71 if (buf_size == 0)
72 return 0; 72 return 0;
73 73
74 // Do memory copy on a background thread. See crbug.com/422489. 74 // Do memory copy asynchronously. See crbug.com/422489.
xunjieli 2017/02/10 16:30:19 Please edit this comment per previous comment. "D
fdoray 2017/02/13 15:37:51 Done.
75 GetTaskRunner()->PostTaskAndReply( 75 base::PostTaskWithTraitsAndReply(
76 FROM_HERE, base::Bind(&CopyData, make_scoped_refptr(buf), buf_size, data_, 76 FROM_HERE, base::TaskTraits().WithShutdownBehavior(
77 next_data_offset_), 77 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN),
78 base::Bind(&CopyData, make_scoped_refptr(buf), buf_size, data_,
79 next_data_offset_),
78 base::Bind(&URLRequestSimpleJob::ReadRawDataComplete, 80 base::Bind(&URLRequestSimpleJob::ReadRawDataComplete,
79 weak_factory_.GetWeakPtr(), buf_size)); 81 weak_factory_.GetWeakPtr(), buf_size));
80 next_data_offset_ += buf_size; 82 next_data_offset_ += buf_size;
81 return ERR_IO_PENDING; 83 return ERR_IO_PENDING;
82 } 84 }
83 85
84 base::TaskRunner* URLRequestSimpleJob::GetTaskRunner() const {
85 return task_runner_.get();
86 }
87
88 int URLRequestSimpleJob::GetData(std::string* mime_type, 86 int URLRequestSimpleJob::GetData(std::string* mime_type,
89 std::string* charset, 87 std::string* charset,
90 std::string* data, 88 std::string* data,
91 const CompletionCallback& callback) const { 89 const CompletionCallback& callback) const {
92 NOTREACHED(); 90 NOTREACHED();
93 return ERR_UNEXPECTED; 91 return ERR_UNEXPECTED;
94 } 92 }
95 93
96 int URLRequestSimpleJob::GetRefCountedData( 94 int URLRequestSimpleJob::GetRefCountedData(
97 std::string* mime_type, 95 std::string* mime_type,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 next_data_offset_ = byte_range_.first_byte_position(); 136 next_data_offset_ = byte_range_.first_byte_position();
139 set_expected_content_size(byte_range_.last_byte_position() - 137 set_expected_content_size(byte_range_.last_byte_position() -
140 next_data_offset_ + 1); 138 next_data_offset_ + 1);
141 NotifyHeadersComplete(); 139 NotifyHeadersComplete();
142 } else { 140 } else {
143 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); 141 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result));
144 } 142 }
145 } 143 }
146 144
147 } // namespace net 145 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_simple_job.h ('k') | net/url_request/url_request_simple_job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698