| OLD | NEW |
| 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 "chrome/browser/media/router/mojo/media_router_mojo_impl.h" | 5 #include "chrome/browser/media/router/mojo/media_router_mojo_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 std::vector<MediaRoute::Id> joinable_routes_converted = | 267 std::vector<MediaRoute::Id> joinable_routes_converted = |
| 268 joinable_route_ids.To<std::vector<std::string>>(); | 268 joinable_route_ids.To<std::vector<std::string>>(); |
| 269 | 269 |
| 270 FOR_EACH_OBSERVER( | 270 FOR_EACH_OBSERVER( |
| 271 MediaRoutesObserver, it->second->observers, | 271 MediaRoutesObserver, it->second->observers, |
| 272 OnRoutesUpdated(routes_converted, joinable_routes_converted)); | 272 OnRoutesUpdated(routes_converted, joinable_routes_converted)); |
| 273 } | 273 } |
| 274 | 274 |
| 275 void MediaRouterMojoImpl::RouteResponseReceived( | 275 void MediaRouterMojoImpl::RouteResponseReceived( |
| 276 const std::string& presentation_id, | 276 const std::string& presentation_id, |
| 277 bool off_the_record, | 277 bool incognito, |
| 278 const std::vector<MediaRouteResponseCallback>& callbacks, | 278 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 279 interfaces::MediaRoutePtr media_route, | 279 interfaces::MediaRoutePtr media_route, |
| 280 mojo::String error_text, | 280 mojo::String error_text, |
| 281 interfaces::RouteRequestResultCode result_code) { | 281 interfaces::RouteRequestResultCode result_code) { |
| 282 std::unique_ptr<RouteRequestResult> result; | 282 std::unique_ptr<RouteRequestResult> result; |
| 283 if (media_route.is_null()) { | 283 if (media_route.is_null()) { |
| 284 // An error occurred. | 284 // An error occurred. |
| 285 DCHECK(!error_text.is_null()); | 285 DCHECK(!error_text.is_null()); |
| 286 std::string error = | 286 std::string error = |
| 287 !error_text.get().empty() ? error_text.get() : "Unknown error."; | 287 !error_text.get().empty() ? error_text.get() : "Unknown error."; |
| 288 result = RouteRequestResult::FromError( | 288 result = RouteRequestResult::FromError( |
| 289 error, mojo::RouteRequestResultCodeFromMojo(result_code)); | 289 error, mojo::RouteRequestResultCodeFromMojo(result_code)); |
| 290 } else if (media_route->off_the_record != off_the_record) { | 290 } else if (media_route->incognito != incognito) { |
| 291 std::string error = base::StringPrintf( | 291 std::string error = base::StringPrintf( |
| 292 "Mismatch in off the record status: request = %d, response = %d", | 292 "Mismatch in incognito status: request = %d, response = %d", incognito, |
| 293 off_the_record, media_route->off_the_record); | 293 media_route->incognito); |
| 294 result = RouteRequestResult::FromError( | 294 result = RouteRequestResult::FromError( |
| 295 error, RouteRequestResult::OFF_THE_RECORD_MISMATCH); | 295 error, RouteRequestResult::INCOGNITO_MISMATCH); |
| 296 } else { | 296 } else { |
| 297 result = RouteRequestResult::FromSuccess( | 297 result = RouteRequestResult::FromSuccess( |
| 298 media_route.To<std::unique_ptr<MediaRoute>>(), presentation_id); | 298 media_route.To<std::unique_ptr<MediaRoute>>(), presentation_id); |
| 299 } | 299 } |
| 300 | 300 |
| 301 // TODO(imcheng): Add UMA histogram based on result code (crbug.com/583044). | 301 // TODO(imcheng): Add UMA histogram based on result code (crbug.com/583044). |
| 302 for (const MediaRouteResponseCallback& callback : callbacks) | 302 for (const MediaRouteResponseCallback& callback : callbacks) |
| 303 callback.Run(*result); | 303 callback.Run(*result); |
| 304 } | 304 } |
| 305 | 305 |
| 306 void MediaRouterMojoImpl::CreateRoute( | 306 void MediaRouterMojoImpl::CreateRoute( |
| 307 const MediaSource::Id& source_id, | 307 const MediaSource::Id& source_id, |
| 308 const MediaSink::Id& sink_id, | 308 const MediaSink::Id& sink_id, |
| 309 const GURL& origin, | 309 const GURL& origin, |
| 310 content::WebContents* web_contents, | 310 content::WebContents* web_contents, |
| 311 const std::vector<MediaRouteResponseCallback>& callbacks, | 311 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 312 base::TimeDelta timeout, | 312 base::TimeDelta timeout, |
| 313 bool off_the_record) { | 313 bool incognito) { |
| 314 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 314 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 315 | 315 |
| 316 if (!origin.is_valid()) { | 316 if (!origin.is_valid()) { |
| 317 DVLOG_WITH_INSTANCE(1) << "Invalid origin: " << origin; | 317 DVLOG_WITH_INSTANCE(1) << "Invalid origin: " << origin; |
| 318 std::unique_ptr<RouteRequestResult> error_result( | 318 std::unique_ptr<RouteRequestResult> error_result( |
| 319 RouteRequestResult::FromError("Invalid origin", | 319 RouteRequestResult::FromError("Invalid origin", |
| 320 RouteRequestResult::INVALID_ORIGIN)); | 320 RouteRequestResult::INVALID_ORIGIN)); |
| 321 for (const MediaRouteResponseCallback& callback : callbacks) | 321 for (const MediaRouteResponseCallback& callback : callbacks) |
| 322 callback.Run(*error_result); | 322 callback.Run(*error_result); |
| 323 return; | 323 return; |
| 324 } | 324 } |
| 325 | 325 |
| 326 SetWakeReason(MediaRouteProviderWakeReason::CREATE_ROUTE); | 326 SetWakeReason(MediaRouteProviderWakeReason::CREATE_ROUTE); |
| 327 int tab_id = SessionTabHelper::IdForTab(web_contents); | 327 int tab_id = SessionTabHelper::IdForTab(web_contents); |
| 328 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoCreateRoute, | 328 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoCreateRoute, |
| 329 base::Unretained(this), source_id, sink_id, | 329 base::Unretained(this), source_id, sink_id, |
| 330 origin.is_empty() ? "" : origin.spec(), tab_id, | 330 origin.is_empty() ? "" : origin.spec(), tab_id, |
| 331 callbacks, timeout, off_the_record)); | 331 callbacks, timeout, incognito)); |
| 332 } | 332 } |
| 333 | 333 |
| 334 void MediaRouterMojoImpl::JoinRoute( | 334 void MediaRouterMojoImpl::JoinRoute( |
| 335 const MediaSource::Id& source_id, | 335 const MediaSource::Id& source_id, |
| 336 const std::string& presentation_id, | 336 const std::string& presentation_id, |
| 337 const GURL& origin, | 337 const GURL& origin, |
| 338 content::WebContents* web_contents, | 338 content::WebContents* web_contents, |
| 339 const std::vector<MediaRouteResponseCallback>& callbacks, | 339 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 340 base::TimeDelta timeout, | 340 base::TimeDelta timeout, |
| 341 bool off_the_record) { | 341 bool incognito) { |
| 342 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 342 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 343 | 343 |
| 344 std::unique_ptr<RouteRequestResult> error_result; | 344 std::unique_ptr<RouteRequestResult> error_result; |
| 345 if (!origin.is_valid()) { | 345 if (!origin.is_valid()) { |
| 346 DVLOG_WITH_INSTANCE(1) << "Invalid origin: " << origin; | 346 DVLOG_WITH_INSTANCE(1) << "Invalid origin: " << origin; |
| 347 error_result = RouteRequestResult::FromError( | 347 error_result = RouteRequestResult::FromError( |
| 348 "Invalid origin", RouteRequestResult::INVALID_ORIGIN); | 348 "Invalid origin", RouteRequestResult::INVALID_ORIGIN); |
| 349 } else if (!HasJoinableRoute()) { | 349 } else if (!HasJoinableRoute()) { |
| 350 DVLOG_WITH_INSTANCE(1) << "No joinable routes"; | 350 DVLOG_WITH_INSTANCE(1) << "No joinable routes"; |
| 351 error_result = RouteRequestResult::FromError( | 351 error_result = RouteRequestResult::FromError( |
| 352 "Route not found", RouteRequestResult::ROUTE_NOT_FOUND); | 352 "Route not found", RouteRequestResult::ROUTE_NOT_FOUND); |
| 353 } | 353 } |
| 354 | 354 |
| 355 if (error_result) { | 355 if (error_result) { |
| 356 for (const MediaRouteResponseCallback& callback : callbacks) | 356 for (const MediaRouteResponseCallback& callback : callbacks) |
| 357 callback.Run(*error_result); | 357 callback.Run(*error_result); |
| 358 return; | 358 return; |
| 359 } | 359 } |
| 360 | 360 |
| 361 SetWakeReason(MediaRouteProviderWakeReason::JOIN_ROUTE); | 361 SetWakeReason(MediaRouteProviderWakeReason::JOIN_ROUTE); |
| 362 int tab_id = SessionTabHelper::IdForTab(web_contents); | 362 int tab_id = SessionTabHelper::IdForTab(web_contents); |
| 363 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoJoinRoute, | 363 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoJoinRoute, |
| 364 base::Unretained(this), source_id, presentation_id, | 364 base::Unretained(this), source_id, presentation_id, |
| 365 origin.is_empty() ? "" : origin.spec(), tab_id, | 365 origin.is_empty() ? "" : origin.spec(), tab_id, |
| 366 callbacks, timeout, off_the_record)); | 366 callbacks, timeout, incognito)); |
| 367 } | 367 } |
| 368 | 368 |
| 369 void MediaRouterMojoImpl::ConnectRouteByRouteId( | 369 void MediaRouterMojoImpl::ConnectRouteByRouteId( |
| 370 const MediaSource::Id& source_id, | 370 const MediaSource::Id& source_id, |
| 371 const MediaRoute::Id& route_id, | 371 const MediaRoute::Id& route_id, |
| 372 const GURL& origin, | 372 const GURL& origin, |
| 373 content::WebContents* web_contents, | 373 content::WebContents* web_contents, |
| 374 const std::vector<MediaRouteResponseCallback>& callbacks, | 374 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 375 base::TimeDelta timeout, | 375 base::TimeDelta timeout, |
| 376 bool off_the_record) { | 376 bool incognito) { |
| 377 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 377 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 378 | 378 |
| 379 if (!origin.is_valid()) { | 379 if (!origin.is_valid()) { |
| 380 DVLOG_WITH_INSTANCE(1) << "Invalid origin: " << origin; | 380 DVLOG_WITH_INSTANCE(1) << "Invalid origin: " << origin; |
| 381 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromError( | 381 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromError( |
| 382 "Invalid origin", RouteRequestResult::INVALID_ORIGIN); | 382 "Invalid origin", RouteRequestResult::INVALID_ORIGIN); |
| 383 for (const MediaRouteResponseCallback& callback : callbacks) | 383 for (const MediaRouteResponseCallback& callback : callbacks) |
| 384 callback.Run(*result); | 384 callback.Run(*result); |
| 385 return; | 385 return; |
| 386 } | 386 } |
| 387 | 387 |
| 388 SetWakeReason(MediaRouteProviderWakeReason::CONNECT_ROUTE_BY_ROUTE_ID); | 388 SetWakeReason(MediaRouteProviderWakeReason::CONNECT_ROUTE_BY_ROUTE_ID); |
| 389 int tab_id = SessionTabHelper::IdForTab(web_contents); | 389 int tab_id = SessionTabHelper::IdForTab(web_contents); |
| 390 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoConnectRouteByRouteId, | 390 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoConnectRouteByRouteId, |
| 391 base::Unretained(this), source_id, route_id, | 391 base::Unretained(this), source_id, route_id, |
| 392 origin.is_empty() ? "" : origin.spec(), tab_id, | 392 origin.is_empty() ? "" : origin.spec(), tab_id, |
| 393 callbacks, timeout, off_the_record)); | 393 callbacks, timeout, incognito)); |
| 394 } | 394 } |
| 395 | 395 |
| 396 void MediaRouterMojoImpl::TerminateRoute(const MediaRoute::Id& route_id) { | 396 void MediaRouterMojoImpl::TerminateRoute(const MediaRoute::Id& route_id) { |
| 397 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 397 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 398 DVLOG(2) << "TerminateRoute " << route_id; | 398 DVLOG(2) << "TerminateRoute " << route_id; |
| 399 SetWakeReason(MediaRouteProviderWakeReason::TERMINATE_ROUTE); | 399 SetWakeReason(MediaRouteProviderWakeReason::TERMINATE_ROUTE); |
| 400 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoTerminateRoute, | 400 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoTerminateRoute, |
| 401 base::Unretained(this), route_id)); | 401 base::Unretained(this), route_id)); |
| 402 } | 402 } |
| 403 | 403 |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 } | 626 } |
| 627 } | 627 } |
| 628 | 628 |
| 629 void MediaRouterMojoImpl::DoCreateRoute( | 629 void MediaRouterMojoImpl::DoCreateRoute( |
| 630 const MediaSource::Id& source_id, | 630 const MediaSource::Id& source_id, |
| 631 const MediaSink::Id& sink_id, | 631 const MediaSink::Id& sink_id, |
| 632 const std::string& origin, | 632 const std::string& origin, |
| 633 int tab_id, | 633 int tab_id, |
| 634 const std::vector<MediaRouteResponseCallback>& callbacks, | 634 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 635 base::TimeDelta timeout, | 635 base::TimeDelta timeout, |
| 636 bool off_the_record) { | 636 bool incognito) { |
| 637 std::string presentation_id = MediaRouterBase::CreatePresentationId(); | 637 std::string presentation_id = MediaRouterBase::CreatePresentationId(); |
| 638 DVLOG_WITH_INSTANCE(1) << "DoCreateRoute " << source_id << "=>" << sink_id | 638 DVLOG_WITH_INSTANCE(1) << "DoCreateRoute " << source_id << "=>" << sink_id |
| 639 << ", presentation ID: " << presentation_id; | 639 << ", presentation ID: " << presentation_id; |
| 640 | 640 |
| 641 media_route_provider_->CreateRoute( | 641 media_route_provider_->CreateRoute( |
| 642 source_id, sink_id, presentation_id, origin, tab_id, | 642 source_id, sink_id, presentation_id, origin, tab_id, |
| 643 timeout > base::TimeDelta() ? timeout.InMilliseconds() : 0, | 643 timeout > base::TimeDelta() ? timeout.InMilliseconds() : 0, incognito, |
| 644 off_the_record, base::Bind(&MediaRouterMojoImpl::RouteResponseReceived, | 644 base::Bind(&MediaRouterMojoImpl::RouteResponseReceived, |
| 645 base::Unretained(this), presentation_id, | 645 base::Unretained(this), presentation_id, incognito, |
| 646 off_the_record, callbacks)); | 646 callbacks)); |
| 647 } | 647 } |
| 648 | 648 |
| 649 void MediaRouterMojoImpl::DoJoinRoute( | 649 void MediaRouterMojoImpl::DoJoinRoute( |
| 650 const MediaSource::Id& source_id, | 650 const MediaSource::Id& source_id, |
| 651 const std::string& presentation_id, | 651 const std::string& presentation_id, |
| 652 const std::string& origin, | 652 const std::string& origin, |
| 653 int tab_id, | 653 int tab_id, |
| 654 const std::vector<MediaRouteResponseCallback>& callbacks, | 654 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 655 base::TimeDelta timeout, | 655 base::TimeDelta timeout, |
| 656 bool off_the_record) { | 656 bool incognito) { |
| 657 DVLOG_WITH_INSTANCE(1) << "DoJoinRoute " << source_id | 657 DVLOG_WITH_INSTANCE(1) << "DoJoinRoute " << source_id |
| 658 << ", presentation ID: " << presentation_id; | 658 << ", presentation ID: " << presentation_id; |
| 659 | 659 |
| 660 media_route_provider_->JoinRoute( | 660 media_route_provider_->JoinRoute( |
| 661 source_id, presentation_id, origin, tab_id, | 661 source_id, presentation_id, origin, tab_id, |
| 662 timeout > base::TimeDelta() ? timeout.InMilliseconds() : 0, | 662 timeout > base::TimeDelta() ? timeout.InMilliseconds() : 0, incognito, |
| 663 off_the_record, base::Bind(&MediaRouterMojoImpl::RouteResponseReceived, | 663 base::Bind(&MediaRouterMojoImpl::RouteResponseReceived, |
| 664 base::Unretained(this), presentation_id, | 664 base::Unretained(this), presentation_id, incognito, |
| 665 off_the_record, callbacks)); | 665 callbacks)); |
| 666 } | 666 } |
| 667 | 667 |
| 668 void MediaRouterMojoImpl::DoConnectRouteByRouteId( | 668 void MediaRouterMojoImpl::DoConnectRouteByRouteId( |
| 669 const MediaSource::Id& source_id, | 669 const MediaSource::Id& source_id, |
| 670 const MediaRoute::Id& route_id, | 670 const MediaRoute::Id& route_id, |
| 671 const std::string& origin, | 671 const std::string& origin, |
| 672 int tab_id, | 672 int tab_id, |
| 673 const std::vector<MediaRouteResponseCallback>& callbacks, | 673 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 674 base::TimeDelta timeout, | 674 base::TimeDelta timeout, |
| 675 bool off_the_record) { | 675 bool incognito) { |
| 676 std::string presentation_id = MediaRouterBase::CreatePresentationId(); | 676 std::string presentation_id = MediaRouterBase::CreatePresentationId(); |
| 677 DVLOG_WITH_INSTANCE(1) << "DoConnectRouteByRouteId " << source_id | 677 DVLOG_WITH_INSTANCE(1) << "DoConnectRouteByRouteId " << source_id |
| 678 << ", route ID: " << route_id | 678 << ", route ID: " << route_id |
| 679 << ", presentation ID: " << presentation_id; | 679 << ", presentation ID: " << presentation_id; |
| 680 | 680 |
| 681 media_route_provider_->ConnectRouteByRouteId( | 681 media_route_provider_->ConnectRouteByRouteId( |
| 682 source_id, route_id, presentation_id, origin, tab_id, | 682 source_id, route_id, presentation_id, origin, tab_id, |
| 683 timeout > base::TimeDelta() ? timeout.InMilliseconds() : 0, | 683 timeout > base::TimeDelta() ? timeout.InMilliseconds() : 0, incognito, |
| 684 off_the_record, base::Bind(&MediaRouterMojoImpl::RouteResponseReceived, | 684 base::Bind(&MediaRouterMojoImpl::RouteResponseReceived, |
| 685 base::Unretained(this), presentation_id, | 685 base::Unretained(this), presentation_id, incognito, |
| 686 off_the_record, callbacks)); | 686 callbacks)); |
| 687 } | 687 } |
| 688 | 688 |
| 689 void MediaRouterMojoImpl::DoTerminateRoute(const MediaRoute::Id& route_id) { | 689 void MediaRouterMojoImpl::DoTerminateRoute(const MediaRoute::Id& route_id) { |
| 690 DVLOG_WITH_INSTANCE(1) << "DoTerminateRoute " << route_id; | 690 DVLOG_WITH_INSTANCE(1) << "DoTerminateRoute " << route_id; |
| 691 media_route_provider_->TerminateRoute( | 691 media_route_provider_->TerminateRoute( |
| 692 route_id, | 692 route_id, |
| 693 base::Bind(&MediaRouterMojoImpl::OnTerminateRouteResult, | 693 base::Bind(&MediaRouterMojoImpl::OnTerminateRouteResult, |
| 694 base::Unretained(this), route_id)); | 694 base::Unretained(this), route_id)); |
| 695 } | 695 } |
| 696 | 696 |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1028 base::Unretained(this), source_id)); | 1028 base::Unretained(this), source_id)); |
| 1029 } | 1029 } |
| 1030 | 1030 |
| 1031 void MediaRouterMojoImpl::DoUpdateMediaSinks( | 1031 void MediaRouterMojoImpl::DoUpdateMediaSinks( |
| 1032 const MediaSource::Id& source_id) { | 1032 const MediaSource::Id& source_id) { |
| 1033 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks" << source_id; | 1033 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks" << source_id; |
| 1034 media_route_provider_->UpdateMediaSinks(source_id); | 1034 media_route_provider_->UpdateMediaSinks(source_id); |
| 1035 } | 1035 } |
| 1036 | 1036 |
| 1037 } // namespace media_router | 1037 } // namespace media_router |
| OLD | NEW |