Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/spdy/spdy_http_stream.h" | 5 #include "net/spdy/spdy_http_stream.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <list> | 8 #include <list> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 (*headers)["cache-control"] = "no-cache"; | 122 (*headers)["cache-control"] = "no-cache"; |
| 123 } else if (info.load_flags & net::LOAD_VALIDATE_CACHE) { | 123 } else if (info.load_flags & net::LOAD_VALIDATE_CACHE) { |
| 124 (*headers)["cache-control"] = "max-age=0"; | 124 (*headers)["cache-control"] = "max-age=0"; |
| 125 } | 125 } |
| 126 } | 126 } |
| 127 | 127 |
| 128 } // anonymous namespace | 128 } // anonymous namespace |
| 129 | 129 |
| 130 namespace net { | 130 namespace net { |
| 131 | 131 |
| 132 SpdyHttpStream::SpdyHttpStream() | 132 SpdyHttpStream::SpdyHttpStream(SpdySession* spdy_session) |
| 133 : ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_factory_(this)), | 133 : ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_factory_(this)), |
| 134 stream_(NULL), | 134 stream_(NULL), |
| 135 spdy_session_(NULL), | 135 spdy_session_(spdy_session), |
| 136 response_info_(NULL), | 136 response_info_(NULL), |
| 137 download_finished_(false), | 137 download_finished_(false), |
| 138 user_callback_(NULL), | 138 user_callback_(NULL), |
| 139 user_buffer_len_(0), | 139 user_buffer_len_(0), |
| 140 buffered_read_callback_pending_(false), | 140 buffered_read_callback_pending_(false), |
| 141 more_read_data_pending_(false) { } | 141 more_read_data_pending_(false) { } |
| 142 | 142 |
| 143 SpdyHttpStream::~SpdyHttpStream() { | 143 SpdyHttpStream::~SpdyHttpStream() { |
| 144 if (stream_) | 144 if (stream_) |
| 145 stream_->DetachDelegate(); | 145 stream_->DetachDelegate(); |
| 146 } | 146 } |
| 147 | 147 |
| 148 int SpdyHttpStream::InitializeStream( | 148 int SpdyHttpStream::InitializeStream(const HttpRequestInfo* request_info, |
| 149 SpdySession* spdy_session, | 149 const BoundNetLog& stream_net_log, |
| 150 const HttpRequestInfo& request_info, | 150 CompletionCallback* callback) { |
| 151 const BoundNetLog& stream_net_log, | |
| 152 CompletionCallback* callback) { | |
| 153 spdy_session_ = spdy_session; | |
| 154 request_info_ = request_info; | 151 request_info_ = request_info; |
| 155 if (request_info_.method == "GET") { | 152 if (request_info_->method == "GET") { |
| 156 int error = spdy_session_->GetPushStream(request_info.url, &stream_, | 153 int error = spdy_session_->GetPushStream(request_info_->url, &stream_, |
| 157 stream_net_log); | 154 stream_net_log); |
| 158 if (error != OK) | 155 if (error != OK) |
| 159 return error; | 156 return error; |
| 160 } | 157 } |
| 161 | 158 |
| 162 if (stream_.get()) | 159 if (stream_.get()) |
| 163 return OK; | 160 return OK; |
| 164 else | 161 else |
| 165 return spdy_session_->CreateStream(request_info_.url, | 162 return spdy_session_->CreateStream(request_info_->url, |
| 166 request_info_.priority, &stream_, | 163 request_info_->priority, &stream_, |
| 167 stream_net_log, callback); | 164 stream_net_log, callback); |
| 168 } | 165 } |
| 169 | 166 |
| 170 void SpdyHttpStream::InitializeRequest( | |
| 171 base::Time request_time, | |
| 172 UploadDataStream* upload_data) { | |
| 173 CHECK(stream_.get()); | |
| 174 stream_->SetDelegate(this); | |
| 175 linked_ptr<spdy::SpdyHeaderBlock> headers(new spdy::SpdyHeaderBlock); | |
| 176 CreateSpdyHeadersFromHttpRequest(request_info_, headers.get()); | |
| 177 stream_->set_spdy_headers(headers); | |
| 178 | |
| 179 stream_->SetRequestTime(request_time); | |
| 180 // This should only get called in the case of a request occuring | |
| 181 // during server push that has already begun but hasn't finished, | |
| 182 // so we set the response's request time to be the actual one | |
| 183 if (response_info_) | |
| 184 response_info_->request_time = request_time; | |
| 185 | |
| 186 CHECK(!request_body_stream_.get()); | |
| 187 if (upload_data) { | |
| 188 if (upload_data->size()) | |
| 189 request_body_stream_.reset(upload_data); | |
| 190 else | |
| 191 delete upload_data; | |
| 192 } | |
| 193 } | |
| 194 | |
| 195 const HttpResponseInfo* SpdyHttpStream::GetResponseInfo() const { | 167 const HttpResponseInfo* SpdyHttpStream::GetResponseInfo() const { |
| 196 return response_info_; | 168 return response_info_; |
| 197 } | 169 } |
| 198 | 170 |
| 199 uint64 SpdyHttpStream::GetUploadProgress() const { | 171 uint64 SpdyHttpStream::GetUploadProgress() const { |
| 200 if (!request_body_stream_.get()) | 172 if (!request_body_stream_.get()) |
| 201 return 0; | 173 return 0; |
| 202 | 174 |
| 203 return request_body_stream_->position(); | 175 return request_body_stream_->position(); |
| 204 } | 176 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 CHECK(!user_callback_); | 227 CHECK(!user_callback_); |
| 256 CHECK(!user_buffer_); | 228 CHECK(!user_buffer_); |
| 257 CHECK_EQ(0, user_buffer_len_); | 229 CHECK_EQ(0, user_buffer_len_); |
| 258 | 230 |
| 259 user_callback_ = callback; | 231 user_callback_ = callback; |
| 260 user_buffer_ = buf; | 232 user_buffer_ = buf; |
| 261 user_buffer_len_ = buf_len; | 233 user_buffer_len_ = buf_len; |
| 262 return ERR_IO_PENDING; | 234 return ERR_IO_PENDING; |
| 263 } | 235 } |
| 264 | 236 |
| 265 int SpdyHttpStream::SendRequest(HttpResponseInfo* response, | 237 int SpdyHttpStream::SendRequest(const std::string& /*headers_string*/, |
|
vandebo (ex-Chrome)
2010/07/28 23:30:39
My mistake, it's in the headers that we comment it
| |
| 238 UploadDataStream* request_body, | |
| 239 HttpResponseInfo* response, | |
| 266 CompletionCallback* callback) { | 240 CompletionCallback* callback) { |
| 241 base::Time request_time = base::Time::Now(); | |
| 242 CHECK(stream_.get()); | |
| 243 | |
| 244 stream_->SetDelegate(this); | |
| 245 linked_ptr<spdy::SpdyHeaderBlock> headers(new spdy::SpdyHeaderBlock); | |
| 246 CreateSpdyHeadersFromHttpRequest(*request_info_, headers.get()); | |
| 247 stream_->set_spdy_headers(headers); | |
| 248 | |
| 249 stream_->SetRequestTime(request_time); | |
| 250 // This should only get called in the case of a request occurring | |
| 251 // during server push that has already begun but hasn't finished, | |
| 252 // so we set the response's request time to be the actual one | |
| 253 if (response_info_) | |
| 254 response_info_->request_time = request_time; | |
| 255 | |
| 256 CHECK(!request_body_stream_.get()); | |
| 257 if (request_body) { | |
| 258 if (request_body->size()) | |
| 259 request_body_stream_.reset(request_body); | |
| 260 else | |
| 261 delete request_body; | |
| 262 } | |
| 263 | |
| 267 CHECK(callback); | 264 CHECK(callback); |
| 268 CHECK(!stream_->cancelled()); | 265 CHECK(!stream_->cancelled()); |
| 269 CHECK(response); | 266 CHECK(response); |
| 270 | 267 |
| 271 if (stream_->response_complete()) { | 268 if (stream_->response_complete()) { |
| 272 if (stream_->response_status() == OK) | 269 if (stream_->response_status() == OK) |
| 273 return ERR_FAILED; | 270 return ERR_FAILED; |
| 274 else | 271 else |
| 275 return stream_->response_status(); | 272 return stream_->response_status(); |
| 276 } | 273 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 push_response_info_.reset(new HttpResponseInfo); | 333 push_response_info_.reset(new HttpResponseInfo); |
| 337 response_info_ = push_response_info_.get(); | 334 response_info_ = push_response_info_.get(); |
| 338 } | 335 } |
| 339 | 336 |
| 340 if (!SpdyHeadersToHttpResponse(response, response_info_)) { | 337 if (!SpdyHeadersToHttpResponse(response, response_info_)) { |
| 341 status = ERR_INVALID_RESPONSE; | 338 status = ERR_INVALID_RESPONSE; |
| 342 } else { | 339 } else { |
| 343 stream_->GetSSLInfo(&response_info_->ssl_info, | 340 stream_->GetSSLInfo(&response_info_->ssl_info, |
| 344 &response_info_->was_npn_negotiated); | 341 &response_info_->was_npn_negotiated); |
| 345 response_info_->request_time = stream_->GetRequestTime(); | 342 response_info_->request_time = stream_->GetRequestTime(); |
| 346 response_info_->vary_data.Init(request_info_, *response_info_->headers); | 343 response_info_->vary_data.Init(*request_info_, *response_info_->headers); |
| 347 // TODO(ahendrickson): This is recorded after the entire SYN_STREAM control | 344 // TODO(ahendrickson): This is recorded after the entire SYN_STREAM control |
| 348 // frame has been received and processed. Move to framer? | 345 // frame has been received and processed. Move to framer? |
| 349 response_info_->response_time = response_time; | 346 response_info_->response_time = response_time; |
| 350 } | 347 } |
| 351 | 348 |
| 352 if (user_callback_) | 349 if (user_callback_) |
| 353 DoCallback(status); | 350 DoCallback(status); |
| 354 return status; | 351 return status; |
| 355 } | 352 } |
| 356 | 353 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 454 CHECK_NE(rv, ERR_IO_PENDING); | 451 CHECK_NE(rv, ERR_IO_PENDING); |
| 455 CHECK(user_callback_); | 452 CHECK(user_callback_); |
| 456 | 453 |
| 457 // Since Run may result in being called back, clear user_callback_ in advance. | 454 // Since Run may result in being called back, clear user_callback_ in advance. |
| 458 CompletionCallback* c = user_callback_; | 455 CompletionCallback* c = user_callback_; |
| 459 user_callback_ = NULL; | 456 user_callback_ = NULL; |
| 460 c->Run(rv); | 457 c->Run(rv); |
| 461 } | 458 } |
| 462 | 459 |
| 463 } // namespace net | 460 } // namespace net |
| OLD | NEW |