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") { ...@@ -427,7 +427,7 @@ source_set("browser") {
"//device/hid", "//device/hid",
"//device/serial", "//device/serial",
"//device/usb", "//device/usb",
"//extensions/browser/api/cast_channel:cast_channel_proto", "//extensions/common/api/cast_channel:cast_channel_proto",
] ]
if (use_openssl) { if (use_openssl) {
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
['enable_extensions==1', { ['enable_extensions==1', {
'dependencies': [ 'dependencies': [
'<(DEPTH)/device/serial/serial.gyp:device_serial_mojo', '<(DEPTH)/device/serial/serial.gyp:device_serial_mojo',
'<(DEPTH)/extensions/common/api/api.gyp:cast_channel_proto',
'<(DEPTH)/skia/skia.gyp:skia', '<(DEPTH)/skia/skia.gyp:skia',
], ],
}], }],
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "extensions/browser/api/api_resource.h" #include "extensions/browser/api/api_resource.h"
#include "extensions/browser/api/api_resource_manager.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 "extensions/common/api/cast_channel.h"
#include "net/base/completion_callback.h" #include "net/base/completion_callback.h"
#include "net/base/io_buffer.h" #include "net/base/io_buffer.h"
...@@ -126,36 +127,6 @@ class CastSocket : public ApiResource { ...@@ -126,36 +127,6 @@ class CastSocket : public ApiResource {
// It is fine to delete the CastSocket object in |callback|. // It is fine to delete the CastSocket object in |callback|.
virtual void Close(const net::CompletionCallback& 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: private:
friend class ApiResourceManager<CastSocket>; friend class ApiResourceManager<CastSocket>;
friend class CastSocketTest; friend class CastSocketTest;
...@@ -260,11 +231,11 @@ class CastSocket : public ApiResource { ...@@ -260,11 +231,11 @@ class CastSocket : public ApiResource {
virtual base::Timer* GetTimer(); virtual base::Timer* GetTimer();
void SetConnectState(ConnectionState connect_state); void SetConnectState(proto::ConnectionState connect_state);
void SetReadyState(ReadyState ready_state); void SetReadyState(ReadyState ready_state);
void SetErrorState(ChannelError error_state); void SetErrorState(ChannelError error_state);
void SetReadState(ReadState read_state); void SetReadState(proto::ReadState read_state);
void SetWriteState(WriteState write_state); void SetWriteState(proto::WriteState write_state);
base::ThreadChecker thread_checker_; base::ThreadChecker thread_checker_;
...@@ -322,11 +293,11 @@ class CastSocket : public ApiResource { ...@@ -322,11 +293,11 @@ class CastSocket : public ApiResource {
scoped_ptr<CastMessage> current_message_; scoped_ptr<CastMessage> current_message_;
// Connection flow state machine state. // Connection flow state machine state.
ConnectionState connect_state_; proto::ConnectionState connect_state_;
// Write flow state machine state. // Write flow state machine state.
WriteState write_state_; proto::WriteState write_state_;
// Read flow state machine state. // Read flow state machine state.
ReadState read_state_; proto::ReadState read_state_;
// The last error encountered by the channel. // The last error encountered by the channel.
ChannelError error_state_; ChannelError error_state_;
// The current status of the channel. // The current status of the channel.
......
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "extensions/browser/api/cast_channel/logger_util.h" #include "extensions/browser/api/cast_channel/logger_util.h"
#include "extensions/browser/api/cast_channel/logging.pb.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
namespace extensions { namespace extensions {
namespace core_api { namespace core_api {
namespace cast_channel { namespace cast_channel {
LastErrors::LastErrors() LastErrors::LastErrors()
: event_type(proto::EVENT_TYPE_UNKNOWN), : event_type(proto::EVENT_TYPE_UNKNOWN),
challenge_reply_error_type(proto::CHALLENGE_REPLY_ERROR_NONE), challenge_reply_error_type(proto::CHALLENGE_REPLY_ERROR_NONE),
...@@ -19,6 +19,51 @@ LastErrors::LastErrors() ...@@ -19,6 +19,51 @@ LastErrors::LastErrors()
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 cast_channel
} // namespace api } // namespace api
} // namespace extensions } // namespace extensions
...@@ -6,13 +6,16 @@ ...@@ -6,13 +6,16 @@
#define EXTENSIONS_BROWSER_API_CAST_CHANNEL_LOGGER_UTIL_H_ #define EXTENSIONS_BROWSER_API_CAST_CHANNEL_LOGGER_UTIL_H_
#include "extensions/browser/api/cast_channel/logging.pb.h" #include "extensions/browser/api/cast_channel/logging.pb.h"
#include "extensions/common/api/cast_channel.h"
namespace extensions { namespace extensions {
namespace core_api { namespace core_api {
namespace cast_channel { 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. // Converts an IDL "ReadyState" to a proto enum "ReadyState".
// CastSocket should not need to know details of the logging protocol message. proto::ReadyState ReadyStateToProto(ReadyState state);
// Holds the most recent errors encountered by a CastSocket. // Holds the most recent errors encountered by a CastSocket.
struct LastErrors { struct LastErrors {
......
...@@ -20,6 +20,7 @@ generated_extensions_api("api_registration") { ...@@ -20,6 +20,7 @@ generated_extensions_api("api_registration") {
if (!is_android) { if (!is_android) {
deps += [ deps += [
"//device/serial", "//device/serial",
"//extensions/common/api/cast_channel:cast_channel_proto",
"//skia", "//skia",
] ]
} }
......
...@@ -16,5 +16,20 @@ ...@@ -16,5 +16,20 @@
'schemas.gypi', '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 @@ ...@@ -4,7 +4,7 @@
import("//third_party/protobuf/proto_library.gni") 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") { proto_library("cast_channel_proto") {
sources = [ sources = [
"cast_channel.proto", "cast_channel.proto",
......
...@@ -284,7 +284,7 @@ ...@@ -284,7 +284,7 @@
'../skia/skia.gyp:skia', '../skia/skia.gyp:skia',
'../third_party/leveldatabase/leveldatabase.gyp:leveldatabase', '../third_party/leveldatabase/leveldatabase.gyp:leveldatabase',
'browser/api/api_registration.gyp:extensions_api_registration', 'browser/api/api_registration.gyp:extensions_api_registration',
'cast_channel_proto', 'common/api/api.gyp:cast_channel_proto',
'common/api/api.gyp:extensions_api', 'common/api/api.gyp:extensions_api',
'extensions_common', 'extensions_common',
'extensions_strings.gyp:extensions_strings', 'extensions_strings.gyp:extensions_strings',
...@@ -1027,7 +1027,7 @@ ...@@ -1027,7 +1027,7 @@
'../testing/gmock.gyp:gmock', '../testing/gmock.gyp:gmock',
'../testing/gtest.gyp:gtest', '../testing/gtest.gyp:gtest',
'../third_party/leveldatabase/leveldatabase.gyp:leveldatabase', '../third_party/leveldatabase/leveldatabase.gyp:leveldatabase',
'cast_channel_proto', 'common/api/api.gyp:cast_channel_proto',
'extensions_common', 'extensions_common',
'extensions_renderer', 'extensions_renderer',
'extensions_resources.gyp:extensions_resources', 'extensions_resources.gyp:extensions_resources',
...@@ -1135,20 +1135,5 @@ ...@@ -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