Don't add an aura tooltip to bubble close buttons on Windows.
[chromium-blink-merge.git] / net / quic / quic_default_packet_writer.cc
blob177d2926ec06e91f8ae68b2c914fca072c3ed74f
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/quic/quic_default_packet_writer.h"
7 #include "base/location.h"
8 #include "base/logging.h"
9 #include "base/metrics/histogram.h"
10 #include "base/metrics/sparse_histogram.h"
11 #include "net/base/io_buffer.h"
12 #include "net/base/net_errors.h"
14 namespace net {
16 QuicDefaultPacketWriter::QuicDefaultPacketWriter() : weak_factory_(this) {
19 QuicDefaultPacketWriter::QuicDefaultPacketWriter(DatagramClientSocket* socket)
20 : socket_(socket),
21 write_blocked_(false),
22 weak_factory_(this) {
25 QuicDefaultPacketWriter::~QuicDefaultPacketWriter() {}
27 WriteResult QuicDefaultPacketWriter::WritePacket(
28 const char* buffer,
29 size_t buf_len,
30 const net::IPAddressNumber& self_address,
31 const net::IPEndPoint& peer_address) {
32 scoped_refptr<StringIOBuffer> buf(
33 new StringIOBuffer(std::string(buffer, buf_len)));
34 DCHECK(!IsWriteBlocked());
35 base::TimeTicks now = base::TimeTicks::Now();
36 int rv = socket_->Write(buf.get(),
37 buf_len,
38 base::Bind(&QuicDefaultPacketWriter::OnWriteComplete,
39 weak_factory_.GetWeakPtr()));
40 WriteStatus status = WRITE_STATUS_OK;
41 if (rv < 0) {
42 if (rv != ERR_IO_PENDING) {
43 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.QuicSession.WriteError", -rv);
44 status = WRITE_STATUS_ERROR;
45 } else {
46 status = WRITE_STATUS_BLOCKED;
47 write_blocked_ = true;
51 base::TimeDelta delta = base::TimeTicks::Now() - now;
52 if (status == WRITE_STATUS_OK) {
53 UMA_HISTOGRAM_TIMES("Net.QuicSession.PacketWriteTime.Synchronous", delta);
54 } else if (status == WRITE_STATUS_BLOCKED) {
55 UMA_HISTOGRAM_TIMES("Net.QuicSession.PacketWriteTime.Asynchronous", delta);
58 return WriteResult(status, rv);
61 bool QuicDefaultPacketWriter::IsWriteBlockedDataBuffered() const {
62 // Chrome sockets' Write() methods buffer the data until the Write is
63 // permitted.
64 return true;
67 bool QuicDefaultPacketWriter::IsWriteBlocked() const {
68 return write_blocked_;
71 void QuicDefaultPacketWriter::SetWritable() {
72 write_blocked_ = false;
75 void QuicDefaultPacketWriter::OnWriteComplete(int rv) {
76 DCHECK_NE(rv, ERR_IO_PENDING);
77 write_blocked_ = false;
78 if (rv < 0) {
79 connection_->OnWriteError(rv);
81 connection_->OnCanWrite();
84 } // namespace net