Commit cf55e6da authored by Yoichi Osato's avatar Yoichi Osato Committed by Commit Bot

[WebSocket] Rename mojom::WebSocket::SendFlowControl to AddReceiveFlowControlQuota

This patch does the renaming mojo and around functions
to avoid mixing up/down flow controls.

Bug: 967524
Change-Id: I4bb840186807879568a8c3f43374a7089ae1562b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1631231Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Reviewed-by: default avatarAdam Rice <ricea@chromium.org>
Commit-Queue: Yoichi Osato <yoichio@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664556}
parent 7eb511af
......@@ -144,8 +144,8 @@ void WebRequestProxyingWebSocket::SendFrame(
proxied_socket_->SendFrame(fin, type, data);
}
void WebRequestProxyingWebSocket::SendFlowControl(int64_t quota) {
proxied_socket_->SendFlowControl(quota);
void WebRequestProxyingWebSocket::AddReceiveFlowControlQuota(int64_t quota) {
proxied_socket_->AddReceiveFlowControlQuota(quota);
}
void WebRequestProxyingWebSocket::StartClosingHandshake(
......
......@@ -65,7 +65,7 @@ class WebRequestProxyingWebSocket
void SendFrame(bool fin,
network::mojom::WebSocketMessageType type,
const std::vector<uint8_t>& data) override;
void SendFlowControl(int64_t quota) override;
void AddReceiveFlowControlQuota(int64_t quota) override;
void StartClosingHandshake(uint16_t code, const std::string& reason) override;
// mojom::WebSocketClient methods:
......
......@@ -392,7 +392,7 @@ WebSocketChannel::ChannelState WebSocketChannel::SendFrame(
// |this| may have been deleted.
}
ChannelState WebSocketChannel::SendFlowControl(int64_t quota) {
ChannelState WebSocketChannel::AddReceiveFlowControlQuota(int64_t quota) {
DCHECK(state_ == CONNECTING || state_ == CONNECTED || state_ == SEND_CLOSED ||
state_ == CLOSE_WAIT);
// TODO(ricea): Kill the renderer if it tries to send us a negative quota
......
......@@ -103,7 +103,7 @@ class NET_EXPORT WebSocketChannel {
// Calling this function may result in synchronous calls to |event_interface_|
// which may result in this object being deleted. In that case, the return
// value will be CHANNEL_DELETED.
ChannelState SendFlowControl(int64_t quota) WARN_UNUSED_RESULT;
ChannelState AddReceiveFlowControlQuota(int64_t quota) WARN_UNUSED_RESULT;
// Starts the closing handshake for a client-initiated shutdown of the
// connection. There is no API to close the connection without a closing
......
......@@ -811,7 +811,8 @@ class WebSocketChannelTest : public TestWithScopedTaskEnvironment {
CreateChannelAndConnect();
// Most tests aren't concerned with flow control from the renderer, so allow
// MAX_INT quota units.
EXPECT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(kPlentyOfQuota));
EXPECT_EQ(CHANNEL_ALIVE,
channel_->AddReceiveFlowControlQuota(kPlentyOfQuota));
connect_data_.argument_saver.connect_delegate->OnSuccess(
std::move(stream_));
}
......@@ -938,7 +939,7 @@ class WebSocketChannelFlowControlTest
// instead of CreateChannelAndConnectSuccessfully().
void CreateChannelAndConnectWithQuota(int64_t quota) {
CreateChannelAndConnect();
EXPECT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(quota));
EXPECT_EQ(CHANNEL_ALIVE, channel_->AddReceiveFlowControlQuota(quota));
connect_data_.argument_saver.connect_delegate->OnSuccess(
std::move(stream_));
}
......@@ -983,7 +984,7 @@ TEST_F(WebSocketChannelTest, EverythingIsPassedToTheCreatorFunction) {
TEST_F(WebSocketChannelTest, SendFlowControlDuringHandshakeOkay) {
CreateChannelAndConnect();
ASSERT_TRUE(channel_);
ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(65536));
ASSERT_EQ(CHANNEL_ALIVE, channel_->AddReceiveFlowControlQuota(65536));
}
TEST_F(WebSocketChannelEventInterfaceTest, ConnectSuccessReported) {
......@@ -1842,7 +1843,8 @@ TEST_F(WebSocketChannelStreamTest, FlowControlEarly) {
set_stream(std::move(mock_stream_));
CreateChannelAndConnect();
ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(kPlentyOfQuota));
ASSERT_EQ(CHANNEL_ALIVE,
channel_->AddReceiveFlowControlQuota(kPlentyOfQuota));
checkpoint.Call(1);
connect_data_.argument_saver.connect_delegate->OnSuccess(std::move(stream_));
checkpoint.Call(2);
......@@ -1869,7 +1871,8 @@ TEST_F(WebSocketChannelStreamTest, FlowControlLate) {
CreateChannelAndConnect();
connect_data_.argument_saver.connect_delegate->OnSuccess(std::move(stream_));
checkpoint.Call(1);
ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(kPlentyOfQuota));
ASSERT_EQ(CHANNEL_ALIVE,
channel_->AddReceiveFlowControlQuota(kPlentyOfQuota));
checkpoint.Call(2);
}
......@@ -1885,7 +1888,7 @@ TEST_F(WebSocketChannelStreamTest, FlowControlStopsReadFrames) {
set_stream(std::move(mock_stream_));
CreateChannelAndConnect();
ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(4));
ASSERT_EQ(CHANNEL_ALIVE, channel_->AddReceiveFlowControlQuota(4));
connect_data_.argument_saver.connect_delegate->OnSuccess(std::move(stream_));
}
......@@ -1908,10 +1911,10 @@ TEST_F(WebSocketChannelStreamTest, FlowControlStartsWithMoreQuota) {
set_stream(std::move(mock_stream_));
CreateChannelAndConnect();
ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(4));
ASSERT_EQ(CHANNEL_ALIVE, channel_->AddReceiveFlowControlQuota(4));
connect_data_.argument_saver.connect_delegate->OnSuccess(std::move(stream_));
checkpoint.Call(1);
ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(4));
ASSERT_EQ(CHANNEL_ALIVE, channel_->AddReceiveFlowControlQuota(4));
}
// ReadFrames() isn't called again until all pending data has been passed to
......@@ -1935,12 +1938,12 @@ TEST_F(WebSocketChannelStreamTest, ReadFramesNotCalledUntilQuotaAvailable) {
set_stream(std::move(mock_stream_));
CreateChannelAndConnect();
ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(2));
ASSERT_EQ(CHANNEL_ALIVE, channel_->AddReceiveFlowControlQuota(2));
connect_data_.argument_saver.connect_delegate->OnSuccess(std::move(stream_));
checkpoint.Call(1);
ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(2));
ASSERT_EQ(CHANNEL_ALIVE, channel_->AddReceiveFlowControlQuota(2));
checkpoint.Call(2);
ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(2));
ASSERT_EQ(CHANNEL_ALIVE, channel_->AddReceiveFlowControlQuota(2));
}
// A message that needs to be split into frames to fit within quota should
......@@ -1969,8 +1972,8 @@ TEST_F(WebSocketChannelFlowControlTest, SingleFrameMessageSplitSync) {
}
CreateChannelAndConnectWithQuota(2);
ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(1));
ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(1));
ASSERT_EQ(CHANNEL_ALIVE, channel_->AddReceiveFlowControlQuota(1));
ASSERT_EQ(CHANNEL_ALIVE, channel_->AddReceiveFlowControlQuota(1));
}
// The code path for async messages is slightly different, so test it
......@@ -2006,9 +2009,9 @@ TEST_F(WebSocketChannelFlowControlTest, SingleFrameMessageSplitAsync) {
checkpoint.Call(1);
base::RunLoop().RunUntilIdle();
checkpoint.Call(2);
ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(1));
ASSERT_EQ(CHANNEL_ALIVE, channel_->AddReceiveFlowControlQuota(1));
checkpoint.Call(3);
ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(1));
ASSERT_EQ(CHANNEL_ALIVE, channel_->AddReceiveFlowControlQuota(1));
}
// A message split into multiple frames which is further split due to quota
......@@ -2052,8 +2055,8 @@ TEST_F(WebSocketChannelFlowControlTest, MultipleFrameSplit) {
AsVector("FRAME IS 24 BYTES.")));
}
CreateChannelAndConnectWithQuota(14);
ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(43));
ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(32));
ASSERT_EQ(CHANNEL_ALIVE, channel_->AddReceiveFlowControlQuota(43));
ASSERT_EQ(CHANNEL_ALIVE, channel_->AddReceiveFlowControlQuota(32));
}
// An empty message handled when we are out of quota must not be delivered
......@@ -2088,7 +2091,7 @@ TEST_F(WebSocketChannelFlowControlTest, EmptyMessageNoQuota) {
}
CreateChannelAndConnectWithQuota(6);
ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(128));
ASSERT_EQ(CHANNEL_ALIVE, channel_->AddReceiveFlowControlQuota(128));
}
// A close frame should not overtake data frames.
......@@ -2135,11 +2138,11 @@ TEST_F(WebSocketChannelFlowControlTest, CloseFrameShouldNotOvertakeDataFrames) {
CreateChannelAndConnectWithQuota(6);
checkpoint.Call(1);
ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(6));
ASSERT_EQ(CHANNEL_ALIVE, channel_->AddReceiveFlowControlQuota(6));
checkpoint.Call(2);
ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(6));
ASSERT_EQ(CHANNEL_ALIVE, channel_->AddReceiveFlowControlQuota(6));
checkpoint.Call(3);
ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(6));
ASSERT_EQ(CHANNEL_ALIVE, channel_->AddReceiveFlowControlQuota(6));
checkpoint.Call(4);
}
......@@ -2170,9 +2173,9 @@ TEST_F(WebSocketChannelFlowControlTest, DoNotSendMultipleCloseRespondFrames) {
CreateChannelAndConnectWithQuota(6);
checkpoint.Call(1);
ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(6));
ASSERT_EQ(CHANNEL_ALIVE, channel_->AddReceiveFlowControlQuota(6));
checkpoint.Call(2);
ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(6));
ASSERT_EQ(CHANNEL_ALIVE, channel_->AddReceiveFlowControlQuota(6));
}
// RFC6455 5.1 "a client MUST mask all frames that it sends to the server".
......@@ -3039,7 +3042,8 @@ class WebSocketChannelStreamTimeoutTest : public WebSocketChannelStreamTest {
void CreateChannelAndConnectSuccessfully() override {
set_stream(std::move(mock_stream_));
CreateChannelAndConnect();
ASSERT_EQ(CHANNEL_ALIVE, channel_->SendFlowControl(kPlentyOfQuota));
ASSERT_EQ(CHANNEL_ALIVE,
channel_->AddReceiveFlowControlQuota(kPlentyOfQuota));
channel_->SetClosingHandshakeTimeoutForTesting(
TimeDelta::FromMilliseconds(kVeryTinyTimeoutMillis));
channel_->SetUnderlyingConnectionCloseTimeoutForTesting(
......
......@@ -136,13 +136,11 @@ interface WebSocket {
// UTF-8. If |fin| is not set, |data| must be non-empty.
SendFrame(bool fin, WebSocketMessageType type, array<uint8> data);
// Add |quota| tokens of send quota for the channel. |quota| must be a
// positive integer. Both the browser and the renderer set send quota for the
// other side, and check that quota has not been exceeded when receiving
// messages. Both sides start a new channel with a quota of 0, and must wait
// for a FlowControl message before calling SendFrame. The total available
// quota on one side must never exceed 0x7FFFFFFFFFFFFFFF tokens.
SendFlowControl(int64 quota);
// Add |quota| bytes of receive quota. |quota| must be positive. Initial quota
// is 0. The browser will wait for an AddReceiveFlowControlQuota() message
// before forwarding any messages to the renderer. Total quota must never
// exceed 0x7FFFFFFFFFFFFFFF bytes.
AddReceiveFlowControlQuota(int64 quota);
// Close the channel gracefully.
//
......
......@@ -422,9 +422,9 @@ void WebSocket::SendFrame(bool fin,
data.size());
}
void WebSocket::SendFlowControl(int64_t quota) {
DVLOG(3) << "WebSocket::OnFlowControl @" << reinterpret_cast<void*>(this)
<< " quota=" << quota;
void WebSocket::AddReceiveFlowControlQuota(int64_t quota) {
DVLOG(3) << "WebSocket::AddReceiveFlowControlQuota @"
<< reinterpret_cast<void*>(this) << " quota=" << quota;
if (!channel_) {
// WebSocketChannel is not yet created due to the delay introduced by
......@@ -434,7 +434,7 @@ void WebSocket::SendFlowControl(int64_t quota) {
return;
}
ignore_result(channel_->SendFlowControl(quota));
ignore_result(channel_->AddReceiveFlowControlQuota(quota));
}
void WebSocket::StartClosingHandshake(uint16_t code,
......@@ -548,7 +548,7 @@ void WebSocket::AddChannel(
channel_->SendAddChannelRequest(socket_url, requested_protocols, origin_,
site_for_cookies, headers_to_pass);
if (quota > 0)
SendFlowControl(quota);
AddReceiveFlowControlQuota(quota);
}
void WebSocket::OnAuthRequiredComplete(
......
......@@ -88,7 +88,7 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) WebSocket : public mojom::WebSocket {
void SendFrame(bool fin,
mojom::WebSocketMessageType type,
const std::vector<uint8_t>& data) override;
void SendFlowControl(int64_t quota) override;
void AddReceiveFlowControlQuota(int64_t quota) override;
void StartClosingHandshake(uint16_t code, const std::string& reason) override;
bool handshake_succeeded() const { return handshake_succeeded_; }
......@@ -168,9 +168,9 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) WebSocket : public mojom::WebSocket {
// Delay used for per-renderer WebSocket throttling.
base::TimeDelta delay_;
// SendFlowControl() is delayed when OnFlowControl() is called before
// AddChannel() is called.
// Zero indicates there is no pending SendFlowControl().
// AddReceiveFlowControlQuota() is delayed when OnFlowControl() is called
// before AddChannel() is called.
// Zero indicates there is no pending AddReceiveFlowControlQuota().
int64_t pending_flow_control_quota_;
uint32_t options_;
......
......@@ -519,19 +519,20 @@ void WebSocketChannelImpl::ProcessSendQueue() {
client_->DidConsumeBufferedAmount(consumed_buffered_amount);
}
void WebSocketChannelImpl::FlowControlIfNecessary() {
void WebSocketChannelImpl::AddReceiveFlowControlIfNecessary() {
if (!handle_ || received_data_size_for_flow_control_ <
kReceivedDataSizeForFlowControlHighWaterMark) {
return;
}
handle_->FlowControl(received_data_size_for_flow_control_);
handle_->AddReceiveFlowControlQuota(received_data_size_for_flow_control_);
received_data_size_for_flow_control_ = 0;
}
void WebSocketChannelImpl::InitialFlowControl() {
void WebSocketChannelImpl::InitialReceiveFlowControl() {
DCHECK_EQ(received_data_size_for_flow_control_, 0u);
DCHECK(handle_);
handle_->FlowControl(kReceivedDataSizeForFlowControlHighWaterMark * 2);
handle_->AddReceiveFlowControlQuota(
kReceivedDataSizeForFlowControlHighWaterMark * 2);
}
void WebSocketChannelImpl::AbortAsyncOperations() {
......@@ -575,7 +576,7 @@ void WebSocketChannelImpl::DidConnect(WebSocketHandle* handle,
return;
}
InitialFlowControl();
InitialReceiveFlowControl();
handshake_throttle_.reset();
......@@ -664,7 +665,7 @@ void WebSocketChannelImpl::DidReceiveData(WebSocketHandle* handle,
receiving_message_data_.Append(data, SafeCast<uint32_t>(size));
received_data_size_for_flow_control_ += size;
FlowControlIfNecessary();
AddReceiveFlowControlIfNecessary();
if (!fin) {
return;
}
......@@ -756,7 +757,7 @@ void WebSocketChannelImpl::OnCompletion(
if (connect_info_) {
// No flow control quota is supplied to the browser until we are ready to
// receive messages. This fixes crbug.com/786776.
InitialFlowControl();
InitialReceiveFlowControl();
client_->DidConnect(std::move(connect_info_->selected_protocol),
std::move(connect_info_->extensions));
......
......@@ -145,8 +145,8 @@ class MODULES_EXPORT WebSocketChannelImpl final : public WebSocketChannel,
wtf_size_t total_size,
uint64_t* consumed_buffered_amount);
void ProcessSendQueue();
void FlowControlIfNecessary();
void InitialFlowControl();
void AddReceiveFlowControlIfNecessary();
void InitialReceiveFlowControl();
void FailAsError(const String& reason) {
Fail(reason, mojom::ConsoleMessageLevel::kError,
location_at_construction_->Clone());
......
......@@ -96,7 +96,7 @@ class MockWebSocketHandle : public WebSocketHandle {
MOCK_METHOD4(
Send,
void(bool, WebSocketHandle::MessageType, const char*, wtf_size_t));
MOCK_METHOD1(FlowControl, void(int64_t));
MOCK_METHOD1(AddReceiveFlowControlQuota, void(int64_t));
MOCK_METHOD2(Close, void(uint16_t, const String&));
};
......@@ -160,7 +160,7 @@ class WebSocketChannelImplTest : public PageTestBase {
InSequence s;
EXPECT_CALL(*Handle(),
Connect(KURL("ws://localhost/"), _, _, _, HandleClient()));
EXPECT_CALL(*Handle(), FlowControl(65536));
EXPECT_CALL(*Handle(), AddReceiveFlowControlQuota(65536));
EXPECT_CALL(*ChannelClient(), DidConnect(String("a"), String("b")));
}
EXPECT_TRUE(Channel()->Connect(KURL("ws://localhost/"), "x"));
......@@ -206,7 +206,7 @@ TEST_F(WebSocketChannelImplTest, connectSuccess) {
KURLEq("http://example.com/"), _, HandleClient()))
.WillOnce(SaveArg<1>(&protocols));
EXPECT_CALL(checkpoint, Call(1));
EXPECT_CALL(*Handle(), FlowControl(65536));
EXPECT_CALL(*Handle(), AddReceiveFlowControlQuota(65536));
EXPECT_CALL(*ChannelClient(), DidConnect(String("a"), String("b")));
}
......@@ -830,7 +830,7 @@ TEST_F(WebSocketChannelImplHandshakeThrottleTest, ThrottleSucceedsFirst) {
EXPECT_CALL(checkpoint, Call(1));
EXPECT_CALL(*handshake_throttle_, Destructor());
EXPECT_CALL(checkpoint, Call(2));
EXPECT_CALL(*Handle(), FlowControl(_));
EXPECT_CALL(*Handle(), AddReceiveFlowControlQuota(_));
EXPECT_CALL(*ChannelClient(), DidConnect(String("a"), String("b")));
}
Channel()->Connect(url(), "");
......@@ -848,7 +848,7 @@ TEST_F(WebSocketChannelImplHandshakeThrottleTest, HandshakeSucceedsFirst) {
EXPECT_CALL(checkpoint, Call(1));
EXPECT_CALL(checkpoint, Call(2));
EXPECT_CALL(*handshake_throttle_, Destructor());
EXPECT_CALL(*Handle(), FlowControl(_));
EXPECT_CALL(*Handle(), AddReceiveFlowControlQuota(_));
EXPECT_CALL(*ChannelClient(), DidConnect(String("a"), String("b")));
}
Channel()->Connect(url(), "");
......
......@@ -69,7 +69,7 @@ class WebSocketHandle {
WebSocketHandleClient*,
base::SingleThreadTaskRunner*) = 0;
virtual void Send(bool fin, MessageType, const char* data, wtf_size_t) = 0;
virtual void FlowControl(int64_t quota) = 0;
virtual void AddReceiveFlowControlQuota(int64_t quota) = 0;
virtual void Close(uint16_t code, const String& reason) = 0;
};
......
......@@ -99,12 +99,12 @@ void WebSocketHandleImpl::Send(bool fin,
websocket_->SendFrame(fin, type_to_pass, data_to_pass);
}
void WebSocketHandleImpl::FlowControl(int64_t quota) {
void WebSocketHandleImpl::AddReceiveFlowControlQuota(int64_t quota) {
DCHECK(websocket_);
NETWORK_DVLOG(1) << this << " flowControl(" << quota << ")";
websocket_->SendFlowControl(quota);
websocket_->AddReceiveFlowControlQuota(quota);
}
void WebSocketHandleImpl::Close(uint16_t code, const String& reason) {
......
......@@ -52,7 +52,7 @@ class WebSocketHandleImpl : public WebSocketHandle,
WebSocketHandleClient*,
base::SingleThreadTaskRunner*) override;
void Send(bool fin, MessageType, const char* data, wtf_size_t) override;
void FlowControl(int64_t quota) override;
void AddReceiveFlowControlQuota(int64_t quota) override;
void Close(uint16_t code, const String& reason) override;
private:
......
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