| 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 | 169 |
| 170 void MediaRouterMojoImpl::OnIssue(const IssueInfo& issue) { | 170 void MediaRouterMojoImpl::OnIssue(const IssueInfo& issue) { |
| 171 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 171 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 172 DVLOG_WITH_INSTANCE(1) << "OnIssue " << issue.title; | 172 DVLOG_WITH_INSTANCE(1) << "OnIssue " << issue.title; |
| 173 issue_manager_.AddIssue(issue); | 173 issue_manager_.AddIssue(issue); |
| 174 } | 174 } |
| 175 | 175 |
| 176 void MediaRouterMojoImpl::OnSinksReceived( | 176 void MediaRouterMojoImpl::OnSinksReceived( |
| 177 const std::string& media_source, | 177 const std::string& media_source, |
| 178 std::vector<mojom::MediaSinkPtr> sinks, | 178 std::vector<mojom::MediaSinkPtr> sinks, |
| 179 const std::vector<url::Origin>& origins) { | 179 const std::vector<std::string>& origins) { |
| 180 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 180 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 181 DVLOG_WITH_INSTANCE(1) << "OnSinksReceived"; | 181 DVLOG_WITH_INSTANCE(1) << "OnSinksReceived"; |
| 182 auto it = sinks_queries_.find(media_source); | 182 auto it = sinks_queries_.find(media_source); |
| 183 if (it == sinks_queries_.end()) { | 183 if (it == sinks_queries_.end()) { |
| 184 DVLOG_WITH_INSTANCE(1) << "Received sink list without MediaSinksQuery."; | 184 DVLOG_WITH_INSTANCE(1) << "Received sink list without MediaSinksQuery."; |
| 185 return; | 185 return; |
| 186 } | 186 } |
| 187 | 187 |
| 188 std::vector<GURL> origin_list; |
| 189 origin_list.reserve(origins.size()); |
| 190 for (size_t i = 0; i < origins.size(); ++i) { |
| 191 GURL origin(origins[i]); |
| 192 if (!origin.is_valid()) { |
| 193 LOG(WARNING) << "Received invalid origin: " << origin |
| 194 << ". Dropping result."; |
| 195 return; |
| 196 } |
| 197 origin_list.push_back(origin); |
| 198 } |
| 199 |
| 188 std::vector<MediaSink> sink_list; | 200 std::vector<MediaSink> sink_list; |
| 189 sink_list.reserve(sinks.size()); | 201 sink_list.reserve(sinks.size()); |
| 190 for (size_t i = 0; i < sinks.size(); ++i) | 202 for (size_t i = 0; i < sinks.size(); ++i) |
| 191 sink_list.push_back(sinks[i].To<MediaSink>()); | 203 sink_list.push_back(sinks[i].To<MediaSink>()); |
| 192 | 204 |
| 193 auto* sinks_query = it->second.get(); | 205 auto* sinks_query = it->second.get(); |
| 194 sinks_query->has_cached_result = true; | 206 sinks_query->has_cached_result = true; |
| 195 sinks_query->origins = origins; | 207 sinks_query->origins.swap(origin_list); |
| 196 sinks_query->cached_sink_list.swap(sink_list); | 208 sinks_query->cached_sink_list.swap(sink_list); |
| 197 | 209 |
| 198 if (!sinks_query->observers.might_have_observers()) { | 210 if (!sinks_query->observers.might_have_observers()) { |
| 199 DVLOG_WITH_INSTANCE(1) | 211 DVLOG_WITH_INSTANCE(1) |
| 200 << "Received sink list without any active observers: " << media_source; | 212 << "Received sink list without any active observers: " << media_source; |
| 201 } else { | 213 } else { |
| 202 for (auto& observer : sinks_query->observers) { | 214 for (auto& observer : sinks_query->observers) { |
| 203 observer.OnSinksUpdated(sinks_query->cached_sink_list, | 215 observer.OnSinksUpdated(sinks_query->cached_sink_list, |
| 204 sinks_query->origins); | 216 sinks_query->origins); |
| 205 } | 217 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 MediaRouterMojoMetrics::RecordJoinRouteResultCode(result->result_code()); | 272 MediaRouterMojoMetrics::RecordJoinRouteResultCode(result->result_code()); |
| 261 else | 273 else |
| 262 MediaRouterMojoMetrics::RecordCreateRouteResultCode(result->result_code()); | 274 MediaRouterMojoMetrics::RecordCreateRouteResultCode(result->result_code()); |
| 263 | 275 |
| 264 RunRouteRequestCallbacks(std::move(result), callbacks); | 276 RunRouteRequestCallbacks(std::move(result), callbacks); |
| 265 } | 277 } |
| 266 | 278 |
| 267 void MediaRouterMojoImpl::CreateRoute( | 279 void MediaRouterMojoImpl::CreateRoute( |
| 268 const MediaSource::Id& source_id, | 280 const MediaSource::Id& source_id, |
| 269 const MediaSink::Id& sink_id, | 281 const MediaSink::Id& sink_id, |
| 270 const url::Origin& origin, | 282 const GURL& origin, |
| 271 content::WebContents* web_contents, | 283 content::WebContents* web_contents, |
| 272 const std::vector<MediaRouteResponseCallback>& callbacks, | 284 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 273 base::TimeDelta timeout, | 285 base::TimeDelta timeout, |
| 274 bool incognito) { | 286 bool incognito) { |
| 275 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 287 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 276 | 288 |
| 289 if (!origin.is_valid()) { |
| 290 DVLOG_WITH_INSTANCE(1) << "Invalid origin: " << origin; |
| 291 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromError( |
| 292 "Invalid origin", RouteRequestResult::INVALID_ORIGIN); |
| 293 MediaRouterMojoMetrics::RecordCreateRouteResultCode(result->result_code()); |
| 294 RunRouteRequestCallbacks(std::move(result), callbacks); |
| 295 return; |
| 296 } |
| 297 |
| 277 SetWakeReason(MediaRouteProviderWakeReason::CREATE_ROUTE); | 298 SetWakeReason(MediaRouteProviderWakeReason::CREATE_ROUTE); |
| 278 int tab_id = SessionTabHelper::IdForTab(web_contents); | 299 int tab_id = SessionTabHelper::IdForTab(web_contents); |
| 279 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoCreateRoute, | 300 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoCreateRoute, |
| 280 base::Unretained(this), source_id, sink_id, origin, | 301 base::Unretained(this), source_id, sink_id, |
| 281 tab_id, callbacks, timeout, incognito)); | 302 origin.is_empty() ? "" : origin.spec(), tab_id, |
| 303 callbacks, timeout, incognito)); |
| 282 } | 304 } |
| 283 | 305 |
| 284 void MediaRouterMojoImpl::JoinRoute( | 306 void MediaRouterMojoImpl::JoinRoute( |
| 285 const MediaSource::Id& source_id, | 307 const MediaSource::Id& source_id, |
| 286 const std::string& presentation_id, | 308 const std::string& presentation_id, |
| 287 const url::Origin& origin, | 309 const GURL& origin, |
| 288 content::WebContents* web_contents, | 310 content::WebContents* web_contents, |
| 289 const std::vector<MediaRouteResponseCallback>& callbacks, | 311 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 290 base::TimeDelta timeout, | 312 base::TimeDelta timeout, |
| 291 bool incognito) { | 313 bool incognito) { |
| 292 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 314 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 293 | 315 |
| 294 if (!HasJoinableRoute()) { | 316 std::unique_ptr<RouteRequestResult> error_result; |
| 317 if (!origin.is_valid()) { |
| 318 DVLOG_WITH_INSTANCE(1) << "Invalid origin: " << origin; |
| 319 error_result = RouteRequestResult::FromError( |
| 320 "Invalid origin", RouteRequestResult::INVALID_ORIGIN); |
| 321 } else if (!HasJoinableRoute()) { |
| 295 DVLOG_WITH_INSTANCE(1) << "No joinable routes"; | 322 DVLOG_WITH_INSTANCE(1) << "No joinable routes"; |
| 296 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromError( | 323 error_result = RouteRequestResult::FromError( |
| 297 "Route not found", RouteRequestResult::ROUTE_NOT_FOUND); | 324 "Route not found", RouteRequestResult::ROUTE_NOT_FOUND); |
| 298 MediaRouterMojoMetrics::RecordJoinRouteResultCode(result->result_code()); | 325 } |
| 299 RunRouteRequestCallbacks(std::move(result), callbacks); | 326 |
| 327 if (error_result) { |
| 328 MediaRouterMojoMetrics::RecordJoinRouteResultCode( |
| 329 error_result->result_code()); |
| 330 RunRouteRequestCallbacks(std::move(error_result), callbacks); |
| 300 return; | 331 return; |
| 301 } | 332 } |
| 302 | 333 |
| 303 SetWakeReason(MediaRouteProviderWakeReason::JOIN_ROUTE); | 334 SetWakeReason(MediaRouteProviderWakeReason::JOIN_ROUTE); |
| 304 int tab_id = SessionTabHelper::IdForTab(web_contents); | 335 int tab_id = SessionTabHelper::IdForTab(web_contents); |
| 305 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoJoinRoute, | 336 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoJoinRoute, |
| 306 base::Unretained(this), source_id, presentation_id, | 337 base::Unretained(this), source_id, presentation_id, |
| 307 origin, tab_id, callbacks, timeout, incognito)); | 338 origin.is_empty() ? "" : origin.spec(), tab_id, |
| 339 callbacks, timeout, incognito)); |
| 308 } | 340 } |
| 309 | 341 |
| 310 void MediaRouterMojoImpl::ConnectRouteByRouteId( | 342 void MediaRouterMojoImpl::ConnectRouteByRouteId( |
| 311 const MediaSource::Id& source_id, | 343 const MediaSource::Id& source_id, |
| 312 const MediaRoute::Id& route_id, | 344 const MediaRoute::Id& route_id, |
| 313 const url::Origin& origin, | 345 const GURL& origin, |
| 314 content::WebContents* web_contents, | 346 content::WebContents* web_contents, |
| 315 const std::vector<MediaRouteResponseCallback>& callbacks, | 347 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 316 base::TimeDelta timeout, | 348 base::TimeDelta timeout, |
| 317 bool incognito) { | 349 bool incognito) { |
| 318 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 350 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 319 | 351 |
| 352 if (!origin.is_valid()) { |
| 353 DVLOG_WITH_INSTANCE(1) << "Invalid origin: " << origin; |
| 354 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromError( |
| 355 "Invalid origin", RouteRequestResult::INVALID_ORIGIN); |
| 356 MediaRouterMojoMetrics::RecordJoinRouteResultCode(result->result_code()); |
| 357 RunRouteRequestCallbacks(std::move(result), callbacks); |
| 358 return; |
| 359 } |
| 360 |
| 320 SetWakeReason(MediaRouteProviderWakeReason::CONNECT_ROUTE_BY_ROUTE_ID); | 361 SetWakeReason(MediaRouteProviderWakeReason::CONNECT_ROUTE_BY_ROUTE_ID); |
| 321 int tab_id = SessionTabHelper::IdForTab(web_contents); | 362 int tab_id = SessionTabHelper::IdForTab(web_contents); |
| 322 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoConnectRouteByRouteId, | 363 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoConnectRouteByRouteId, |
| 323 base::Unretained(this), source_id, route_id, origin, | 364 base::Unretained(this), source_id, route_id, |
| 324 tab_id, callbacks, timeout, incognito)); | 365 origin.is_empty() ? "" : origin.spec(), tab_id, |
| 366 callbacks, timeout, incognito)); |
| 325 } | 367 } |
| 326 | 368 |
| 327 void MediaRouterMojoImpl::TerminateRoute(const MediaRoute::Id& route_id) { | 369 void MediaRouterMojoImpl::TerminateRoute(const MediaRoute::Id& route_id) { |
| 328 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 370 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 329 DVLOG(2) << "TerminateRoute " << route_id; | 371 DVLOG(2) << "TerminateRoute " << route_id; |
| 330 SetWakeReason(MediaRouteProviderWakeReason::TERMINATE_ROUTE); | 372 SetWakeReason(MediaRouteProviderWakeReason::TERMINATE_ROUTE); |
| 331 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoTerminateRoute, | 373 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoTerminateRoute, |
| 332 base::Unretained(this), route_id)); | 374 base::Unretained(this), route_id)); |
| 333 } | 375 } |
| 334 | 376 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 new_query = true; | 452 new_query = true; |
| 411 sinks_query = base::MakeUnique<MediaSinksQuery>(); | 453 sinks_query = base::MakeUnique<MediaSinksQuery>(); |
| 412 } else { | 454 } else { |
| 413 DCHECK(!sinks_query->observers.HasObserver(observer)); | 455 DCHECK(!sinks_query->observers.HasObserver(observer)); |
| 414 } | 456 } |
| 415 | 457 |
| 416 // If sink availability is UNAVAILABLE, then there is no need to call MRPM. | 458 // If sink availability is UNAVAILABLE, then there is no need to call MRPM. |
| 417 // |observer| can be immediately notified with an empty list. | 459 // |observer| can be immediately notified with an empty list. |
| 418 sinks_query->observers.AddObserver(observer); | 460 sinks_query->observers.AddObserver(observer); |
| 419 if (availability_ == mojom::MediaRouter::SinkAvailability::UNAVAILABLE) { | 461 if (availability_ == mojom::MediaRouter::SinkAvailability::UNAVAILABLE) { |
| 420 observer->OnSinksUpdated(std::vector<MediaSink>(), | 462 observer->OnSinksUpdated(std::vector<MediaSink>(), std::vector<GURL>()); |
| 421 std::vector<url::Origin>()); | |
| 422 } else { | 463 } else { |
| 423 // Need to call MRPM to start observing sinks if the query is new. | 464 // Need to call MRPM to start observing sinks if the query is new. |
| 424 if (new_query) { | 465 if (new_query) { |
| 425 SetWakeReason(MediaRouteProviderWakeReason::START_OBSERVING_MEDIA_SINKS); | 466 SetWakeReason(MediaRouteProviderWakeReason::START_OBSERVING_MEDIA_SINKS); |
| 426 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks, | 467 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks, |
| 427 base::Unretained(this), source_id)); | 468 base::Unretained(this), source_id)); |
| 428 } else if (sinks_query->has_cached_result) { | 469 } else if (sinks_query->has_cached_result) { |
| 429 observer->OnSinksUpdated(sinks_query->cached_sink_list, | 470 observer->OnSinksUpdated(sinks_query->cached_sink_list, |
| 430 sinks_query->origins); | 471 sinks_query->origins); |
| 431 } | 472 } |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 SetWakeReason( | 595 SetWakeReason( |
| 555 MediaRouteProviderWakeReason::STOP_LISTENING_FOR_ROUTE_MESSAGES); | 596 MediaRouteProviderWakeReason::STOP_LISTENING_FOR_ROUTE_MESSAGES); |
| 556 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStopListeningForRouteMessages, | 597 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStopListeningForRouteMessages, |
| 557 base::Unretained(this), route_id)); | 598 base::Unretained(this), route_id)); |
| 558 } | 599 } |
| 559 } | 600 } |
| 560 | 601 |
| 561 void MediaRouterMojoImpl::DoCreateRoute( | 602 void MediaRouterMojoImpl::DoCreateRoute( |
| 562 const MediaSource::Id& source_id, | 603 const MediaSource::Id& source_id, |
| 563 const MediaSink::Id& sink_id, | 604 const MediaSink::Id& sink_id, |
| 564 const url::Origin& origin, | 605 const std::string& origin, |
| 565 int tab_id, | 606 int tab_id, |
| 566 const std::vector<MediaRouteResponseCallback>& callbacks, | 607 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 567 base::TimeDelta timeout, | 608 base::TimeDelta timeout, |
| 568 bool incognito) { | 609 bool incognito) { |
| 569 std::string presentation_id = MediaRouterBase::CreatePresentationId(); | 610 std::string presentation_id = MediaRouterBase::CreatePresentationId(); |
| 570 DVLOG_WITH_INSTANCE(1) << "DoCreateRoute " << source_id << "=>" << sink_id | 611 DVLOG_WITH_INSTANCE(1) << "DoCreateRoute " << source_id << "=>" << sink_id |
| 571 << ", presentation ID: " << presentation_id; | 612 << ", presentation ID: " << presentation_id; |
| 613 |
| 572 media_route_provider_->CreateRoute( | 614 media_route_provider_->CreateRoute( |
| 573 source_id, sink_id, presentation_id, origin, tab_id, timeout, incognito, | 615 source_id, sink_id, presentation_id, origin, tab_id, timeout, incognito, |
| 574 base::Bind(&MediaRouterMojoImpl::RouteResponseReceived, | 616 base::Bind(&MediaRouterMojoImpl::RouteResponseReceived, |
| 575 base::Unretained(this), presentation_id, incognito, callbacks, | 617 base::Unretained(this), presentation_id, incognito, callbacks, |
| 576 false)); | 618 false)); |
| 577 } | 619 } |
| 578 | 620 |
| 579 void MediaRouterMojoImpl::DoJoinRoute( | 621 void MediaRouterMojoImpl::DoJoinRoute( |
| 580 const MediaSource::Id& source_id, | 622 const MediaSource::Id& source_id, |
| 581 const std::string& presentation_id, | 623 const std::string& presentation_id, |
| 582 const url::Origin& origin, | 624 const std::string& origin, |
| 583 int tab_id, | 625 int tab_id, |
| 584 const std::vector<MediaRouteResponseCallback>& callbacks, | 626 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 585 base::TimeDelta timeout, | 627 base::TimeDelta timeout, |
| 586 bool incognito) { | 628 bool incognito) { |
| 587 DVLOG_WITH_INSTANCE(1) << "DoJoinRoute " << source_id | 629 DVLOG_WITH_INSTANCE(1) << "DoJoinRoute " << source_id |
| 588 << ", presentation ID: " << presentation_id; | 630 << ", presentation ID: " << presentation_id; |
| 589 | 631 |
| 590 media_route_provider_->JoinRoute( | 632 media_route_provider_->JoinRoute( |
| 591 source_id, presentation_id, origin, tab_id, timeout, incognito, | 633 source_id, presentation_id, origin, tab_id, timeout, incognito, |
| 592 base::Bind(&MediaRouterMojoImpl::RouteResponseReceived, | 634 base::Bind(&MediaRouterMojoImpl::RouteResponseReceived, |
| 593 base::Unretained(this), presentation_id, incognito, callbacks, | 635 base::Unretained(this), presentation_id, incognito, callbacks, |
| 594 true)); | 636 true)); |
| 595 } | 637 } |
| 596 | 638 |
| 597 void MediaRouterMojoImpl::DoConnectRouteByRouteId( | 639 void MediaRouterMojoImpl::DoConnectRouteByRouteId( |
| 598 const MediaSource::Id& source_id, | 640 const MediaSource::Id& source_id, |
| 599 const MediaRoute::Id& route_id, | 641 const MediaRoute::Id& route_id, |
| 600 const url::Origin& origin, | 642 const std::string& origin, |
| 601 int tab_id, | 643 int tab_id, |
| 602 const std::vector<MediaRouteResponseCallback>& callbacks, | 644 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 603 base::TimeDelta timeout, | 645 base::TimeDelta timeout, |
| 604 bool incognito) { | 646 bool incognito) { |
| 605 std::string presentation_id = MediaRouterBase::CreatePresentationId(); | 647 std::string presentation_id = MediaRouterBase::CreatePresentationId(); |
| 606 DVLOG_WITH_INSTANCE(1) << "DoConnectRouteByRouteId " << source_id | 648 DVLOG_WITH_INSTANCE(1) << "DoConnectRouteByRouteId " << source_id |
| 607 << ", route ID: " << route_id | 649 << ", route ID: " << route_id |
| 608 << ", presentation ID: " << presentation_id; | 650 << ", presentation ID: " << presentation_id; |
| 609 | 651 |
| 610 media_route_provider_->ConnectRouteByRouteId( | 652 media_route_provider_->ConnectRouteByRouteId( |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 base::Unretained(this), source_id)); | 987 base::Unretained(this), source_id)); |
| 946 } | 988 } |
| 947 | 989 |
| 948 void MediaRouterMojoImpl::DoUpdateMediaSinks( | 990 void MediaRouterMojoImpl::DoUpdateMediaSinks( |
| 949 const MediaSource::Id& source_id) { | 991 const MediaSource::Id& source_id) { |
| 950 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks" << source_id; | 992 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks" << source_id; |
| 951 media_route_provider_->UpdateMediaSinks(source_id); | 993 media_route_provider_->UpdateMediaSinks(source_id); |
| 952 } | 994 } |
| 953 | 995 |
| 954 } // namespace media_router | 996 } // namespace media_router |
| OLD | NEW |