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

Side by Side Diff: chrome/browser/media/router/browser_presentation_connection_proxy.cc

Issue 2471573005: [Presentation API] (5th) (1-UA) integrate controller and receiver side for 1-UA messaging (Closed)
Patch Set: merge with issue 2471263003 Created 3 years, 10 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
(Empty)
1 // Copyright 2017 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 // TODO(crbug.com/632623): remove this function when we finish typemaps for
14 // presentation.mojom.
15 std::unique_ptr<content::PresentationConnectionMessage>
16 GetPresentationConnectionMessage(blink::mojom::ConnectionMessagePtr input) {
mark a. foltz 2017/01/27 00:44:21 PresentationConnectionMessageFromMojo
zhaobin 2017/01/27 05:05:46 Done.
17 std::unique_ptr<content::PresentationConnectionMessage> output;
18 if (input.is_null())
19 return output;
20
21 switch (input->type) {
22 case blink::mojom::PresentationMessageType::TEXT: {
23 // Return nullptr content::PresentationSessionMessage if invalid (unset
24 // |message|, set |data|, or size too large).
25 if (input->data || !input->message ||
26 input->message->size() >
27 content::kMaxPresentationConnectionMessageSize)
28 return output;
29
30 output.reset(new content::PresentationConnectionMessage(
31 content::PresentationMessageType::TEXT));
32 output->message = std::move(input->message.value());
33 return output;
34 }
35 case blink::mojom::PresentationMessageType::BINARY: {
36 // Return nullptr content::PresentationSessionMessage if invalid (unset
37 // |data|, set |message|, or size too large).
38 if (!input->data || input->message ||
39 input->data->size() > content::kMaxPresentationConnectionMessageSize)
40 return output;
41
42 output.reset(new content::PresentationConnectionMessage(
43 content::PresentationMessageType::BINARY));
44 output->data.reset(
45 new std::vector<uint8_t>(std::move(input->data.value())));
46 return output;
47 }
48 }
49
50 NOTREACHED() << "Invalid presentation message type " << input->type;
51 return output;
52 }
53
54 } // namespace
55
56 namespace media_router {
57
58 BrowserPresentationConnectionProxy::BrowserPresentationConnectionProxy(
59 const content::PresentationSessionInfo& session_info,
60 MediaRouter* router,
61 MediaRoute* route)
62 : session_info_(session_info),
63 router_(router),
64 route_(route),
65 binding_(this) {}
66
67 BrowserPresentationConnectionProxy::~BrowserPresentationConnectionProxy() {}
68
69 void BrowserPresentationConnectionProxy::Bind(
70 blink::mojom::PresentationConnectionRequest target_conn_request) {
71 binding_.Bind(std::move(target_conn_request));
72 }
73
74 void BrowserPresentationConnectionProxy::SetTargetConnection(
75 blink::mojom::PresentationConnectionPtr connection) {
76 DCHECK(!target_connection_);
77
78 target_connection_ = std::move(connection);
79 target_connection_->DidChangeState(
80 blink::mojom::PresentationConnectionState::CONNECTED);
81 }
82
83 void BrowserPresentationConnectionProxy::OnMessage(
84 blink::mojom::ConnectionMessagePtr session_message,
85 const OnMessageCallback& on_message_callback) {
86 DVLOG(2) << "BrowserPresentationConnectionProxy::OnMessage "
87 << "[presentation_id]: " << session_info_.presentation_id;
88 DCHECK(!session_message.is_null());
89
90 if (!router_) {
91 on_message_callback.Run(false);
92 return;
93 }
94
95 std::unique_ptr<content::PresentationConnectionMessage> message =
96 GetPresentationConnectionMessage(std::move(session_message));
97
98 if (message->is_binary()) {
99 router_->SendRouteBinaryMessage(route_->media_route_id(),
100 std::move(message->data),
101 on_message_callback);
102 } else {
103 router_->SendRouteMessage(route_->media_route_id(), message->message,
104 on_message_callback);
105 }
106 }
107
108 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698