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

Add traffic annotation to WebSocketBasicStream.

Network traffic annotaiton is added to the socket write in
WebSocketBasicStream::WriteEverything().

Bug: 656607
Change-Id: Id9ae38031afb9b8bd6485c1b6db8932a83527fa8
Reviewed-on: https://chromium-review.googlesource.com/877888
Commit-Queue: Ramin Halavati <rhalavati@chromium.org>
Reviewed-by: default avatarAdam Rice <ricea@chromium.org>
Cr-Commit-Position: refs/heads/master@{#531872}
parent a53fa339
......@@ -19,6 +19,7 @@
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/socket/client_socket_handle.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "net/websockets/websocket_errors.h"
#include "net/websockets/websocket_frame.h"
#include "net/websockets/websocket_frame_parser.h"
......@@ -27,6 +28,35 @@ namespace net {
namespace {
// Please refer to the comment in class header if the usage changes.
constexpr net::NetworkTrafficAnnotationTag kTrafficAnnotation =
net::DefineNetworkTrafficAnnotation("websocket_basic_stream", R"(
semantics {
sender: "WebSocket Basic Stream"
description:
"Implementation of WebSocket API from web content (a page the user "
"visits)."
trigger: "Website calls the WebSocket API."
data:
"Any data provided by web content, masked and framed in accordance "
"with RFC6455."
destination: OTHER
destination_other:
"The address that the website has chosen to communicate to."
}
policy {
cookies_allowed: YES
cookies_store: "user"
setting: "These requests cannot be disabled."
policy_exception_justification:
"Not implemented. WebSocket is a core web platform API."
}
comments:
"The browser will never add cookies to a WebSocket message. But the "
"handshake that was performed when the WebSocket connection was "
"established may have contained cookies."
)");
// This uses type uint64_t to match the definition of
// WebSocketFrameHeader::payload_length in websocket_frame.h.
const uint64_t kMaxControlFramePayload = 125;
......@@ -205,12 +235,10 @@ int WebSocketBasicStream::WriteEverything(
// The use of base::Unretained() here is safe because on destruction we
// disconnect the socket, preventing any further callbacks.
int result = connection_->socket()->Write(
buffer.get(),
buffer->BytesRemaining(),
buffer.get(), buffer->BytesRemaining(),
base::Bind(&WebSocketBasicStream::OnWriteComplete,
base::Unretained(this),
buffer,
callback));
base::Unretained(this), buffer, callback),
kTrafficAnnotation);
if (result > 0) {
UMA_HISTOGRAM_COUNTS_100000("Net.WebSocket.DataUse.Upstream", result);
buffer->DidConsume(result);
......
......@@ -26,6 +26,11 @@ struct WebSocketFrameChunk;
// Implementation of WebSocketStream for non-multiplexed ws:// connections (or
// the physical side of a multiplexed ws:// connection).
//
// Please update the traffic annotations in the websocket_basic_stream.cc and
// websocket_stream.cc if the class is used for any communication with Google.
// In such a case, annotation should be passed from the callers to this class
// and a local annotation can not be used anymore.
class NET_EXPORT_PRIVATE WebSocketBasicStream : public WebSocketStream {
public:
typedef WebSocketMaskingKey (*WebSocketMaskingKeyGeneratorFunction)();
......
......@@ -30,6 +30,7 @@
namespace {
// Please refer to the comment in class header if the usage changes.
constexpr net::NetworkTrafficAnnotationTag kTrafficAnnotation =
net::DefineNetworkTrafficAnnotation("websocket_stream", R"(
semantics {
......
......@@ -64,6 +64,11 @@ class NET_EXPORT_PRIVATE WebSocketStreamRequest {
// be finished synchronously, the function returns ERR_IO_PENDING, and
// |callback| will be called when the operation is finished. Non-null |callback|
// must be provided to these functions.
//
// Please update the traffic annotations in the websocket_basic_stream.cc and
// websocket_stream.cc if the class is used for any communication with Google.
// In such a case, annotation should be passed from the callers to this class
// and a local annotation can not be used anymore.
class NET_EXPORT_PRIVATE WebSocketStream {
public:
......
......@@ -43447,6 +43447,7 @@ Called by update_traffic_annotation_histograms.py.-->
<int value="50816767" label="lib_address_input"/>
<int value="50859288" label="cloud_print_proxy"/>
<int value="51164680" label="profile_avatar"/>
<int value="51586722" label="websocket_basic_stream"/>
<int value="52821843" label="geo_language_provider"/>
<int value="53695122" label="credenential_avatar"/>
<int value="54836939" label="cryptauth_enrollment_flow_finish"/>
......@@ -43517,6 +43518,7 @@ Called by update_traffic_annotation_histograms.py.-->
<int value="97199008" label="doodle_fetcher"/>
<int value="97978464" label="gaia_auth_fetch_for_uber"/>
<int value="98123737" label="devtools_interceptor"/>
<int value="98658519" label="accounts_image_fetcher"/>
<int value="99279418" label="rlz_ping"/>
<int value="100545943" label="webui_content_scripts_download"/>
<int value="101725581" label="cros_recovery_image_download"/>
......@@ -226,6 +226,7 @@ Refer to README.md for content description and update process.
<item id="web_history_query" hash_code="17400350" type="1" second_id="110307337" content_hash_code="36075147" os_list="linux,windows" semantics_fields="2,3,4" policy_fields="5" file_path="components/history/core/browser/browsing_history_service.cc"/>
<item id="web_history_service" hash_code="110307337" type="2" content_hash_code="16140045" os_list="linux,windows" semantics_fields="1,5" policy_fields="-2,4" file_path="components/history/core/browser/web_history_service.cc"/>
<item id="webrtc_log_upload" hash_code="62443804" type="0" content_hash_code="33661169" os_list="linux,windows" file_path="chrome/browser/media/webrtc/webrtc_log_uploader.cc"/>
<item id="websocket_basic_stream" hash_code="51586722" type="0" content_hash_code="68121427" os_list="linux,windows" file_path="net/websockets/websocket_basic_stream.cc"/>
<item id="websocket_stream" hash_code="17188928" type="0" content_hash_code="7250776" os_list="linux,windows" file_path="net/websockets/websocket_stream.cc"/>
<item id="webstore_data_fetcher" hash_code="26302604" type="0" content_hash_code="24000746" os_list="linux,windows" file_path="chrome/browser/extensions/webstore_data_fetcher.cc"/>
<item id="webstore_install_helper" hash_code="25921771" type="0" content_hash_code="10206361" os_list="linux,windows" file_path="chrome/browser/extensions/webstore_install_helper.cc"/>
......
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