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