| 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/ui/webui/media_router/media_router_ui.h" | 5 #include "chrome/browser/ui/webui/media_router/media_router_ui.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <unordered_map> | 9 #include <unordered_map> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 | 159 |
| 160 callback_.Run(routes_for_display, joinable_route_ids_for_display); | 160 callback_.Run(routes_for_display, joinable_route_ids_for_display); |
| 161 } | 161 } |
| 162 | 162 |
| 163 MediaRouterUI::MediaRouterUI(content::WebUI* web_ui) | 163 MediaRouterUI::MediaRouterUI(content::WebUI* web_ui) |
| 164 : ConstrainedWebDialogUI(web_ui), | 164 : ConstrainedWebDialogUI(web_ui), |
| 165 handler_(new MediaRouterWebUIMessageHandler(this)), | 165 handler_(new MediaRouterWebUIMessageHandler(this)), |
| 166 ui_initialized_(false), | 166 ui_initialized_(false), |
| 167 initial_routes_received_(false), |
| 167 current_route_request_id_(-1), | 168 current_route_request_id_(-1), |
| 168 route_request_counter_(0), | 169 route_request_counter_(0), |
| 169 initiator_(nullptr), | 170 initiator_(nullptr), |
| 170 router_(nullptr), | 171 router_(nullptr), |
| 171 weak_factory_(this) { | 172 weak_factory_(this) { |
| 172 // Create a WebUIDataSource containing the chrome://media-router page's | 173 // Create a WebUIDataSource containing the chrome://media-router page's |
| 173 // content. | 174 // content. |
| 174 std::unique_ptr<content::WebUIDataSource> html_source( | 175 std::unique_ptr<content::WebUIDataSource> html_source( |
| 175 content::WebUIDataSource::Create(chrome::kChromeUIMediaRouterHost)); | 176 content::WebUIDataSource::Create(chrome::kChromeUIMediaRouterHost)); |
| 176 | 177 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 } | 360 } |
| 360 | 361 |
| 361 void MediaRouterUI::UIInitialized() { | 362 void MediaRouterUI::UIInitialized() { |
| 362 TRACE_EVENT_NESTABLE_ASYNC_END0("media_router", "UI", initiator_); | 363 TRACE_EVENT_NESTABLE_ASYNC_END0("media_router", "UI", initiator_); |
| 363 ui_initialized_ = true; | 364 ui_initialized_ = true; |
| 364 | 365 |
| 365 // Register for Issue updates. | 366 // Register for Issue updates. |
| 366 if (!issues_observer_) | 367 if (!issues_observer_) |
| 367 issues_observer_.reset(new UIIssuesObserver(router_, this)); | 368 issues_observer_.reset(new UIIssuesObserver(router_, this)); |
| 368 issues_observer_->RegisterObserver(); | 369 issues_observer_->RegisterObserver(); |
| 370 |
| 371 if (initial_routes_received_) |
| 372 handler_->UpdateRoutes(routes_, joinable_route_ids_, current_cast_modes_); |
| 369 } | 373 } |
| 370 | 374 |
| 371 bool MediaRouterUI::CreateRoute(const MediaSink::Id& sink_id, | 375 bool MediaRouterUI::CreateRoute(const MediaSink::Id& sink_id, |
| 372 MediaCastMode cast_mode) { | 376 MediaCastMode cast_mode) { |
| 373 MediaSource::Id source_id; | 377 MediaSource::Id source_id; |
| 374 GURL origin; | 378 GURL origin; |
| 375 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 379 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 376 base::TimeDelta timeout; | 380 base::TimeDelta timeout; |
| 377 bool incognito; | 381 bool incognito; |
| 378 if (!SetRouteParameters(sink_id, cast_mode, &source_id, &origin, | 382 if (!SetRouteParameters(sink_id, cast_mode, &source_id, &origin, |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 std::sort(sinks_.begin(), sinks_.end(), | 519 std::sort(sinks_.begin(), sinks_.end(), |
| 516 [collator_ptr](const MediaSinkWithCastModes& sink1, | 520 [collator_ptr](const MediaSinkWithCastModes& sink1, |
| 517 const MediaSinkWithCastModes& sink2) { | 521 const MediaSinkWithCastModes& sink2) { |
| 518 return sink1.sink.CompareUsingCollator(sink2.sink, collator_ptr); | 522 return sink1.sink.CompareUsingCollator(sink2.sink, collator_ptr); |
| 519 }); | 523 }); |
| 520 | 524 |
| 521 if (ui_initialized_) handler_->UpdateSinks(sinks_); | 525 if (ui_initialized_) handler_->UpdateSinks(sinks_); |
| 522 } | 526 } |
| 523 | 527 |
| 524 void MediaRouterUI::SetIssue(const Issue* issue) { | 528 void MediaRouterUI::SetIssue(const Issue* issue) { |
| 525 if (ui_initialized_) handler_->UpdateIssue(issue); | 529 if (ui_initialized_) |
| 530 handler_->UpdateIssue(issue); |
| 526 } | 531 } |
| 527 | 532 |
| 528 void MediaRouterUI::OnRoutesUpdated( | 533 void MediaRouterUI::OnRoutesUpdated( |
| 529 const std::vector<MediaRoute>& routes, | 534 const std::vector<MediaRoute>& routes, |
| 530 const std::vector<MediaRoute::Id>& joinable_route_ids) { | 535 const std::vector<MediaRoute::Id>& joinable_route_ids) { |
| 531 routes_ = routes; | 536 routes_ = routes; |
| 532 joinable_route_ids_ = joinable_route_ids; | 537 joinable_route_ids_ = joinable_route_ids; |
| 533 | 538 |
| 534 std::unordered_map<MediaSource::Id, MediaCastMode> available_source_map; | 539 std::unordered_map<MediaSource::Id, MediaCastMode> available_source_map; |
| 535 for (const auto& cast_mode : cast_modes_) { | 540 for (const auto& cast_mode : cast_modes_) { |
| 536 for (const auto& source : | 541 for (const auto& source : |
| 537 query_result_manager_->GetSourcesForCastMode(cast_mode)) { | 542 query_result_manager_->GetSourcesForCastMode(cast_mode)) { |
| 538 available_source_map.insert(std::make_pair(source.id(), cast_mode)); | 543 available_source_map.insert(std::make_pair(source.id(), cast_mode)); |
| 539 } | 544 } |
| 540 } | 545 } |
| 541 | 546 |
| 542 current_cast_modes_.clear(); | 547 current_cast_modes_.clear(); |
| 543 for (const auto& route : routes) { | 548 for (const auto& route : routes) { |
| 544 auto source_entry = available_source_map.find(route.media_source().id()); | 549 auto source_entry = available_source_map.find(route.media_source().id()); |
| 545 if (source_entry != available_source_map.end()) { | 550 if (source_entry != available_source_map.end()) { |
| 546 current_cast_modes_.insert( | 551 current_cast_modes_.insert( |
| 547 std::make_pair(route.media_route_id(), source_entry->second)); | 552 std::make_pair(route.media_route_id(), source_entry->second)); |
| 548 } | 553 } |
| 549 } | 554 } |
| 550 | 555 |
| 551 if (ui_initialized_) | 556 if (ui_initialized_) |
| 552 handler_->UpdateRoutes(routes_, joinable_route_ids_, current_cast_modes_); | 557 handler_->UpdateRoutes(routes_, joinable_route_ids_, current_cast_modes_); |
| 558 if (!initial_routes_received_) |
| 559 initial_routes_received_ = true; |
| 553 } | 560 } |
| 554 | 561 |
| 555 void MediaRouterUI::OnRouteResponseReceived( | 562 void MediaRouterUI::OnRouteResponseReceived( |
| 556 int route_request_id, | 563 int route_request_id, |
| 557 const MediaSink::Id& sink_id, | 564 const MediaSink::Id& sink_id, |
| 558 MediaCastMode cast_mode, | 565 MediaCastMode cast_mode, |
| 559 const base::string16& presentation_request_source_name, | 566 const base::string16& presentation_request_source_name, |
| 560 const RouteRequestResult& result) { | 567 const RouteRequestResult& result) { |
| 561 DVLOG(1) << "OnRouteResponseReceived"; | 568 DVLOG(1) << "OnRouteResponseReceived"; |
| 562 // If we receive a new route that we aren't expecting, do nothing. | 569 // If we receive a new route that we aren't expecting, do nothing. |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 base::Time::Now() - start_time_); | 697 base::Time::Now() - start_time_); |
| 691 start_time_ = base::Time(); | 698 start_time_ = base::Time(); |
| 692 } | 699 } |
| 693 } | 700 } |
| 694 | 701 |
| 695 void MediaRouterUI::UpdateMaxDialogHeight(int height) { | 702 void MediaRouterUI::UpdateMaxDialogHeight(int height) { |
| 696 handler_->UpdateMaxDialogHeight(height); | 703 handler_->UpdateMaxDialogHeight(height); |
| 697 } | 704 } |
| 698 | 705 |
| 699 } // namespace media_router | 706 } // namespace media_router |
| OLD | NEW |