OLD | NEW |
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/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
15 #include "base/threading/worker_pool.h" | 15 #include "base/threading/worker_pool.h" |
16 #include "net/base/io_buffer.h" | 16 #include "net/base/io_buffer.h" |
17 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
18 #include "net/http/http_request_headers.h" | 18 #include "net/http/http_request_headers.h" |
19 #include "net/http/http_util.h" | 19 #include "net/http/http_util.h" |
20 #include "net/url_request/url_request_status.h" | 20 #include "net/url_request/url_request_status.h" |
21 | 21 |
22 namespace net { | 22 namespace net { |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 void CopyData(const scoped_refptr<IOBuffer>& buf, | 26 void CopyData(const scoped_refptr<IOBuffer>& buf, |
27 int buf_size, | 27 int buf_size, |
28 const scoped_refptr<base::RefCountedMemory>& data, | 28 const scoped_refptr<base::RefCountedMemory>& data, |
29 int64 data_offset) { | 29 int64_t data_offset) { |
30 memcpy(buf->data(), data->front() + data_offset, buf_size); | 30 memcpy(buf->data(), data->front() + data_offset, buf_size); |
31 } | 31 } |
32 | 32 |
33 } // namespace | 33 } // namespace |
34 | 34 |
35 URLRequestSimpleJob::URLRequestSimpleJob(URLRequest* request, | 35 URLRequestSimpleJob::URLRequestSimpleJob(URLRequest* request, |
36 NetworkDelegate* network_delegate) | 36 NetworkDelegate* network_delegate) |
37 : URLRangeRequestJob(request, network_delegate), | 37 : URLRangeRequestJob(request, network_delegate), |
38 next_data_offset_(0), | 38 next_data_offset_(0), |
39 task_runner_(base::WorkerPool::GetTaskRunner(false)), | 39 task_runner_(base::WorkerPool::GetTaskRunner(false)), |
(...skipping 19 matching lines...) Expand all Loading... |
59 } | 59 } |
60 | 60 |
61 bool URLRequestSimpleJob::GetCharset(std::string* charset) { | 61 bool URLRequestSimpleJob::GetCharset(std::string* charset) { |
62 *charset = charset_; | 62 *charset = charset_; |
63 return true; | 63 return true; |
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>(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 on a background thread. See crbug.com/422489. |
75 GetTaskRunner()->PostTaskAndReply( | 75 GetTaskRunner()->PostTaskAndReply( |
76 FROM_HERE, base::Bind(&CopyData, make_scoped_refptr(buf), buf_size, data_, | 76 FROM_HERE, base::Bind(&CopyData, make_scoped_refptr(buf), buf_size, data_, |
77 next_data_offset_), | 77 next_data_offset_), |
78 base::Bind(&URLRequestSimpleJob::ReadRawDataComplete, | 78 base::Bind(&URLRequestSimpleJob::ReadRawDataComplete, |
79 weak_factory_.GetWeakPtr(), buf_size)); | 79 weak_factory_.GetWeakPtr(), buf_size)); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 next_data_offset_ = byte_range_.first_byte_position(); | 138 next_data_offset_ = byte_range_.first_byte_position(); |
139 set_expected_content_size(byte_range_.last_byte_position() - | 139 set_expected_content_size(byte_range_.last_byte_position() - |
140 next_data_offset_ + 1); | 140 next_data_offset_ + 1); |
141 NotifyHeadersComplete(); | 141 NotifyHeadersComplete(); |
142 } else { | 142 } else { |
143 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); | 143 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); |
144 } | 144 } |
145 } | 145 } |
146 | 146 |
147 } // namespace net | 147 } // namespace net |
OLD | NEW |