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

Side by Side Diff: net/quic/test_tools/quic_test_utils.h

Issue 475113005: Refactoring: Create per-connection packet writers in QuicDispatcher. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add new files to net/BUILD.gn Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « net/quic/test_tools/quic_connection_peer.cc ('k') | net/quic/test_tools/quic_test_utils.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) 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 // Common utilities for Quic tests 5 // Common utilities for Quic tests
6 6
7 #ifndef NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ 7 #ifndef NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_
8 #define NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ 8 #define NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_
9 9
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/strings/string_piece.h" 13 #include "base/strings/string_piece.h"
14 #include "net/quic/congestion_control/loss_detection_interface.h" 14 #include "net/quic/congestion_control/loss_detection_interface.h"
15 #include "net/quic/congestion_control/send_algorithm_interface.h" 15 #include "net/quic/congestion_control/send_algorithm_interface.h"
16 #include "net/quic/quic_ack_notifier.h" 16 #include "net/quic/quic_ack_notifier.h"
17 #include "net/quic/quic_client_session_base.h" 17 #include "net/quic/quic_client_session_base.h"
18 #include "net/quic/quic_connection.h" 18 #include "net/quic/quic_connection.h"
19 #include "net/quic/quic_dispatcher.h"
19 #include "net/quic/quic_framer.h" 20 #include "net/quic/quic_framer.h"
21 #include "net/quic/quic_per_connection_packet_writer.h"
20 #include "net/quic/quic_sent_packet_manager.h" 22 #include "net/quic/quic_sent_packet_manager.h"
21 #include "net/quic/quic_session.h" 23 #include "net/quic/quic_session.h"
22 #include "net/quic/test_tools/mock_clock.h" 24 #include "net/quic/test_tools/mock_clock.h"
23 #include "net/quic/test_tools/mock_random.h" 25 #include "net/quic/test_tools/mock_random.h"
24 #include "net/spdy/spdy_framer.h" 26 #include "net/spdy/spdy_framer.h"
25 #include "testing/gmock/include/gmock/gmock.h" 27 #include "testing/gmock/include/gmock/gmock.h"
26 28
27 namespace net { 29 namespace net {
28 30
29 namespace test { 31 namespace test {
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 public: 538 public:
537 MockNetworkChangeVisitor(); 539 MockNetworkChangeVisitor();
538 virtual ~MockNetworkChangeVisitor(); 540 virtual ~MockNetworkChangeVisitor();
539 541
540 MOCK_METHOD1(OnCongestionWindowChange, void(QuicByteCount)); 542 MOCK_METHOD1(OnCongestionWindowChange, void(QuicByteCount));
541 543
542 private: 544 private:
543 DISALLOW_COPY_AND_ASSIGN(MockNetworkChangeVisitor); 545 DISALLOW_COPY_AND_ASSIGN(MockNetworkChangeVisitor);
544 }; 546 };
545 547
548 // Creates per-connection packet writers that register themselves with the
549 // TestWriterFactory on each write so that TestWriterFactory::OnPacketSent can
550 // be routed to the appropriate QuicConnection.
551 class TestWriterFactory : public QuicDispatcher::PacketWriterFactory {
552 public:
553 TestWriterFactory();
554 virtual ~TestWriterFactory();
555
556 virtual QuicPacketWriter* Create(QuicServerPacketWriter* writer,
557 QuicConnection* connection) OVERRIDE;
558
559 // Calls OnPacketSent on the last QuicConnection to write through one of the
560 // packet writers created by this factory.
561 void OnPacketSent(WriteResult result);
562
563 private:
564 class PerConnectionPacketWriter : public QuicPerConnectionPacketWriter {
565 public:
566 PerConnectionPacketWriter(TestWriterFactory* factory,
567 QuicServerPacketWriter* writer,
568 QuicConnection* connection);
569 virtual ~PerConnectionPacketWriter();
570
571 virtual WriteResult WritePacket(
572 const char* buffer,
573 size_t buf_len,
574 const IPAddressNumber& self_address,
575 const IPEndPoint& peer_address) OVERRIDE;
576
577 private:
578 TestWriterFactory* factory_;
579 };
580
581 // If an asynchronous write is happening and |writer| gets deleted, this
582 // clears the pointer to it to prevent use-after-free.
583 void Unregister(PerConnectionPacketWriter* writer);
584
585 PerConnectionPacketWriter* current_writer_;
586 };
587
546 } // namespace test 588 } // namespace test
547 } // namespace net 589 } // namespace net
548 590
549 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ 591 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_
OLDNEW
« no previous file with comments | « net/quic/test_tools/quic_connection_peer.cc ('k') | net/quic/test_tools/quic_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698