Chromium Code Reviews| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 } | 83 } |
| 84 | 84 |
| 85 void OffscreenPresentationManager::OnOffscreenPresentationReceiverTerminated( | 85 void OffscreenPresentationManager::OnOffscreenPresentationReceiverTerminated( |
| 86 const std::string& presentation_id) { | 86 const std::string& presentation_id) { |
| 87 DVLOG(2) << __FUNCTION__ << " [presentation_id]: " << presentation_id; | 87 DVLOG(2) << __FUNCTION__ << " [presentation_id]: " << presentation_id; |
| 88 DCHECK(thread_checker_.CalledOnValidThread()); | 88 DCHECK(thread_checker_.CalledOnValidThread()); |
| 89 | 89 |
| 90 offscreen_presentations_.erase(presentation_id); | 90 offscreen_presentations_.erase(presentation_id); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void OffscreenPresentationManager::RegisterOffscreenPresentationRoute( | |
| 94 const std::string& presentation_id, | |
| 95 const GURL& presentation_url, | |
| 96 const MediaRoute& route) { | |
| 97 auto* presentation = | |
| 98 GetOrCreateOffscreenPresentation(presentation_id, presentation_url); | |
| 99 presentation->RegisterRoute(route); | |
| 100 } | |
| 101 | |
| 102 bool OffscreenPresentationManager::IsOffscreenPresentation( | |
| 103 const std::string& presentation_id) { | |
| 104 return base::ContainsKey(offscreen_presentations_, presentation_id); | |
| 105 } | |
| 106 | |
| 107 const MediaRoute* OffscreenPresentationManager::GetRoute( | |
| 108 const std::string& presentation_id) { | |
| 109 auto it = offscreen_presentations_.find(presentation_id); | |
| 110 if (it == offscreen_presentations_.end()) | |
| 111 return nullptr; | |
| 112 | |
| 113 return it->second->route_.get(); | |
| 114 } | |
| 115 | |
| 93 // OffscreenPresentation implementation. | 116 // OffscreenPresentation implementation. |
| 94 OffscreenPresentationManager::OffscreenPresentation::OffscreenPresentation( | 117 OffscreenPresentationManager::OffscreenPresentation::OffscreenPresentation( |
| 95 const std::string& presentation_id, | 118 const std::string& presentation_id, |
| 96 const GURL& presentation_url) | 119 const GURL& presentation_url) |
| 97 : presentation_id_(presentation_id), presentation_url_(presentation_url) {} | 120 : presentation_id_(presentation_id), presentation_url_(presentation_url) {} |
| 98 | 121 |
| 99 OffscreenPresentationManager::OffscreenPresentation::~OffscreenPresentation() {} | 122 OffscreenPresentationManager::OffscreenPresentation::~OffscreenPresentation() {} |
| 100 | 123 |
| 101 void OffscreenPresentationManager::OffscreenPresentation::RegisterController( | 124 void OffscreenPresentationManager::OffscreenPresentation::RegisterController( |
| 102 const RenderFrameHostId& render_frame_host_id, | 125 const RenderFrameHostId& render_frame_host_id, |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 127 for (auto& controller : pending_controllers_) { | 150 for (auto& controller : pending_controllers_) { |
| 128 receiver_callback.Run( | 151 receiver_callback.Run( |
| 129 content::PresentationSessionInfo(presentation_url_, presentation_id_), | 152 content::PresentationSessionInfo(presentation_url_, presentation_id_), |
| 130 std::move(controller.second->controller_connection_ptr), | 153 std::move(controller.second->controller_connection_ptr), |
| 131 std::move(controller.second->receiver_connection_request)); | 154 std::move(controller.second->receiver_connection_request)); |
| 132 } | 155 } |
| 133 receiver_callback_ = receiver_callback; | 156 receiver_callback_ = receiver_callback; |
| 134 pending_controllers_.clear(); | 157 pending_controllers_.clear(); |
| 135 } | 158 } |
| 136 | 159 |
| 160 void OffscreenPresentationManager::OffscreenPresentation::RegisterRoute( | |
| 161 const MediaRoute& route) { | |
| 162 DCHECK(!route_); | |
| 163 route_ = base::MakeUnique<MediaRoute>(route); | |
|
mark a. foltz
2017/03/01 06:26:32
Is it important that this take ownership of the pa
zhaobin
2017/03/15 18:18:56
Done.
imcheng
2017/03/16 01:42:51
I thought this was a unique_ptr because there's a
zhaobin
2017/03/16 18:50:30
Done.
| |
| 164 } | |
| 165 | |
| 137 bool OffscreenPresentationManager::OffscreenPresentation::IsValid() const { | 166 bool OffscreenPresentationManager::OffscreenPresentation::IsValid() const { |
| 138 return !(pending_controllers_.empty() && receiver_callback_.is_null()); | 167 return !(pending_controllers_.empty() && receiver_callback_.is_null()); |
| 139 } | 168 } |
| 140 | 169 |
| 141 OffscreenPresentationManager::OffscreenPresentation::ControllerConnection:: | 170 OffscreenPresentationManager::OffscreenPresentation::ControllerConnection:: |
| 142 ControllerConnection( | 171 ControllerConnection( |
| 143 content::PresentationConnectionPtr controller_connection_ptr, | 172 content::PresentationConnectionPtr controller_connection_ptr, |
| 144 content::PresentationConnectionRequest receiver_connection_request) | 173 content::PresentationConnectionRequest receiver_connection_request) |
| 145 : controller_connection_ptr(std::move(controller_connection_ptr)), | 174 : controller_connection_ptr(std::move(controller_connection_ptr)), |
| 146 receiver_connection_request(std::move(receiver_connection_request)) {} | 175 receiver_connection_request(std::move(receiver_connection_request)) {} |
| 147 | 176 |
| 148 OffscreenPresentationManager::OffscreenPresentation::ControllerConnection:: | 177 OffscreenPresentationManager::OffscreenPresentation::ControllerConnection:: |
| 149 ~ControllerConnection() {} | 178 ~ControllerConnection() {} |
| 150 | 179 |
| 151 } // namespace media_router | 180 } // namespace media_router |
| OLD | NEW |