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_job.h" | 5 #include "net/url_request/url_request_job.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
15 #include "base/power_monitor/power_monitor.h" | |
16 #include "base/profiler/scoped_tracker.h" | 15 #include "base/profiler/scoped_tracker.h" |
17 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
18 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
19 #include "base/strings/string_split.h" | 18 #include "base/strings/string_split.h" |
20 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
21 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
22 #include "base/values.h" | 21 #include "base/values.h" |
23 #include "net/base/auth.h" | 22 #include "net/base/auth.h" |
24 #include "net/base/host_port_pair.h" | 23 #include "net/base/host_port_pair.h" |
25 #include "net/base/io_buffer.h" | 24 #include "net/base/io_buffer.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 : request_(request), | 157 : request_(request), |
159 done_(false), | 158 done_(false), |
160 prefilter_bytes_read_(0), | 159 prefilter_bytes_read_(0), |
161 postfilter_bytes_read_(0), | 160 postfilter_bytes_read_(0), |
162 has_handled_response_(false), | 161 has_handled_response_(false), |
163 expected_content_size_(-1), | 162 expected_content_size_(-1), |
164 network_delegate_(network_delegate), | 163 network_delegate_(network_delegate), |
165 last_notified_total_received_bytes_(0), | 164 last_notified_total_received_bytes_(0), |
166 last_notified_total_sent_bytes_(0), | 165 last_notified_total_sent_bytes_(0), |
167 weak_factory_(this) { | 166 weak_factory_(this) { |
168 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); | |
169 if (power_monitor) | |
170 power_monitor->AddObserver(this); | |
171 } | 167 } |
172 | 168 |
173 URLRequestJob::~URLRequestJob() { | 169 URLRequestJob::~URLRequestJob() { |
174 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); | |
175 if (power_monitor) | |
176 power_monitor->RemoveObserver(this); | |
177 } | 170 } |
178 | 171 |
179 void URLRequestJob::SetUpload(UploadDataStream* upload) { | 172 void URLRequestJob::SetUpload(UploadDataStream* upload) { |
180 } | 173 } |
181 | 174 |
182 void URLRequestJob::SetExtraRequestHeaders(const HttpRequestHeaders& headers) { | 175 void URLRequestJob::SetExtraRequestHeaders(const HttpRequestHeaders& headers) { |
183 } | 176 } |
184 | 177 |
185 void URLRequestJob::SetPriority(RequestPriority priority) { | 178 void URLRequestJob::SetPriority(RequestPriority priority) { |
186 } | 179 } |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 HttpResponseHeaders* headers = request_->response_headers(); | 329 HttpResponseHeaders* headers = request_->response_headers(); |
337 if (!headers) | 330 if (!headers) |
338 return -1; | 331 return -1; |
339 return headers->response_code(); | 332 return headers->response_code(); |
340 } | 333 } |
341 | 334 |
342 HostPortPair URLRequestJob::GetSocketAddress() const { | 335 HostPortPair URLRequestJob::GetSocketAddress() const { |
343 return HostPortPair(); | 336 return HostPortPair(); |
344 } | 337 } |
345 | 338 |
346 void URLRequestJob::OnSuspend() { | |
347 // Most errors generated by the Job come as the result of the one current | |
348 // operation the job is waiting on returning an error. This event is unusual | |
349 // in that the Job may have another operation ongoing, or the Job may be idle | |
350 // and waiting on the next call. | |
351 // | |
352 // Need to cancel through the request to make sure everything is notified | |
353 // of the failure (Particularly that the NetworkDelegate, which the Job may be | |
354 // waiting on, is notified synchronously) and torn down correctly. | |
355 // | |
356 // TODO(mmenke): This should probably fail the request with | |
357 // NETWORK_IO_SUSPENDED instead. | |
358 request_->Cancel(); | |
359 } | |
360 | |
361 void URLRequestJob::NotifyURLRequestDestroyed() { | 339 void URLRequestJob::NotifyURLRequestDestroyed() { |
362 } | 340 } |
363 | 341 |
364 void URLRequestJob::GetConnectionAttempts(ConnectionAttempts* out) const { | 342 void URLRequestJob::GetConnectionAttempts(ConnectionAttempts* out) const { |
365 out->clear(); | 343 out->clear(); |
366 } | 344 } |
367 | 345 |
368 // static | 346 // static |
369 GURL URLRequestJob::ComputeReferrerForRedirect( | 347 GURL URLRequestJob::ComputeReferrerForRedirect( |
370 URLRequest::ReferrerPolicy policy, | 348 URLRequest::ReferrerPolicy policy, |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 int64_t total_sent_bytes = GetTotalSentBytes(); | 830 int64_t total_sent_bytes = GetTotalSentBytes(); |
853 DCHECK_GE(total_sent_bytes, last_notified_total_sent_bytes_); | 831 DCHECK_GE(total_sent_bytes, last_notified_total_sent_bytes_); |
854 if (total_sent_bytes > last_notified_total_sent_bytes_) { | 832 if (total_sent_bytes > last_notified_total_sent_bytes_) { |
855 network_delegate_->NotifyNetworkBytesSent( | 833 network_delegate_->NotifyNetworkBytesSent( |
856 request_, total_sent_bytes - last_notified_total_sent_bytes_); | 834 request_, total_sent_bytes - last_notified_total_sent_bytes_); |
857 } | 835 } |
858 last_notified_total_sent_bytes_ = total_sent_bytes; | 836 last_notified_total_sent_bytes_ = total_sent_bytes; |
859 } | 837 } |
860 | 838 |
861 } // namespace net | 839 } // namespace net |
OLD | NEW |