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

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

Issue 2471573005: [Presentation API] (5th) (1-UA) integrate controller and receiver side for 1-UA messaging (Closed)
Patch Set: Fix PresentationDispatcherTest failures 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_dispatcher.h" 5 #include "content/renderer/presentation/presentation_dispatcher.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 message_request_queue_.push(base::WrapUnique(CreateSendBinaryMessageRequest( 220 message_request_queue_.push(base::WrapUnique(CreateSendBinaryMessageRequest(
221 presentationUrl, presentationId, 221 presentationUrl, presentationId,
222 blink::mojom::PresentationMessageType::BINARY, data, length, 222 blink::mojom::PresentationMessageType::BINARY, data, length,
223 connection_proxy))); 223 connection_proxy)));
224 // Start processing request if only one in the queue. 224 // Start processing request if only one in the queue.
225 if (message_request_queue_.size() == 1) 225 if (message_request_queue_.size() == 1)
226 DoSendMessage(message_request_queue_.front().get()); 226 DoSendMessage(message_request_queue_.front().get());
227 } 227 }
228 228
229 void PresentationDispatcher::DoSendMessage(SendMessageRequest* request) { 229 void PresentationDispatcher::DoSendMessage(SendMessageRequest* request) {
230 ConnectToPresentationServiceIfNeeded(); 230 DCHECK(request->connection_proxy);
231 231 // TODO(crbug.com/684116): Remove static_cast after moving message queue logic
232 presentation_service_->SendConnectionMessage( 232 // from PresentationDispatcher to PresentationConnectionProxy.
233 std::move(request->session_info), std::move(request->message), 233 static_cast<const PresentationConnectionProxy*>(request->connection_proxy)
234 base::Bind(&PresentationDispatcher::HandleSendMessageRequests, 234 ->SendConnectionMessage(
235 base::Unretained(this))); 235 std::move(request->message),
236 base::Bind(&PresentationDispatcher::HandleSendMessageRequests,
237 base::Unretained(this)));
236 } 238 }
237 239
238 void PresentationDispatcher::HandleSendMessageRequests(bool success) { 240 void PresentationDispatcher::HandleSendMessageRequests(bool success) {
239 // In normal cases, message_request_queue_ should not be empty at this point 241 // In normal cases, message_request_queue_ should not be empty at this point
240 // of time, but when DidCommitProvisionalLoad() is invoked before receiving 242 // of time, but when DidCommitProvisionalLoad() is invoked before receiving
241 // the callback for previous send mojo call, queue would have been emptied. 243 // the callback for previous send mojo call, queue would have been emptied.
242 if (message_request_queue_.empty()) 244 if (message_request_queue_.empty())
243 return; 245 return;
244 246
245 if (!success) { 247 if (!success) {
246 // PresentationServiceImpl is informing that Frame has been detached or 248 // PresentationServiceImpl is informing that Frame has been detached or
247 // navigated away. Invalidate all pending requests. 249 // navigated away. Invalidate all pending requests.
248 MessageRequestQueue empty; 250 MessageRequestQueue empty;
249 std::swap(message_request_queue_, empty); 251 std::swap(message_request_queue_, empty);
250 return; 252 return;
251 } 253 }
252 254
253 message_request_queue_.pop(); 255 message_request_queue_.pop();
254 if (!message_request_queue_.empty()) { 256 if (!message_request_queue_.empty()) {
255 DoSendMessage(message_request_queue_.front().get()); 257 DoSendMessage(message_request_queue_.front().get());
256 } 258 }
257 } 259 }
258 260
261 void PresentationDispatcher::SetControllerConnection(
262 blink::mojom::PresentationSessionInfoPtr session_info,
263 blink::WebPresentationConnection* connection) {
264 DCHECK(connection);
265
266 auto* controller_connection_proxy = new ControllerConnectionProxy(connection);
267 connection->bindProxy(base::WrapUnique(controller_connection_proxy));
268
269 ConnectToPresentationServiceIfNeeded();
270 presentation_service_->SetPresentationConnection(
271 session_info.Clone(), controller_connection_proxy->Bind(),
272 controller_connection_proxy->MakeRemoteRequest());
273 }
274
259 void PresentationDispatcher::closeSession( 275 void PresentationDispatcher::closeSession(
260 const blink::WebURL& presentationUrl, 276 const blink::WebURL& presentationUrl,
261 const blink::WebString& presentationId) { 277 const blink::WebString& presentationId) {
262 ConnectToPresentationServiceIfNeeded(); 278 ConnectToPresentationServiceIfNeeded();
263 presentation_service_->CloseConnection(presentationUrl, 279 presentation_service_->CloseConnection(presentationUrl,
264 presentationId.utf8()); 280 presentationId.utf8());
265 } 281 }
266 282
267 void PresentationDispatcher::terminateSession( 283 void PresentationDispatcher::terminateSession(
268 const blink::WebURL& presentationUrl, 284 const blink::WebURL& presentationUrl,
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 for (auto* listener : modified_listeners) 497 for (auto* listener : modified_listeners)
482 TryRemoveAvailabilityListener(listener); 498 TryRemoveAvailabilityListener(listener);
483 } 499 }
484 500
485 void PresentationDispatcher::OnDefaultSessionStarted( 501 void PresentationDispatcher::OnDefaultSessionStarted(
486 blink::mojom::PresentationSessionInfoPtr session_info) { 502 blink::mojom::PresentationSessionInfoPtr session_info) {
487 if (!controller_) 503 if (!controller_)
488 return; 504 return;
489 505
490 if (!session_info.is_null()) { 506 if (!session_info.is_null()) {
491 presentation_service_->ListenForConnectionMessages(session_info.Clone());
492 auto* connection = controller_->didStartDefaultSession( 507 auto* connection = controller_->didStartDefaultSession(
493 mojo::ConvertTo<blink::WebPresentationSessionInfo>(session_info)); 508 mojo::ConvertTo<blink::WebPresentationSessionInfo>(session_info));
494 connection->bindProxy( 509
495 base::MakeUnique<ControllerConnectionProxy>(connection)); 510 if (connection) {
511 SetControllerConnection(session_info.Clone(), connection);
512 // Change blink connection state to 'connected' before listening to
513 // connection message. Remove ListenForConnectionMessage() after
514 // TODO(crbug.com/687011): use BrowserPresentationConnectionProxy to send
515 // message from route to blink connection.
516 presentation_service_->ListenForConnectionMessages(session_info.Clone());
517 }
496 } 518 }
497 } 519 }
498 520
499 void PresentationDispatcher::OnSessionCreated( 521 void PresentationDispatcher::OnSessionCreated(
500 std::unique_ptr<blink::WebPresentationConnectionCallbacks> callback, 522 std::unique_ptr<blink::WebPresentationConnectionCallbacks> callback,
501 blink::mojom::PresentationSessionInfoPtr session_info, 523 blink::mojom::PresentationSessionInfoPtr session_info,
502 blink::mojom::PresentationErrorPtr error) { 524 blink::mojom::PresentationErrorPtr error) {
503 DCHECK(callback); 525 DCHECK(callback);
504 if (!error.is_null()) { 526 if (!error.is_null()) {
505 DCHECK(session_info.is_null()); 527 DCHECK(session_info.is_null());
506 callback->onError(blink::WebPresentationError( 528 callback->onError(blink::WebPresentationError(
507 GetWebPresentationErrorTypeFromMojo(error->error_type), 529 GetWebPresentationErrorTypeFromMojo(error->error_type),
508 blink::WebString::fromUTF8(error->message))); 530 blink::WebString::fromUTF8(error->message)));
509 return; 531 return;
510 } 532 }
511 533
512 DCHECK(!session_info.is_null()); 534 DCHECK(!session_info.is_null());
513 presentation_service_->ListenForConnectionMessages(session_info.Clone());
514 callback->onSuccess( 535 callback->onSuccess(
515 mojo::ConvertTo<blink::WebPresentationSessionInfo>(session_info)); 536 mojo::ConvertTo<blink::WebPresentationSessionInfo>(session_info));
516 537 // Change blink connection state to 'connected' before listening to
517 auto* connection = callback->getConnection(); 538 // connection message. Remove ListenForConnectionMessage() after
518 connection->bindProxy( 539 // TODO(crbug.com/687011): use BrowserPresentationConnectionProxy to send
519 base::MakeUnique<ControllerConnectionProxy>(connection)); 540 // message from route to blink connection.
541 SetControllerConnection(session_info.Clone(), callback->getConnection());
542 presentation_service_->ListenForConnectionMessages(session_info.Clone());
520 } 543 }
521 544
522 void PresentationDispatcher::OnReceiverConnectionAvailable( 545 void PresentationDispatcher::OnReceiverConnectionAvailable(
523 blink::mojom::PresentationSessionInfoPtr session_info, 546 blink::mojom::PresentationSessionInfoPtr session_info,
524 blink::mojom::PresentationConnectionPtr controller_connection_ptr, 547 blink::mojom::PresentationConnectionPtr controller_connection_ptr,
525 blink::mojom::PresentationConnectionRequest receiver_connection_request) { 548 blink::mojom::PresentationConnectionRequest receiver_connection_request) {
526 DCHECK(receiver_); 549 DCHECK(receiver_);
550
527 // Bind receiver_connection_proxy with PresentationConnection in receiver 551 // Bind receiver_connection_proxy with PresentationConnection in receiver
528 // page. 552 // page.
529 auto* connection = receiver_->onReceiverConnectionAvailable( 553 auto* connection = receiver_->onReceiverConnectionAvailable(
530 mojo::ConvertTo<blink::WebPresentationSessionInfo>(session_info)); 554 mojo::ConvertTo<blink::WebPresentationSessionInfo>(session_info));
531 auto* receiver_connection_proxy = new ReceiverConnectionProxy(connection); 555 auto* receiver_connection_proxy = new ReceiverConnectionProxy(connection);
532 connection->bindProxy(base::WrapUnique(receiver_connection_proxy)); 556 connection->bindProxy(base::WrapUnique(receiver_connection_proxy));
533 557
534 receiver_connection_proxy->Bind(std::move(receiver_connection_request)); 558 receiver_connection_proxy->Bind(std::move(receiver_connection_request));
535 receiver_connection_proxy->BindControllerConnection( 559 receiver_connection_proxy->BindControllerConnection(
536 std::move(controller_connection_ptr)); 560 std::move(controller_connection_ptr));
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 785
762 PresentationDispatcher::ListeningStatus::ListeningStatus( 786 PresentationDispatcher::ListeningStatus::ListeningStatus(
763 const GURL& availability_url) 787 const GURL& availability_url)
764 : url(availability_url), 788 : url(availability_url),
765 last_known_availability(ScreenAvailability::UNKNOWN), 789 last_known_availability(ScreenAvailability::UNKNOWN),
766 listening_state(ListeningState::INACTIVE) {} 790 listening_state(ListeningState::INACTIVE) {}
767 791
768 PresentationDispatcher::ListeningStatus::~ListeningStatus() {} 792 PresentationDispatcher::ListeningStatus::~ListeningStatus() {}
769 793
770 } // namespace content 794 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698