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