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

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 master 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_router.h"
8 #include "content/public/common/presentation_constants.h"
9
10 namespace {
11
12 // TODO(crbug.com/632623): remove this function when we finish typemaps for
13 // presentation.mojom.
14 std::unique_ptr<content::PresentationConnectionMessage>
15 PresentationConnectionMessageFromMojo(
16 blink::mojom::ConnectionMessagePtr input) {
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 MediaRouter* router,
60 const MediaRoute::Id& route_id,
61 blink::mojom::PresentationConnectionRequest receiver_connection_request,
62 blink::mojom::PresentationConnectionPtr controller_connection_ptr)
63 : router_(router),
64 route_id_(route_id),
65 binding_(this),
66 target_connection_ptr_(std::move(controller_connection_ptr)) {
67 DCHECK(router);
68 DCHECK(target_connection_ptr_);
69
70 binding_.Bind(std::move(receiver_connection_request));
71 target_connection_ptr_->DidChangeState(
72 content::PRESENTATION_CONNECTION_STATE_CONNECTED);
73 }
74
75 BrowserPresentationConnectionProxy::~BrowserPresentationConnectionProxy() {}
76
77 void BrowserPresentationConnectionProxy::OnMessage(
78 blink::mojom::ConnectionMessagePtr connection_message,
79 const OnMessageCallback& on_message_callback) {
80 DVLOG(2) << "BrowserPresentationConnectionProxy::OnMessage";
81 DCHECK(!connection_message.is_null());
82
83 auto message =
84 PresentationConnectionMessageFromMojo(std::move(connection_message));
85
86 if (message->is_binary()) {
87 router_->SendRouteBinaryMessage(route_id_, std::move(message->data),
88 on_message_callback);
89 } else {
90 router_->SendRouteMessage(route_id_, message->message, on_message_callback);
91 }
92 }
93
94 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698