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

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

Issue 895853003: Update from https://crrev.com/314320 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 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/memory/ref_counted_memory.h" 11 #include "base/memory/ref_counted_memory.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/profiler/scoped_tracker.h"
14 #include "base/threading/worker_pool.h" 13 #include "base/threading/worker_pool.h"
15 #include "net/base/io_buffer.h" 14 #include "net/base/io_buffer.h"
16 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
17 #include "net/http/http_request_headers.h" 16 #include "net/http/http_request_headers.h"
18 #include "net/http/http_util.h" 17 #include "net/http/http_util.h"
19 #include "net/url_request/url_request_status.h" 18 #include "net/url_request/url_request_status.h"
20 19
21 namespace net { 20 namespace net {
22 21
23 namespace { 22 namespace {
24 23
25 void CopyData(const scoped_refptr<IOBuffer>& buf, 24 void CopyData(const scoped_refptr<IOBuffer>& buf,
26 int buf_size, 25 int buf_size,
27 const scoped_refptr<base::RefCountedMemory>& data, 26 const scoped_refptr<base::RefCountedMemory>& data,
28 int64 data_offset) { 27 int64 data_offset) {
29 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422489 is fixed.
30 tracked_objects::ScopedTracker tracking_profile(
31 FROM_HERE_WITH_EXPLICIT_FUNCTION("422489 CopyData"));
32
33 memcpy(buf->data(), data->front() + data_offset, buf_size); 28 memcpy(buf->data(), data->front() + data_offset, buf_size);
34 } 29 }
35 30
36 } // namespace 31 } // namespace
37 32
38 URLRequestSimpleJob::URLRequestSimpleJob(URLRequest* request, 33 URLRequestSimpleJob::URLRequestSimpleJob(URLRequest* request,
39 NetworkDelegate* network_delegate) 34 NetworkDelegate* network_delegate)
40 : URLRangeRequestJob(request, network_delegate), 35 : URLRangeRequestJob(request, network_delegate),
41 next_data_offset_(0), 36 next_data_offset_(0),
42 task_runner_(base::WorkerPool::GetTaskRunner(false)), 37 task_runner_(base::WorkerPool::GetTaskRunner(false)),
(...skipping 15 matching lines...) Expand all
58 53
59 bool URLRequestSimpleJob::GetCharset(std::string* charset) { 54 bool URLRequestSimpleJob::GetCharset(std::string* charset) {
60 *charset = charset_; 55 *charset = charset_;
61 return true; 56 return true;
62 } 57 }
63 58
64 URLRequestSimpleJob::~URLRequestSimpleJob() {} 59 URLRequestSimpleJob::~URLRequestSimpleJob() {}
65 60
66 bool URLRequestSimpleJob::ReadRawData(IOBuffer* buf, int buf_size, 61 bool URLRequestSimpleJob::ReadRawData(IOBuffer* buf, int buf_size,
67 int* bytes_read) { 62 int* bytes_read) {
68 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422489 is fixed.
69 tracked_objects::ScopedTracker tracking_profile(
70 FROM_HERE_WITH_EXPLICIT_FUNCTION(
71 "422489 URLRequestSimpleJob::ReadRawData"));
72
73 DCHECK(bytes_read); 63 DCHECK(bytes_read);
74 buf_size = static_cast<int>( 64 buf_size = static_cast<int>(
75 std::min(static_cast<int64>(buf_size), 65 std::min(static_cast<int64>(buf_size),
76 byte_range_.last_byte_position() - next_data_offset_ + 1)); 66 byte_range_.last_byte_position() - next_data_offset_ + 1));
77 DCHECK_GE(buf_size, 0); 67 DCHECK_GE(buf_size, 0);
78 if (buf_size == 0) { 68 if (buf_size == 0) {
79 *bytes_read = 0; 69 *bytes_read = 0;
80 return true; 70 return true;
81 } 71 }
82 72
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 int result = GetData(mime_type, charset, &str_data->data(), callback); 107 int result = GetData(mime_type, charset, &str_data->data(), callback);
118 *data = str_data; 108 *data = str_data;
119 return result; 109 return result;
120 } 110 }
121 111
122 void URLRequestSimpleJob::StartAsync() { 112 void URLRequestSimpleJob::StartAsync() {
123 if (!request_) 113 if (!request_)
124 return; 114 return;
125 115
126 if (ranges().size() > 1) { 116 if (ranges().size() > 1) {
127 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422489 is fixed.
128 tracked_objects::ScopedTracker tracking_profile(
129 FROM_HERE_WITH_EXPLICIT_FUNCTION(
130 "422489 URLRequestSimpleJob::StartAsync 1"));
131
132 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, 117 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED,
133 ERR_REQUEST_RANGE_NOT_SATISFIABLE)); 118 ERR_REQUEST_RANGE_NOT_SATISFIABLE));
134 return; 119 return;
135 } 120 }
136 121
137 if (!ranges().empty() && range_parse_result() == OK) 122 if (!ranges().empty() && range_parse_result() == OK)
138 byte_range_ = ranges().front(); 123 byte_range_ = ranges().front();
139 124
140 int result; 125 const int result =
141 { 126 GetRefCountedData(&mime_type_, &charset_, &data_,
142 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422489 is fixed. 127 base::Bind(&URLRequestSimpleJob::OnGetDataCompleted,
143 // Remove the block and assign 'result' in its declaration. 128 weak_factory_.GetWeakPtr()));
144 tracked_objects::ScopedTracker tracking_profile(
145 FROM_HERE_WITH_EXPLICIT_FUNCTION(
146 "422489 URLRequestSimpleJob::StartAsync 2"));
147 129
148 result = 130 if (result != ERR_IO_PENDING)
149 GetRefCountedData(&mime_type_, &charset_, &data_,
150 base::Bind(&URLRequestSimpleJob::OnGetDataCompleted,
151 weak_factory_.GetWeakPtr()));
152 }
153
154 if (result != ERR_IO_PENDING) {
155 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422489 is fixed.
156 tracked_objects::ScopedTracker tracking_profile(
157 FROM_HERE_WITH_EXPLICIT_FUNCTION(
158 "422489 URLRequestSimpleJob::StartAsync 3"));
159
160 OnGetDataCompleted(result); 131 OnGetDataCompleted(result);
161 }
162 } 132 }
163 133
164 void URLRequestSimpleJob::OnGetDataCompleted(int result) { 134 void URLRequestSimpleJob::OnGetDataCompleted(int result) {
165 // TODO(vadimt): Remove ScopedTracker below once crbug.com/422489 is fixed.
166 tracked_objects::ScopedTracker tracking_profile(
167 FROM_HERE_WITH_EXPLICIT_FUNCTION(
168 "422489 URLRequestSimpleJob::OnGetDataCompleted"));
169
170 if (result == OK) { 135 if (result == OK) {
171 // Notify that the headers are complete 136 // Notify that the headers are complete
172 if (!byte_range_.ComputeBounds(data_->size())) { 137 if (!byte_range_.ComputeBounds(data_->size())) {
173 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, 138 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED,
174 ERR_REQUEST_RANGE_NOT_SATISFIABLE)); 139 ERR_REQUEST_RANGE_NOT_SATISFIABLE));
175 return; 140 return;
176 } 141 }
177 142
178 next_data_offset_ = byte_range_.first_byte_position(); 143 next_data_offset_ = byte_range_.first_byte_position();
179 set_expected_content_size(byte_range_.last_byte_position() - 144 set_expected_content_size(byte_range_.last_byte_position() -
180 next_data_offset_ + 1); 145 next_data_offset_ + 1);
181 NotifyHeadersComplete(); 146 NotifyHeadersComplete();
182 } else { 147 } else {
183 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); 148 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result));
184 } 149 }
185 } 150 }
186 151
187 } // namespace net 152 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/sdch_dictionary_fetcher_unittest.cc ('k') | net/websockets/websocket_basic_handshake_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698