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

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

Issue 2706463002: [Presentation API] Mojo typemap for content::PresentationConnectionMessage (Closed)
Patch Set: Fix compile error after rebase Created 3 years, 9 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 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 #include "chrome/browser/media/router/browser_presentation_connection_proxy.h" 5 #include "chrome/browser/media/router/browser_presentation_connection_proxy.h"
6 6
7 #include <vector>
8
9 #include "base/memory/ptr_util.h"
10
7 #include "chrome/browser/media/router/media_router.h" 11 #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 12
56 namespace media_router { 13 namespace media_router {
57 14
58 BrowserPresentationConnectionProxy::BrowserPresentationConnectionProxy( 15 BrowserPresentationConnectionProxy::BrowserPresentationConnectionProxy(
59 MediaRouter* router, 16 MediaRouter* router,
60 const MediaRoute::Id& route_id, 17 const MediaRoute::Id& route_id,
61 blink::mojom::PresentationConnectionRequest receiver_connection_request, 18 blink::mojom::PresentationConnectionRequest receiver_connection_request,
62 blink::mojom::PresentationConnectionPtr controller_connection_ptr) 19 blink::mojom::PresentationConnectionPtr controller_connection_ptr)
63 : router_(router), 20 : router_(router),
64 route_id_(route_id), 21 route_id_(route_id),
65 binding_(this), 22 binding_(this),
66 target_connection_ptr_(std::move(controller_connection_ptr)) { 23 target_connection_ptr_(std::move(controller_connection_ptr)) {
67 DCHECK(router); 24 DCHECK(router);
68 DCHECK(target_connection_ptr_); 25 DCHECK(target_connection_ptr_);
69 26
70 binding_.Bind(std::move(receiver_connection_request)); 27 binding_.Bind(std::move(receiver_connection_request));
71 target_connection_ptr_->DidChangeState( 28 target_connection_ptr_->DidChangeState(
72 content::PRESENTATION_CONNECTION_STATE_CONNECTED); 29 content::PRESENTATION_CONNECTION_STATE_CONNECTED);
73 } 30 }
74 31
75 BrowserPresentationConnectionProxy::~BrowserPresentationConnectionProxy() {} 32 BrowserPresentationConnectionProxy::~BrowserPresentationConnectionProxy() {}
76 33
77 void BrowserPresentationConnectionProxy::OnMessage( 34 void BrowserPresentationConnectionProxy::OnMessage(
78 blink::mojom::ConnectionMessagePtr connection_message, 35 content::PresentationConnectionMessage message,
79 const OnMessageCallback& on_message_callback) { 36 const OnMessageCallback& on_message_callback) {
80 DVLOG(2) << "BrowserPresentationConnectionProxy::OnMessage"; 37 DVLOG(2) << "BrowserPresentationConnectionProxy::OnMessage";
81 DCHECK(!connection_message.is_null()); 38 if (message.is_binary()) {
82 39 router_->SendRouteBinaryMessage(
83 auto message = 40 route_id_,
84 PresentationConnectionMessageFromMojo(std::move(connection_message)); 41 base::MakeUnique<std::vector<uint8_t>>(std::move(message.data.value())),
85 42 on_message_callback);
86 if (message->is_binary()) {
87 router_->SendRouteBinaryMessage(route_id_, std::move(message->data),
88 on_message_callback);
89 } else { 43 } else {
90 router_->SendRouteMessage(route_id_, message->message, on_message_callback); 44 router_->SendRouteMessage(route_id_, message.message.value(),
45 on_message_callback);
91 } 46 }
92 } 47 }
93 48
94 } // namespace media_router 49 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698