Chromium Code Reviews| 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<std::string>& origins) { | 179 const std::vector<url::Origin>& 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; | 188 std::vector<url::Origin> origin_list; |
| 189 origin_list.reserve(origins.size()); | 189 origin_list.reserve(origins.size()); |
| 190 for (size_t i = 0; i < origins.size(); ++i) { | 190 for (size_t i = 0; i < origins.size(); ++i) { |
|
mark a. foltz
2017/01/24 04:04:17
Is the copying to origin_list necessary any more?
steimel
2017/01/25 19:01:11
Yes, because |origins| is a const std::vector<> an
| |
| 191 GURL origin(origins[i]); | 191 origin_list.push_back(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 } | 192 } |
| 199 | 193 |
| 200 std::vector<MediaSink> sink_list; | 194 std::vector<MediaSink> sink_list; |
| 201 sink_list.reserve(sinks.size()); | 195 sink_list.reserve(sinks.size()); |
| 202 for (size_t i = 0; i < sinks.size(); ++i) | 196 for (size_t i = 0; i < sinks.size(); ++i) |
| 203 sink_list.push_back(sinks[i].To<MediaSink>()); | 197 sink_list.push_back(sinks[i].To<MediaSink>()); |
| 204 | 198 |
| 205 auto* sinks_query = it->second.get(); | 199 auto* sinks_query = it->second.get(); |
| 206 sinks_query->has_cached_result = true; | 200 sinks_query->has_cached_result = true; |
| 207 sinks_query->origins.swap(origin_list); | 201 sinks_query->origins.swap(origin_list); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 MediaRouterMojoMetrics::RecordJoinRouteResultCode(result->result_code()); | 266 MediaRouterMojoMetrics::RecordJoinRouteResultCode(result->result_code()); |
| 273 else | 267 else |
| 274 MediaRouterMojoMetrics::RecordCreateRouteResultCode(result->result_code()); | 268 MediaRouterMojoMetrics::RecordCreateRouteResultCode(result->result_code()); |
| 275 | 269 |
| 276 RunRouteRequestCallbacks(std::move(result), callbacks); | 270 RunRouteRequestCallbacks(std::move(result), callbacks); |
| 277 } | 271 } |
| 278 | 272 |
| 279 void MediaRouterMojoImpl::CreateRoute( | 273 void MediaRouterMojoImpl::CreateRoute( |
| 280 const MediaSource::Id& source_id, | 274 const MediaSource::Id& source_id, |
| 281 const MediaSink::Id& sink_id, | 275 const MediaSink::Id& sink_id, |
| 282 const GURL& origin, | 276 const url::Origin& origin, |
| 283 content::WebContents* web_contents, | 277 content::WebContents* web_contents, |
| 284 const std::vector<MediaRouteResponseCallback>& callbacks, | 278 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 285 base::TimeDelta timeout, | 279 base::TimeDelta timeout, |
| 286 bool incognito) { | 280 bool incognito) { |
| 287 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 281 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 288 | 282 |
| 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 | |
| 298 SetWakeReason(MediaRouteProviderWakeReason::CREATE_ROUTE); | 283 SetWakeReason(MediaRouteProviderWakeReason::CREATE_ROUTE); |
| 299 int tab_id = SessionTabHelper::IdForTab(web_contents); | 284 int tab_id = SessionTabHelper::IdForTab(web_contents); |
| 300 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoCreateRoute, | 285 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoCreateRoute, |
| 301 base::Unretained(this), source_id, sink_id, | 286 base::Unretained(this), source_id, sink_id, origin, |
| 302 origin.is_empty() ? "" : origin.spec(), tab_id, | 287 tab_id, callbacks, timeout, incognito)); |
| 303 callbacks, timeout, incognito)); | |
| 304 } | 288 } |
| 305 | 289 |
| 306 void MediaRouterMojoImpl::JoinRoute( | 290 void MediaRouterMojoImpl::JoinRoute( |
| 307 const MediaSource::Id& source_id, | 291 const MediaSource::Id& source_id, |
| 308 const std::string& presentation_id, | 292 const std::string& presentation_id, |
| 309 const GURL& origin, | 293 const url::Origin& origin, |
| 310 content::WebContents* web_contents, | 294 content::WebContents* web_contents, |
| 311 const std::vector<MediaRouteResponseCallback>& callbacks, | 295 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 312 base::TimeDelta timeout, | 296 base::TimeDelta timeout, |
| 313 bool incognito) { | 297 bool incognito) { |
| 314 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 298 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 315 | 299 |
| 316 std::unique_ptr<RouteRequestResult> error_result; | 300 if (!HasJoinableRoute()) { |
| 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()) { | |
| 322 DVLOG_WITH_INSTANCE(1) << "No joinable routes"; | 301 DVLOG_WITH_INSTANCE(1) << "No joinable routes"; |
| 323 error_result = RouteRequestResult::FromError( | 302 std::unique_ptr<RouteRequestResult> result = RouteRequestResult::FromError( |
| 324 "Route not found", RouteRequestResult::ROUTE_NOT_FOUND); | 303 "Route not found", RouteRequestResult::ROUTE_NOT_FOUND); |
| 325 } | 304 MediaRouterMojoMetrics::RecordJoinRouteResultCode(result->result_code()); |
| 326 | 305 RunRouteRequestCallbacks(std::move(result), callbacks); |
| 327 if (error_result) { | |
| 328 MediaRouterMojoMetrics::RecordJoinRouteResultCode( | |
| 329 error_result->result_code()); | |
| 330 RunRouteRequestCallbacks(std::move(error_result), callbacks); | |
| 331 return; | 306 return; |
| 332 } | 307 } |
| 333 | 308 |
| 334 SetWakeReason(MediaRouteProviderWakeReason::JOIN_ROUTE); | 309 SetWakeReason(MediaRouteProviderWakeReason::JOIN_ROUTE); |
| 335 int tab_id = SessionTabHelper::IdForTab(web_contents); | 310 int tab_id = SessionTabHelper::IdForTab(web_contents); |
| 336 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoJoinRoute, | 311 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoJoinRoute, |
| 337 base::Unretained(this), source_id, presentation_id, | 312 base::Unretained(this), source_id, presentation_id, |
| 338 origin.is_empty() ? "" : origin.spec(), tab_id, | 313 origin, tab_id, callbacks, timeout, incognito)); |
| 339 callbacks, timeout, incognito)); | |
| 340 } | 314 } |
| 341 | 315 |
| 342 void MediaRouterMojoImpl::ConnectRouteByRouteId( | 316 void MediaRouterMojoImpl::ConnectRouteByRouteId( |
| 343 const MediaSource::Id& source_id, | 317 const MediaSource::Id& source_id, |
| 344 const MediaRoute::Id& route_id, | 318 const MediaRoute::Id& route_id, |
| 345 const GURL& origin, | 319 const url::Origin& origin, |
| 346 content::WebContents* web_contents, | 320 content::WebContents* web_contents, |
| 347 const std::vector<MediaRouteResponseCallback>& callbacks, | 321 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 348 base::TimeDelta timeout, | 322 base::TimeDelta timeout, |
| 349 bool incognito) { | 323 bool incognito) { |
| 350 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 324 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 351 | 325 |
| 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 | |
| 361 SetWakeReason(MediaRouteProviderWakeReason::CONNECT_ROUTE_BY_ROUTE_ID); | 326 SetWakeReason(MediaRouteProviderWakeReason::CONNECT_ROUTE_BY_ROUTE_ID); |
| 362 int tab_id = SessionTabHelper::IdForTab(web_contents); | 327 int tab_id = SessionTabHelper::IdForTab(web_contents); |
| 363 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoConnectRouteByRouteId, | 328 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoConnectRouteByRouteId, |
| 364 base::Unretained(this), source_id, route_id, | 329 base::Unretained(this), source_id, route_id, origin, |
| 365 origin.is_empty() ? "" : origin.spec(), tab_id, | 330 tab_id, callbacks, timeout, incognito)); |
| 366 callbacks, timeout, incognito)); | |
| 367 } | 331 } |
| 368 | 332 |
| 369 void MediaRouterMojoImpl::TerminateRoute(const MediaRoute::Id& route_id) { | 333 void MediaRouterMojoImpl::TerminateRoute(const MediaRoute::Id& route_id) { |
| 370 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 334 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 371 DVLOG(2) << "TerminateRoute " << route_id; | 335 DVLOG(2) << "TerminateRoute " << route_id; |
| 372 SetWakeReason(MediaRouteProviderWakeReason::TERMINATE_ROUTE); | 336 SetWakeReason(MediaRouteProviderWakeReason::TERMINATE_ROUTE); |
| 373 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoTerminateRoute, | 337 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoTerminateRoute, |
| 374 base::Unretained(this), route_id)); | 338 base::Unretained(this), route_id)); |
| 375 } | 339 } |
| 376 | 340 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 452 new_query = true; | 416 new_query = true; |
| 453 sinks_query = base::MakeUnique<MediaSinksQuery>(); | 417 sinks_query = base::MakeUnique<MediaSinksQuery>(); |
| 454 } else { | 418 } else { |
| 455 DCHECK(!sinks_query->observers.HasObserver(observer)); | 419 DCHECK(!sinks_query->observers.HasObserver(observer)); |
| 456 } | 420 } |
| 457 | 421 |
| 458 // If sink availability is UNAVAILABLE, then there is no need to call MRPM. | 422 // If sink availability is UNAVAILABLE, then there is no need to call MRPM. |
| 459 // |observer| can be immediately notified with an empty list. | 423 // |observer| can be immediately notified with an empty list. |
| 460 sinks_query->observers.AddObserver(observer); | 424 sinks_query->observers.AddObserver(observer); |
| 461 if (availability_ == mojom::MediaRouter::SinkAvailability::UNAVAILABLE) { | 425 if (availability_ == mojom::MediaRouter::SinkAvailability::UNAVAILABLE) { |
| 462 observer->OnSinksUpdated(std::vector<MediaSink>(), std::vector<GURL>()); | 426 observer->OnSinksUpdated(std::vector<MediaSink>(), |
| 427 std::vector<url::Origin>()); | |
| 463 } else { | 428 } else { |
| 464 // Need to call MRPM to start observing sinks if the query is new. | 429 // Need to call MRPM to start observing sinks if the query is new. |
| 465 if (new_query) { | 430 if (new_query) { |
| 466 SetWakeReason(MediaRouteProviderWakeReason::START_OBSERVING_MEDIA_SINKS); | 431 SetWakeReason(MediaRouteProviderWakeReason::START_OBSERVING_MEDIA_SINKS); |
| 467 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks, | 432 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStartObservingMediaSinks, |
| 468 base::Unretained(this), source_id)); | 433 base::Unretained(this), source_id)); |
| 469 } else if (sinks_query->has_cached_result) { | 434 } else if (sinks_query->has_cached_result) { |
| 470 observer->OnSinksUpdated(sinks_query->cached_sink_list, | 435 observer->OnSinksUpdated(sinks_query->cached_sink_list, |
| 471 sinks_query->origins); | 436 sinks_query->origins); |
| 472 } | 437 } |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 595 SetWakeReason( | 560 SetWakeReason( |
| 596 MediaRouteProviderWakeReason::STOP_LISTENING_FOR_ROUTE_MESSAGES); | 561 MediaRouteProviderWakeReason::STOP_LISTENING_FOR_ROUTE_MESSAGES); |
| 597 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStopListeningForRouteMessages, | 562 RunOrDefer(base::Bind(&MediaRouterMojoImpl::DoStopListeningForRouteMessages, |
| 598 base::Unretained(this), route_id)); | 563 base::Unretained(this), route_id)); |
| 599 } | 564 } |
| 600 } | 565 } |
| 601 | 566 |
| 602 void MediaRouterMojoImpl::DoCreateRoute( | 567 void MediaRouterMojoImpl::DoCreateRoute( |
| 603 const MediaSource::Id& source_id, | 568 const MediaSource::Id& source_id, |
| 604 const MediaSink::Id& sink_id, | 569 const MediaSink::Id& sink_id, |
| 605 const std::string& origin, | 570 const url::Origin& origin, |
| 606 int tab_id, | 571 int tab_id, |
| 607 const std::vector<MediaRouteResponseCallback>& callbacks, | 572 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 608 base::TimeDelta timeout, | 573 base::TimeDelta timeout, |
| 609 bool incognito) { | 574 bool incognito) { |
| 610 std::string presentation_id = MediaRouterBase::CreatePresentationId(); | 575 std::string presentation_id = MediaRouterBase::CreatePresentationId(); |
| 611 DVLOG_WITH_INSTANCE(1) << "DoCreateRoute " << source_id << "=>" << sink_id | 576 DVLOG_WITH_INSTANCE(1) << "DoCreateRoute " << source_id << "=>" << sink_id |
| 612 << ", presentation ID: " << presentation_id; | 577 << ", presentation ID: " << presentation_id; |
| 613 | |
| 614 media_route_provider_->CreateRoute( | 578 media_route_provider_->CreateRoute( |
| 615 source_id, sink_id, presentation_id, origin, tab_id, timeout, incognito, | 579 source_id, sink_id, presentation_id, origin, tab_id, timeout, incognito, |
| 616 base::Bind(&MediaRouterMojoImpl::RouteResponseReceived, | 580 base::Bind(&MediaRouterMojoImpl::RouteResponseReceived, |
| 617 base::Unretained(this), presentation_id, incognito, callbacks, | 581 base::Unretained(this), presentation_id, incognito, callbacks, |
| 618 false)); | 582 false)); |
| 619 } | 583 } |
| 620 | 584 |
| 621 void MediaRouterMojoImpl::DoJoinRoute( | 585 void MediaRouterMojoImpl::DoJoinRoute( |
| 622 const MediaSource::Id& source_id, | 586 const MediaSource::Id& source_id, |
| 623 const std::string& presentation_id, | 587 const std::string& presentation_id, |
| 624 const std::string& origin, | 588 const url::Origin& origin, |
| 625 int tab_id, | 589 int tab_id, |
| 626 const std::vector<MediaRouteResponseCallback>& callbacks, | 590 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 627 base::TimeDelta timeout, | 591 base::TimeDelta timeout, |
| 628 bool incognito) { | 592 bool incognito) { |
| 629 DVLOG_WITH_INSTANCE(1) << "DoJoinRoute " << source_id | 593 DVLOG_WITH_INSTANCE(1) << "DoJoinRoute " << source_id |
| 630 << ", presentation ID: " << presentation_id; | 594 << ", presentation ID: " << presentation_id; |
| 631 | 595 |
| 632 media_route_provider_->JoinRoute( | 596 media_route_provider_->JoinRoute( |
| 633 source_id, presentation_id, origin, tab_id, timeout, incognito, | 597 source_id, presentation_id, origin, tab_id, timeout, incognito, |
| 634 base::Bind(&MediaRouterMojoImpl::RouteResponseReceived, | 598 base::Bind(&MediaRouterMojoImpl::RouteResponseReceived, |
| 635 base::Unretained(this), presentation_id, incognito, callbacks, | 599 base::Unretained(this), presentation_id, incognito, callbacks, |
| 636 true)); | 600 true)); |
| 637 } | 601 } |
| 638 | 602 |
| 639 void MediaRouterMojoImpl::DoConnectRouteByRouteId( | 603 void MediaRouterMojoImpl::DoConnectRouteByRouteId( |
| 640 const MediaSource::Id& source_id, | 604 const MediaSource::Id& source_id, |
| 641 const MediaRoute::Id& route_id, | 605 const MediaRoute::Id& route_id, |
| 642 const std::string& origin, | 606 const url::Origin& origin, |
| 643 int tab_id, | 607 int tab_id, |
| 644 const std::vector<MediaRouteResponseCallback>& callbacks, | 608 const std::vector<MediaRouteResponseCallback>& callbacks, |
| 645 base::TimeDelta timeout, | 609 base::TimeDelta timeout, |
| 646 bool incognito) { | 610 bool incognito) { |
| 647 std::string presentation_id = MediaRouterBase::CreatePresentationId(); | 611 std::string presentation_id = MediaRouterBase::CreatePresentationId(); |
| 648 DVLOG_WITH_INSTANCE(1) << "DoConnectRouteByRouteId " << source_id | 612 DVLOG_WITH_INSTANCE(1) << "DoConnectRouteByRouteId " << source_id |
| 649 << ", route ID: " << route_id | 613 << ", route ID: " << route_id |
| 650 << ", presentation ID: " << presentation_id; | 614 << ", presentation ID: " << presentation_id; |
| 651 | 615 |
| 652 media_route_provider_->ConnectRouteByRouteId( | 616 media_route_provider_->ConnectRouteByRouteId( |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 987 base::Unretained(this), source_id)); | 951 base::Unretained(this), source_id)); |
| 988 } | 952 } |
| 989 | 953 |
| 990 void MediaRouterMojoImpl::DoUpdateMediaSinks( | 954 void MediaRouterMojoImpl::DoUpdateMediaSinks( |
| 991 const MediaSource::Id& source_id) { | 955 const MediaSource::Id& source_id) { |
| 992 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks" << source_id; | 956 DVLOG_WITH_INSTANCE(1) << "DoUpdateMediaSinks" << source_id; |
| 993 media_route_provider_->UpdateMediaSinks(source_id); | 957 media_route_provider_->UpdateMediaSinks(source_id); |
| 994 } | 958 } |
| 995 | 959 |
| 996 } // namespace media_router | 960 } // namespace media_router |
| OLD | NEW |