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

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

Issue 1459333002: Revert "Reland: URLRequestJob: change ReadRawData contract" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « net/url_request/url_request_simple_job.h ('k') | net/url_request/url_request_status.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 return true; 58 return true;
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 bool URLRequestSimpleJob::ReadRawData(IOBuffer* buf,
69 buf_size = std::min(static_cast<int64>(buf_size), 69 int buf_size,
70 byte_range_.last_byte_position() - next_data_offset_ + 1); 70 int* bytes_read) {
71 if (buf_size == 0) 71 DCHECK(bytes_read);
72 return 0; 72 buf_size = static_cast<int>(
73 std::min(static_cast<int64>(buf_size),
74 byte_range_.last_byte_position() - next_data_offset_ + 1));
75 DCHECK_GE(buf_size, 0);
76 if (buf_size == 0) {
77 *bytes_read = 0;
78 return true;
79 }
73 80
74 // Do memory copy on a background thread. See crbug.com/422489. 81 // Do memory copy on a background thread. See crbug.com/422489.
75 GetTaskRunner()->PostTaskAndReply( 82 GetTaskRunner()->PostTaskAndReply(
76 FROM_HERE, base::Bind(&CopyData, make_scoped_refptr(buf), buf_size, data_, 83 FROM_HERE, base::Bind(&CopyData, make_scoped_refptr(buf), buf_size, data_,
77 next_data_offset_), 84 next_data_offset_),
78 base::Bind(&URLRequestSimpleJob::ReadRawDataComplete, 85 base::Bind(&URLRequestSimpleJob::OnReadCompleted,
79 weak_factory_.GetWeakPtr(), buf_size)); 86 weak_factory_.GetWeakPtr(), buf_size));
80 next_data_offset_ += buf_size; 87 next_data_offset_ += buf_size;
81 return ERR_IO_PENDING; 88 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
89 return false;
90 }
91
92 void URLRequestSimpleJob::OnReadCompleted(int bytes_read) {
93 SetStatus(URLRequestStatus());
94 NotifyReadComplete(bytes_read);
82 } 95 }
83 96
84 base::TaskRunner* URLRequestSimpleJob::GetTaskRunner() const { 97 base::TaskRunner* URLRequestSimpleJob::GetTaskRunner() const {
85 return task_runner_.get(); 98 return task_runner_.get();
86 } 99 }
87 100
88 int URLRequestSimpleJob::GetData(std::string* mime_type, 101 int URLRequestSimpleJob::GetData(std::string* mime_type,
89 std::string* charset, 102 std::string* charset,
90 std::string* data, 103 std::string* data,
91 const CompletionCallback& callback) const { 104 const CompletionCallback& callback) const {
(...skipping 10 matching lines...) Expand all
102 int result = GetData(mime_type, charset, &str_data->data(), callback); 115 int result = GetData(mime_type, charset, &str_data->data(), callback);
103 *data = str_data; 116 *data = str_data;
104 return result; 117 return result;
105 } 118 }
106 119
107 void URLRequestSimpleJob::StartAsync() { 120 void URLRequestSimpleJob::StartAsync() {
108 if (!request_) 121 if (!request_)
109 return; 122 return;
110 123
111 if (ranges().size() > 1) { 124 if (ranges().size() > 1) {
112 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, 125 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED,
113 ERR_REQUEST_RANGE_NOT_SATISFIABLE)); 126 ERR_REQUEST_RANGE_NOT_SATISFIABLE));
114 return; 127 return;
115 } 128 }
116 129
117 if (!ranges().empty() && range_parse_result() == OK) 130 if (!ranges().empty() && range_parse_result() == OK)
118 byte_range_ = ranges().front(); 131 byte_range_ = ranges().front();
119 132
120 const int result = 133 const int result =
121 GetRefCountedData(&mime_type_, &charset_, &data_, 134 GetRefCountedData(&mime_type_, &charset_, &data_,
122 base::Bind(&URLRequestSimpleJob::OnGetDataCompleted, 135 base::Bind(&URLRequestSimpleJob::OnGetDataCompleted,
123 weak_factory_.GetWeakPtr())); 136 weak_factory_.GetWeakPtr()));
124 137
125 if (result != ERR_IO_PENDING) 138 if (result != ERR_IO_PENDING)
126 OnGetDataCompleted(result); 139 OnGetDataCompleted(result);
127 } 140 }
128 141
129 void URLRequestSimpleJob::OnGetDataCompleted(int result) { 142 void URLRequestSimpleJob::OnGetDataCompleted(int result) {
130 if (result == OK) { 143 if (result == OK) {
131 // Notify that the headers are complete 144 // Notify that the headers are complete
132 if (!byte_range_.ComputeBounds(data_->size())) { 145 if (!byte_range_.ComputeBounds(data_->size())) {
133 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, 146 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED,
134 ERR_REQUEST_RANGE_NOT_SATISFIABLE)); 147 ERR_REQUEST_RANGE_NOT_SATISFIABLE));
135 return; 148 return;
136 } 149 }
137 150
138 next_data_offset_ = byte_range_.first_byte_position(); 151 next_data_offset_ = byte_range_.first_byte_position();
139 set_expected_content_size(byte_range_.last_byte_position() - 152 set_expected_content_size(byte_range_.last_byte_position() -
140 next_data_offset_ + 1); 153 next_data_offset_ + 1);
141 NotifyHeadersComplete(); 154 NotifyHeadersComplete();
142 } else { 155 } else {
143 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result)); 156 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, result));
144 } 157 }
145 } 158 }
146 159
147 } // namespace net 160 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_simple_job.h ('k') | net/url_request/url_request_status.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698