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

Side by Side Diff: blimp/net/stream_packet_writer.cc

Issue 1962393004: Added a debug info UI for Blimp (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added statistics object to BlimpEngineSession Created 4 years, 7 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 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 "blimp/net/stream_packet_writer.h" 5 #include "blimp/net/stream_packet_writer.h"
6 6
7 #include <iostream> 7 #include <iostream>
8 8
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/sys_byteorder.h" 13 #include "base/sys_byteorder.h"
14 #include "blimp/common/proto/blimp_message.pb.h" 14 #include "blimp/common/proto/blimp_message.pb.h"
15 #include "blimp/net/blimp_connection_statistics.h"
15 #include "blimp/net/common.h" 16 #include "blimp/net/common.h"
16 #include "net/base/io_buffer.h" 17 #include "net/base/io_buffer.h"
17 #include "net/base/net_errors.h" 18 #include "net/base/net_errors.h"
18 #include "net/socket/stream_socket.h" 19 #include "net/socket/stream_socket.h"
19 20
20 namespace blimp { 21 namespace blimp {
21 22
22 std::ostream& operator<<(std::ostream& out, 23 std::ostream& operator<<(std::ostream& out,
23 const StreamPacketWriter::WriteState state) { 24 const StreamPacketWriter::WriteState state) {
24 switch (state) { 25 switch (state) {
25 case StreamPacketWriter::WriteState::IDLE: 26 case StreamPacketWriter::WriteState::IDLE:
26 out << "IDLE"; 27 out << "IDLE";
27 break; 28 break;
28 case StreamPacketWriter::WriteState::HEADER: 29 case StreamPacketWriter::WriteState::HEADER:
29 out << "HEADER"; 30 out << "HEADER";
30 break; 31 break;
31 case StreamPacketWriter::WriteState::PAYLOAD: 32 case StreamPacketWriter::WriteState::PAYLOAD:
32 out << "PAYLOAD"; 33 out << "PAYLOAD";
33 break; 34 break;
34 } 35 }
35 return out; 36 return out;
36 } 37 }
37 38
38 StreamPacketWriter::StreamPacketWriter(net::StreamSocket* socket) 39 StreamPacketWriter::StreamPacketWriter(net::StreamSocket* socket,
40 BlimpConnectionStatistics* statistics)
39 : write_state_(WriteState::IDLE), 41 : write_state_(WriteState::IDLE),
40 socket_(socket), 42 socket_(socket),
41 header_buffer_( 43 header_buffer_(
42 new net::DrainableIOBuffer(new net::IOBuffer(kPacketHeaderSizeBytes), 44 new net::DrainableIOBuffer(new net::IOBuffer(kPacketHeaderSizeBytes),
43 kPacketHeaderSizeBytes)), 45 kPacketHeaderSizeBytes)),
46 statistics_(statistics),
44 weak_factory_(this) { 47 weak_factory_(this) {
45 DCHECK(socket_); 48 DCHECK(socket_);
Kevin M 2016/05/24 22:56:40 DCHECK(statistics_)
46 } 49 }
47 50
48 StreamPacketWriter::~StreamPacketWriter() {} 51 StreamPacketWriter::~StreamPacketWriter() {}
49 52
50 void StreamPacketWriter::WritePacket( 53 void StreamPacketWriter::WritePacket(
51 const scoped_refptr<net::DrainableIOBuffer>& data, 54 const scoped_refptr<net::DrainableIOBuffer>& data,
52 const net::CompletionCallback& callback) { 55 const net::CompletionCallback& callback) {
53 DCHECK_EQ(WriteState::IDLE, write_state_); 56 DCHECK_EQ(WriteState::IDLE, write_state_);
54 DCHECK(data); 57 DCHECK(data);
55 CHECK(data->BytesRemaining()); 58 CHECK(data->BytesRemaining());
56 59
57 write_state_ = WriteState::HEADER; 60 write_state_ = WriteState::HEADER;
58 header_buffer_->SetOffset(0); 61 header_buffer_->SetOffset(0);
59 *reinterpret_cast<uint32_t*>(header_buffer_->data()) = 62 *reinterpret_cast<uint32_t*>(header_buffer_->data()) =
60 base::HostToNet32(data->BytesRemaining()); 63 base::HostToNet32(data->BytesRemaining());
61 payload_buffer_ = data; 64 payload_buffer_ = data;
62 65
66 statistics_->Add(BlimpConnectionStatistics::BYTES_SENT,
67 payload_buffer_->BytesRemaining());
63 int result = DoWriteLoop(net::OK); 68 int result = DoWriteLoop(net::OK);
64 if (result != net::ERR_IO_PENDING) { 69 if (result != net::ERR_IO_PENDING) {
65 // Release the payload buffer, since the write operation has completed 70 // Release the payload buffer, since the write operation has completed
66 // synchronously. 71 // synchronously.
67 payload_buffer_ = nullptr; 72 payload_buffer_ = nullptr;
68 73
69 // Adapt synchronous completion to an asynchronous style. 74 // Adapt synchronous completion to an asynchronous style.
70 base::MessageLoop::current()->PostTask(FROM_HERE, 75 base::MessageLoop::current()->PostTask(FROM_HERE,
71 base::Bind(callback, result)); 76 base::Bind(callback, result));
72 } else { 77 } else {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 147
143 // If the write finished, either successfully or by error, inform the 148 // If the write finished, either successfully or by error, inform the
144 // caller. 149 // caller.
145 if (result != net::ERR_IO_PENDING) { 150 if (result != net::ERR_IO_PENDING) {
146 payload_buffer_ = nullptr; 151 payload_buffer_ = nullptr;
147 base::ResetAndReturn(&callback_).Run(result); 152 base::ResetAndReturn(&callback_).Run(result);
148 } 153 }
149 } 154 }
150 155
151 } // namespace blimp 156 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698