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

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: add unit test for browser_presentation_connection_proxy 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 PresentationConnectionMessageFromMojo(
17 blink::mojom::ConnectionMessagePtr input) {
18 std::unique_ptr<content::PresentationConnectionMessage> output;
19 if (input.is_null())
20 return output;
21
22 switch (input->type) {
23 case blink::mojom::PresentationMessageType::TEXT: {
24 // Return nullptr content::PresentationSessionMessage if invalid (unset
25 // |message|, set |data|, or size too large).
26 if (input->data || !input->message ||
27 input->message->size() >
28 content::kMaxPresentationConnectionMessageSize)
29 return output;
30
31 output.reset(new content::PresentationConnectionMessage(
32 content::PresentationMessageType::TEXT));
33 output->message = std::move(input->message.value());
34 return output;
35 }
36 case blink::mojom::PresentationMessageType::BINARY: {
37 // Return nullptr content::PresentationSessionMessage if invalid (unset
38 // |data|, set |message|, or size too large).
39 if (!input->data || input->message ||
40 input->data->size() > content::kMaxPresentationConnectionMessageSize)
41 return output;
42
43 output.reset(new content::PresentationConnectionMessage(
44 content::PresentationMessageType::BINARY));
45 output->data.reset(
46 new std::vector<uint8_t>(std::move(input->data.value())));
47 return output;
48 }
49 }
50
51 NOTREACHED() << "Invalid presentation message type " << input->type;
52 return output;
53 }
54
55 } // namespace
56
57 namespace media_router {
58
59 BrowserPresentationConnectionProxy::BrowserPresentationConnectionProxy(
60 MediaRouter* router,
61 const MediaRoute* route)
62 : router_(router),
63 route_(route),
64 binding_(this),
65 target_connection_ptr_(nullptr) {}
66
67 BrowserPresentationConnectionProxy::~BrowserPresentationConnectionProxy() {}
68
69 void BrowserPresentationConnectionProxy::Bind(
70 blink::mojom::PresentationConnectionRequest receiver_connection_request) {
71 binding_.Bind(std::move(receiver_connection_request));
72 }
73
74 void BrowserPresentationConnectionProxy::BindControllerConnection(
75 blink::mojom::PresentationConnectionPtr controller_connection_ptr) {
76 DCHECK(!target_connection_ptr_);
77
78 target_connection_ptr_ = std::move(controller_connection_ptr);
79 target_connection_ptr_->DidChangeState(
80 blink::mojom::PresentationConnectionState::CONNECTED);
81 }
82
83 void BrowserPresentationConnectionProxy::OnMessage(
84 blink::mojom::ConnectionMessagePtr connection_message,
85 const OnMessageCallback& on_message_callback) {
86 DVLOG(2) << "BrowserPresentationConnectionProxy::OnMessage";
87
88 DCHECK(!connection_message.is_null());
89 if (!router_) {
imcheng 2017/01/31 01:53:24 Why would this be nullptr? Maybe there should be a
zhaobin 2017/01/31 18:44:15 Done.
90 on_message_callback.Run(false);
91 return;
92 }
93
94 auto message =
95 PresentationConnectionMessageFromMojo(std::move(connection_message));
96
97 if (message->is_binary()) {
98 router_->SendRouteBinaryMessage(route_->media_route_id(),
99 std::move(message->data),
100 on_message_callback);
101 } else {
102 router_->SendRouteMessage(route_->media_route_id(), message->message,
103 on_message_callback);
104 }
105 }
106
107 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698