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

Side by Side Diff: net/test/url_request/url_request_failed_job.cc

Issue 1439953006: Reland: URLRequestJob: change ReadRawData contract (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address David's comment 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
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/test/url_request/url_request_failed_job.h" 5 #include "net/test/url_request/url_request_failed_job.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 CHECK_LT(net_error, OK); 90 CHECK_LT(net_error, OK);
91 } 91 }
92 92
93 URLRequestFailedJob::URLRequestFailedJob(URLRequest* request, 93 URLRequestFailedJob::URLRequestFailedJob(URLRequest* request,
94 NetworkDelegate* network_delegate, 94 NetworkDelegate* network_delegate,
95 int net_error) 95 int net_error)
96 : URLRequestFailedJob(request, network_delegate, START, net_error) { 96 : URLRequestFailedJob(request, network_delegate, START, net_error) {
97 } 97 }
98 98
99 void URLRequestFailedJob::Start() { 99 void URLRequestFailedJob::Start() {
100 if (phase_ == START) { 100 base::ThreadTaskRunnerHandle::Get()->PostTask(
101 if (net_error_ != ERR_IO_PENDING) { 101 FROM_HERE,
102 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, net_error_)); 102 base::Bind(&URLRequestFailedJob::StartAsync, weak_factory_.GetWeakPtr()));
103 return;
104 }
105 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
106 return;
107 }
108 response_info_.headers = new net::HttpResponseHeaders("HTTP/1.1 200 OK");
109 NotifyHeadersComplete();
110 } 103 }
111 104
112 bool URLRequestFailedJob::ReadRawData(IOBuffer* buf, 105 int URLRequestFailedJob::ReadRawData(IOBuffer* buf, int buf_size) {
113 int buf_size,
114 int* bytes_read) {
115 CHECK(phase_ == READ_SYNC || phase_ == READ_ASYNC); 106 CHECK(phase_ == READ_SYNC || phase_ == READ_ASYNC);
116 if (net_error_ != ERR_IO_PENDING && phase_ == READ_SYNC) { 107 if (net_error_ == ERR_IO_PENDING || phase_ == READ_SYNC)
117 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, net_error_)); 108 return net_error_;
118 return false;
119 }
120
121 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
122
123 if (net_error_ == ERR_IO_PENDING)
124 return false;
125
126 DCHECK_EQ(READ_ASYNC, phase_);
127 DCHECK_NE(ERR_IO_PENDING, net_error_);
128 109
129 base::ThreadTaskRunnerHandle::Get()->PostTask( 110 base::ThreadTaskRunnerHandle::Get()->PostTask(
130 FROM_HERE, 111 FROM_HERE, base::Bind(&URLRequestFailedJob::ReadRawDataComplete,
131 base::Bind(&URLRequestFailedJob::NotifyDone, weak_factory_.GetWeakPtr(), 112 weak_factory_.GetWeakPtr(), net_error_));
132 URLRequestStatus(URLRequestStatus::FAILED, net_error_))); 113 return ERR_IO_PENDING;
133 return false;
134 } 114 }
135 115
136 int URLRequestFailedJob::GetResponseCode() const { 116 int URLRequestFailedJob::GetResponseCode() const {
137 // If we have headers, get the response code from them. 117 // If we have headers, get the response code from them.
138 if (response_info_.headers) 118 if (response_info_.headers)
139 return response_info_.headers->response_code(); 119 return response_info_.headers->response_code();
140 return URLRequestJob::GetResponseCode(); 120 return URLRequestJob::GetResponseCode();
141 } 121 }
142 122
143 void URLRequestFailedJob::GetResponseInfo(HttpResponseInfo* info) { 123 void URLRequestFailedJob::GetResponseInfo(HttpResponseInfo* info) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 // static 168 // static
189 GURL URLRequestFailedJob::GetMockHttpsUrlForHostname( 169 GURL URLRequestFailedJob::GetMockHttpsUrlForHostname(
190 int net_error, 170 int net_error,
191 const std::string& hostname) { 171 const std::string& hostname) {
192 return GetMockUrl("https", hostname, START, net_error); 172 return GetMockUrl("https", hostname, START, net_error);
193 } 173 }
194 174
195 URLRequestFailedJob::~URLRequestFailedJob() { 175 URLRequestFailedJob::~URLRequestFailedJob() {
196 } 176 }
197 177
178 void URLRequestFailedJob::StartAsync() {
179 if (phase_ == START) {
180 if (net_error_ != ERR_IO_PENDING) {
181 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, net_error_));
182 return;
183 }
184 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
185 return;
186 }
187 response_info_.headers = new net::HttpResponseHeaders("HTTP/1.1 200 OK");
188 NotifyHeadersComplete();
189 }
190
198 } // namespace net 191 } // namespace net
OLDNEW
« no previous file with comments | « net/test/url_request/url_request_failed_job.h ('k') | net/test/url_request/url_request_mock_data_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698