Commit f1624ddc authored by kmarshall's avatar kmarshall Committed by Commit bot

Make protobuf enums canonical for ReadState/WriteState/ConnectState.

Delete redundant non-proto ReadState/WriteState/ConnectState enums.
Add cast protogen rule to extension registration deps.

BUG=

Review URL: https://codereview.chromium.org/576483003

Cr-Commit-Position: refs/heads/master@{#295602}
parent eaa3d4fa
......@@ -427,7 +427,7 @@ source_set("browser") {
"//device/hid",
"//device/serial",
"//device/usb",
"//extensions/browser/api/cast_channel:cast_channel_proto",
"//extensions/common/api/cast_channel:cast_channel_proto",
]
if (use_openssl) {
......
......@@ -21,6 +21,7 @@
['enable_extensions==1', {
'dependencies': [
'<(DEPTH)/device/serial/serial.gyp:device_serial_mojo',
'<(DEPTH)/extensions/common/api/api.gyp:cast_channel_proto',
'<(DEPTH)/skia/skia.gyp:skia',
],
}],
......
......@@ -16,6 +16,7 @@
#include "base/timer/timer.h"
#include "extensions/browser/api/api_resource.h"
#include "extensions/browser/api/api_resource_manager.h"
#include "extensions/browser/api/cast_channel/logging.pb.h"
#include "extensions/common/api/cast_channel.h"
#include "net/base/completion_callback.h"
#include "net/base/io_buffer.h"
......@@ -126,36 +127,6 @@ class CastSocket : public ApiResource {
// It is fine to delete the CastSocket object in |callback|.
virtual void Close(const net::CompletionCallback& callback);
// Internal connection states.
enum ConnectionState {
CONN_STATE_NONE,
CONN_STATE_TCP_CONNECT,
CONN_STATE_TCP_CONNECT_COMPLETE,
CONN_STATE_SSL_CONNECT,
CONN_STATE_SSL_CONNECT_COMPLETE,
CONN_STATE_AUTH_CHALLENGE_SEND,
CONN_STATE_AUTH_CHALLENGE_SEND_COMPLETE,
CONN_STATE_AUTH_CHALLENGE_REPLY_COMPLETE,
};
// Internal write states.
enum WriteState {
WRITE_STATE_NONE,
WRITE_STATE_WRITE,
WRITE_STATE_WRITE_COMPLETE,
WRITE_STATE_DO_CALLBACK,
WRITE_STATE_ERROR,
};
// Internal read states.
enum ReadState {
READ_STATE_NONE,
READ_STATE_READ,
READ_STATE_READ_COMPLETE,
READ_STATE_DO_CALLBACK,
READ_STATE_ERROR,
};
private:
friend class ApiResourceManager<CastSocket>;
friend class CastSocketTest;
......@@ -260,11 +231,11 @@ class CastSocket : public ApiResource {
virtual base::Timer* GetTimer();
void SetConnectState(ConnectionState connect_state);
void SetConnectState(proto::ConnectionState connect_state);
void SetReadyState(ReadyState ready_state);
void SetErrorState(ChannelError error_state);
void SetReadState(ReadState read_state);
void SetWriteState(WriteState write_state);
void SetReadState(proto::ReadState read_state);
void SetWriteState(proto::WriteState write_state);
base::ThreadChecker thread_checker_;
......@@ -322,11 +293,11 @@ class CastSocket : public ApiResource {
scoped_ptr<CastMessage> current_message_;
// Connection flow state machine state.
ConnectionState connect_state_;
proto::ConnectionState connect_state_;
// Write flow state machine state.
WriteState write_state_;
proto::WriteState write_state_;
// Read flow state machine state.
ReadState read_state_;
proto::ReadState read_state_;
// The last error encountered by the channel.
ChannelError error_state_;
// The current status of the channel.
......
......@@ -3,12 +3,12 @@
// found in the LICENSE file.
#include "extensions/browser/api/cast_channel/logger_util.h"
#include "extensions/browser/api/cast_channel/logging.pb.h"
#include "net/base/net_errors.h"
namespace extensions {
namespace core_api {
namespace cast_channel {
LastErrors::LastErrors()
: event_type(proto::EVENT_TYPE_UNKNOWN),
challenge_reply_error_type(proto::CHALLENGE_REPLY_ERROR_NONE),
......@@ -19,6 +19,51 @@ LastErrors::LastErrors()
LastErrors::~LastErrors() {
}
proto::ErrorState ErrorStateToProto(ChannelError state) {
switch (state) {
case CHANNEL_ERROR_NONE:
return proto::CHANNEL_ERROR_NONE;
case CHANNEL_ERROR_CHANNEL_NOT_OPEN:
return proto::CHANNEL_ERROR_CHANNEL_NOT_OPEN;
case CHANNEL_ERROR_AUTHENTICATION_ERROR:
return proto::CHANNEL_ERROR_AUTHENTICATION_ERROR;
case CHANNEL_ERROR_CONNECT_ERROR:
return proto::CHANNEL_ERROR_CONNECT_ERROR;
case CHANNEL_ERROR_SOCKET_ERROR:
return proto::CHANNEL_ERROR_SOCKET_ERROR;
case CHANNEL_ERROR_TRANSPORT_ERROR:
return proto::CHANNEL_ERROR_TRANSPORT_ERROR;
case CHANNEL_ERROR_INVALID_MESSAGE:
return proto::CHANNEL_ERROR_INVALID_MESSAGE;
case CHANNEL_ERROR_INVALID_CHANNEL_ID:
return proto::CHANNEL_ERROR_INVALID_CHANNEL_ID;
case CHANNEL_ERROR_CONNECT_TIMEOUT:
return proto::CHANNEL_ERROR_CONNECT_TIMEOUT;
case CHANNEL_ERROR_UNKNOWN:
return proto::CHANNEL_ERROR_UNKNOWN;
default:
NOTREACHED();
return proto::CHANNEL_ERROR_NONE;
}
}
proto::ReadyState ReadyStateToProto(ReadyState state) {
switch (state) {
case READY_STATE_NONE:
return proto::READY_STATE_NONE;
case READY_STATE_CONNECTING:
return proto::READY_STATE_CONNECTING;
case READY_STATE_OPEN:
return proto::READY_STATE_OPEN;
case READY_STATE_CLOSING:
return proto::READY_STATE_CLOSING;
case READY_STATE_CLOSED:
return proto::READY_STATE_CLOSED;
default:
NOTREACHED();
return proto::READY_STATE_NONE;
}
}
} // namespace cast_channel
} // namespace api
} // namespace extensions
......@@ -6,13 +6,16 @@
#define EXTENSIONS_BROWSER_API_CAST_CHANNEL_LOGGER_UTIL_H_
#include "extensions/browser/api/cast_channel/logging.pb.h"
#include "extensions/common/api/cast_channel.h"
namespace extensions {
namespace core_api {
namespace cast_channel {
// Converts an IDL "ChannelError" to a proto enum "ErrorState".
proto::ErrorState ErrorStateToProto(ChannelError state);
// TODO(mfoltz): Move the *ToProto functions from cast_socket.cc here.
// CastSocket should not need to know details of the logging protocol message.
// Converts an IDL "ReadyState" to a proto enum "ReadyState".
proto::ReadyState ReadyStateToProto(ReadyState state);
// Holds the most recent errors encountered by a CastSocket.
struct LastErrors {
......
......@@ -20,6 +20,7 @@ generated_extensions_api("api_registration") {
if (!is_android) {
deps += [
"//device/serial",
"//extensions/common/api/cast_channel:cast_channel_proto",
"//skia",
]
}
......
......@@ -16,5 +16,20 @@
'schemas.gypi',
],
},
{
# Protobuf compiler / generator for chrome.cast.channel-related protocol buffers.
# GN version: //extensions/browser/api/cast_channel:cast_channel_proto
'target_name': 'cast_channel_proto',
'type': 'static_library',
'sources': [
'cast_channel/cast_channel.proto',
'cast_channel/logging.proto'
],
'variables': {
'proto_in_dir': 'cast_channel',
'proto_out_dir': 'extensions/common/api/cast_channel',
},
'includes': [ '../../../build/protoc.gypi' ]
},
],
}
......@@ -4,7 +4,7 @@
import("//third_party/protobuf/proto_library.gni")
# GYP version: extensions/extensions.gyp:cast_channel_proto
# GYP version: extensions/common/api/api.gyp:cast_channel_proto
proto_library("cast_channel_proto") {
sources = [
"cast_channel.proto",
......
......@@ -284,7 +284,7 @@
'../skia/skia.gyp:skia',
'../third_party/leveldatabase/leveldatabase.gyp:leveldatabase',
'browser/api/api_registration.gyp:extensions_api_registration',
'cast_channel_proto',
'common/api/api.gyp:cast_channel_proto',
'common/api/api.gyp:extensions_api',
'extensions_common',
'extensions_strings.gyp:extensions_strings',
......@@ -1027,7 +1027,7 @@
'../testing/gmock.gyp:gmock',
'../testing/gtest.gyp:gtest',
'../third_party/leveldatabase/leveldatabase.gyp:leveldatabase',
'cast_channel_proto',
'common/api/api.gyp:cast_channel_proto',
'extensions_common',
'extensions_renderer',
'extensions_resources.gyp:extensions_resources',
......@@ -1135,20 +1135,5 @@
}],
],
},
{
# Protobuf compiler / generator for chrome.cast.channel-related protocol buffers.
# GN version: //extensions/browser/api/cast_channel:cast_channel_proto
'target_name': 'cast_channel_proto',
'type': 'static_library',
'sources': [
'browser/api/cast_channel/cast_channel.proto',
'browser/api/cast_channel/logging.proto'
],
'variables': {
'proto_in_dir': 'browser/api/cast_channel',
'proto_out_dir': 'extensions/browser/api/cast_channel',
},
'includes': [ '../build/protoc.gypi' ]
},
]
}
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