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

Side by Side Diff: net/tools/quic/quic_client_base.cc

Issue 2740453006: Add QuicStringPiece which is actually StringPiece. (Closed)
Patch Set: fix compile error and rebase Created 3 years, 9 months 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/tools/quic/quic_client_base.h ('k') | net/tools/quic/quic_client_bin.cc » ('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) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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/tools/quic/quic_client_base.h" 5 #include "net/tools/quic/quic_client_base.h"
6 6
7 #include "net/quic/core/crypto/quic_random.h" 7 #include "net/quic/core/crypto/quic_random.h"
8 #include "net/quic/core/quic_flags.h" 8 #include "net/quic/core/quic_flags.h"
9 #include "net/quic/core/quic_server_id.h" 9 #include "net/quic/core/quic_server_id.h"
10 #include "net/quic/core/spdy_utils.h" 10 #include "net/quic/core/spdy_utils.h"
11 #include "net/quic/platform/api/quic_logging.h" 11 #include "net/quic/platform/api/quic_logging.h"
12 #include "net/quic/platform/api/quic_text_utils.h" 12 #include "net/quic/platform/api/quic_text_utils.h"
13 13
14 using base::StringPiece;
15 using base::StringToInt; 14 using base::StringToInt;
16 using std::string; 15 using std::string;
17 16
18 namespace net { 17 namespace net {
19 18
20 void QuicClientBase::ClientQuicDataToResend::Resend() { 19 void QuicClientBase::ClientQuicDataToResend::Resend() {
21 client_->SendRequest(*headers_, body_, fin_); 20 client_->SendRequest(*headers_, body_, fin_);
22 headers_ = nullptr; 21 headers_ = nullptr;
23 } 22 }
24 23
25 QuicClientBase::QuicDataToResend::QuicDataToResend( 24 QuicClientBase::QuicDataToResend::QuicDataToResend(
26 std::unique_ptr<SpdyHeaderBlock> headers, 25 std::unique_ptr<SpdyHeaderBlock> headers,
27 StringPiece body, 26 QuicStringPiece body,
28 bool fin) 27 bool fin)
29 : headers_(std::move(headers)), body_(body), fin_(fin) {} 28 : headers_(std::move(headers)), body_(body), fin_(fin) {}
30 29
31 QuicClientBase::QuicDataToResend::~QuicDataToResend() {} 30 QuicClientBase::QuicDataToResend::~QuicDataToResend() {}
32 31
33 QuicClientBase::QuicClientBase(const QuicServerId& server_id, 32 QuicClientBase::QuicClientBase(const QuicServerId& server_id,
34 const QuicVersionVector& supported_versions, 33 const QuicVersionVector& supported_versions,
35 const QuicConfig& config, 34 const QuicConfig& config,
36 QuicConnectionHelperInterface* helper, 35 QuicConnectionHelperInterface* helper,
37 QuicAlarmFactory* alarm_factory, 36 QuicAlarmFactory* alarm_factory,
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 199 }
201 return session_.get(); 200 return session_.get();
202 } 201 }
203 202
204 bool QuicClientBase::EncryptionBeingEstablished() { 203 bool QuicClientBase::EncryptionBeingEstablished() {
205 return !session_->IsEncryptionEstablished() && 204 return !session_->IsEncryptionEstablished() &&
206 session_->connection()->connected(); 205 session_->connection()->connected();
207 } 206 }
208 207
209 void QuicClientBase::SendRequest(const SpdyHeaderBlock& headers, 208 void QuicClientBase::SendRequest(const SpdyHeaderBlock& headers,
210 StringPiece body, 209 QuicStringPiece body,
211 bool fin) { 210 bool fin) {
212 QuicClientPushPromiseIndex::TryHandle* handle; 211 QuicClientPushPromiseIndex::TryHandle* handle;
213 QuicAsyncStatus rv = push_promise_index()->Try(headers, this, &handle); 212 QuicAsyncStatus rv = push_promise_index()->Try(headers, this, &handle);
214 if (rv == QUIC_SUCCESS) 213 if (rv == QUIC_SUCCESS)
215 return; 214 return;
216 215
217 if (rv == QUIC_PENDING) { 216 if (rv == QUIC_PENDING) {
218 // May need to retry request if asynchronous rendezvous fails. 217 // May need to retry request if asynchronous rendezvous fails.
219 AddPromiseDataToResend(headers, body, fin); 218 AddPromiseDataToResend(headers, body, fin);
220 return; 219 return;
221 } 220 }
222 221
223 QuicSpdyClientStream* stream = CreateClientStream(); 222 QuicSpdyClientStream* stream = CreateClientStream();
224 if (stream == nullptr) { 223 if (stream == nullptr) {
225 QUIC_BUG << "stream creation failed!"; 224 QUIC_BUG << "stream creation failed!";
226 return; 225 return;
227 } 226 }
228 stream->SendRequest(headers.Clone(), body, fin); 227 stream->SendRequest(headers.Clone(), body, fin);
229 // Record this in case we need to resend. 228 // Record this in case we need to resend.
230 MaybeAddDataToResend(headers, body, fin); 229 MaybeAddDataToResend(headers, body, fin);
231 } 230 }
232 231
233 void QuicClientBase::SendRequestAndWaitForResponse( 232 void QuicClientBase::SendRequestAndWaitForResponse(
234 const SpdyHeaderBlock& headers, 233 const SpdyHeaderBlock& headers,
235 StringPiece body, 234 QuicStringPiece body,
236 bool fin) { 235 bool fin) {
237 SendRequest(headers, body, fin); 236 SendRequest(headers, body, fin);
238 while (WaitForEvents()) { 237 while (WaitForEvents()) {
239 } 238 }
240 } 239 }
241 240
242 void QuicClientBase::SendRequestsAndWaitForResponse( 241 void QuicClientBase::SendRequestsAndWaitForResponse(
243 const std::vector<string>& url_list) { 242 const std::vector<string>& url_list) {
244 for (size_t i = 0; i < url_list.size(); ++i) { 243 for (size_t i = 0; i < url_list.size(); ++i) {
245 SpdyHeaderBlock headers; 244 SpdyHeaderBlock headers;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 return cached->has_server_designated_connection_id() 387 return cached->has_server_designated_connection_id()
389 ? cached->GetNextServerDesignatedConnectionId() 388 ? cached->GetNextServerDesignatedConnectionId()
390 : 0; 389 : 0;
391 } 390 }
392 391
393 QuicConnectionId QuicClientBase::GenerateNewConnectionId() { 392 QuicConnectionId QuicClientBase::GenerateNewConnectionId() {
394 return QuicRandom::GetInstance()->RandUint64(); 393 return QuicRandom::GetInstance()->RandUint64();
395 } 394 }
396 395
397 void QuicClientBase::MaybeAddDataToResend(const SpdyHeaderBlock& headers, 396 void QuicClientBase::MaybeAddDataToResend(const SpdyHeaderBlock& headers,
398 StringPiece body, 397 QuicStringPiece body,
399 bool fin) { 398 bool fin) {
400 if (!FLAGS_quic_reloadable_flag_enable_quic_stateless_reject_support) { 399 if (!FLAGS_quic_reloadable_flag_enable_quic_stateless_reject_support) {
401 return; 400 return;
402 } 401 }
403 402
404 if (session()->IsCryptoHandshakeConfirmed()) { 403 if (session()->IsCryptoHandshakeConfirmed()) {
405 // The handshake is confirmed. No need to continue saving requests to 404 // The handshake is confirmed. No need to continue saving requests to
406 // resend. 405 // resend.
407 data_to_resend_on_connect_.clear(); 406 data_to_resend_on_connect_.clear();
408 return; 407 return;
(...skipping 21 matching lines...) Expand all
430 // Calling Resend will re-enqueue the data, so swap out 429 // Calling Resend will re-enqueue the data, so swap out
431 // data_to_resend_on_connect_ before iterating. 430 // data_to_resend_on_connect_ before iterating.
432 std::vector<std::unique_ptr<QuicDataToResend>> old_data; 431 std::vector<std::unique_ptr<QuicDataToResend>> old_data;
433 old_data.swap(data_to_resend_on_connect_); 432 old_data.swap(data_to_resend_on_connect_);
434 for (const auto& data : old_data) { 433 for (const auto& data : old_data) {
435 data->Resend(); 434 data->Resend();
436 } 435 }
437 } 436 }
438 437
439 void QuicClientBase::AddPromiseDataToResend(const SpdyHeaderBlock& headers, 438 void QuicClientBase::AddPromiseDataToResend(const SpdyHeaderBlock& headers,
440 StringPiece body, 439 QuicStringPiece body,
441 bool fin) { 440 bool fin) {
442 std::unique_ptr<SpdyHeaderBlock> new_headers( 441 std::unique_ptr<SpdyHeaderBlock> new_headers(
443 new SpdyHeaderBlock(headers.Clone())); 442 new SpdyHeaderBlock(headers.Clone()));
444 push_promise_data_to_resend_.reset( 443 push_promise_data_to_resend_.reset(
445 new ClientQuicDataToResend(std::move(new_headers), body, fin, this)); 444 new ClientQuicDataToResend(std::move(new_headers), body, fin, this));
446 } 445 }
447 446
448 bool QuicClientBase::CheckVary(const SpdyHeaderBlock& client_request, 447 bool QuicClientBase::CheckVary(const SpdyHeaderBlock& client_request,
449 const SpdyHeaderBlock& promise_request, 448 const SpdyHeaderBlock& promise_request,
450 const SpdyHeaderBlock& promise_response) { 449 const SpdyHeaderBlock& promise_response) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 QUIC_BUG_IF(!store_response_) << "Response not stored!"; 485 QUIC_BUG_IF(!store_response_) << "Response not stored!";
487 return latest_response_body_; 486 return latest_response_body_;
488 } 487 }
489 488
490 const string& QuicClientBase::latest_response_trailers() const { 489 const string& QuicClientBase::latest_response_trailers() const {
491 QUIC_BUG_IF(!store_response_) << "Response not stored!"; 490 QUIC_BUG_IF(!store_response_) << "Response not stored!";
492 return latest_response_trailers_; 491 return latest_response_trailers_;
493 } 492 }
494 493
495 } // namespace net 494 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_client_base.h ('k') | net/tools/quic/quic_client_bin.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698