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_CHANNEL_API_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ |
6 #define EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ | 6 #define EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 void AsyncWorkStart() override; | 127 void AsyncWorkStart() override; |
128 | 128 |
129 private: | 129 private: |
130 DECLARE_EXTENSION_FUNCTION("cast.channel.open", CAST_CHANNEL_OPEN) | 130 DECLARE_EXTENSION_FUNCTION("cast.channel.open", CAST_CHANNEL_OPEN) |
131 | 131 |
132 // Defines a callback used to send events to the extension's | 132 // Defines a callback used to send events to the extension's |
133 // EventRouter. | 133 // EventRouter. |
134 // Parameter #0 is a scoped pointer to the event payload. | 134 // Parameter #0 is a scoped pointer to the event payload. |
135 using EventDispatchCallback = base::Callback<void(std::unique_ptr<Event>)>; | 135 using EventDispatchCallback = base::Callback<void(std::unique_ptr<Event>)>; |
136 | 136 |
137 // Receives incoming messages and errors and provides additional API and | 137 // Receives incoming messages and errors and provides additional API context. |
138 // origin socket context. | 138 class CastMessageHandler : public cast_channel::CastSocket::Observer { |
139 class CastMessageHandler : public cast_channel::CastTransport::Delegate { | |
140 public: | 139 public: |
141 CastMessageHandler(const EventDispatchCallback& ui_dispatch_cb, | 140 CastMessageHandler(const EventDispatchCallback& ui_dispatch_cb, |
142 cast_channel::CastSocket* socket, | |
143 scoped_refptr<cast_channel::Logger> logger); | 141 scoped_refptr<cast_channel::Logger> logger); |
144 ~CastMessageHandler() override; | 142 ~CastMessageHandler() override; |
145 | 143 |
146 // CastTransport::Delegate implementation. | 144 // CastSocket::Observer implementation. |
147 void OnError(cast_channel::ChannelError error_state) override; | 145 void OnError(const cast_channel::CastSocket& socket, |
148 void OnMessage(const cast_channel::CastMessage& message) override; | 146 cast_channel::ChannelError error_state) override; |
149 void Start() override; | 147 void OnMessage(const cast_channel::CastSocket& socket, |
| 148 const cast_channel::CastMessage& message) override; |
150 | 149 |
151 private: | 150 private: |
152 // Callback for sending events to the extension. | 151 // Callback for sending events to the extension. |
153 // Should be bound to a weak pointer, to prevent any use-after-free | 152 // Should be bound to a weak pointer, to prevent any use-after-free |
154 // conditions. | 153 // conditions. |
155 EventDispatchCallback const ui_dispatch_cb_; | 154 EventDispatchCallback const ui_dispatch_cb_; |
156 cast_channel::CastSocket* const socket_; | |
157 // Logger object for reporting error details. | 155 // Logger object for reporting error details. |
158 scoped_refptr<cast_channel::Logger> logger_; | 156 scoped_refptr<cast_channel::Logger> logger_; |
159 | 157 |
160 DISALLOW_COPY_AND_ASSIGN(CastMessageHandler); | 158 DISALLOW_COPY_AND_ASSIGN(CastMessageHandler); |
161 }; | 159 }; |
162 | 160 |
163 // Validates that |connect_info| represents a valid IP end point and returns a | 161 // Validates that |connect_info| represents a valid IP end point and returns a |
164 // new IPEndPoint if so. Otherwise returns nullptr. | 162 // new IPEndPoint if so. Otherwise returns nullptr. |
165 static net::IPEndPoint* ParseConnectInfo( | 163 static net::IPEndPoint* ParseConnectInfo( |
166 const api::cast_channel::ConnectInfo& connect_info); | 164 const api::cast_channel::ConnectInfo& connect_info); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 | 217 |
220 std::unique_ptr<api::cast_channel::Close::Params> params_; | 218 std::unique_ptr<api::cast_channel::Close::Params> params_; |
221 CastChannelAPI* api_; | 219 CastChannelAPI* api_; |
222 | 220 |
223 DISALLOW_COPY_AND_ASSIGN(CastChannelCloseFunction); | 221 DISALLOW_COPY_AND_ASSIGN(CastChannelCloseFunction); |
224 }; | 222 }; |
225 | 223 |
226 } // namespace extensions | 224 } // namespace extensions |
227 | 225 |
228 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ | 226 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_CHANNEL_API_H_ |
OLD | NEW |