OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/media/router/browser_presentation_connection_proxy.h" | |
6 | |
7 #include "chrome/browser/media/router/media_route.h" | |
8 #include "chrome/browser/media/router/media_router.h" | |
9 #include "content/public/common/presentation_constants.h" | |
10 | |
11 namespace { | |
12 | |
13 std::unique_ptr<content::PresentationConnectionMessage> | |
mark a. foltz
2017/01/23 22:29:34
This will go away once we finish typemaps for pres
zhaobin
2017/01/24 19:28:46
Done.
| |
14 GetPresentationConnectionMessage(blink::mojom::ConnectionMessagePtr input) { | |
15 std::unique_ptr<content::PresentationConnectionMessage> output; | |
16 if (input.is_null()) | |
17 return output; | |
18 | |
19 switch (input->type) { | |
20 case blink::mojom::PresentationMessageType::TEXT: { | |
21 // Return nullptr content::PresentationSessionMessage if invalid (unset | |
22 // |message|, set |data|, or size too large). | |
23 if (input->data || !input->message || | |
24 input->message->size() > | |
25 content::kMaxPresentationConnectionMessageSize) | |
26 return output; | |
27 | |
28 output.reset(new content::PresentationConnectionMessage( | |
29 content::PresentationMessageType::TEXT)); | |
30 output->message = std::move(input->message.value()); | |
31 return output; | |
32 } | |
33 case blink::mojom::PresentationMessageType::BINARY: { | |
34 // Return nullptr content::PresentationSessionMessage if invalid (unset | |
35 // |data|, set | |
36 // |message|, or size too large). | |
37 if (!input->data || input->message || | |
mark a. foltz
2017/01/23 22:29:34
It's really unfortunate that we have to duplicate
| |
38 input->data->size() > content::kMaxPresentationConnectionMessageSize) | |
39 return output; | |
40 | |
41 output.reset(new content::PresentationConnectionMessage( | |
42 content::PresentationMessageType::BINARY)); | |
43 output->data.reset( | |
44 new std::vector<uint8_t>(std::move(input->data.value()))); | |
45 return output; | |
46 } | |
47 } | |
48 | |
49 NOTREACHED() << "Invalid presentation message type " << input->type; | |
50 return output; | |
51 } | |
52 | |
53 } // namespace | |
54 | |
55 namespace media_router { | |
56 | |
57 BrowserPresentationConnectionProxy::BrowserPresentationConnectionProxy( | |
58 const content::PresentationSessionInfo& session_info, | |
59 MediaRouter* router, | |
60 MediaRoute* route) | |
61 : session_info_(session_info), | |
62 router_(router), | |
63 route_(route), | |
64 binding_(this) { | |
65 DVLOG(2) << __FUNCTION__ << " [id]: " << session_info.presentation_id; | |
66 } | |
67 | |
68 BrowserPresentationConnectionProxy::~BrowserPresentationConnectionProxy() { | |
69 DVLOG(2) << __FUNCTION__; | |
mark a. foltz
2017/01/23 22:29:34
Are these function-only log statements needed perm
zhaobin
2017/01/24 19:28:46
Just for debugging. Removed.
| |
70 } | |
71 | |
72 void BrowserPresentationConnectionProxy::Bind( | |
73 blink::mojom::PresentationConnectionRequest target_conn_request) { | |
74 binding_.Bind(std::move(target_conn_request)); | |
75 } | |
76 | |
77 void BrowserPresentationConnectionProxy::SetTargetConnection( | |
78 blink::mojom::PresentationConnectionPtr connection) { | |
79 DVLOG(2) << __FUNCTION__; | |
80 DCHECK(!target_connection_); | |
81 | |
82 target_connection_ = std::move(connection); | |
83 target_connection_->DidChangeState( | |
84 blink::mojom::PresentationConnectionState::CONNECTED); | |
85 } | |
86 | |
87 void BrowserPresentationConnectionProxy::OnMessage( | |
88 blink::mojom::ConnectionMessagePtr session_message, | |
89 const OnMessageCallback& on_message_callback) { | |
90 DVLOG(2) << __FUNCTION__ << " [id]: " << session_info_.presentation_id; | |
91 DCHECK(!session_message.is_null()); | |
92 | |
93 if (!router_) { | |
94 on_message_callback.Run(false); | |
95 return; | |
96 } | |
97 | |
98 std::unique_ptr<content::PresentationConnectionMessage> message = | |
99 GetPresentationConnectionMessage(std::move(session_message)); | |
100 | |
101 if (message->is_binary()) { | |
102 router_->SendRouteBinaryMessage(route_->media_route_id(), | |
103 std::move(message->data), | |
104 on_message_callback); | |
105 } else { | |
106 router_->SendRouteMessage(route_->media_route_id(), message->message, | |
107 on_message_callback); | |
108 } | |
109 } | |
110 | |
111 } // namespace media_router | |
OLD | NEW |