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/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/profiler/scoped_profile.h" |
12 #include "net/base/io_buffer.h" | 13 #include "net/base/io_buffer.h" |
13 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
14 #include "net/http/http_request_headers.h" | 15 #include "net/http/http_request_headers.h" |
15 #include "net/http/http_util.h" | 16 #include "net/http/http_util.h" |
16 #include "net/url_request/url_request_status.h" | 17 #include "net/url_request/url_request_status.h" |
17 | 18 |
18 namespace net { | 19 namespace net { |
19 | 20 |
20 URLRequestSimpleJob::URLRequestSimpleJob( | 21 URLRequestSimpleJob::URLRequestSimpleJob( |
21 URLRequest* request, NetworkDelegate* network_delegate) | 22 URLRequest* request, NetworkDelegate* network_delegate) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 data_offset_ += buf_size; | 54 data_offset_ += buf_size; |
54 *bytes_read = buf_size; | 55 *bytes_read = buf_size; |
55 return true; | 56 return true; |
56 } | 57 } |
57 | 58 |
58 void URLRequestSimpleJob::StartAsync() { | 59 void URLRequestSimpleJob::StartAsync() { |
59 if (!request_) | 60 if (!request_) |
60 return; | 61 return; |
61 | 62 |
62 if (ranges().size() > 1) { | 63 if (ranges().size() > 1) { |
| 64 // TODO(vadimt): Remove ScopedProfile below once crbug.com/422489 is fixed. |
| 65 tracked_objects::ScopedProfile tracking_profile( |
| 66 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 67 "422489 URLRequestSimpleJob::StartAsync 1")); |
| 68 |
63 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, | 69 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, |
64 ERR_REQUEST_RANGE_NOT_SATISFIABLE)); | 70 ERR_REQUEST_RANGE_NOT_SATISFIABLE)); |
65 return; | 71 return; |
66 } | 72 } |
67 | 73 |
68 if (!ranges().empty() && range_parse_result() == OK) | 74 if (!ranges().empty() && range_parse_result() == OK) |
69 byte_range_ = ranges().front(); | 75 byte_range_ = ranges().front(); |
70 | 76 |
71 int result = GetData(&mime_type_, &charset_, &data_, | 77 int result; |
72 base::Bind(&URLRequestSimpleJob::OnGetDataCompleted, | 78 { |
73 weak_factory_.GetWeakPtr())); | 79 // TODO(vadimt): Remove ScopedProfile below once crbug.com/422489 is fixed. |
74 if (result != ERR_IO_PENDING) | 80 // Remove the block and assign 'result' in its declaration. |
| 81 tracked_objects::ScopedProfile tracking_profile( |
| 82 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 83 "422489 URLRequestSimpleJob::StartAsync 2")); |
| 84 |
| 85 result = GetData(&mime_type_, |
| 86 &charset_, |
| 87 &data_, |
| 88 base::Bind(&URLRequestSimpleJob::OnGetDataCompleted, |
| 89 weak_factory_.GetWeakPtr())); |
| 90 } |
| 91 |
| 92 if (result != ERR_IO_PENDING) { |
| 93 // TODO(vadimt): Remove ScopedProfile below once crbug.com/422489 is fixed. |
| 94 tracked_objects::ScopedProfile tracking_profile( |
| 95 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 96 "422489 URLRequestSimpleJob::StartAsync 3")); |
| 97 |
75 OnGetDataCompleted(result); | 98 OnGetDataCompleted(result); |
| 99 } |
76 } | 100 } |
77 | 101 |
78 void URLRequestSimpleJob::OnGetDataCompleted(int result) { | 102 void URLRequestSimpleJob::OnGetDataCompleted(int result) { |
79 if (result == OK) { | 103 if (result == OK) { |
80 // Notify that the headers are complete | 104 // Notify that the headers are complete |
81 if (!byte_range_.ComputeBounds(data_.size())) { | 105 if (!byte_range_.ComputeBounds(data_.size())) { |
82 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, | 106 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, |
83 ERR_REQUEST_RANGE_NOT_SATISFIABLE)); | 107 ERR_REQUEST_RANGE_NOT_SATISFIABLE)); |
84 return; | 108 return; |
85 } | 109 } |
86 | 110 |
87 data_offset_ = byte_range_.first_byte_position(); | 111 data_offset_ = byte_range_.first_byte_position(); |
88 int remaining_bytes = byte_range_.last_byte_position() - | 112 int remaining_bytes = byte_range_.last_byte_position() - |
89 byte_range_.first_byte_position() + 1; | 113 byte_range_.first_byte_position() + 1; |
90 set_expected_content_size(remaining_bytes); | 114 set_expected_content_size(remaining_bytes); |
91 NotifyHeadersComplete(); | 115 NotifyHeadersComplete(); |
92 } else { | 116 } else { |
93 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); | 117 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); |
94 } | 118 } |
95 } | 119 } |
96 | 120 |
97 } // namespace net | 121 } // namespace net |
OLD | NEW |