Commit 3149a284 authored by rhalavati@google.com's avatar rhalavati@google.com Committed by Commit Bot

Add Traffic Annotation to Sockets Extensions API.

Network Traffic Annotation is added to extensions/browser/api/socket
classes.

Bug: 656607
Change-Id: Ieb1f5559b1b2885154d3faf101b4b8d65a3ebe5d
Reviewed-on: https://chromium-review.googlesource.com/813534Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Commit-Queue: Ramin Halavati <rhalavati@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523725}
parent 19ecd2fc
......@@ -55,10 +55,9 @@ void Socket::WriteData() {
DCHECK(request.byte_count >= request.bytes_written);
io_buffer_write_ = new net::WrappedIOBuffer(request.io_buffer->data() +
request.bytes_written);
int result =
WriteImpl(io_buffer_write_.get(),
request.byte_count - request.bytes_written,
base::Bind(&Socket::OnWriteComplete, base::Unretained(this)));
int result = WriteImpl(
io_buffer_write_.get(), request.byte_count - request.bytes_written,
base::Bind(&Socket::OnWriteComplete, base::Unretained(this)));
if (result != net::ERR_IO_PENDING)
OnWriteComplete(result);
......@@ -140,4 +139,34 @@ Socket::WriteRequest::WriteRequest(const WriteRequest& other) = default;
Socket::WriteRequest::~WriteRequest() {}
// static
net::NetworkTrafficAnnotationTag Socket::GetNetworkTrafficAnnotationTag() {
return net::DefineNetworkTrafficAnnotation("chrome_apps_socket_api", R"(
semantics {
sender: "Chrome Apps Socket API"
description:
"Chrome Apps can use this API to send and receive data over "
"the network using TCP and UDP connections."
trigger: "A request from a Chrome App."
data: "Any data that the app sends."
destination: OTHER
destination_other:
"Data can be sent to any destination included in the app manifest."
}
policy {
cookies_allowed: NO
setting:
"No settings control. Chrome Connectivity Diagnostics component "
"uses this API. Other than that, this request will not be sent if "
"the user does not install a Chrome App that uses the Socket API."
chrome_policy {
ExtensionInstallBlacklist {
ExtensionInstallBlacklist: {
entries: '*'
}
}
}
})");
}
} // namespace extensions
......@@ -20,6 +20,7 @@
#include "net/base/io_buffer.h"
#include "net/base/ip_endpoint.h"
#include "net/socket/tcp_client_socket.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#if defined(OS_CHROMEOS)
#include "extensions/browser/api/socket/app_firewall_hole_manager.h"
......@@ -121,6 +122,8 @@ class Socket : public ApiResource {
std::string* ip_address_str,
uint16_t* port);
static net::NetworkTrafficAnnotationTag GetNetworkTrafficAnnotationTag();
protected:
explicit Socket(const std::string& owner_extension_id_);
......
......@@ -16,7 +16,6 @@
#include "net/base/rand_callback.h"
#include "net/log/net_log_source.h"
#include "net/socket/tcp_client_socket.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
namespace extensions {
......@@ -270,14 +269,13 @@ Socket::SocketType TCPSocket::GetSocketType() const { return Socket::TYPE_TCP; }
int TCPSocket::WriteImpl(net::IOBuffer* io_buffer,
int io_buffer_size,
const net::CompletionCallback& callback) {
// TODO(crbug.com/656607): Add proper annotation.
if (socket_mode_ != CLIENT)
return net::ERR_FAILED;
else if (!socket_.get() || !IsConnected())
return net::ERR_SOCKET_NOT_CONNECTED;
else
return socket_->Write(io_buffer, io_buffer_size, callback,
NO_TRAFFIC_ANNOTATION_BUG_656607);
Socket::GetNetworkTrafficAnnotationTag());
}
void TCPSocket::RefreshConnectionStatus() {
......
......@@ -138,7 +138,8 @@ int TLSSocket::WriteImpl(net::IOBuffer* io_buffer,
if (!IsConnected()) {
return net::ERR_SOCKET_NOT_CONNECTED;
}
return tls_socket_->Write(io_buffer, io_buffer_size, callback);
return tls_socket_->Write(io_buffer, io_buffer_size, callback,
Socket::GetNetworkTrafficAnnotationTag());
}
bool TLSSocket::SetKeepAlive(bool enable, int delay) {
......
......@@ -139,7 +139,8 @@ int UDPSocket::WriteImpl(net::IOBuffer* io_buffer,
if (!socket_.is_connected())
return net::ERR_SOCKET_NOT_CONNECTED;
else
return socket_.Write(io_buffer, io_buffer_size, callback);
return socket_.Write(io_buffer, io_buffer_size, callback,
Socket::GetNetworkTrafficAnnotationTag());
}
void UDPSocket::RecvFrom(int count,
......
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