OLD | NEW |
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 "content/renderer/presentation/presentation_connection_proxy.h" | 5 #include "content/renderer/presentation/presentation_connection_proxy.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/public/common/presentation_info.h" | 8 #include "content/public/common/presentation_info.h" |
9 #include "content/renderer/presentation/presentation_dispatcher.h" | 9 #include "content/renderer/presentation/presentation_dispatcher.h" |
10 #include "third_party/WebKit/public/platform/WebString.h" | 10 #include "third_party/WebKit/public/platform/WebString.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 blink::WebPresentationConnectionState::kConnected); | 56 blink::WebPresentationConnectionState::kConnected); |
57 } else if (state == content::PRESENTATION_CONNECTION_STATE_CLOSED) { | 57 } else if (state == content::PRESENTATION_CONNECTION_STATE_CLOSED) { |
58 source_connection_->DidClose(); | 58 source_connection_->DidClose(); |
59 } else { | 59 } else { |
60 NOTREACHED(); | 60 NOTREACHED(); |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 void PresentationConnectionProxy::OnClose() { | 64 void PresentationConnectionProxy::OnClose() { |
65 DCHECK(target_connection_ptr_); | 65 DCHECK(target_connection_ptr_); |
66 source_connection_->DidClose(); | 66 DidChangeState(content::PRESENTATION_CONNECTION_STATE_CLOSED); |
67 target_connection_ptr_->DidChangeState( | 67 target_connection_ptr_->DidChangeState( |
68 content::PRESENTATION_CONNECTION_STATE_CLOSED); | 68 content::PRESENTATION_CONNECTION_STATE_CLOSED); |
69 } | 69 } |
70 | 70 |
71 void PresentationConnectionProxy::Close() const { | 71 void PresentationConnectionProxy::Close() const { |
72 DCHECK(target_connection_ptr_); | 72 DCHECK(target_connection_ptr_); |
73 target_connection_ptr_->OnClose(); | 73 target_connection_ptr_->OnClose(); |
74 } | 74 } |
75 | 75 |
76 ControllerConnectionProxy::ControllerConnectionProxy( | 76 ControllerConnectionProxy::ControllerConnectionProxy( |
77 blink::WebPresentationConnection* controller_connection) | 77 blink::WebPresentationConnection* controller_connection) |
78 : PresentationConnectionProxy(controller_connection) {} | 78 : PresentationConnectionProxy(controller_connection) {} |
79 | 79 |
80 ControllerConnectionProxy::~ControllerConnectionProxy() = default; | 80 ControllerConnectionProxy::~ControllerConnectionProxy() = default; |
81 | 81 |
82 blink::mojom::PresentationConnectionPtr ControllerConnectionProxy::Bind() { | 82 blink::mojom::PresentationConnectionPtr ControllerConnectionProxy::Bind() { |
83 return binding_.CreateInterfacePtrAndBind(); | 83 return binding_.CreateInterfacePtrAndBind(); |
84 } | 84 } |
85 | 85 |
86 blink::mojom::PresentationConnectionRequest | 86 blink::mojom::PresentationConnectionRequest |
87 ControllerConnectionProxy::MakeRemoteRequest() { | 87 ControllerConnectionProxy::MakeRemoteRequest() { |
88 DCHECK(!target_connection_ptr_) | 88 DCHECK(!target_connection_ptr_) |
89 << "target_connection_ptr_ should only be bound once."; | 89 << "target_connection_ptr_ should only be bound once."; |
90 return mojo::MakeRequest(&target_connection_ptr_); | 90 return mojo::MakeRequest(&target_connection_ptr_); |
91 } | 91 } |
92 | 92 |
93 ReceiverConnectionProxy::ReceiverConnectionProxy( | 93 ReceiverConnectionProxy::ReceiverConnectionProxy( |
94 blink::WebPresentationConnection* receiver_connection) | 94 blink::WebPresentationConnection* receiver_connection, |
95 : PresentationConnectionProxy(receiver_connection) {} | 95 const OnConnectionClosedCallback& connection_closed_callback) |
| 96 : PresentationConnectionProxy(receiver_connection), |
| 97 connection_closed_callback_(connection_closed_callback) { |
| 98 DCHECK(connection_closed_callback_); |
| 99 } |
96 | 100 |
97 ReceiverConnectionProxy::~ReceiverConnectionProxy() = default; | 101 ReceiverConnectionProxy::~ReceiverConnectionProxy() = default; |
98 | 102 |
99 void ReceiverConnectionProxy::Bind( | 103 void ReceiverConnectionProxy::Bind( |
100 blink::mojom::PresentationConnectionRequest receiver_connection_request) { | 104 blink::mojom::PresentationConnectionRequest receiver_connection_request) { |
101 binding_.Bind(std::move(receiver_connection_request)); | 105 binding_.Bind(std::move(receiver_connection_request)); |
102 } | 106 } |
103 | 107 |
104 void ReceiverConnectionProxy::BindControllerConnection( | 108 void ReceiverConnectionProxy::BindControllerConnection( |
105 blink::mojom::PresentationConnectionPtr controller_connection_ptr) { | 109 blink::mojom::PresentationConnectionPtr controller_connection_ptr) { |
106 DCHECK(!target_connection_ptr_); | 110 DCHECK(!target_connection_ptr_); |
107 target_connection_ptr_ = std::move(controller_connection_ptr); | 111 target_connection_ptr_ = std::move(controller_connection_ptr); |
108 target_connection_ptr_->DidChangeState( | 112 target_connection_ptr_->DidChangeState( |
109 content::PRESENTATION_CONNECTION_STATE_CONNECTED); | 113 content::PRESENTATION_CONNECTION_STATE_CONNECTED); |
110 | 114 |
111 DidChangeState(content::PRESENTATION_CONNECTION_STATE_CONNECTED); | 115 DidChangeState(content::PRESENTATION_CONNECTION_STATE_CONNECTED); |
112 } | 116 } |
113 | 117 |
| 118 void ReceiverConnectionProxy::DidChangeState( |
| 119 content::PresentationConnectionState state) { |
| 120 PresentationConnectionProxy::DidChangeState(state); |
| 121 if (state == content::PRESENTATION_CONNECTION_STATE_CLOSED) |
| 122 connection_closed_callback_.Run(); |
| 123 } |
| 124 |
114 } // namespace content | 125 } // namespace content |
OLD | NEW |