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

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: resolve code review comments from Mark Created 3 years, 11 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 const content::PresentationSessionInfo& session_info,
61 MediaRouter* router,
62 const MediaRoute* route)
63 : session_info_(session_info),
64 router_(router),
65 route_(route),
66 binding_(this) {}
67
68 BrowserPresentationConnectionProxy::~BrowserPresentationConnectionProxy() {}
69
70 void BrowserPresentationConnectionProxy::Bind(
71 blink::mojom::PresentationConnectionRequest target_conn_request) {
mark a. foltz 2017/01/27 18:30:05 target_request (prefer not using abbreviations in
zhaobin 2017/01/27 22:11:40 Done.
72 binding_.Bind(std::move(target_conn_request));
73 }
74
75 void BrowserPresentationConnectionProxy::SetTargetConnection(
76 blink::mojom::PresentationConnectionPtr connection) {
77 DCHECK(!target_connection_);
78
79 target_connection_ = std::move(connection);
80 target_connection_->DidChangeState(
81 blink::mojom::PresentationConnectionState::CONNECTED);
82 }
83
84 void BrowserPresentationConnectionProxy::OnMessage(
85 blink::mojom::ConnectionMessagePtr session_message,
mark a. foltz 2017/01/27 18:30:05 The parameter names here don't match the declarati
zhaobin 2017/01/27 22:11:40 Done.
86 const OnMessageCallback& on_message_callback) {
87 DVLOG(2) << "BrowserPresentationConnectionProxy::OnMessage "
88 << "[presentation_id]: " << session_info_.presentation_id;
89 DCHECK(!session_message.is_null());
90
91 if (!router_) {
92 on_message_callback.Run(false);
93 return;
94 }
95
96 std::unique_ptr<content::PresentationConnectionMessage> message =
97 PresentationConnectionMessageFromMojo(std::move(session_message));
98
99 if (message->is_binary()) {
100 router_->SendRouteBinaryMessage(route_->media_route_id(),
101 std::move(message->data),
102 on_message_callback);
103 } else {
104 router_->SendRouteMessage(route_->media_route_id(), message->message,
105 on_message_callback);
106 }
107 }
108
109 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698