| 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/offscreen_presentation_manager.h" | 5 #include "chrome/browser/media/router/offscreen_presentation_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "content/public/browser/render_frame_host.h" | 10 #include "content/public/browser/render_frame_host.h" |
| 11 #include "content/public/browser/render_process_host.h" | 11 #include "content/public/browser/render_process_host.h" |
| 12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 13 | 13 |
| 14 namespace media_router { | 14 namespace media_router { |
| 15 | 15 |
| 16 // OffscreenPresentationManager implementation. //////////////////////////////// | 16 // OffscreenPresentationManager implementation. //////////////////////////////// |
| 17 OffscreenPresentationManager::OffscreenPresentationManager() {} | 17 OffscreenPresentationManager::OffscreenPresentationManager() {} |
| 18 | 18 |
| 19 OffscreenPresentationManager::~OffscreenPresentationManager() {} | 19 OffscreenPresentationManager::~OffscreenPresentationManager() {} |
| 20 | 20 |
| 21 void OffscreenPresentationManager::RegisterOffscreenPresentationController( | 21 void OffscreenPresentationManager::RegisterOffscreenPresentationController( |
| 22 const std::string& presentation_id, | 22 const std::string& presentation_id, |
| 23 const std::string& presentation_url, |
| 23 int render_frame_id, | 24 int render_frame_id, |
| 24 content::OffscreenPresentationClient* controller) { | 25 content::OffscreenPresentationClient* controller) { |
| 25 DVLOG(2) << __FUNCTION__ << " [presentation_id]: " << presentation_id | 26 DVLOG(2) << __FUNCTION__ << " [presentation_id]: " << presentation_id |
| 26 << ", [render_frame_id]: " << render_frame_id; | 27 << ", [render_frame_id]: " << render_frame_id; |
| 27 | 28 |
| 28 auto it = offscreen_presentations_.find(presentation_id); | 29 auto it = offscreen_presentations_.find(presentation_id); |
| 29 // Create a new presentation. | 30 // Create a new presentation. |
| 30 if (it == offscreen_presentations_.end()) { | 31 if (it == offscreen_presentations_.end()) { |
| 31 it = offscreen_presentations_ | 32 it = offscreen_presentations_ |
| 32 .insert(std::make_pair( | 33 .insert(std::make_pair(presentation_id, |
| 33 presentation_id, | 34 base::MakeUnique<OffscreenPresentation>( |
| 34 base::MakeUnique<OffscreenPresentation>(presentation_id))) | 35 presentation_id, presentation_url))) |
| 35 .first; | 36 .first; |
| 36 } | 37 } |
| 37 it->second->RegisterController(render_frame_id, controller); | 38 it->second->RegisterController(render_frame_id, controller); |
| 38 } | 39 } |
| 39 | 40 |
| 40 void OffscreenPresentationManager::UnregisterOffscreenPresentationController( | 41 void OffscreenPresentationManager::UnregisterOffscreenPresentationController( |
| 41 const std::string& presentation_id, | 42 const std::string& presentation_id, |
| 42 int render_frame_id) { | 43 int render_frame_id) { |
| 43 DVLOG(2) << __FUNCTION__ << " [presentation_id]: " << presentation_id | 44 DVLOG(2) << __FUNCTION__ << " [presentation_id]: " << presentation_id |
| 44 << ", [render_frame_id]: " << render_frame_id; | 45 << ", [render_frame_id]: " << render_frame_id; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 64 it->second->RegisterReceiver(receiver_callback); | 65 it->second->RegisterReceiver(receiver_callback); |
| 65 } | 66 } |
| 66 | 67 |
| 67 void OffscreenPresentationManager::UnregisterOffscreenPresentationReceiver( | 68 void OffscreenPresentationManager::UnregisterOffscreenPresentationReceiver( |
| 68 const std::string& presentation_id) { | 69 const std::string& presentation_id) { |
| 69 DVLOG(2) << __FUNCTION__ << " [presentation_id]: " << presentation_id; | 70 DVLOG(2) << __FUNCTION__ << " [presentation_id]: " << presentation_id; |
| 70 offscreen_presentations_.erase(presentation_id); | 71 offscreen_presentations_.erase(presentation_id); |
| 71 } | 72 } |
| 72 | 73 |
| 73 // OffscreenPresentation implementation. /////////////////////////////////////// | 74 // OffscreenPresentation implementation. /////////////////////////////////////// |
| 74 OffscreenPresentation::OffscreenPresentation(const std::string& presentation_id) | 75 OffscreenPresentation::OffscreenPresentation( |
| 75 : presentation_id_(presentation_id), receiver_callback_(nullptr) {} | 76 const std::string& presentation_id, |
| 77 const std::string& presentation_url) |
| 78 : presentation_id_(presentation_id), |
| 79 presentation_url_(presentation_url), |
| 80 receiver_callback_(nullptr) {} |
| 76 | 81 |
| 77 OffscreenPresentation::~OffscreenPresentation() {} | 82 OffscreenPresentation::~OffscreenPresentation() {} |
| 78 | 83 |
| 79 void OffscreenPresentation::RegisterController( | 84 void OffscreenPresentation::RegisterController( |
| 80 int render_frame_id, | 85 int render_frame_id, |
| 81 content::OffscreenPresentationClient* controller) { | 86 content::OffscreenPresentationClient* controller) { |
| 82 // Connect controller PSImpl and receiver PSImpl. | 87 // Connect controller PSImpl and receiver PSImpl. |
| 83 if (receiver_callback_) { | 88 if (receiver_callback_) { |
| 84 receiver_callback_.Run( | 89 receiver_callback_.Run( |
| 85 content::PresentationSessionInfo(presentation_url_, presentation_id_), | 90 content::PresentationSessionInfo(presentation_url_, presentation_id_), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 98 for (const auto& controller : controllers_) { | 103 for (const auto& controller : controllers_) { |
| 99 receiver_callback.Run( | 104 receiver_callback.Run( |
| 100 content::PresentationSessionInfo(presentation_url_, presentation_id_), | 105 content::PresentationSessionInfo(presentation_url_, presentation_id_), |
| 101 controller.second); | 106 controller.second); |
| 102 } | 107 } |
| 103 receiver_callback_ = receiver_callback; | 108 receiver_callback_ = receiver_callback; |
| 104 controllers_.clear(); | 109 controllers_.clear(); |
| 105 } | 110 } |
| 106 | 111 |
| 107 } // namespace media_router | 112 } // namespace media_router |
| OLD | NEW |