| 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 <list> | 8 #include <list> |
| 9 #include <string> |
| 8 | 10 |
| 9 #include "base/logging.h" | 11 #include "base/logging.h" |
| 10 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 11 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 12 #include "net/base/load_flags.h" | 14 #include "net/base/load_flags.h" |
| 13 #include "net/http/http_request_info.h" | 15 #include "net/http/http_request_info.h" |
| 14 #include "net/http/http_response_info.h" | 16 #include "net/http/http_response_info.h" |
| 15 #include "net/spdy/spdy_session.h" | 17 #include "net/spdy/spdy_session.h" |
| 16 | 18 |
| 17 namespace { | 19 namespace { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 (*headers)["cache-control"] = "no-cache"; | 121 (*headers)["cache-control"] = "no-cache"; |
| 120 } else if (info.load_flags & net::LOAD_VALIDATE_CACHE) { | 122 } else if (info.load_flags & net::LOAD_VALIDATE_CACHE) { |
| 121 (*headers)["cache-control"] = "max-age=0"; | 123 (*headers)["cache-control"] = "max-age=0"; |
| 122 } | 124 } |
| 123 } | 125 } |
| 124 | 126 |
| 125 } // anonymous namespace | 127 } // anonymous namespace |
| 126 | 128 |
| 127 namespace net { | 129 namespace net { |
| 128 | 130 |
| 129 SpdyHttpStream::SpdyHttpStream(const scoped_refptr<SpdyStream>& stream) | 131 SpdyHttpStream::SpdyHttpStream() |
| 130 : ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_factory_(this)), | 132 : ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_factory_(this)), |
| 131 stream_(stream), | 133 stream_(NULL), |
| 134 spdy_session_(NULL), |
| 132 response_info_(NULL), | 135 response_info_(NULL), |
| 133 download_finished_(false), | 136 download_finished_(false), |
| 134 user_callback_(NULL), | 137 user_callback_(NULL), |
| 135 user_buffer_len_(0), | 138 user_buffer_len_(0), |
| 136 buffered_read_callback_pending_(false), | 139 buffered_read_callback_pending_(false), |
| 137 more_read_data_pending_(false) { | 140 more_read_data_pending_(false) { } |
| 138 CHECK(stream_.get()); | 141 |
| 139 stream_->SetDelegate(this); | 142 SpdyHttpStream::~SpdyHttpStream() { |
| 143 if (stream_) |
| 144 stream_->DetachDelegate(); |
| 140 } | 145 } |
| 141 | 146 |
| 142 SpdyHttpStream::~SpdyHttpStream() { | 147 int SpdyHttpStream::InitializeStream( |
| 143 stream_->DetachDelegate(); | 148 SpdySession* spdy_session, |
| 149 const HttpRequestInfo& request_info, |
| 150 const BoundNetLog& stream_net_log, |
| 151 CompletionCallback* callback) { |
| 152 spdy_session_ = spdy_session; |
| 153 request_info_ = request_info; |
| 154 if (request_info_.method == "GET") { |
| 155 int error = spdy_session_->GetPushStream(request_info.url, &stream_, |
| 156 stream_net_log); |
| 157 if (error != OK) |
| 158 return error; |
| 159 } |
| 160 |
| 161 if (stream_.get()) |
| 162 return OK; |
| 163 else |
| 164 return spdy_session_->CreateStream(request_info_.url, |
| 165 request_info_.priority, &stream_, |
| 166 stream_net_log, callback, this); |
| 144 } | 167 } |
| 145 | 168 |
| 146 void SpdyHttpStream::InitializeRequest( | 169 void SpdyHttpStream::InitializeRequest( |
| 147 const HttpRequestInfo& request_info, | |
| 148 base::Time request_time, | 170 base::Time request_time, |
| 149 UploadDataStream* upload_data) { | 171 UploadDataStream* upload_data) { |
| 150 request_info_ = request_info; | 172 CHECK(stream_.get()); |
| 173 stream_->SetDelegate(this); |
| 151 linked_ptr<spdy::SpdyHeaderBlock> headers(new spdy::SpdyHeaderBlock); | 174 linked_ptr<spdy::SpdyHeaderBlock> headers(new spdy::SpdyHeaderBlock); |
| 152 CreateSpdyHeadersFromHttpRequest(request_info_, headers.get()); | 175 CreateSpdyHeadersFromHttpRequest(request_info_, headers.get()); |
| 153 stream_->set_spdy_headers(headers); | 176 stream_->set_spdy_headers(headers); |
| 154 | 177 |
| 155 stream_->SetRequestTime(request_time); | 178 stream_->SetRequestTime(request_time); |
| 156 // This should only get called in the case of a request occuring | 179 // This should only get called in the case of a request occuring |
| 157 // during server push that has already begun but hasn't finished, | 180 // during server push that has already begun but hasn't finished, |
| 158 // so we set the response's request time to be the actual one | 181 // so we set the response's request time to be the actual one |
| 159 if (response_info_) | 182 if (response_info_) |
| 160 response_info_->request_time = request_time; | 183 response_info_->request_time = request_time; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 bool has_upload_data = request_body_stream_.get() != NULL; | 294 bool has_upload_data = request_body_stream_.get() != NULL; |
| 272 int result = stream_->DoSendRequest(has_upload_data); | 295 int result = stream_->DoSendRequest(has_upload_data); |
| 273 if (result == ERR_IO_PENDING) { | 296 if (result == ERR_IO_PENDING) { |
| 274 CHECK(!user_callback_); | 297 CHECK(!user_callback_); |
| 275 user_callback_ = callback; | 298 user_callback_ = callback; |
| 276 } | 299 } |
| 277 return result; | 300 return result; |
| 278 } | 301 } |
| 279 | 302 |
| 280 void SpdyHttpStream::Cancel() { | 303 void SpdyHttpStream::Cancel() { |
| 304 if (spdy_session_) |
| 305 spdy_session_->CancelPendingCreateStreams(this); |
| 281 user_callback_ = NULL; | 306 user_callback_ = NULL; |
| 282 stream_->Cancel(); | 307 if (stream_) |
| 308 stream_->Cancel(); |
| 283 } | 309 } |
| 284 | 310 |
| 285 bool SpdyHttpStream::OnSendHeadersComplete(int status) { | 311 bool SpdyHttpStream::OnSendHeadersComplete(int status) { |
| 286 return request_body_stream_.get() == NULL; | 312 return request_body_stream_.get() == NULL; |
| 287 } | 313 } |
| 288 | 314 |
| 289 int SpdyHttpStream::OnSendBody() { | 315 int SpdyHttpStream::OnSendBody() { |
| 290 CHECK(request_body_stream_.get()); | 316 CHECK(request_body_stream_.get()); |
| 291 int buf_len = static_cast<int>(request_body_stream_->buf_len()); | 317 int buf_len = static_cast<int>(request_body_stream_->buf_len()); |
| 292 if (!buf_len) | 318 if (!buf_len) |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 CHECK_NE(rv, ERR_IO_PENDING); | 446 CHECK_NE(rv, ERR_IO_PENDING); |
| 421 CHECK(user_callback_); | 447 CHECK(user_callback_); |
| 422 | 448 |
| 423 // Since Run may result in being called back, clear user_callback_ in advance. | 449 // Since Run may result in being called back, clear user_callback_ in advance. |
| 424 CompletionCallback* c = user_callback_; | 450 CompletionCallback* c = user_callback_; |
| 425 user_callback_ = NULL; | 451 user_callback_ = NULL; |
| 426 c->Run(rv); | 452 c->Run(rv); |
| 427 } | 453 } |
| 428 | 454 |
| 429 } // namespace net | 455 } // namespace net |
| OLD | NEW |