| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 presentation_id, presentation_url))) | 31 presentation_id, presentation_url))) |
| 32 .first; | 32 .first; |
| 33 } | 33 } |
| 34 return it->second.get(); | 34 return it->second.get(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 void OffscreenPresentationManager::RegisterOffscreenPresentationController( | 37 void OffscreenPresentationManager::RegisterOffscreenPresentationController( |
| 38 const std::string& presentation_id, | 38 const std::string& presentation_id, |
| 39 const GURL& presentation_url, | 39 const GURL& presentation_url, |
| 40 const RenderFrameHostId& render_frame_host_id, | 40 const RenderFrameHostId& render_frame_host_id, |
| 41 content::PresentationConnectionPtr controller) { | 41 content::PresentationConnectionPtr controller_connection_ptr, |
| 42 content::PresentationConnectionRequest receiver_connection_request) { |
| 42 DVLOG(2) << __FUNCTION__ << " [presentation_id]: " << presentation_id | 43 DVLOG(2) << __FUNCTION__ << " [presentation_id]: " << presentation_id |
| 43 << ", [render_frame_host_id]: " << render_frame_host_id.second; | 44 << ", [render_frame_host_id]: " << render_frame_host_id.second; |
| 44 DCHECK(thread_checker_.CalledOnValidThread()); | 45 DCHECK(thread_checker_.CalledOnValidThread()); |
| 45 | 46 |
| 46 auto* presentation = | 47 auto* presentation = |
| 47 GetOrCreateOffscreenPresentation(presentation_id, presentation_url); | 48 GetOrCreateOffscreenPresentation(presentation_id, presentation_url); |
| 48 presentation->RegisterController(render_frame_host_id, std::move(controller)); | 49 presentation->RegisterController(render_frame_host_id, |
| 50 std::move(controller_connection_ptr), |
| 51 std::move(receiver_connection_request)); |
| 49 } | 52 } |
| 50 | 53 |
| 51 void OffscreenPresentationManager::UnregisterOffscreenPresentationController( | 54 void OffscreenPresentationManager::UnregisterOffscreenPresentationController( |
| 52 const std::string& presentation_id, | 55 const std::string& presentation_id, |
| 53 const RenderFrameHostId& render_frame_host_id) { | 56 const RenderFrameHostId& render_frame_host_id) { |
| 54 DVLOG(2) << __FUNCTION__ << " [presentation_id]: " << presentation_id | 57 DVLOG(2) << __FUNCTION__ << " [presentation_id]: " << presentation_id |
| 55 << ", [render_frame_host_id]: " << render_frame_host_id.second; | 58 << ", [render_frame_host_id]: " << render_frame_host_id.second; |
| 56 DCHECK(thread_checker_.CalledOnValidThread()); | 59 DCHECK(thread_checker_.CalledOnValidThread()); |
| 57 | 60 |
| 58 auto it = offscreen_presentations_.find(presentation_id); | 61 auto it = offscreen_presentations_.find(presentation_id); |
| 59 if (it == offscreen_presentations_.end()) | 62 if (it == offscreen_presentations_.end()) |
| 60 return; | 63 return; |
| 61 | 64 |
| 62 // Remove presentation if no controller and receiver. | 65 // Remove presentation if no controller and receiver. |
| 63 it->second->UnregisterController(render_frame_host_id); | 66 it->second->UnregisterController(render_frame_host_id); |
| 64 if (!it->second->IsValid()) { | 67 if (!it->second->IsValid()) { |
| 65 DLOG(WARNING) << __func__ << "no receiver callback has been registered to " | 68 DLOG(WARNING) << __func__ << " no receiver callback has been registered to " |
| 66 << "[presentation_id]: " << presentation_id; | 69 << "[presentation_id]: " << presentation_id; |
| 67 offscreen_presentations_.erase(presentation_id); | 70 offscreen_presentations_.erase(presentation_id); |
| 68 } | 71 } |
| 69 } | 72 } |
| 70 | 73 |
| 71 void OffscreenPresentationManager::OnOffscreenPresentationReceiverCreated( | 74 void OffscreenPresentationManager::OnOffscreenPresentationReceiverCreated( |
| 72 const std::string& presentation_id, | 75 const std::string& presentation_id, |
| 73 const GURL& presentation_url, | 76 const GURL& presentation_url, |
| 74 const content::ReceiverConnectionAvailableCallback& receiver_callback) { | 77 const content::ReceiverConnectionAvailableCallback& receiver_callback) { |
| 75 DVLOG(2) << __FUNCTION__ << " [presentation_id]: " << presentation_id; | 78 DVLOG(2) << __FUNCTION__ << " [presentation_id]: " << presentation_id; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 90 // OffscreenPresentation implementation. | 93 // OffscreenPresentation implementation. |
| 91 OffscreenPresentationManager::OffscreenPresentation::OffscreenPresentation( | 94 OffscreenPresentationManager::OffscreenPresentation::OffscreenPresentation( |
| 92 const std::string& presentation_id, | 95 const std::string& presentation_id, |
| 93 const GURL& presentation_url) | 96 const GURL& presentation_url) |
| 94 : presentation_id_(presentation_id), presentation_url_(presentation_url) {} | 97 : presentation_id_(presentation_id), presentation_url_(presentation_url) {} |
| 95 | 98 |
| 96 OffscreenPresentationManager::OffscreenPresentation::~OffscreenPresentation() {} | 99 OffscreenPresentationManager::OffscreenPresentation::~OffscreenPresentation() {} |
| 97 | 100 |
| 98 void OffscreenPresentationManager::OffscreenPresentation::RegisterController( | 101 void OffscreenPresentationManager::OffscreenPresentation::RegisterController( |
| 99 const RenderFrameHostId& render_frame_host_id, | 102 const RenderFrameHostId& render_frame_host_id, |
| 100 content::PresentationConnectionPtr controller) { | 103 content::PresentationConnectionPtr controller_connection_ptr, |
| 104 content::PresentationConnectionRequest receiver_connection_request) { |
| 101 if (!receiver_callback_.is_null()) { | 105 if (!receiver_callback_.is_null()) { |
| 102 receiver_callback_.Run( | 106 receiver_callback_.Run( |
| 103 content::PresentationSessionInfo(presentation_url_, presentation_id_), | 107 content::PresentationSessionInfo(presentation_url_, presentation_id_), |
| 104 std::move(controller)); | 108 std::move(controller_connection_ptr), |
| 109 std::move(receiver_connection_request)); |
| 105 } else { | 110 } else { |
| 106 pending_controllers_.insert( | 111 pending_controllers_.insert(std::make_pair( |
| 107 std::make_pair(render_frame_host_id, std::move(controller))); | 112 render_frame_host_id, base::MakeUnique<ControllerConnection>( |
| 113 std::move(controller_connection_ptr), |
| 114 std::move(receiver_connection_request)))); |
| 108 } | 115 } |
| 109 } | 116 } |
| 110 | 117 |
| 111 void OffscreenPresentationManager::OffscreenPresentation::UnregisterController( | 118 void OffscreenPresentationManager::OffscreenPresentation::UnregisterController( |
| 112 const RenderFrameHostId& render_frame_host_id) { | 119 const RenderFrameHostId& render_frame_host_id) { |
| 113 pending_controllers_.erase(render_frame_host_id); | 120 pending_controllers_.erase(render_frame_host_id); |
| 114 } | 121 } |
| 115 | 122 |
| 116 void OffscreenPresentationManager::OffscreenPresentation::RegisterReceiver( | 123 void OffscreenPresentationManager::OffscreenPresentation::RegisterReceiver( |
| 117 const content::ReceiverConnectionAvailableCallback& receiver_callback) { | 124 const content::ReceiverConnectionAvailableCallback& receiver_callback) { |
| 118 DCHECK(receiver_callback_.is_null()); | 125 DCHECK(receiver_callback_.is_null()); |
| 119 | 126 |
| 120 for (auto& controller : pending_controllers_) { | 127 for (auto& controller : pending_controllers_) { |
| 121 receiver_callback.Run( | 128 receiver_callback.Run( |
| 122 content::PresentationSessionInfo(presentation_url_, presentation_id_), | 129 content::PresentationSessionInfo(presentation_url_, presentation_id_), |
| 123 std::move(controller.second)); | 130 std::move(controller.second->controller_connection_ptr), |
| 131 std::move(controller.second->receiver_connection_request)); |
| 124 } | 132 } |
| 125 receiver_callback_ = receiver_callback; | 133 receiver_callback_ = receiver_callback; |
| 126 pending_controllers_.clear(); | 134 pending_controllers_.clear(); |
| 127 } | 135 } |
| 128 | 136 |
| 129 bool OffscreenPresentationManager::OffscreenPresentation::IsValid() const { | 137 bool OffscreenPresentationManager::OffscreenPresentation::IsValid() const { |
| 130 return !(pending_controllers_.empty() && receiver_callback_.is_null()); | 138 return !(pending_controllers_.empty() && receiver_callback_.is_null()); |
| 131 } | 139 } |
| 132 | 140 |
| 141 OffscreenPresentationManager::OffscreenPresentation::ControllerConnection:: |
| 142 ControllerConnection( |
| 143 content::PresentationConnectionPtr controller_connection_ptr, |
| 144 content::PresentationConnectionRequest receiver_connection_request) |
| 145 : controller_connection_ptr(std::move(controller_connection_ptr)), |
| 146 receiver_connection_request(std::move(receiver_connection_request)) {} |
| 147 |
| 148 OffscreenPresentationManager::OffscreenPresentation::ControllerConnection:: |
| 149 ~ControllerConnection() {} |
| 150 |
| 133 } // namespace media_router | 151 } // namespace media_router |
| OLD | NEW |