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

Side by Side Diff: content/renderer/presentation/presentation_connection_proxy.cc

Issue 2471263003: [Presentation API] (4th)(1-UA blink side) Add WebPresentationConnection and WebPresentationConnecti… (Closed)
Patch Set: resolve code review comments from dcheng 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 "content/renderer/presentation/presentation_connection_proxy.h"
6
7 #include "base/logging.h"
8 #include "content/renderer/presentation/presentation_dispatcher.h"
9 #include "third_party/WebKit/public/platform/WebString.h"
10 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nConnection.h"
11 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nController.h"
12 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nSessionInfo.h"
13
14 namespace content {
15
16 PresentationConnectionProxy::PresentationConnectionProxy(
17 blink::WebPresentationConnection* connection)
18 : binding_(this),
19 target_connection_(nullptr),
20 source_connection_(connection) {
21 DCHECK(source_connection_);
22 }
23
24 PresentationConnectionProxy::~PresentationConnectionProxy() = default;
25
26 void PresentationConnectionProxy::SendConnectionMessage(
27 blink::mojom::ConnectionMessagePtr session_message,
28 const OnMessageCallback& callback) const {
29 DCHECK(target_connection_);
imcheng 2017/01/20 20:15:43 What prevents this method from being called before
zhaobin 2017/01/23 19:38:49 Yes.
30 target_connection_->OnMessage(std::move(session_message), callback);
31 }
32
33 void PresentationConnectionProxy::OnMessage(
34 blink::mojom::ConnectionMessagePtr message,
35 const OnMessageCallback& callback) {
36 DCHECK(source_connection_);
imcheng 2017/01/20 20:15:43 This DCHECK already exists in the constructor. Not
zhaobin 2017/01/23 19:38:48 Done.
37 DCHECK(!callback.is_null());
38
39 switch (message->type) {
40 case blink::mojom::PresentationMessageType::TEXT: {
41 DCHECK(message->message);
42 source_connection_->didReceiveTextMessage(
43 blink::WebString::fromUTF8(message->message.value()));
44 break;
45 }
46 case blink::mojom::PresentationMessageType::BINARY: {
47 DCHECK(message->data);
48 source_connection_->didReceiveBinaryMessage(&(message->data->front()),
49 message->data->size());
50 break;
51 }
52 default: {
53 callback.Run(false);
54 NOTREACHED();
55 break;
56 }
57 }
58
59 callback.Run(true);
60 }
61
62 void PresentationConnectionProxy::DidChangeState(
imcheng 2017/01/20 20:15:43 If I were to close() one side of a 1-UA presentati
zhaobin 2017/01/23 19:38:48 Yes.
63 blink::mojom::PresentationConnectionState state) {
64 DCHECK(source_connection_);
imcheng 2017/01/20 20:15:43 ditto on DCHECK
zhaobin 2017/01/23 19:38:48 Done.
65 if (state == blink::mojom::PresentationConnectionState::CONNECTED) {
66 source_connection_->didChangeState(
67 blink::WebPresentationConnectionState::Connected);
68 } else {
69 // |DidChangeState| should only handles state transition from connecting ->
imcheng 2017/01/20 20:15:43 s/handles/handle
zhaobin 2017/01/23 19:38:49 Done.
70 // connected. PresentationService and MRP handles other state transitions.
71 NOTREACHED();
72 }
73 }
74
75 ControllerConnectionProxy::ControllerConnectionProxy(
76 blink::WebPresentationConnection* connection)
77 : PresentationConnectionProxy(connection) {}
78
79 ControllerConnectionProxy::~ControllerConnectionProxy() {}
80
81 blink::mojom::PresentationConnectionPtr ControllerConnectionProxy::Bind() {
82 return binding_.CreateInterfacePtrAndBind();
83 }
84
85 blink::mojom::PresentationConnectionRequest
86 ControllerConnectionProxy::MakeRemoteRequest() {
87 DCHECK(!target_connection_)
88 << "target_connection_ should only be bound once.";
89 return mojo::MakeRequest(&target_connection_);
90 }
91
92 ReceiverConnectionProxy::ReceiverConnectionProxy(
93 blink::WebPresentationConnection* connection)
94 : PresentationConnectionProxy(connection) {}
95
96 ReceiverConnectionProxy::~ReceiverConnectionProxy() {}
97
98 void ReceiverConnectionProxy::Bind(
99 blink::mojom::PresentationConnectionRequest target_connection_request) {
100 binding_.Bind(std::move(target_connection_request));
101 }
102
103 void ReceiverConnectionProxy::BindTargetConnection(
104 blink::mojom::PresentationConnectionPtr connection) {
105 DCHECK(!target_connection_);
106 target_connection_ = std::move(connection);
107 target_connection_->DidChangeState(
108 blink::mojom::PresentationConnectionState::CONNECTED);
109
110 DidChangeState(blink::mojom::PresentationConnectionState::CONNECTED);
111 }
112
113 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698