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

Side by Side Diff: chrome/browser/media/cast_remoting_connector.cc

Issue 2947403004: [MediaRouter] Replace RouteMessage with PresentationConnectionMessage (Closed)
Patch Set: emplace_back Created 3 years, 5 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chrome/browser/media/cast_remoting_connector.h" 5 #include "chrome/browser/media/cast_remoting_connector.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "chrome/browser/media/cast_remoting_connector_messaging.h" 13 #include "chrome/browser/media/cast_remoting_connector_messaging.h"
14 #include "chrome/browser/media/cast_remoting_sender.h" 14 #include "chrome/browser/media/cast_remoting_sender.h"
15 #include "chrome/browser/media/router/media_router.h" 15 #include "chrome/browser/media/router/media_router.h"
16 #include "chrome/browser/media/router/media_router_factory.h" 16 #include "chrome/browser/media/router/media_router_factory.h"
17 #include "chrome/browser/media/router/route_message_observer.h" 17 #include "chrome/browser/media/router/route_message_observer.h"
18 #include "chrome/browser/sessions/session_tab_helper.h" 18 #include "chrome/browser/sessions/session_tab_helper.h"
19 #include "chrome/common/chrome_features.h" 19 #include "chrome/common/chrome_features.h"
20 #include "chrome/common/media_router/media_source_helper.h" 20 #include "chrome/common/media_router/media_source_helper.h"
21 #include "chrome/common/media_router/route_message.h"
22 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
23 #include "content/public/browser/render_frame_host.h" 22 #include "content/public/browser/render_frame_host.h"
24 #include "content/public/browser/render_process_host.h" 23 #include "content/public/browser/render_process_host.h"
25 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
26 #include "mojo/public/cpp/bindings/strong_binding.h" 25 #include "mojo/public/cpp/bindings/strong_binding.h"
27 26
28 using content::BrowserThread; 27 using content::BrowserThread;
29 using media::mojom::RemotingSinkCapabilities; 28 using media::mojom::RemotingSinkCapabilities;
30 using media::mojom::RemotingStartFailReason; 29 using media::mojom::RemotingStartFailReason;
31 using media::mojom::RemotingStopReason; 30 using media::mojom::RemotingStopReason;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 : public media_router::RouteMessageObserver { 115 : public media_router::RouteMessageObserver {
117 public: 116 public:
118 MessageObserver(media_router::MediaRouter* router, 117 MessageObserver(media_router::MediaRouter* router,
119 const media_router::MediaRoute::Id& route_id, 118 const media_router::MediaRoute::Id& route_id,
120 CastRemotingConnector* connector) 119 CastRemotingConnector* connector)
121 : RouteMessageObserver(router, route_id), connector_(connector) {} 120 : RouteMessageObserver(router, route_id), connector_(connector) {}
122 ~MessageObserver() final {} 121 ~MessageObserver() final {}
123 122
124 private: 123 private:
125 void OnMessagesReceived( 124 void OnMessagesReceived(
126 const std::vector<media_router::RouteMessage>& messages) final { 125 const std::vector<content::PresentationConnectionMessage>& messages)
126 final {
127 connector_->ProcessMessagesFromRoute(messages); 127 connector_->ProcessMessagesFromRoute(messages);
128 } 128 }
129 129
130 CastRemotingConnector* const connector_; 130 CastRemotingConnector* const connector_;
131 }; 131 };
132 132
133 // static 133 // static
134 const void* const CastRemotingConnector::kUserDataKey = &kUserDataKey; 134 const void* const CastRemotingConnector::kUserDataKey = &kUserDataKey;
135 135
136 // static 136 // static
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 struct Helper { 358 struct Helper {
359 static void IgnoreSendMessageResult(bool ignored) {} 359 static void IgnoreSendMessageResult(bool ignored) {}
360 }; 360 };
361 media_router::MediaRoutesObserver::router()->SendRouteMessage( 361 media_router::MediaRoutesObserver::router()->SendRouteMessage(
362 message_observer_->route_id(), message, 362 message_observer_->route_id(), message,
363 base::Bind(&Helper::IgnoreSendMessageResult)); 363 base::Bind(&Helper::IgnoreSendMessageResult));
364 } 364 }
365 } 365 }
366 366
367 void CastRemotingConnector::ProcessMessagesFromRoute( 367 void CastRemotingConnector::ProcessMessagesFromRoute(
368 const std::vector<media_router::RouteMessage>& messages) { 368 const std::vector<content::PresentationConnectionMessage>& messages) {
369 DCHECK_CURRENTLY_ON(BrowserThread::UI); 369 DCHECK_CURRENTLY_ON(BrowserThread::UI);
370 370
371 // Note: If any calls to message parsing functions are added/changed here, 371 // Note: If any calls to message parsing functions are added/changed here,
372 // please update cast_remoting_connector_fuzzertest.cc as well! 372 // please update cast_remoting_connector_fuzzertest.cc as well!
373 373
374 for (const media_router::RouteMessage& message : messages) { 374 for (const auto& message : messages) {
375 switch (message.type) { 375 if (message.is_binary()) {
376 case media_router::RouteMessage::TEXT: 376 // All binary messages are passed through to the source during an active
377 // This is a notification message from the Cast Provider, about the 377 // remoting session.
378 // execution state of the media remoting session between Chrome and the 378 if (active_bridge_)
379 // remote device. 379 active_bridge_->OnMessageFromSink(*message.data);
380 DCHECK(message.text);
381 380
382 // If this is a "start streams" acknowledgement message, the 381 continue;
383 // CastRemotingSenders should now be available to begin consuming from 382 }
384 // the data pipes.
385 if (active_bridge_ &&
386 Messaging::IsMessageForSession(
387 *message.text,
388 Messaging::kStartedStreamsMessageFormatPartial,
389 session_counter_)) {
390 if (pending_audio_sender_request_.is_pending()) {
391 cast::CastRemotingSender::FindAndBind(
392 Messaging::GetStreamIdFromStartedMessage(
393 *message.text,
394 Messaging::kStartedStreamsMessageAudioIdSpecifier),
395 std::move(pending_audio_pipe_),
396 std::move(pending_audio_sender_request_),
397 base::Bind(&CastRemotingConnector::OnDataSendFailed,
398 weak_factory_.GetWeakPtr()));
399 }
400 if (pending_video_sender_request_.is_pending()) {
401 cast::CastRemotingSender::FindAndBind(
402 Messaging::GetStreamIdFromStartedMessage(
403 *message.text,
404 Messaging::kStartedStreamsMessageVideoIdSpecifier),
405 std::move(pending_video_pipe_),
406 std::move(pending_video_sender_request_),
407 base::Bind(&CastRemotingConnector::OnDataSendFailed,
408 weak_factory_.GetWeakPtr()));
409 }
410 break;
411 }
412 383
413 // If this is a failure message, call StopRemoting(). 384 DCHECK(message.message);
miu 2017/06/29 22:07:59 nit: The |*message.message| expressions below will
imcheng 2017/07/05 18:06:24 Done.
414 if (active_bridge_ && 385 // This is a notification message from the Cast Provider, about the
415 Messaging::IsMessageForSession(*message.text, 386 // execution state of the media remoting session between Chrome and the
416 Messaging::kFailedMessageFormat, 387 // remote device.
417 session_counter_)) {
418 StopRemoting(active_bridge_, RemotingStopReason::UNEXPECTED_FAILURE);
419 break;
420 }
421 388
422 // If this is a stop acknowledgement message, indicating that the last 389 // If this is a "start streams" acknowledgement message, the
423 // session was stopped, notify all sources that the sink is once again 390 // CastRemotingSenders should now be available to begin consuming from
424 // available. 391 // the data pipes.
425 if (Messaging::IsMessageForSession(*message.text, 392 if (active_bridge_ &&
426 Messaging::kStoppedMessageFormat, 393 Messaging::IsMessageForSession(
427 session_counter_)) { 394 *message.message, Messaging::kStartedStreamsMessageFormatPartial,
428 if (active_bridge_) { 395 session_counter_)) {
429 // Hmm...The Cast Provider was in a state that disagrees with this 396 if (pending_audio_sender_request_.is_pending()) {
430 // connector. Attempt to resolve this by shutting everything down to 397 cast::CastRemotingSender::FindAndBind(
431 // effectively reset to a known state. 398 Messaging::GetStreamIdFromStartedMessage(
432 LOG(WARNING) << "BUG: Cast Provider sent 'stopped' message during " 399 *message.message,
433 "an active remoting session."; 400 Messaging::kStartedStreamsMessageAudioIdSpecifier),
434 StopRemoting(active_bridge_, 401 std::move(pending_audio_pipe_),
435 RemotingStopReason::UNEXPECTED_FAILURE); 402 std::move(pending_audio_sender_request_),
436 } 403 base::Bind(&CastRemotingConnector::OnDataSendFailed,
437 for (RemotingBridge* notifyee : bridges_) 404 weak_factory_.GetWeakPtr()));
438 notifyee->OnSinkAvailable(enabled_features_); 405 }
439 break; 406 if (pending_video_sender_request_.is_pending()) {
440 } 407 cast::CastRemotingSender::FindAndBind(
441 408 Messaging::GetStreamIdFromStartedMessage(
442 LOG(WARNING) << "BUG: Unexpected message from Cast Provider: " 409 *message.message,
443 << *message.text; 410 Messaging::kStartedStreamsMessageVideoIdSpecifier),
444 break; 411 std::move(pending_video_pipe_),
445 412 std::move(pending_video_sender_request_),
446 case media_router::RouteMessage::BINARY: // This is for the source. 413 base::Bind(&CastRemotingConnector::OnDataSendFailed,
447 DCHECK(message.binary); 414 weak_factory_.GetWeakPtr()));
448 415 }
449 // All binary messages are passed through to the source during an active 416 } else if (active_bridge_ &&
450 // remoting session. 417 Messaging::IsMessageForSession(*message.message,
451 if (active_bridge_) 418 Messaging::kFailedMessageFormat,
452 active_bridge_->OnMessageFromSink(*message.binary); 419 session_counter_)) {
453 break; 420 // If this is a failure message, call StopRemoting().
421 StopRemoting(active_bridge_, RemotingStopReason::UNEXPECTED_FAILURE);
422 } else if (Messaging::IsMessageForSession(*message.message,
423 Messaging::kStoppedMessageFormat,
424 session_counter_)) {
425 // If this is a stop acknowledgement message, indicating that the last
426 // session was stopped, notify all sources that the sink is once again
427 // available.
428 if (active_bridge_) {
429 // Hmm...The Cast Provider was in a state that disagrees with this
430 // connector. Attempt to resolve this by shutting everything down to
431 // effectively reset to a known state.
432 LOG(WARNING) << "BUG: Cast Provider sent 'stopped' message during "
433 "an active remoting session.";
434 StopRemoting(active_bridge_, RemotingStopReason::UNEXPECTED_FAILURE);
435 }
436 for (RemotingBridge* notifyee : bridges_)
437 notifyee->OnSinkAvailable(enabled_features_);
438 } else {
439 LOG(WARNING) << "BUG: Unexpected message from Cast Provider: "
440 << *message.message;
454 } 441 }
455 } 442 }
456 } 443 }
457 444
458 void CastRemotingConnector::HandleSendMessageResult(bool success) { 445 void CastRemotingConnector::HandleSendMessageResult(bool success) {
459 DCHECK_CURRENTLY_ON(BrowserThread::UI); 446 DCHECK_CURRENTLY_ON(BrowserThread::UI);
460 // A single message send failure is treated as fatal to an active remoting 447 // A single message send failure is treated as fatal to an active remoting
461 // session. 448 // session.
462 if (!success && active_bridge_) 449 if (!success && active_bridge_)
463 StopRemoting(active_bridge_, RemotingStopReason::MESSAGE_SEND_FAILED); 450 StopRemoting(active_bridge_, RemotingStopReason::MESSAGE_SEND_FAILED);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 media_router::MediaRoutesObserver::router(), route.media_route_id(), 492 media_router::MediaRoutesObserver::router(), route.media_route_id(),
506 this)); 493 this));
507 // TODO(miu): In the future, scan the route ID for sink capabilities 494 // TODO(miu): In the future, scan the route ID for sink capabilities
508 // properties and pass these to the source in the OnSinkAvailable() 495 // properties and pass these to the source in the OnSinkAvailable()
509 // notification. 496 // notification.
510 for (RemotingBridge* notifyee : bridges_) 497 for (RemotingBridge* notifyee : bridges_)
511 notifyee->OnSinkAvailable(enabled_features_); 498 notifyee->OnSinkAvailable(enabled_features_);
512 break; 499 break;
513 } 500 }
514 } 501 }
OLDNEW
« no previous file with comments | « chrome/browser/media/cast_remoting_connector.h ('k') | chrome/browser/media/cast_remoting_connector_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698