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

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

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

Powered by Google App Engine
This is Rietveld 408576698