| OLD | NEW |
| 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_TRANSPORT_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_TRANSPORT_H_ |
| 6 #define EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_TRANSPORT_H_ | 6 #define EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_TRANSPORT_H_ |
| 7 | 7 |
| 8 #include <queue> | 8 #include <queue> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/threading/non_thread_safe.h" | 13 #include "base/threading/non_thread_safe.h" |
| 14 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
| 15 #include "components/cast_channel/cast_channel_type.h" |
| 15 #include "extensions/browser/api/cast_channel/logger.h" | 16 #include "extensions/browser/api/cast_channel/logger.h" |
| 16 #include "extensions/common/api/cast_channel.h" | |
| 17 #include "extensions/common/api/cast_channel/logging.pb.h" | 17 #include "extensions/common/api/cast_channel/logging.pb.h" |
| 18 #include "net/base/completion_callback.h" | 18 #include "net/base/completion_callback.h" |
| 19 #include "net/base/ip_endpoint.h" | 19 #include "net/base/ip_endpoint.h" |
| 20 | 20 |
| 21 namespace net { | 21 namespace net { |
| 22 class DrainableIOBuffer; | 22 class DrainableIOBuffer; |
| 23 class DrainableIOBuffer; | 23 class DrainableIOBuffer; |
| 24 class GrowableIOBuffer; | 24 class GrowableIOBuffer; |
| 25 class Socket; | 25 class Socket; |
| 26 } // namespace net | 26 } // namespace net |
| 27 | 27 |
| 28 namespace extensions { | 28 namespace extensions { |
| 29 namespace api { | 29 namespace api { |
| 30 namespace cast_channel { | 30 namespace cast_channel { |
| 31 class CastMessage; | 31 class CastMessage; |
| 32 class MessageFramer; | 32 class MessageFramer; |
| 33 | 33 |
| 34 class CastTransport { | 34 class CastTransport { |
| 35 public: | 35 public: |
| 36 virtual ~CastTransport() {} | 36 virtual ~CastTransport() {} |
| 37 | 37 |
| 38 // Object to be informed of incoming messages and read errors. | 38 // Object to be informed of incoming messages and read errors. |
| 39 class Delegate { | 39 class Delegate { |
| 40 public: | 40 public: |
| 41 using ChannelError = ::cast_channel::ChannelError; |
| 42 |
| 41 virtual ~Delegate() {} | 43 virtual ~Delegate() {} |
| 42 | 44 |
| 43 // Called once Transport is successfully initialized and started. | 45 // Called once Transport is successfully initialized and started. |
| 44 // Owned read delegates are Start()ed automatically. | 46 // Owned read delegates are Start()ed automatically. |
| 45 virtual void Start() = 0; | 47 virtual void Start() = 0; |
| 46 | 48 |
| 47 // An error occurred on the channel. | 49 // An error occurred on the channel. |
| 48 // The caller is responsible for closing |socket| if an error occurred. | 50 // The caller is responsible for closing |socket| if an error occurred. |
| 49 virtual void OnError(ChannelError error_state) = 0; | 51 virtual void OnError(ChannelError error_state) = 0; |
| 50 | 52 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 67 // Changes the delegate for processing read events. Pending reads remain | 69 // Changes the delegate for processing read events. Pending reads remain |
| 68 // in-flight. | 70 // in-flight. |
| 69 // Ownership of the pointee of |delegate| is assumed by the transport. | 71 // Ownership of the pointee of |delegate| is assumed by the transport. |
| 70 // Prior delegates are deleted automatically. | 72 // Prior delegates are deleted automatically. |
| 71 virtual void SetReadDelegate(std::unique_ptr<Delegate> delegate) = 0; | 73 virtual void SetReadDelegate(std::unique_ptr<Delegate> delegate) = 0; |
| 72 }; | 74 }; |
| 73 | 75 |
| 74 // Manager class for reading and writing messages to/from a socket. | 76 // Manager class for reading and writing messages to/from a socket. |
| 75 class CastTransportImpl : public CastTransport, public base::NonThreadSafe { | 77 class CastTransportImpl : public CastTransport, public base::NonThreadSafe { |
| 76 public: | 78 public: |
| 79 using ChannelAuthType = ::cast_channel::ChannelAuthType; |
| 80 using ChannelError = ::cast_channel::ChannelError; |
| 81 |
| 77 // Adds a CastMessage read/write layer to a socket. | 82 // Adds a CastMessage read/write layer to a socket. |
| 78 // Message read events are propagated to the owner via |read_delegate|. | 83 // Message read events are propagated to the owner via |read_delegate|. |
| 79 // |vlog_prefix| sets the prefix used for all VLOGged output. | 84 // |vlog_prefix| sets the prefix used for all VLOGged output. |
| 80 // |socket| and |logger| must all out-live the | 85 // |socket| and |logger| must all out-live the |
| 81 // CastTransportImpl instance. | 86 // CastTransportImpl instance. |
| 82 // |read_delegate| is owned by this CastTransportImpl object. | 87 // |read_delegate| is owned by this CastTransportImpl object. |
| 83 CastTransportImpl(net::Socket* socket, | 88 CastTransportImpl(net::Socket* socket, |
| 84 int channel_id, | 89 int channel_id, |
| 85 const net::IPEndPoint& ip_endpoint_, | 90 const net::IPEndPoint& ip_endpoint_, |
| 86 ChannelAuthType channel_auth_, | 91 ChannelAuthType channel_auth_, |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 // Accumulates details of events and errors, for debugging purposes. | 220 // Accumulates details of events and errors, for debugging purposes. |
| 216 scoped_refptr<Logger> logger_; | 221 scoped_refptr<Logger> logger_; |
| 217 | 222 |
| 218 DISALLOW_COPY_AND_ASSIGN(CastTransportImpl); | 223 DISALLOW_COPY_AND_ASSIGN(CastTransportImpl); |
| 219 }; | 224 }; |
| 220 } // namespace cast_channel | 225 } // namespace cast_channel |
| 221 } // namespace api | 226 } // namespace api |
| 222 } // namespace extensions | 227 } // namespace extensions |
| 223 | 228 |
| 224 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_TRANSPORT_H_ | 229 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_TRANSPORT_H_ |
| OLD | NEW |