Commit b2940b17 authored by Ramin Halavati's avatar Ramin Halavati Committed by Commit Bot

Add traffic annotation to Jingle Glue Sockets.

Network traffic annotation is added to socket writes of:
jingle/glue/chrome_async_socket.cc
jingle/glue/fake_ssl_client_socket.cc

Bug: 656607
Change-Id: I01e083c9a7154a6fc5071839a4f26007e3717ea4
Reviewed-on: https://chromium-review.googlesource.com/885812Reviewed-by: default avatarNicolas Zea <zea@chromium.org>
Commit-Queue: Ramin Halavati <rhalavati@chromium.org>
Cr-Commit-Position: refs/heads/master@{#531867}
parent 0d47ae36
......@@ -29,7 +29,8 @@ namespace jingle_glue {
ChromeAsyncSocket::ChromeAsyncSocket(
ResolvingClientSocketFactory* resolving_client_socket_factory,
size_t read_buf_size,
size_t write_buf_size)
size_t write_buf_size,
const net::NetworkTrafficAnnotationTag& traffic_annotation)
: resolving_client_socket_factory_(resolving_client_socket_factory),
state_(STATE_CLOSED),
error_(ERROR_NONE),
......@@ -41,6 +42,7 @@ ChromeAsyncSocket::ChromeAsyncSocket(
write_state_(IDLE),
write_buf_(new net::IOBufferWithSize(write_buf_size)),
write_end_(0U),
traffic_annotation_(traffic_annotation),
weak_ptr_factory_(this) {
DCHECK(resolving_client_socket_factory_.get());
DCHECK_GT(read_buf_size, 0U);
......@@ -299,10 +301,10 @@ void ChromeAsyncSocket::DoWrite() {
// have received a reply to a message we sent to the server and
// before we send the next message.
int status =
transport_socket_->Write(
write_buf_.get(), write_end_,
transport_socket_->Write(write_buf_.get(), write_end_,
base::Bind(&ChromeAsyncSocket::ProcessWriteDone,
weak_ptr_factory_.GetWeakPtr()));
weak_ptr_factory_.GetWeakPtr()),
traffic_annotation_);
write_state_ = PENDING;
if (status != net::ERR_IO_PENDING) {
ProcessWriteDone(status);
......
......@@ -19,6 +19,7 @@
#include "base/memory/weak_ptr.h"
#include "net/base/completion_callback.h"
#include "net/base/net_errors.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "third_party/libjingle_xmpp/xmpp/asyncsocket.h"
namespace net {
......@@ -36,7 +37,8 @@ class ChromeAsyncSocket : public buzz::AsyncSocket {
ChromeAsyncSocket(
ResolvingClientSocketFactory* resolving_client_socket_factory,
size_t read_buf_size,
size_t write_buf_size);
size_t write_buf_size,
const net::NetworkTrafficAnnotationTag& traffic_annotation);
// Does not raise any signals.
~ChromeAsyncSocket() override;
......@@ -203,6 +205,11 @@ class ChromeAsyncSocket : public buzz::AsyncSocket {
scoped_refptr<net::IOBufferWithSize> write_buf_;
size_t write_end_;
// Network traffic annotation for downstream socket write. ChromeAsyncSocket
// is not reused, hence annotation can be added in constructor and used in all
// subsequent writes.
const net::NetworkTrafficAnnotationTag traffic_annotation_;
base::WeakPtrFactory<ChromeAsyncSocket> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(ChromeAsyncSocket);
......
......@@ -26,6 +26,7 @@
#include "net/socket/socket_test_util.h"
#include "net/socket/ssl_client_socket.h"
#include "net/ssl/ssl_config_service.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "net/url_request/url_request_context_getter.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/webrtc/rtc_base/ipaddress.h"
......@@ -182,8 +183,8 @@ class ChromeAsyncSocketTest
mock_xmpp_client_socket_factory(new MockXmppClientSocketFactory(
mock_client_socket_factory.release(), address_list));
chrome_async_socket_.reset(
new ChromeAsyncSocket(mock_xmpp_client_socket_factory.release(),
14, 20)),
new ChromeAsyncSocket(mock_xmpp_client_socket_factory.release(), 14, 20,
TRAFFIC_ANNOTATION_FOR_TESTS)),
chrome_async_socket_->SignalConnected.connect(
this, &ChromeAsyncSocketTest::OnConnect);
......
......@@ -14,7 +14,7 @@
#include "base/macros.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
namespace jingle_glue {
......@@ -209,7 +209,8 @@ int FakeSSLClientSocket::DoSendClientHello() {
int status = transport_socket_->Write(
write_buf_.get(), write_buf_->BytesRemaining(),
base::Bind(&FakeSSLClientSocket::OnSendClientHelloDone,
base::Unretained(this)));
base::Unretained(this)),
TRAFFIC_ANNOTATION_FOR_TESTS);
if (status < net::OK) {
return status;
}
......
......@@ -16,6 +16,7 @@
#include "jingle/notifier/base/weak_xmpp_client.h"
#include "net/socket/client_socket_factory.h"
#include "net/ssl/ssl_config_service.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "net/url_request/url_request_context.h"
#include "third_party/libjingle_xmpp/xmpp/xmppclientsettings.h"
......@@ -42,8 +43,10 @@ buzz::AsyncSocket* CreateSocket(
ssl_config,
request_context_getter,
use_fake_ssl_client_socket);
return new jingle_glue::ChromeAsyncSocket(client_socket_factory,
kReadBufSize, kWriteBufSize);
// TODO(crbug.com/656607): Add proper traffic annotation.
return new jingle_glue::ChromeAsyncSocket(client_socket_factory, kReadBufSize,
kWriteBufSize,
NO_TRAFFIC_ANNOTATION_BUG_656607);
}
} // namespace
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment