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

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: 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
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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 message_request_queue_.push(base::WrapUnique(CreateSendBinaryMessageRequest( 217 message_request_queue_.push(base::WrapUnique(CreateSendBinaryMessageRequest(
218 presentationUrl, presentationId, 218 presentationUrl, presentationId,
219 blink::mojom::PresentationMessageType::BINARY, data, length, 219 blink::mojom::PresentationMessageType::BINARY, data, length,
220 connection_proxy))); 220 connection_proxy)));
221 // Start processing request if only one in the queue. 221 // Start processing request if only one in the queue.
222 if (message_request_queue_.size() == 1) 222 if (message_request_queue_.size() == 1)
223 DoSendMessage(message_request_queue_.front().get()); 223 DoSendMessage(message_request_queue_.front().get());
224 } 224 }
225 225
226 void PresentationDispatcher::DoSendMessage(SendMessageRequest* request) { 226 void PresentationDispatcher::DoSendMessage(SendMessageRequest* request) {
227 ConnectToPresentationServiceIfNeeded(); 227 DCHECK(request->connection_proxy);
228 228 static_cast<const PresentationConnectionProxy*>(request->connection_proxy)
imcheng 2017/01/31 01:53:25 Hmm... it seems a bit odd that we have to do this
zhaobin 2017/01/31 18:44:16 Done.
229 presentation_service_->SendConnectionMessage( 229 ->SendConnectionMessage(
230 std::move(request->session_info), std::move(request->message), 230 std::move(request->message),
231 base::Bind(&PresentationDispatcher::HandleSendMessageRequests, 231 base::Bind(&PresentationDispatcher::HandleSendMessageRequests,
232 base::Unretained(this))); 232 base::Unretained(this)));
233 } 233 }
234 234
235 void PresentationDispatcher::HandleSendMessageRequests(bool success) { 235 void PresentationDispatcher::HandleSendMessageRequests(bool success) {
236 // In normal cases, message_request_queue_ should not be empty at this point 236 // In normal cases, message_request_queue_ should not be empty at this point
237 // of time, but when DidCommitProvisionalLoad() is invoked before receiving 237 // of time, but when DidCommitProvisionalLoad() is invoked before receiving
238 // the callback for previous send mojo call, queue would have been emptied. 238 // the callback for previous send mojo call, queue would have been emptied.
239 if (message_request_queue_.empty()) 239 if (message_request_queue_.empty())
240 return; 240 return;
241 241
242 if (!success) { 242 if (!success) {
243 // PresentationServiceImpl is informing that Frame has been detached or 243 // PresentationServiceImpl is informing that Frame has been detached or
244 // navigated away. Invalidate all pending requests. 244 // navigated away. Invalidate all pending requests.
245 MessageRequestQueue empty; 245 MessageRequestQueue empty;
246 std::swap(message_request_queue_, empty); 246 std::swap(message_request_queue_, empty);
247 return; 247 return;
248 } 248 }
249 249
250 message_request_queue_.pop(); 250 message_request_queue_.pop();
251 if (!message_request_queue_.empty()) { 251 if (!message_request_queue_.empty()) {
252 DoSendMessage(message_request_queue_.front().get()); 252 DoSendMessage(message_request_queue_.front().get());
253 } 253 }
254 } 254 }
255 255
256 void PresentationDispatcher::SetControllerConnection(
257 blink::mojom::PresentationSessionInfoPtr session_info,
258 blink::WebPresentationConnection* connection) {
259 DCHECK(connection);
260
261 auto* controller_connection_proxy = new ControllerConnectionProxy(connection);
262 connection->bindProxy(base::WrapUnique(controller_connection_proxy));
263
264 ConnectToPresentationServiceIfNeeded();
265 presentation_service_->SetPresentationConnection(
266 session_info.Clone(), controller_connection_proxy->Bind(),
267 controller_connection_proxy->MakeRemoteRequest());
268 }
269
256 void PresentationDispatcher::closeSession( 270 void PresentationDispatcher::closeSession(
257 const blink::WebURL& presentationUrl, 271 const blink::WebURL& presentationUrl,
258 const blink::WebString& presentationId) { 272 const blink::WebString& presentationId) {
259 ConnectToPresentationServiceIfNeeded(); 273 ConnectToPresentationServiceIfNeeded();
260 presentation_service_->CloseConnection(presentationUrl, 274 presentation_service_->CloseConnection(presentationUrl,
261 presentationId.utf8()); 275 presentationId.utf8());
262 } 276 }
263 277
264 void PresentationDispatcher::terminateSession( 278 void PresentationDispatcher::terminateSession(
265 const blink::WebURL& presentationUrl, 279 const blink::WebURL& presentationUrl,
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 495
482 void PresentationDispatcher::OnDefaultSessionStarted( 496 void PresentationDispatcher::OnDefaultSessionStarted(
483 blink::mojom::PresentationSessionInfoPtr session_info) { 497 blink::mojom::PresentationSessionInfoPtr session_info) {
484 if (!controller_) 498 if (!controller_)
485 return; 499 return;
486 500
487 if (!session_info.is_null()) { 501 if (!session_info.is_null()) {
488 presentation_service_->ListenForConnectionMessages(session_info.Clone()); 502 presentation_service_->ListenForConnectionMessages(session_info.Clone());
489 auto* connection = controller_->didStartDefaultSession( 503 auto* connection = controller_->didStartDefaultSession(
490 mojo::ConvertTo<blink::WebPresentationSessionInfo>(session_info)); 504 mojo::ConvertTo<blink::WebPresentationSessionInfo>(session_info));
491 auto* controller_connection_proxy = 505 if (connection)
492 new ControllerConnectionProxy(connection); 506 SetControllerConnection(session_info.Clone(), connection);
493 connection->bindProxy(base::WrapUnique(controller_connection_proxy));
494 } 507 }
495 } 508 }
496 509
497 void PresentationDispatcher::OnSessionCreated( 510 void PresentationDispatcher::OnSessionCreated(
498 std::unique_ptr<blink::WebPresentationConnectionCallbacks> callback, 511 std::unique_ptr<blink::WebPresentationConnectionCallbacks> callback,
499 blink::mojom::PresentationSessionInfoPtr session_info, 512 blink::mojom::PresentationSessionInfoPtr session_info,
500 blink::mojom::PresentationErrorPtr error) { 513 blink::mojom::PresentationErrorPtr error) {
501 DCHECK(callback); 514 DCHECK(callback);
502 if (!error.is_null()) { 515 if (!error.is_null()) {
503 DCHECK(session_info.is_null()); 516 DCHECK(session_info.is_null());
504 callback->onError(blink::WebPresentationError( 517 callback->onError(blink::WebPresentationError(
505 GetWebPresentationErrorTypeFromMojo(error->error_type), 518 GetWebPresentationErrorTypeFromMojo(error->error_type),
506 blink::WebString::fromUTF8(error->message))); 519 blink::WebString::fromUTF8(error->message)));
507 return; 520 return;
508 } 521 }
509 522
510 DCHECK(!session_info.is_null()); 523 DCHECK(!session_info.is_null());
511 presentation_service_->ListenForConnectionMessages(session_info.Clone()); 524 presentation_service_->ListenForConnectionMessages(session_info.Clone());
512 callback->onSuccess( 525 callback->onSuccess(
513 mojo::ConvertTo<blink::WebPresentationSessionInfo>(session_info)); 526 mojo::ConvertTo<blink::WebPresentationSessionInfo>(session_info));
514 527 SetControllerConnection(session_info.Clone(), callback->getConnection());
515 auto* connection = callback->getConnection();
516 DCHECK(connection);
517 auto* controller_connection_proxy = new ControllerConnectionProxy(connection);
518 connection->bindProxy(base::WrapUnique(controller_connection_proxy));
519 } 528 }
520 529
521 void PresentationDispatcher::OnReceiverConnectionAvailable( 530 void PresentationDispatcher::OnReceiverConnectionAvailable(
522 blink::mojom::PresentationSessionInfoPtr session_info, 531 blink::mojom::PresentationSessionInfoPtr session_info,
523 blink::mojom::PresentationConnectionPtr controller_connection_ptr, 532 blink::mojom::PresentationConnectionPtr controller_connection_ptr,
524 blink::mojom::PresentationConnectionRequest receiver_connection_request) { 533 blink::mojom::PresentationConnectionRequest receiver_connection_request) {
525 DCHECK(receiver_); 534 DCHECK(receiver_);
535
526 // Bind receiver_connection_proxy with PresentationConnection in receiver 536 // Bind receiver_connection_proxy with PresentationConnection in receiver
527 // page. 537 // page.
528 auto* connection = receiver_->onReceiverConnectionAvailable( 538 auto* connection = receiver_->onReceiverConnectionAvailable(
529 mojo::ConvertTo<blink::WebPresentationSessionInfo>(session_info)); 539 mojo::ConvertTo<blink::WebPresentationSessionInfo>(session_info));
530 auto* receiver_connection_proxy = new ReceiverConnectionProxy(connection); 540 auto* receiver_connection_proxy = new ReceiverConnectionProxy(connection);
531 connection->bindProxy(base::WrapUnique(receiver_connection_proxy)); 541 connection->bindProxy(base::WrapUnique(receiver_connection_proxy));
532 542
533 receiver_connection_proxy->Bind(std::move(receiver_connection_request)); 543 receiver_connection_proxy->Bind(std::move(receiver_connection_request));
534 receiver_connection_proxy->BindControllerConnection( 544 receiver_connection_proxy->BindControllerConnection(
535 std::move(controller_connection_ptr)); 545 std::move(controller_connection_ptr));
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 770
761 PresentationDispatcher::ListeningStatus::ListeningStatus( 771 PresentationDispatcher::ListeningStatus::ListeningStatus(
762 const GURL& availability_url) 772 const GURL& availability_url)
763 : url(availability_url), 773 : url(availability_url),
764 last_known_availability(ScreenAvailability::UNKNOWN), 774 last_known_availability(ScreenAvailability::UNKNOWN),
765 listening_state(ListeningState::INACTIVE) {} 775 listening_state(ListeningState::INACTIVE) {}
766 776
767 PresentationDispatcher::ListeningStatus::~ListeningStatus() {} 777 PresentationDispatcher::ListeningStatus::~ListeningStatus() {}
768 778
769 } // namespace content 779 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698