Commit 4165de96 authored by Yutaka Hirano's avatar Yutaka Hirano Committed by Commit Bot

Remove WebSocketEventInterface::ChanneState

ChannelState was invented in order to address synchronous IPC failures.
As mojo doesn't have such synchronous failures, we can remove it to
simplify the code.

Cq-Include-Trybots: master.tryserver.chromium.linux:linux_mojo
Change-Id: Ia4e5c57c65b0f431a6770fa29bd71b706c15479d
Reviewed-on: https://chromium-review.googlesource.com/1004072
Commit-Queue: Yutaka Hirano <yhirano@chromium.org>
Reviewed-by: default avatarAdam Rice <ricea@chromium.org>
Cr-Commit-Position: refs/heads/master@{#549489}
parent 00fc4acd
This diff is collapsed.
......@@ -62,7 +62,7 @@ class NET_EXPORT WebSocketChannel {
// Methods which return a value of type ChannelState may delete |this|. If the
// return value is CHANNEL_DELETED, then the caller must return without making
// any further access to member variables or methods.
using ChannelState = WebSocketEventInterface::ChannelState;
enum ChannelState { CHANNEL_ALIVE, CHANNEL_DELETED };
// Creates a new WebSocketChannel in an idle state.
// SendAddChannelRequest() must be called immediately afterwards to start the
......@@ -289,12 +289,11 @@ class NET_EXPORT WebSocketChannel {
// Javascript. Javascript will see a Close code of AbnormalClosure (1006) with
// an empty reason string. If state_ is CONNECTED then a Close message is sent
// to the remote host containing the supplied |code| and |reason|. If the
// stream is open, closes it and sets state_ to CLOSED. FailChannel() always
// returns CHANNEL_DELETED. It is not valid to access any member variables or
// methods after calling FailChannel().
ChannelState FailChannel(const std::string& message,
uint16_t code,
const std::string& reason) WARN_UNUSED_RESULT;
// stream is open, closes it and sets state_ to CLOSED. This function deletes
// |this|.
void FailChannel(const std::string& message,
uint16_t code,
const std::string& reason);
// Sends a Close frame to Start the WebSocket Closing Handshake, or to respond
// to a Close frame from the server. As a special case, setting |code| to
......@@ -317,12 +316,8 @@ class NET_EXPORT WebSocketChannel {
// Drop this channel.
// If there are pending opening handshake notifications, notify them
// before dropping.
//
// Always returns CHANNEL_DELETED.
ChannelState DoDropChannel(bool was_clean,
uint16_t code,
const std::string& reason);
// before dropping. This function deletes |this|.
void DoDropChannel(bool was_clean, uint16_t code, const std::string& reason);
// Called if the closing handshake times out. Closes the connection and
// informs the |event_interface_| if appropriate.
......
This diff is collapsed.
......@@ -73,31 +73,31 @@ class ConnectTestingEventInterface : public WebSocketEventInterface {
// Implementation of WebSocketEventInterface.
void OnCreateURLRequest(URLRequest* request) override {}
ChannelState OnAddChannelResponse(const std::string& selected_subprotocol,
const std::string& extensions) override;
void OnAddChannelResponse(const std::string& selected_subprotocol,
const std::string& extensions) override;
ChannelState OnDataFrame(bool fin,
WebSocketMessageType type,
scoped_refptr<IOBuffer> data,
size_t data_size) override;
void OnDataFrame(bool fin,
WebSocketMessageType type,
scoped_refptr<IOBuffer> data,
size_t data_size) override;
ChannelState OnFlowControl(int64_t quota) override;
void OnFlowControl(int64_t quota) override;
ChannelState OnClosingHandshake() override;
void OnClosingHandshake() override;
ChannelState OnDropChannel(bool was_clean,
uint16_t code,
const std::string& reason) override;
void OnDropChannel(bool was_clean,
uint16_t code,
const std::string& reason) override;
ChannelState OnFailChannel(const std::string& message) override;
void OnFailChannel(const std::string& message) override;
ChannelState OnStartOpeningHandshake(
void OnStartOpeningHandshake(
std::unique_ptr<WebSocketHandshakeRequestInfo> request) override;
ChannelState OnFinishOpeningHandshake(
void OnFinishOpeningHandshake(
std::unique_ptr<WebSocketHandshakeResponseInfo> response) override;
ChannelState OnSSLCertificateError(
void OnSSLCertificateError(
std::unique_ptr<SSLErrorCallbacks> ssl_error_callbacks,
const GURL& url,
const SSLInfo& ssl_info,
......@@ -135,60 +135,40 @@ std::string ConnectTestingEventInterface::extensions() const {
return extensions_;
}
// Make the function definitions below less verbose.
typedef ConnectTestingEventInterface::ChannelState ChannelState;
ChannelState ConnectTestingEventInterface::OnAddChannelResponse(
void ConnectTestingEventInterface::OnAddChannelResponse(
const std::string& selected_subprotocol,
const std::string& extensions) {
selected_subprotocol_ = selected_subprotocol;
extensions_ = extensions;
QuitNestedEventLoop();
return CHANNEL_ALIVE;
}
ChannelState ConnectTestingEventInterface::OnDataFrame(
bool fin,
WebSocketMessageType type,
scoped_refptr<IOBuffer> data,
size_t data_size) {
return CHANNEL_ALIVE;
}
void ConnectTestingEventInterface::OnDataFrame(bool fin,
WebSocketMessageType type,
scoped_refptr<IOBuffer> data,
size_t data_size) {}
ChannelState ConnectTestingEventInterface::OnFlowControl(int64_t quota) {
return CHANNEL_ALIVE;
}
void ConnectTestingEventInterface::OnFlowControl(int64_t quota) {}
ChannelState ConnectTestingEventInterface::OnClosingHandshake() {
return CHANNEL_ALIVE;
}
void ConnectTestingEventInterface::OnClosingHandshake() {}
ChannelState ConnectTestingEventInterface::OnDropChannel(
bool was_clean,
uint16_t code,
const std::string& reason) {
return CHANNEL_DELETED;
}
void ConnectTestingEventInterface::OnDropChannel(bool was_clean,
uint16_t code,
const std::string& reason) {}
ChannelState ConnectTestingEventInterface::OnFailChannel(
const std::string& message) {
void ConnectTestingEventInterface::OnFailChannel(const std::string& message) {
failed_ = true;
failure_message_ = message;
QuitNestedEventLoop();
return CHANNEL_DELETED;
}
ChannelState ConnectTestingEventInterface::OnStartOpeningHandshake(
std::unique_ptr<WebSocketHandshakeRequestInfo> request) {
return CHANNEL_ALIVE;
}
void ConnectTestingEventInterface::OnStartOpeningHandshake(
std::unique_ptr<WebSocketHandshakeRequestInfo> request) {}
ChannelState ConnectTestingEventInterface::OnFinishOpeningHandshake(
std::unique_ptr<WebSocketHandshakeResponseInfo> response) {
return CHANNEL_ALIVE;
}
void ConnectTestingEventInterface::OnFinishOpeningHandshake(
std::unique_ptr<WebSocketHandshakeResponseInfo> response) {}
ChannelState ConnectTestingEventInterface::OnSSLCertificateError(
void ConnectTestingEventInterface::OnSSLCertificateError(
std::unique_ptr<SSLErrorCallbacks> ssl_error_callbacks,
const GURL& url,
const SSLInfo& ssl_info,
......@@ -197,7 +177,6 @@ ChannelState ConnectTestingEventInterface::OnSSLCertificateError(
FROM_HERE, base::Bind(&SSLErrorCallbacks::CancelSSLRequest,
base::Owned(ssl_error_callbacks.release()),
ERR_SSL_PROTOCOL_ERROR, &ssl_info));
return CHANNEL_ALIVE;
}
void ConnectTestingEventInterface::QuitNestedEventLoop() {
......
......@@ -32,14 +32,6 @@ class NET_EXPORT WebSocketEventInterface {
public:
typedef int WebSocketMessageType;
// Any event can cause the Channel to be deleted. The Channel needs to avoid
// doing further processing in this case. It does not need to do cleanup, as
// cleanup will already have been done as a result of the deletion.
enum ChannelState {
CHANNEL_ALIVE,
CHANNEL_DELETED
};
virtual ~WebSocketEventInterface() {}
// Called when a URLRequest is created for handshaking.
......@@ -47,27 +39,26 @@ class NET_EXPORT WebSocketEventInterface {
// Called in response to an AddChannelRequest. This means that a response has
// been received from the remote server.
virtual ChannelState OnAddChannelResponse(
const std::string& selected_subprotocol,
const std::string& extensions) WARN_UNUSED_RESULT = 0;
virtual void OnAddChannelResponse(const std::string& selected_subprotocol,
const std::string& extensions) = 0;
// Called when a data frame has been received from the remote host and needs
// to be forwarded to the renderer process.
virtual ChannelState OnDataFrame(bool fin,
WebSocketMessageType type,
scoped_refptr<IOBuffer> buffer,
size_t buffer_size) WARN_UNUSED_RESULT = 0;
virtual void OnDataFrame(bool fin,
WebSocketMessageType type,
scoped_refptr<IOBuffer> buffer,
size_t buffer_size) = 0;
// Called to provide more send quota for this channel to the renderer
// process. Currently the quota units are always bytes of message body
// data. In future it might depend on the type of multiplexing in use.
virtual ChannelState OnFlowControl(int64_t quota) WARN_UNUSED_RESULT = 0;
virtual void OnFlowControl(int64_t quota) = 0;
// Called when the remote server has Started the WebSocket Closing
// Handshake. The client should not attempt to send any more messages after
// receiving this message. It will be followed by OnDropChannel() when the
// closing handshake is complete.
virtual ChannelState OnClosingHandshake() WARN_UNUSED_RESULT = 0;
virtual void OnClosingHandshake() = 0;
// Called when the channel has been dropped, either due to a network close, a
// network error, or a protocol error. This may or may not be preceeded by a
......@@ -82,32 +73,26 @@ class NET_EXPORT WebSocketEventInterface {
// The channel should not be used again after OnDropChannel() has been
// called.
//
// This method returns a ChannelState for consistency, but all implementations
// must delete the Channel and return CHANNEL_DELETED.
virtual ChannelState OnDropChannel(bool was_clean,
uint16_t code,
const std::string& reason)
WARN_UNUSED_RESULT = 0;
// This function deletes the Channel.
virtual void OnDropChannel(bool was_clean,
uint16_t code,
const std::string& reason) = 0;
// Called when the browser fails the channel, as specified in the spec.
//
// The channel should not be used again after OnFailChannel() has been
// called.
//
// This method returns a ChannelState for consistency, but all implementations
// must delete the Channel and return CHANNEL_DELETED.
virtual ChannelState OnFailChannel(const std::string& message)
WARN_UNUSED_RESULT = 0;
// This function deletes the Channel.
virtual void OnFailChannel(const std::string& message) = 0;
// Called when the browser starts the WebSocket Opening Handshake.
virtual ChannelState OnStartOpeningHandshake(
std::unique_ptr<WebSocketHandshakeRequestInfo> request)
WARN_UNUSED_RESULT = 0;
virtual void OnStartOpeningHandshake(
std::unique_ptr<WebSocketHandshakeRequestInfo> request) = 0;
// Called when the browser finishes the WebSocket Opening Handshake.
virtual ChannelState OnFinishOpeningHandshake(
std::unique_ptr<WebSocketHandshakeResponseInfo> response)
WARN_UNUSED_RESULT = 0;
virtual void OnFinishOpeningHandshake(
std::unique_ptr<WebSocketHandshakeResponseInfo> response) = 0;
// Callbacks to be used in response to a call to OnSSLCertificateError. Very
// similar to content::SSLErrorHandler::Delegate (which we can't use directly
......@@ -129,11 +114,11 @@ class NET_EXPORT WebSocketEventInterface {
// this method will delegate to content::SSLManager::OnSSLCertificateError to
// make the actual decision. The callbacks must not be called after the
// WebSocketChannel has been destroyed.
virtual ChannelState OnSSLCertificateError(
virtual void OnSSLCertificateError(
std::unique_ptr<SSLErrorCallbacks> ssl_error_callbacks,
const GURL& url,
const SSLInfo& ssl_info,
bool fatal) WARN_UNUSED_RESULT = 0;
bool fatal) = 0;
protected:
WebSocketEventInterface() {}
......
......@@ -33,8 +33,6 @@
namespace network {
namespace {
typedef net::WebSocketEventInterface::ChannelState ChannelState;
// Convert a mojom::WebSocketMessageType to a
// net::WebSocketFrameHeader::OpCode
net::WebSocketFrameHeader::OpCode MessageTypeToOpCode(
......@@ -80,23 +78,23 @@ class WebSocket::WebSocketEventHandler final
// net::WebSocketEventInterface implementation
void OnCreateURLRequest(net::URLRequest* url_request) override;
ChannelState OnAddChannelResponse(const std::string& selected_subprotocol,
const std::string& extensions) override;
ChannelState OnDataFrame(bool fin,
WebSocketMessageType type,
scoped_refptr<net::IOBuffer> buffer,
size_t buffer_size) override;
ChannelState OnClosingHandshake() override;
ChannelState OnFlowControl(int64_t quota) override;
ChannelState OnDropChannel(bool was_clean,
uint16_t code,
const std::string& reason) override;
ChannelState OnFailChannel(const std::string& message) override;
ChannelState OnStartOpeningHandshake(
void OnAddChannelResponse(const std::string& selected_subprotocol,
const std::string& extensions) override;
void OnDataFrame(bool fin,
WebSocketMessageType type,
scoped_refptr<net::IOBuffer> buffer,
size_t buffer_size) override;
void OnClosingHandshake() override;
void OnFlowControl(int64_t quota) override;
void OnDropChannel(bool was_clean,
uint16_t code,
const std::string& reason) override;
void OnFailChannel(const std::string& message) override;
void OnStartOpeningHandshake(
std::unique_ptr<net::WebSocketHandshakeRequestInfo> request) override;
ChannelState OnFinishOpeningHandshake(
void OnFinishOpeningHandshake(
std::unique_ptr<net::WebSocketHandshakeResponseInfo> response) override;
ChannelState OnSSLCertificateError(
void OnSSLCertificateError(
std::unique_ptr<net::WebSocketEventInterface::SSLErrorCallbacks>
callbacks,
const GURL& url,
......@@ -126,7 +124,7 @@ void WebSocket::WebSocketEventHandler::OnCreateURLRequest(
url_request);
}
ChannelState WebSocket::WebSocketEventHandler::OnAddChannelResponse(
void WebSocket::WebSocketEventHandler::OnAddChannelResponse(
const std::string& selected_protocol,
const std::string& extensions) {
DVLOG(3) << "WebSocketEventHandler::OnAddChannelResponse @"
......@@ -138,11 +136,9 @@ ChannelState WebSocket::WebSocketEventHandler::OnAddChannelResponse(
impl_->pending_connection_tracker_.OnCompleteHandshake();
impl_->client_->OnAddChannelResponse(selected_protocol, extensions);
return net::WebSocketEventInterface::CHANNEL_ALIVE;
}
ChannelState WebSocket::WebSocketEventHandler::OnDataFrame(
void WebSocket::WebSocketEventHandler::OnDataFrame(
bool fin,
net::WebSocketFrameHeader::OpCode type,
scoped_refptr<net::IOBuffer> buffer,
......@@ -159,29 +155,23 @@ ChannelState WebSocket::WebSocketEventHandler::OnDataFrame(
}
impl_->client_->OnDataFrame(fin, OpCodeToMessageType(type), data_to_pass);
return net::WebSocketEventInterface::CHANNEL_ALIVE;
}
ChannelState WebSocket::WebSocketEventHandler::OnClosingHandshake() {
void WebSocket::WebSocketEventHandler::OnClosingHandshake() {
DVLOG(3) << "WebSocketEventHandler::OnClosingHandshake @"
<< reinterpret_cast<void*>(this);
impl_->client_->OnClosingHandshake();
return net::WebSocketEventInterface::CHANNEL_ALIVE;
}
ChannelState WebSocket::WebSocketEventHandler::OnFlowControl(int64_t quota) {
void WebSocket::WebSocketEventHandler::OnFlowControl(int64_t quota) {
DVLOG(3) << "WebSocketEventHandler::OnFlowControl @"
<< reinterpret_cast<void*>(this) << " quota=" << quota;
impl_->client_->OnFlowControl(quota);
return net::WebSocketEventInterface::CHANNEL_ALIVE;
}
ChannelState WebSocket::WebSocketEventHandler::OnDropChannel(
void WebSocket::WebSocketEventHandler::OnDropChannel(
bool was_clean,
uint16_t code,
const std::string& reason) {
......@@ -193,11 +183,9 @@ ChannelState WebSocket::WebSocketEventHandler::OnDropChannel(
// net::WebSocketChannel requires that we delete it at this point.
impl_->channel_.reset();
return net::WebSocketEventInterface::CHANNEL_DELETED;
}
ChannelState WebSocket::WebSocketEventHandler::OnFailChannel(
void WebSocket::WebSocketEventHandler::OnFailChannel(
const std::string& message) {
DVLOG(3) << "WebSocketEventHandler::OnFailChannel @"
<< reinterpret_cast<void*>(this) << " message=\"" << message << "\"";
......@@ -206,11 +194,9 @@ ChannelState WebSocket::WebSocketEventHandler::OnFailChannel(
// net::WebSocketChannel requires that we delete it at this point.
impl_->channel_.reset();
return net::WebSocketEventInterface::CHANNEL_DELETED;
}
ChannelState WebSocket::WebSocketEventHandler::OnStartOpeningHandshake(
void WebSocket::WebSocketEventHandler::OnStartOpeningHandshake(
std::unique_ptr<net::WebSocketHandshakeRequestInfo> request) {
bool should_send = impl_->delegate_->CanReadRawCookies();
......@@ -218,7 +204,7 @@ ChannelState WebSocket::WebSocketEventHandler::OnStartOpeningHandshake(
<< reinterpret_cast<void*>(this) << " should_send=" << should_send;
if (!should_send)
return WebSocketEventInterface::CHANNEL_ALIVE;
return;
mojom::WebSocketHandshakeRequestPtr request_to_pass(
mojom::WebSocketHandshakeRequest::New());
......@@ -236,11 +222,9 @@ ChannelState WebSocket::WebSocketEventHandler::OnStartOpeningHandshake(
request->headers.ToString();
impl_->client_->OnStartOpeningHandshake(std::move(request_to_pass));
return WebSocketEventInterface::CHANNEL_ALIVE;
}
ChannelState WebSocket::WebSocketEventHandler::OnFinishOpeningHandshake(
void WebSocket::WebSocketEventHandler::OnFinishOpeningHandshake(
std::unique_ptr<net::WebSocketHandshakeResponseInfo> response) {
bool should_send = impl_->delegate_->CanReadRawCookies();
......@@ -248,7 +232,7 @@ ChannelState WebSocket::WebSocketEventHandler::OnFinishOpeningHandshake(
<< reinterpret_cast<void*>(this) << " should_send=" << should_send;
if (!should_send)
return WebSocketEventInterface::CHANNEL_ALIVE;
return;
mojom::WebSocketHandshakeResponsePtr response_to_pass(
mojom::WebSocketHandshakeResponse::New());
......@@ -268,11 +252,9 @@ ChannelState WebSocket::WebSocketEventHandler::OnFinishOpeningHandshake(
response->headers->raw_headers());
impl_->client_->OnFinishOpeningHandshake(std::move(response_to_pass));
return WebSocketEventInterface::CHANNEL_ALIVE;
}
ChannelState WebSocket::WebSocketEventHandler::OnSSLCertificateError(
void WebSocket::WebSocketEventHandler::OnSSLCertificateError(
std::unique_ptr<net::WebSocketEventInterface::SSLErrorCallbacks> callbacks,
const GURL& url,
const net::SSLInfo& ssl_info,
......@@ -283,8 +265,6 @@ ChannelState WebSocket::WebSocketEventHandler::OnSSLCertificateError(
impl_->delegate_->OnSSLCertificateError(std::move(callbacks), url,
impl_->child_id_, impl_->frame_id_,
ssl_info, fatal);
// The above method is always asynchronous.
return WebSocketEventInterface::CHANNEL_ALIVE;
}
WebSocket::WebSocket(
......
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