Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(877)

Side by Side Diff: extensions/browser/api/cast_channel/cast_socket.h

Issue 576483003: Make proto enums canonical for ReadState/WriteState/ConnectState. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_SOCKET_H_ 5 #ifndef EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_SOCKET_H_
6 #define EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_SOCKET_H_ 6 #define EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_SOCKET_H_
7 7
8 #include <queue> 8 #include <queue>
9 #include <string> 9 #include <string>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/cancelable_callback.h" 12 #include "base/cancelable_callback.h"
13 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
16 #include "base/timer/timer.h" 16 #include "base/timer/timer.h"
17 #include "extensions/browser/api/api_resource.h" 17 #include "extensions/browser/api/api_resource.h"
18 #include "extensions/browser/api/api_resource_manager.h" 18 #include "extensions/browser/api/api_resource_manager.h"
19 #include "extensions/browser/api/cast_channel/logging.pb.h"
19 #include "extensions/common/api/cast_channel.h" 20 #include "extensions/common/api/cast_channel.h"
20 #include "net/base/completion_callback.h" 21 #include "net/base/completion_callback.h"
21 #include "net/base/io_buffer.h" 22 #include "net/base/io_buffer.h"
22 #include "net/base/ip_endpoint.h" 23 #include "net/base/ip_endpoint.h"
23 #include "net/base/net_log.h" 24 #include "net/base/net_log.h"
24 25
25 namespace net { 26 namespace net {
26 class AddressList; 27 class AddressList;
27 class CertVerifier; 28 class CertVerifier;
28 class SSLClientSocket; 29 class SSLClientSocket;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // DO NOT delete the CastSocket object in |callback|. Instead use Close(). 120 // DO NOT delete the CastSocket object in |callback|. Instead use Close().
120 virtual void SendMessage(const MessageInfo& message, 121 virtual void SendMessage(const MessageInfo& message,
121 const net::CompletionCallback& callback); 122 const net::CompletionCallback& callback);
122 123
123 // Closes the channel if not already closed. On completion, the channel will 124 // Closes the channel if not already closed. On completion, the channel will
124 // be in READY_STATE_CLOSED. 125 // be in READY_STATE_CLOSED.
125 // 126 //
126 // It is fine to delete the CastSocket object in |callback|. 127 // It is fine to delete the CastSocket object in |callback|.
127 virtual void Close(const net::CompletionCallback& callback); 128 virtual void Close(const net::CompletionCallback& callback);
128 129
129 // Internal connection states.
130 enum ConnectionState {
131 CONN_STATE_NONE,
132 CONN_STATE_TCP_CONNECT,
133 CONN_STATE_TCP_CONNECT_COMPLETE,
134 CONN_STATE_SSL_CONNECT,
135 CONN_STATE_SSL_CONNECT_COMPLETE,
136 CONN_STATE_AUTH_CHALLENGE_SEND,
137 CONN_STATE_AUTH_CHALLENGE_SEND_COMPLETE,
138 CONN_STATE_AUTH_CHALLENGE_REPLY_COMPLETE,
139 };
140
141 // Internal write states.
142 enum WriteState {
143 WRITE_STATE_NONE,
144 WRITE_STATE_WRITE,
145 WRITE_STATE_WRITE_COMPLETE,
146 WRITE_STATE_DO_CALLBACK,
147 WRITE_STATE_ERROR,
148 };
149
150 // Internal read states.
151 enum ReadState {
152 READ_STATE_NONE,
153 READ_STATE_READ,
154 READ_STATE_READ_COMPLETE,
155 READ_STATE_DO_CALLBACK,
156 READ_STATE_ERROR,
157 };
158
159 private: 130 private:
160 friend class ApiResourceManager<CastSocket>; 131 friend class ApiResourceManager<CastSocket>;
161 friend class CastSocketTest; 132 friend class CastSocketTest;
162 friend class TestCastSocket; 133 friend class TestCastSocket;
163 134
164 static const char* service_name() { return "CastSocketManager"; } 135 static const char* service_name() { return "CastSocketManager"; }
165 136
166 // Creates an instance of TCPClientSocket. 137 // Creates an instance of TCPClientSocket.
167 virtual scoped_ptr<net::TCPClientSocket> CreateTcpSocket(); 138 virtual scoped_ptr<net::TCPClientSocket> CreateTcpSocket();
168 // Creates an instance of SSLClientSocket with the given underlying |socket|. 139 // Creates an instance of SSLClientSocket with the given underlying |socket|.
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 // pending operations will fail because the socket has been closed. 224 // pending operations will fail because the socket has been closed.
254 void RunPendingCallbacksOnClose(); 225 void RunPendingCallbacksOnClose();
255 // Serializes the content of message_proto (with a header) to |message_data|. 226 // Serializes the content of message_proto (with a header) to |message_data|.
256 static bool Serialize(const CastMessage& message_proto, 227 static bool Serialize(const CastMessage& message_proto,
257 std::string* message_data); 228 std::string* message_data);
258 229
259 virtual bool CalledOnValidThread() const; 230 virtual bool CalledOnValidThread() const;
260 231
261 virtual base::Timer* GetTimer(); 232 virtual base::Timer* GetTimer();
262 233
263 void SetConnectState(ConnectionState connect_state); 234 void SetConnectState(proto::ConnectionState connect_state);
264 void SetReadyState(ReadyState ready_state); 235 void SetReadyState(ReadyState ready_state);
265 void SetErrorState(ChannelError error_state); 236 void SetErrorState(ChannelError error_state);
266 void SetReadState(ReadState read_state); 237 void SetReadState(proto::ReadState read_state);
267 void SetWriteState(WriteState write_state); 238 void SetWriteState(proto::WriteState write_state);
268 239
269 base::ThreadChecker thread_checker_; 240 base::ThreadChecker thread_checker_;
270 241
271 // The id of the channel. 242 // The id of the channel.
272 int channel_id_; 243 int channel_id_;
273 244
274 // The IP endpoint that the the channel is connected to. 245 // The IP endpoint that the the channel is connected to.
275 net::IPEndPoint ip_endpoint_; 246 net::IPEndPoint ip_endpoint_;
276 // Receiver authentication requested for the channel. 247 // Receiver authentication requested for the channel.
277 ChannelAuthType channel_auth_; 248 ChannelAuthType channel_auth_;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 base::TimeDelta connect_timeout_; 286 base::TimeDelta connect_timeout_;
316 // Timer invoked when the connection has timed out. 287 // Timer invoked when the connection has timed out.
317 scoped_ptr<base::Timer> connect_timeout_timer_; 288 scoped_ptr<base::Timer> connect_timeout_timer_;
318 // Set when a timeout is triggered and the connection process has 289 // Set when a timeout is triggered and the connection process has
319 // canceled. 290 // canceled.
320 bool is_canceled_; 291 bool is_canceled_;
321 292
322 scoped_ptr<CastMessage> current_message_; 293 scoped_ptr<CastMessage> current_message_;
323 294
324 // Connection flow state machine state. 295 // Connection flow state machine state.
325 ConnectionState connect_state_; 296 proto::ConnectionState connect_state_;
326 // Write flow state machine state. 297 // Write flow state machine state.
327 WriteState write_state_; 298 proto::WriteState write_state_;
328 // Read flow state machine state. 299 // Read flow state machine state.
329 ReadState read_state_; 300 proto::ReadState read_state_;
330 // The last error encountered by the channel. 301 // The last error encountered by the channel.
331 ChannelError error_state_; 302 ChannelError error_state_;
332 // The current status of the channel. 303 // The current status of the channel.
333 ReadyState ready_state_; 304 ReadyState ready_state_;
334 305
335 // Task invoked to (re)start the connect loop. Canceled on entry to the 306 // Task invoked to (re)start the connect loop. Canceled on entry to the
336 // connect loop. 307 // connect loop.
337 base::CancelableClosure connect_loop_callback_; 308 base::CancelableClosure connect_loop_callback_;
338 // Task invoked to send the auth challenge. Canceled when the auth challenge 309 // Task invoked to send the auth challenge. Canceled when the auth challenge
339 // has been sent. 310 // has been sent.
(...skipping 24 matching lines...) Expand all
364 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestReadHeaderParseError); 335 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestReadHeaderParseError);
365 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestReadMany); 336 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestReadMany);
366 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestWriteErrorLargeMessage); 337 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestWriteErrorLargeMessage);
367 DISALLOW_COPY_AND_ASSIGN(CastSocket); 338 DISALLOW_COPY_AND_ASSIGN(CastSocket);
368 }; 339 };
369 } // namespace cast_channel 340 } // namespace cast_channel
370 } // namespace core_api 341 } // namespace core_api
371 } // namespace extensions 342 } // namespace extensions
372 343
373 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_SOCKET_H_ 344 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_SOCKET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698