| 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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 error, mojo::RouteRequestResultCodeFromMojo(result_code)); | 298 error, mojo::RouteRequestResultCodeFromMojo(result_code)); |
| 299 } else if (media_route->off_the_record != off_the_record) { | 299 } else if (media_route->off_the_record != off_the_record) { |
| 300 std::string error = base::StringPrintf( | 300 std::string error = base::StringPrintf( |
| 301 "Mismatch in off the record status: request = %d, response = %d", | 301 "Mismatch in off the record status: request = %d, response = %d", |
| 302 off_the_record, media_route->off_the_record); | 302 off_the_record, media_route->off_the_record); |
| 303 result = RouteRequestResult::FromError( | 303 result = RouteRequestResult::FromError( |
| 304 error, RouteRequestResult::OFF_THE_RECORD_MISMATCH); | 304 error, RouteRequestResult::OFF_THE_RECORD_MISMATCH); |
| 305 } else { | 305 } else { |
| 306 result = RouteRequestResult::FromSuccess( | 306 result = RouteRequestResult::FromSuccess( |
| 307 media_route.To<std::unique_ptr<MediaRoute>>(), presentation_id); | 307 media_route.To<std::unique_ptr<MediaRoute>>(), presentation_id); |
| 308 if (result->route()->off_the_record()) | |
| 309 OnOffTheRecordRouteCreated(result->route()->media_route_id()); | |
| 310 } | 308 } |
| 311 | 309 |
| 312 // TODO(imcheng): Add UMA histogram based on result code (crbug.com/583044). | 310 // TODO(imcheng): Add UMA histogram based on result code (crbug.com/583044). |
| 313 for (const MediaRouteResponseCallback& callback : callbacks) | 311 for (const MediaRouteResponseCallback& callback : callbacks) |
| 314 callback.Run(*result); | 312 callback.Run(*result); |
| 315 } | 313 } |
| 316 | 314 |
| 317 void MediaRouterMojoImpl::CreateRoute( | 315 void MediaRouterMojoImpl::CreateRoute( |
| 318 const MediaSource::Id& source_id, | 316 const MediaSource::Id& source_id, |
| 319 const MediaSink::Id& sink_id, | 317 const MediaSink::Id& sink_id, |
| 320 const GURL& origin, | 318 const GURL& origin, |
| 321 content::WebContents* web_contents, | 319 content::WebContents* web_contents, |
| 322 const std::vector<MediaRouteResponseCallback>& callbacks, | 320 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 323 base::TimeDelta timeout, | 321 base::TimeDelta timeout, |
| 324 bool off_the_record) { | 322 bool off_the_record) { |
| 325 DCHECK(thread_checker_.CalledOnValidThread()); | 323 DCHECK(thread_checker_.CalledOnValidThread()); |
| 326 | 324 |
| 327 if (!origin.is_valid()) { | 325 if (!origin.is_valid()) { |
| 328 DVLOG_WITH_INSTANCE(1) << "Invalid origin: " << origin; | 326 DVLOG_WITH_INSTANCE(1) << "Invalid origin: " << origin; |
| 329 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromError( | 327 std::unique_ptr<RouteRequestResult> error_result( |
| 330 "Invalid origin", RouteRequestResult::INVALID_ORIGIN); | 328 RouteRequestResult::FromError("Invalid origin", |
| 329 RouteRequestResult::INVALID_ORIGIN)); |
| 331 for (const MediaRouteResponseCallback& callback : callbacks) | 330 for (const MediaRouteResponseCallback& callback : callbacks) |
| 332 callback.Run(*result); | 331 callback.Run(*error_result); |
| 333 return; | 332 return; |
| 334 } | 333 } |
| 335 | 334 |
| 336 SetWakeReason(MediaRouteProviderWakeReason::CREATE_ROUTE); | 335 SetWakeReason(MediaRouteProviderWakeReason::CREATE_ROUTE); |
| 337 int tab_id = SessionTabHelper::IdForTab(web_contents); | 336 int tab_id = SessionTabHelper::IdForTab(web_contents); |
| 338 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoCreateRoute, | 337 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoCreateRoute, |
| 339 base::Unretained(this), source_id, sink_id, | 338 base::Unretained(this), source_id, sink_id, |
| 340 origin.is_empty() ? "" : origin.spec(), tab_id, | 339 origin.is_empty() ? "" : origin.spec(), tab_id, |
| 341 callbacks, timeout, off_the_record)); | 340 callbacks, timeout, off_the_record)); |
| 342 } | 341 } |
| 343 | 342 |
| 344 void MediaRouterMojoImpl::JoinRoute( | 343 void MediaRouterMojoImpl::JoinRoute( |
| 345 const MediaSource::Id& source_id, | 344 const MediaSource::Id& source_id, |
| 346 const std::string& presentation_id, | 345 const std::string& presentation_id, |
| 347 const GURL& origin, | 346 const GURL& origin, |
| 348 content::WebContents* web_contents, | 347 content::WebContents* web_contents, |
| 349 const std::vector<MediaRouteResponseCallback>& callbacks, | 348 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 350 base::TimeDelta timeout, | 349 base::TimeDelta timeout, |
| 351 bool off_the_record) { | 350 bool off_the_record) { |
| 352 DCHECK(thread_checker_.CalledOnValidThread()); | 351 DCHECK(thread_checker_.CalledOnValidThread()); |
| 353 | 352 |
| 353 std::unique_ptr<RouteRequestResult> error_result; |
| 354 if (!origin.is_valid()) { | 354 if (!origin.is_valid()) { |
| 355 DVLOG_WITH_INSTANCE(1) << "Invalid origin: " << origin; | 355 DVLOG_WITH_INSTANCE(1) << "Invalid origin: " << origin; |
| 356 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromError( | 356 error_result = RouteRequestResult::FromError( |
| 357 "Invalid origin", RouteRequestResult::INVALID_ORIGIN); | 357 "Invalid origin", RouteRequestResult::INVALID_ORIGIN); |
| 358 } else if (!HasLocalRoute()) { |
| 359 DVLOG_WITH_INSTANCE(1) << "No local routes"; |
| 360 error_result = RouteRequestResult::FromError( |
| 361 "Route not found", RouteRequestResult::ROUTE_NOT_FOUND); |
| 362 } |
| 363 |
| 364 if (error_result) { |
| 358 for (const MediaRouteResponseCallback& callback : callbacks) | 365 for (const MediaRouteResponseCallback& callback : callbacks) |
| 359 callback.Run(*result); | 366 callback.Run(*error_result); |
| 360 return; | 367 return; |
| 361 } | 368 } |
| 362 | 369 |
| 363 SetWakeReason(MediaRouteProviderWakeReason::JOIN_ROUTE); | 370 SetWakeReason(MediaRouteProviderWakeReason::JOIN_ROUTE); |
| 364 int tab_id = SessionTabHelper::IdForTab(web_contents); | 371 int tab_id = SessionTabHelper::IdForTab(web_contents); |
| 365 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoJoinRoute, | 372 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoJoinRoute, |
| 366 base::Unretained(this), source_id, presentation_id, | 373 base::Unretained(this), source_id, presentation_id, |
| 367 origin.is_empty() ? "" : origin.spec(), tab_id, | 374 origin.is_empty() ? "" : origin.spec(), tab_id, |
| 368 callbacks, timeout, off_the_record)); | 375 callbacks, timeout, off_the_record)); |
| 369 } | 376 } |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 source_id, route_id, presentation_id, origin, tab_id, | 696 source_id, route_id, presentation_id, origin, tab_id, |
| 690 timeout > base::TimeDelta() ? timeout.InMilliseconds() : 0, | 697 timeout > base::TimeDelta() ? timeout.InMilliseconds() : 0, |
| 691 off_the_record, base::Bind(&MediaRouterMojoImpl::RouteResponseReceived, | 698 off_the_record, base::Bind(&MediaRouterMojoImpl::RouteResponseReceived, |
| 692 base::Unretained(this), presentation_id, | 699 base::Unretained(this), presentation_id, |
| 693 off_the_record, callbacks)); | 700 off_the_record, callbacks)); |
| 694 } | 701 } |
| 695 | 702 |
| 696 void MediaRouterMojoImpl::DoTerminateRoute(const MediaRoute::Id& route_id) { | 703 void MediaRouterMojoImpl::DoTerminateRoute(const MediaRoute::Id& route_id) { |
| 697 DVLOG_WITH_INSTANCE(1) << "DoTerminateRoute " << route_id; | 704 DVLOG_WITH_INSTANCE(1) << "DoTerminateRoute " << route_id; |
| 698 media_route_provider_->TerminateRoute(route_id); | 705 media_route_provider_->TerminateRoute(route_id); |
| 699 OnRouteTerminated(route_id); | |
| 700 } | 706 } |
| 701 | 707 |
| 702 void MediaRouterMojoImpl::DoDetachRoute(const MediaRoute::Id& route_id) { | 708 void MediaRouterMojoImpl::DoDetachRoute(const MediaRoute::Id& route_id) { |
| 703 DVLOG_WITH_INSTANCE(1) << "DoDetachRoute " << route_id; | 709 DVLOG_WITH_INSTANCE(1) << "DoDetachRoute " << route_id; |
| 704 media_route_provider_->DetachRoute(route_id); | 710 media_route_provider_->DetachRoute(route_id); |
| 705 } | 711 } |
| 706 | 712 |
| 707 void MediaRouterMojoImpl::DoSendSessionMessage( | 713 void MediaRouterMojoImpl::DoSendSessionMessage( |
| 708 const MediaRoute::Id& route_id, | 714 const MediaRoute::Id& route_id, |
| 709 const std::string& message, | 715 const std::string& message, |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1069 base::Unretained(this), source_id)); | 1075 base::Unretained(this), source_id)); |
| 1070 } | 1076 } |
| 1071 | 1077 |
| 1072 void MediaRouterMojoImpl::DoUpdateMediaSinks( | 1078 void MediaRouterMojoImpl::DoUpdateMediaSinks( |
| 1073 const MediaSource::Id& source_id) { | 1079 const MediaSource::Id& source_id) { |
| 1074 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks" << source_id; | 1080 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks" << source_id; |
| 1075 media_route_provider_->UpdateMediaSinks(source_id); | 1081 media_route_provider_->UpdateMediaSinks(source_id); |
| 1076 } | 1082 } |
| 1077 | 1083 |
| 1078 } // namespace media_router | 1084 } // namespace media_router |
| OLD | NEW |