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

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

Issue 1908103002: Landing Recent QUIC changes until 4/15/2016 17:20 UTC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 years, 8 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_simple_client.h ('k') | net/tools/quic/quic_simple_server.h » ('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) 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/tools/quic/quic_simple_client.h" 5 #include "net/tools/quic/quic_simple_client.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/thread_task_runner_handle.h" 9 #include "base/thread_task_runner_handle.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
11 #include "net/http/http_request_info.h" 11 #include "net/http/http_request_info.h"
12 #include "net/http/http_response_info.h" 12 #include "net/http/http_response_info.h"
13 #include "net/quic/crypto/quic_random.h" 13 #include "net/quic/crypto/quic_random.h"
14 #include "net/quic/quic_chromium_alarm_factory.h"
14 #include "net/quic/quic_chromium_connection_helper.h" 15 #include "net/quic/quic_chromium_connection_helper.h"
15 #include "net/quic/quic_chromium_packet_reader.h" 16 #include "net/quic/quic_chromium_packet_reader.h"
16 #include "net/quic/quic_chromium_packet_writer.h" 17 #include "net/quic/quic_chromium_packet_writer.h"
17 #include "net/quic/quic_connection.h" 18 #include "net/quic/quic_connection.h"
18 #include "net/quic/quic_flags.h" 19 #include "net/quic/quic_flags.h"
19 #include "net/quic/quic_protocol.h" 20 #include "net/quic/quic_protocol.h"
20 #include "net/quic/quic_server_id.h" 21 #include "net/quic/quic_server_id.h"
21 #include "net/quic/spdy_utils.h" 22 #include "net/quic/spdy_utils.h"
22 #include "net/spdy/spdy_header_block.h" 23 #include "net/spdy/spdy_header_block.h"
23 #include "net/spdy/spdy_http_utils.h" 24 #include "net/spdy/spdy_http_utils.h"
(...skipping 11 matching lines...) Expand all
35 } 36 }
36 37
37 QuicSimpleClient::QuicSimpleClient(IPEndPoint server_address, 38 QuicSimpleClient::QuicSimpleClient(IPEndPoint server_address,
38 const QuicServerId& server_id, 39 const QuicServerId& server_id,
39 const QuicVersionVector& supported_versions, 40 const QuicVersionVector& supported_versions,
40 ProofVerifier* proof_verifier) 41 ProofVerifier* proof_verifier)
41 : QuicClientBase(server_id, 42 : QuicClientBase(server_id,
42 supported_versions, 43 supported_versions,
43 QuicConfig(), 44 QuicConfig(),
44 CreateQuicConnectionHelper(), 45 CreateQuicConnectionHelper(),
46 CreateQuicAlarmFactory(),
45 proof_verifier), 47 proof_verifier),
46 server_address_(server_address), 48 server_address_(server_address),
47 local_port_(0), 49 local_port_(0),
48 initialized_(false), 50 initialized_(false),
49 packet_reader_started_(false), 51 packet_reader_started_(false),
50 weak_factory_(this) {} 52 weak_factory_(this) {}
51 53
52 QuicSimpleClient::QuicSimpleClient(IPEndPoint server_address, 54 QuicSimpleClient::QuicSimpleClient(IPEndPoint server_address,
53 const QuicServerId& server_id, 55 const QuicServerId& server_id,
54 const QuicVersionVector& supported_versions, 56 const QuicVersionVector& supported_versions,
55 const QuicConfig& config, 57 const QuicConfig& config,
56 ProofVerifier* proof_verifier) 58 ProofVerifier* proof_verifier)
57 : QuicClientBase(server_id, 59 : QuicClientBase(server_id,
58 supported_versions, 60 supported_versions,
59 config, 61 config,
60 CreateQuicConnectionHelper(), 62 CreateQuicConnectionHelper(),
63 CreateQuicAlarmFactory(),
61 proof_verifier), 64 proof_verifier),
62 server_address_(server_address), 65 server_address_(server_address),
63 local_port_(0), 66 local_port_(0),
64 initialized_(false), 67 initialized_(false),
65 packet_reader_started_(false), 68 packet_reader_started_(false),
66 weak_factory_(this) {} 69 weak_factory_(this) {}
67 70
68 QuicSimpleClient::~QuicSimpleClient() { 71 QuicSimpleClient::~QuicSimpleClient() {
69 if (connected()) { 72 if (connected()) {
70 session()->connection()->CloseConnection( 73 session()->connection()->CloseConnection(
71 QUIC_PEER_GOING_AWAY, "", 74 QUIC_PEER_GOING_AWAY, "Shutting down",
72 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); 75 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET);
73 } 76 }
74 STLDeleteElements(&data_to_resend_on_connect_); 77 STLDeleteElements(&data_to_resend_on_connect_);
75 STLDeleteElements(&data_sent_before_handshake_); 78 STLDeleteElements(&data_sent_before_handshake_);
76 } 79 }
77 80
78 bool QuicSimpleClient::Initialize() { 81 bool QuicSimpleClient::Initialize() {
79 DCHECK(!initialized_); 82 DCHECK(!initialized_);
80 83
81 QuicClientBase::Initialize(); 84 QuicClientBase::Initialize();
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 // If the last error was due to a stateless reject, queue up the data to 210 // If the last error was due to a stateless reject, queue up the data to
208 // be resent on the next successful connection. 211 // be resent on the next successful connection.
209 // TODO(jokulik): I'm a little bit concerned about ordering here. Maybe 212 // TODO(jokulik): I'm a little bit concerned about ordering here. Maybe
210 // we should just maintain one queue? 213 // we should just maintain one queue?
211 DCHECK(data_to_resend_on_connect_.empty()); 214 DCHECK(data_to_resend_on_connect_.empty());
212 data_to_resend_on_connect_.swap(data_sent_before_handshake_); 215 data_to_resend_on_connect_.swap(data_sent_before_handshake_);
213 } 216 }
214 } 217 }
215 218
216 CreateQuicClientSession(new QuicConnection( 219 CreateQuicClientSession(new QuicConnection(
217 GetNextConnectionId(), server_address_, helper(), writer(), 220 GetNextConnectionId(), server_address_, helper(), alarm_factory(),
221 writer(),
218 /* owns_writer= */ false, Perspective::IS_CLIENT, supported_versions())); 222 /* owns_writer= */ false, Perspective::IS_CLIENT, supported_versions()));
219 223
220 session()->Initialize(); 224 session()->Initialize();
221 session()->CryptoConnect(); 225 session()->CryptoConnect();
222 set_connected_or_attempting_connect(true); 226 set_connected_or_attempting_connect(true);
223 } 227 }
224 228
225 void QuicSimpleClient::Disconnect() { 229 void QuicSimpleClient::Disconnect() {
226 DCHECK(initialized_); 230 DCHECK(initialized_);
227 231
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 const string& QuicSimpleClient::latest_response_body() const { 373 const string& QuicSimpleClient::latest_response_body() const {
370 LOG_IF(DFATAL, !store_response_) << "Response not stored!"; 374 LOG_IF(DFATAL, !store_response_) << "Response not stored!";
371 return latest_response_body_; 375 return latest_response_body_;
372 } 376 }
373 377
374 QuicConnectionId QuicSimpleClient::GenerateNewConnectionId() { 378 QuicConnectionId QuicSimpleClient::GenerateNewConnectionId() {
375 return helper()->GetRandomGenerator()->RandUint64(); 379 return helper()->GetRandomGenerator()->RandUint64();
376 } 380 }
377 381
378 QuicChromiumConnectionHelper* QuicSimpleClient::CreateQuicConnectionHelper() { 382 QuicChromiumConnectionHelper* QuicSimpleClient::CreateQuicConnectionHelper() {
379 return new QuicChromiumConnectionHelper( 383 return new QuicChromiumConnectionHelper(&clock_, QuicRandom::GetInstance());
380 base::ThreadTaskRunnerHandle::Get().get(), &clock_, 384 }
381 QuicRandom::GetInstance()); 385
386 QuicChromiumAlarmFactory* QuicSimpleClient::CreateQuicAlarmFactory() {
387 return new QuicChromiumAlarmFactory(base::ThreadTaskRunnerHandle::Get().get(),
388 &clock_);
382 } 389 }
383 390
384 QuicPacketWriter* QuicSimpleClient::CreateQuicPacketWriter() { 391 QuicPacketWriter* QuicSimpleClient::CreateQuicPacketWriter() {
385 return new QuicChromiumPacketWriter(socket_.get()); 392 return new QuicChromiumPacketWriter(socket_.get());
386 } 393 }
387 394
388 void QuicSimpleClient::OnReadError(int result, 395 void QuicSimpleClient::OnReadError(int result,
389 const DatagramClientSocket* socket) { 396 const DatagramClientSocket* socket) {
390 LOG(ERROR) << "QuicSimpleClient read failed: " << ErrorToShortString(result); 397 LOG(ERROR) << "QuicSimpleClient read failed: " << ErrorToShortString(result);
391 Disconnect(); 398 Disconnect();
392 } 399 }
393 400
394 bool QuicSimpleClient::OnPacket(const QuicReceivedPacket& packet, 401 bool QuicSimpleClient::OnPacket(const QuicReceivedPacket& packet,
395 IPEndPoint local_address, 402 IPEndPoint local_address,
396 IPEndPoint peer_address) { 403 IPEndPoint peer_address) {
397 session()->connection()->ProcessUdpPacket(local_address, peer_address, 404 session()->connection()->ProcessUdpPacket(local_address, peer_address,
398 packet); 405 packet);
399 if (!session()->connection()->connected()) { 406 if (!session()->connection()->connected()) {
400 return false; 407 return false;
401 } 408 }
402 409
403 return true; 410 return true;
404 } 411 }
405 412
406 } // namespace net 413 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_simple_client.h ('k') | net/tools/quic/quic_simple_server.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698