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

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

Issue 1410643007: URLRequestJob: change ReadRawData contract (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move NotifyReadCompleted 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, net_error_)); 102 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, net_error_));
103 return; 103 return;
104 } 104 }
105 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); 105 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
106 return; 106 return;
107 } 107 }
108 response_info_.headers = new net::HttpResponseHeaders("HTTP/1.1 200 OK"); 108 response_info_.headers = new net::HttpResponseHeaders("HTTP/1.1 200 OK");
109 NotifyHeadersComplete(); 109 NotifyHeadersComplete();
110 } 110 }
111 111
112 bool URLRequestFailedJob::ReadRawData(IOBuffer* buf, 112 int URLRequestFailedJob::ReadRawData(IOBuffer* buf, int buf_size) {
113 int buf_size,
114 int* bytes_read) {
115 CHECK(phase_ == READ_SYNC || phase_ == READ_ASYNC); 113 CHECK(phase_ == READ_SYNC || phase_ == READ_ASYNC);
116 if (net_error_ != ERR_IO_PENDING && phase_ == READ_SYNC) { 114 if (net_error_ == ERR_IO_PENDING || phase_ == READ_SYNC)
117 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, net_error_)); 115 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 116
126 DCHECK_EQ(READ_ASYNC, phase_); 117 DCHECK_EQ(READ_ASYNC, phase_);
127 DCHECK_NE(ERR_IO_PENDING, net_error_); 118 DCHECK_NE(ERR_IO_PENDING, net_error_);
mmenke 2015/10/28 16:40:42 nit: Can remove these - they were for documentati
xunjieli 2015/10/28 21:11:52 Done.
128 119
129 base::ThreadTaskRunnerHandle::Get()->PostTask( 120 base::ThreadTaskRunnerHandle::Get()->PostTask(
130 FROM_HERE, 121 FROM_HERE, base::Bind(&URLRequestFailedJob::ReadRawDataComplete,
131 base::Bind(&URLRequestFailedJob::NotifyDone, weak_factory_.GetWeakPtr(), 122 weak_factory_.GetWeakPtr(), net_error_));
132 URLRequestStatus(URLRequestStatus::FAILED, net_error_))); 123 return ERR_IO_PENDING;
133 return false;
134 } 124 }
135 125
136 int URLRequestFailedJob::GetResponseCode() const { 126 int URLRequestFailedJob::GetResponseCode() const {
137 // If we have headers, get the response code from them. 127 // If we have headers, get the response code from them.
138 if (response_info_.headers) 128 if (response_info_.headers)
139 return response_info_.headers->response_code(); 129 return response_info_.headers->response_code();
140 return URLRequestJob::GetResponseCode(); 130 return URLRequestJob::GetResponseCode();
141 } 131 }
142 132
143 void URLRequestFailedJob::GetResponseInfo(HttpResponseInfo* info) { 133 void URLRequestFailedJob::GetResponseInfo(HttpResponseInfo* info) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 GURL URLRequestFailedJob::GetMockHttpsUrlForHostname( 179 GURL URLRequestFailedJob::GetMockHttpsUrlForHostname(
190 int net_error, 180 int net_error,
191 const std::string& hostname) { 181 const std::string& hostname) {
192 return GetMockUrl("https", hostname, START, net_error); 182 return GetMockUrl("https", hostname, START, net_error);
193 } 183 }
194 184
195 URLRequestFailedJob::~URLRequestFailedJob() { 185 URLRequestFailedJob::~URLRequestFailedJob() {
196 } 186 }
197 187
198 } // namespace net 188 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698