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

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

Issue 467963002: Refactoring: Create per-connection packet writers in QuicDispatcher. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compilation 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
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 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 public: 537 public:
536 MockNetworkChangeVisitor(); 538 MockNetworkChangeVisitor();
537 virtual ~MockNetworkChangeVisitor(); 539 virtual ~MockNetworkChangeVisitor();
538 540
539 MOCK_METHOD1(OnCongestionWindowChange, void(QuicByteCount)); 541 MOCK_METHOD1(OnCongestionWindowChange, void(QuicByteCount));
540 542
541 private: 543 private:
542 DISALLOW_COPY_AND_ASSIGN(MockNetworkChangeVisitor); 544 DISALLOW_COPY_AND_ASSIGN(MockNetworkChangeVisitor);
543 }; 545 };
544 546
547 // Creates per-connection packet writers that register themselves with the
548 // TestWriterFactory on each write so that TestWriterFactory::OnPacketSent can
549 // be routed to the appropriate QuicConnection.
550 class TestWriterFactory : public QuicDispatcher::PacketWriterFactory {
551 public:
552 TestWriterFactory();
553 virtual ~TestWriterFactory();
554
555 virtual QuicPacketWriter* Create(QuicServerPacketWriter* writer,
556 QuicConnection* connection) OVERRIDE;
557
558 // Calls OnPacketSent on the last QuicConnection to write through one of the
559 // packet writers created by this factory.
560 void OnPacketSent(WriteResult result);
561
562 private:
563 class PerConnectionPacketWriter : public QuicPerConnectionPacketWriter {
564 public:
565 PerConnectionPacketWriter(TestWriterFactory* factory,
566 QuicServerPacketWriter* writer,
567 QuicConnection* connection);
568 virtual ~PerConnectionPacketWriter();
569
570 virtual WriteResult WritePacket(
571 const char* buffer,
572 size_t buf_len,
573 const IPAddressNumber& self_address,
574 const IPEndPoint& peer_address) OVERRIDE;
575
576 private:
577 TestWriterFactory* factory_;
578 };
579
580 // If an asynchronous write is happening and |writer| gets deleted, this
581 // clears the pointer to it to prevent use-after-free.
582 void Unregister(PerConnectionPacketWriter* writer);
583
584 PerConnectionPacketWriter* current_writer_;
585 };
586
545 } // namespace test 587 } // namespace test
546 } // namespace net 588 } // namespace net
547 589
548 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_ 590 #endif // NET_QUIC_TEST_TOOLS_QUIC_TEST_UTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698