| 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/presentation_service_delegate_impl.h" | 5 #include "chrome/browser/media/router/presentation_service_delegate_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/containers/scoped_ptr_hash_map.h" | 9 #include "base/containers/scoped_ptr_hash_map.h" |
| 10 #include "base/containers/small_map.h" | 10 #include "base/containers/small_map.h" |
| 11 #include "base/guid.h" | 11 #include "base/guid.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "chrome/browser/media/router/create_presentation_connection_request.h" | 14 #include "chrome/browser/media/router/create_presentation_connection_request.h" |
| 15 #include "chrome/browser/media/router/media_route.h" | 15 #include "chrome/browser/media/router/media_route.h" |
| 16 #include "chrome/browser/media/router/media_router.h" | 16 #include "chrome/browser/media/router/media_router.h" |
| 17 #include "chrome/browser/media/router/media_router_dialog_controller.h" | 17 #include "chrome/browser/media/router/media_router_dialog_controller.h" |
| 18 #include "chrome/browser/media/router/media_router_factory.h" | 18 #include "chrome/browser/media/router/media_router_factory.h" |
| 19 #include "chrome/browser/media/router/media_sink.h" | 19 #include "chrome/browser/media/router/media_sink.h" |
| 20 #include "chrome/browser/media/router/media_source_helper.h" | 20 #include "chrome/browser/media/router/media_source_helper.h" |
| 21 #include "chrome/browser/media/router/presentation_media_sinks_observer.h" | 21 #include "chrome/browser/media/router/presentation_media_sinks_observer.h" |
| 22 #include "chrome/browser/media/router/presentation_session_messages_observer.h" | 22 #include "chrome/browser/media/router/presentation_session_messages_observer.h" |
| 23 #include "chrome/browser/media/router/presentation_session_state_observer.h" | |
| 24 #include "chrome/browser/sessions/session_tab_helper.h" | 23 #include "chrome/browser/sessions/session_tab_helper.h" |
| 25 #include "content/public/browser/presentation_screen_availability_listener.h" | 24 #include "content/public/browser/presentation_screen_availability_listener.h" |
| 26 #include "content/public/browser/presentation_session.h" | 25 #include "content/public/browser/presentation_session.h" |
| 27 #include "content/public/browser/render_frame_host.h" | 26 #include "content/public/browser/render_frame_host.h" |
| 28 #include "content/public/browser/render_process_host.h" | 27 #include "content/public/browser/render_process_host.h" |
| 29 | 28 |
| 30 DEFINE_WEB_CONTENTS_USER_DATA_KEY( | 29 DEFINE_WEB_CONTENTS_USER_DATA_KEY( |
| 31 media_router::PresentationServiceDelegateImpl); | 30 media_router::PresentationServiceDelegateImpl); |
| 32 | 31 |
| 33 using content::RenderFrameHost; | 32 using content::RenderFrameHost; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 ~PresentationFrame(); | 67 ~PresentationFrame(); |
| 69 | 68 |
| 70 // Mirror corresponding APIs in PresentationServiceDelegateImpl. | 69 // Mirror corresponding APIs in PresentationServiceDelegateImpl. |
| 71 bool SetScreenAvailabilityListener( | 70 bool SetScreenAvailabilityListener( |
| 72 content::PresentationScreenAvailabilityListener* listener); | 71 content::PresentationScreenAvailabilityListener* listener); |
| 73 bool RemoveScreenAvailabilityListener( | 72 bool RemoveScreenAvailabilityListener( |
| 74 content::PresentationScreenAvailabilityListener* listener); | 73 content::PresentationScreenAvailabilityListener* listener); |
| 75 bool HasScreenAvailabilityListenerForTest( | 74 bool HasScreenAvailabilityListenerForTest( |
| 76 const MediaSource::Id& source_id) const; | 75 const MediaSource::Id& source_id) const; |
| 77 std::string GetDefaultPresentationId() const; | 76 std::string GetDefaultPresentationId() const; |
| 78 void ListenForSessionStateChange( | 77 void ListenForConnectionStateChange( |
| 79 const content::SessionStateChangedCallback& state_changed_cb); | 78 const content::PresentationSessionInfo& connection, |
| 79 const content::PresentationConnectionStateChangedCallback& |
| 80 state_changed_cb); |
| 80 void ListenForSessionMessages( | 81 void ListenForSessionMessages( |
| 81 const content::PresentationSessionInfo& session, | 82 const content::PresentationSessionInfo& session, |
| 82 const content::PresentationSessionMessageCallback& message_cb); | 83 const content::PresentationSessionMessageCallback& message_cb); |
| 83 | 84 |
| 84 void Reset(); | 85 void Reset(); |
| 85 | 86 |
| 86 const MediaRoute::Id GetRouteId(const std::string& presentation_id) const; | 87 const MediaRoute::Id GetRouteId(const std::string& presentation_id) const; |
| 87 const std::vector<MediaRoute::Id> GetRouteIds() const; | 88 const std::vector<MediaRoute::Id> GetRouteIds() const; |
| 88 void OnPresentationSessionClosed(const std::string& presentation_id); | |
| 89 | 89 |
| 90 void OnPresentationSessionStarted( | 90 void OnPresentationSessionStarted( |
| 91 const content::PresentationSessionInfo& session, | 91 const content::PresentationSessionInfo& session, |
| 92 const MediaRoute::Id& route_id); | 92 const MediaRoute::Id& route_id); |
| 93 void OnPresentationServiceDelegateDestroyed() const; | 93 void OnPresentationServiceDelegateDestroyed() const; |
| 94 | 94 |
| 95 void set_delegate_observer(DelegateObserver* observer) { | 95 void set_delegate_observer(DelegateObserver* observer) { |
| 96 delegate_observer_ = observer; | 96 delegate_observer_ = observer; |
| 97 } | 97 } |
| 98 | 98 |
| 99 private: | 99 private: |
| 100 MediaSource GetMediaSourceFromListener( | 100 MediaSource GetMediaSourceFromListener( |
| 101 content::PresentationScreenAvailabilityListener* listener) const; | 101 content::PresentationScreenAvailabilityListener* listener) const; |
| 102 MediaRouteIdToPresentationSessionMapping route_id_to_presentation_; | |
| 103 base::SmallMap<std::map<std::string, MediaRoute::Id>> | 102 base::SmallMap<std::map<std::string, MediaRoute::Id>> |
| 104 presentation_id_to_route_id_; | 103 presentation_id_to_route_id_; |
| 105 scoped_ptr<PresentationMediaSinksObserver> sinks_observer_; | 104 scoped_ptr<PresentationMediaSinksObserver> sinks_observer_; |
| 106 scoped_ptr<PresentationSessionStateObserver> session_state_observer_; | 105 base::ScopedPtrHashMap<MediaRoute::Id, |
| 106 scoped_ptr<PresentationConnectionStateSubscription>> |
| 107 connection_state_subscriptions_; |
| 107 ScopedVector<PresentationSessionMessagesObserver> session_messages_observers_; | 108 ScopedVector<PresentationSessionMessagesObserver> session_messages_observers_; |
| 108 | 109 |
| 109 // References to the owning WebContents, and the corresponding MediaRouter. | 110 // References to the owning WebContents, and the corresponding MediaRouter. |
| 110 const content::WebContents* web_contents_; | 111 const content::WebContents* web_contents_; |
| 111 MediaRouter* router_; | 112 MediaRouter* router_; |
| 112 | 113 |
| 113 DelegateObserver* delegate_observer_; | 114 DelegateObserver* delegate_observer_; |
| 114 }; | 115 }; |
| 115 | 116 |
| 116 PresentationFrame::PresentationFrame(content::WebContents* web_contents, | 117 PresentationFrame::PresentationFrame(content::WebContents* web_contents, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 127 | 128 |
| 128 void PresentationFrame::OnPresentationServiceDelegateDestroyed() const { | 129 void PresentationFrame::OnPresentationServiceDelegateDestroyed() const { |
| 129 if (delegate_observer_) | 130 if (delegate_observer_) |
| 130 delegate_observer_->OnDelegateDestroyed(); | 131 delegate_observer_->OnDelegateDestroyed(); |
| 131 } | 132 } |
| 132 | 133 |
| 133 void PresentationFrame::OnPresentationSessionStarted( | 134 void PresentationFrame::OnPresentationSessionStarted( |
| 134 const content::PresentationSessionInfo& session, | 135 const content::PresentationSessionInfo& session, |
| 135 const MediaRoute::Id& route_id) { | 136 const MediaRoute::Id& route_id) { |
| 136 presentation_id_to_route_id_[session.presentation_id] = route_id; | 137 presentation_id_to_route_id_[session.presentation_id] = route_id; |
| 137 route_id_to_presentation_.Add(route_id, session); | |
| 138 if (session_state_observer_) | |
| 139 session_state_observer_->OnPresentationSessionConnected(route_id); | |
| 140 } | |
| 141 | |
| 142 void PresentationFrame::OnPresentationSessionClosed( | |
| 143 const std::string& presentation_id) { | |
| 144 auto it = presentation_id_to_route_id_.find(presentation_id); | |
| 145 if (it != presentation_id_to_route_id_.end()) { | |
| 146 route_id_to_presentation_.Remove(it->second); | |
| 147 presentation_id_to_route_id_.erase(it); | |
| 148 } | |
| 149 // TODO(imcheng): Notify |session_state_observer_|? | |
| 150 } | 138 } |
| 151 | 139 |
| 152 const MediaRoute::Id PresentationFrame::GetRouteId( | 140 const MediaRoute::Id PresentationFrame::GetRouteId( |
| 153 const std::string& presentation_id) const { | 141 const std::string& presentation_id) const { |
| 154 auto it = presentation_id_to_route_id_.find(presentation_id); | 142 auto it = presentation_id_to_route_id_.find(presentation_id); |
| 155 return it != presentation_id_to_route_id_.end() ? it->second : ""; | 143 return it != presentation_id_to_route_id_.end() ? it->second : ""; |
| 156 } | 144 } |
| 157 | 145 |
| 158 const std::vector<MediaRoute::Id> PresentationFrame::GetRouteIds() const { | 146 const std::vector<MediaRoute::Id> PresentationFrame::GetRouteIds() const { |
| 159 std::vector<MediaRoute::Id> route_ids; | 147 std::vector<MediaRoute::Id> route_ids; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 188 } | 176 } |
| 189 return false; | 177 return false; |
| 190 } | 178 } |
| 191 | 179 |
| 192 bool PresentationFrame::HasScreenAvailabilityListenerForTest( | 180 bool PresentationFrame::HasScreenAvailabilityListenerForTest( |
| 193 const MediaSource::Id& source_id) const { | 181 const MediaSource::Id& source_id) const { |
| 194 return sinks_observer_ && sinks_observer_->source().id() == source_id; | 182 return sinks_observer_ && sinks_observer_->source().id() == source_id; |
| 195 } | 183 } |
| 196 | 184 |
| 197 void PresentationFrame::Reset() { | 185 void PresentationFrame::Reset() { |
| 198 route_id_to_presentation_.Clear(); | |
| 199 | |
| 200 for (const auto& pid_route_id : presentation_id_to_route_id_) | 186 for (const auto& pid_route_id : presentation_id_to_route_id_) |
| 201 router_->OnPresentationSessionDetached(pid_route_id.second); | 187 router_->OnPresentationSessionDetached(pid_route_id.second); |
| 202 | 188 |
| 203 presentation_id_to_route_id_.clear(); | 189 presentation_id_to_route_id_.clear(); |
| 204 sinks_observer_.reset(); | 190 sinks_observer_.reset(); |
| 205 if (session_state_observer_) | 191 connection_state_subscriptions_.clear(); |
| 206 session_state_observer_->Reset(); | |
| 207 | |
| 208 session_messages_observers_.clear(); | 192 session_messages_observers_.clear(); |
| 209 } | 193 } |
| 210 | 194 |
| 211 void PresentationFrame::ListenForSessionStateChange( | 195 void PresentationFrame::ListenForConnectionStateChange( |
| 212 const content::SessionStateChangedCallback& state_changed_cb) { | 196 const content::PresentationSessionInfo& connection, |
| 213 CHECK(!session_state_observer_.get()); | 197 const content::PresentationConnectionStateChangedCallback& |
| 214 session_state_observer_.reset(new PresentationSessionStateObserver( | 198 state_changed_cb) { |
| 215 state_changed_cb, &route_id_to_presentation_, router_)); | 199 auto it = presentation_id_to_route_id_.find(connection.presentation_id); |
| 200 if (it == presentation_id_to_route_id_.end()) { |
| 201 DLOG(ERROR) << __FUNCTION__ << "route id not found for presentation: " |
| 202 << connection.presentation_id; |
| 203 return; |
| 204 } |
| 205 |
| 206 const MediaRoute::Id& route_id = it->second; |
| 207 if (connection_state_subscriptions_.contains(route_id)) { |
| 208 DLOG(ERROR) << __FUNCTION__ << "Already listening connection state change " |
| 209 "for route: " |
| 210 << route_id; |
| 211 return; |
| 212 } |
| 213 |
| 214 connection_state_subscriptions_.add( |
| 215 route_id, router_->AddPresentationConnectionStateChangedCallback( |
| 216 it->second, state_changed_cb)); |
| 216 } | 217 } |
| 217 | 218 |
| 218 void PresentationFrame::ListenForSessionMessages( | 219 void PresentationFrame::ListenForSessionMessages( |
| 219 const content::PresentationSessionInfo& session, | 220 const content::PresentationSessionInfo& session, |
| 220 const content::PresentationSessionMessageCallback& message_cb) { | 221 const content::PresentationSessionMessageCallback& message_cb) { |
| 221 auto it = presentation_id_to_route_id_.find(session.presentation_id); | 222 auto it = presentation_id_to_route_id_.find(session.presentation_id); |
| 222 if (it == presentation_id_to_route_id_.end()) { | 223 if (it == presentation_id_to_route_id_.end()) { |
| 223 DVLOG(2) << "ListenForSessionMessages: no route for " | 224 DVLOG(2) << "ListenForSessionMessages: no route for " |
| 224 << session.presentation_id; | 225 << session.presentation_id; |
| 225 return; | 226 return; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 245 MediaRouter* router); | 246 MediaRouter* router); |
| 246 ~PresentationFrameManager(); | 247 ~PresentationFrameManager(); |
| 247 | 248 |
| 248 // Mirror corresponding APIs in PresentationServiceDelegateImpl. | 249 // Mirror corresponding APIs in PresentationServiceDelegateImpl. |
| 249 bool SetScreenAvailabilityListener( | 250 bool SetScreenAvailabilityListener( |
| 250 const RenderFrameHostId& render_frame_host_id, | 251 const RenderFrameHostId& render_frame_host_id, |
| 251 content::PresentationScreenAvailabilityListener* listener); | 252 content::PresentationScreenAvailabilityListener* listener); |
| 252 bool RemoveScreenAvailabilityListener( | 253 bool RemoveScreenAvailabilityListener( |
| 253 const RenderFrameHostId& render_frame_host_id, | 254 const RenderFrameHostId& render_frame_host_id, |
| 254 content::PresentationScreenAvailabilityListener* listener); | 255 content::PresentationScreenAvailabilityListener* listener); |
| 255 void ListenForSessionStateChange( | 256 void ListenForConnectionStateChange( |
| 256 const RenderFrameHostId& render_frame_host_id, | 257 const RenderFrameHostId& render_frame_host_id, |
| 257 const content::SessionStateChangedCallback& state_changed_cb); | 258 const content::PresentationSessionInfo& connection, |
| 259 const content::PresentationConnectionStateChangedCallback& |
| 260 state_changed_cb); |
| 258 void ListenForSessionMessages( | 261 void ListenForSessionMessages( |
| 259 const RenderFrameHostId& render_frame_host_id, | 262 const RenderFrameHostId& render_frame_host_id, |
| 260 const content::PresentationSessionInfo& session, | 263 const content::PresentationSessionInfo& session, |
| 261 const content::PresentationSessionMessageCallback& message_cb); | 264 const content::PresentationSessionMessageCallback& message_cb); |
| 262 | 265 |
| 263 // Sets or clears the default presentation request and callback for the given | 266 // Sets or clears the default presentation request and callback for the given |
| 264 // frame. Also sets / clears the default presentation requests for the owning | 267 // frame. Also sets / clears the default presentation requests for the owning |
| 265 // tab WebContents. | 268 // tab WebContents. |
| 266 void SetDefaultPresentationUrl( | 269 void SetDefaultPresentationUrl( |
| 267 const RenderFrameHostId& render_frame_host_id, | 270 const RenderFrameHostId& render_frame_host_id, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 284 | 287 |
| 285 void OnPresentationSessionStarted( | 288 void OnPresentationSessionStarted( |
| 286 const RenderFrameHostId& render_frame_host_id, | 289 const RenderFrameHostId& render_frame_host_id, |
| 287 const content::PresentationSessionInfo& session, | 290 const content::PresentationSessionInfo& session, |
| 288 const MediaRoute::Id& route_id); | 291 const MediaRoute::Id& route_id); |
| 289 void OnDefaultPresentationSessionStarted( | 292 void OnDefaultPresentationSessionStarted( |
| 290 const PresentationRequest& request, | 293 const PresentationRequest& request, |
| 291 const content::PresentationSessionInfo& session, | 294 const content::PresentationSessionInfo& session, |
| 292 const MediaRoute::Id& route_id); | 295 const MediaRoute::Id& route_id); |
| 293 | 296 |
| 294 void OnPresentationSessionClosed( | |
| 295 const RenderFrameHostId& render_frame_host_id, | |
| 296 const std::string& presentation_id); | |
| 297 const MediaRoute::Id GetRouteId(const RenderFrameHostId& render_frame_host_id, | 297 const MediaRoute::Id GetRouteId(const RenderFrameHostId& render_frame_host_id, |
| 298 const std::string& presentation_id) const; | 298 const std::string& presentation_id) const; |
| 299 const std::vector<MediaRoute::Id> GetRouteIds( | 299 const std::vector<MediaRoute::Id> GetRouteIds( |
| 300 const RenderFrameHostId& render_frame_host_id) const; | 300 const RenderFrameHostId& render_frame_host_id) const; |
| 301 | 301 |
| 302 const PresentationRequest* default_presentation_request() const { | 302 const PresentationRequest* default_presentation_request() const { |
| 303 return default_presentation_request_.get(); | 303 return default_presentation_request_.get(); |
| 304 } | 304 } |
| 305 | 305 |
| 306 private: | 306 private: |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 | 352 |
| 353 PresentationFrameManager::~PresentationFrameManager() { | 353 PresentationFrameManager::~PresentationFrameManager() { |
| 354 for (auto& frame : presentation_frames_) | 354 for (auto& frame : presentation_frames_) |
| 355 frame.second->OnPresentationServiceDelegateDestroyed(); | 355 frame.second->OnPresentationServiceDelegateDestroyed(); |
| 356 } | 356 } |
| 357 | 357 |
| 358 void PresentationFrameManager::OnPresentationSessionStarted( | 358 void PresentationFrameManager::OnPresentationSessionStarted( |
| 359 const RenderFrameHostId& render_frame_host_id, | 359 const RenderFrameHostId& render_frame_host_id, |
| 360 const content::PresentationSessionInfo& session, | 360 const content::PresentationSessionInfo& session, |
| 361 const MediaRoute::Id& route_id) { | 361 const MediaRoute::Id& route_id) { |
| 362 auto presentation_frame = presentation_frames_.get(render_frame_host_id); | 362 auto presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); |
| 363 if (presentation_frame) | 363 presentation_frame->OnPresentationSessionStarted(session, route_id); |
| 364 presentation_frame->OnPresentationSessionStarted(session, route_id); | |
| 365 } | 364 } |
| 366 | 365 |
| 367 void PresentationFrameManager::OnDefaultPresentationSessionStarted( | 366 void PresentationFrameManager::OnDefaultPresentationSessionStarted( |
| 368 const PresentationRequest& request, | 367 const PresentationRequest& request, |
| 369 const content::PresentationSessionInfo& session, | 368 const content::PresentationSessionInfo& session, |
| 370 const MediaRoute::Id& route_id) { | 369 const MediaRoute::Id& route_id) { |
| 371 auto presentation_frame = | 370 auto presentation_frame = |
| 372 presentation_frames_.get(request.render_frame_host_id()); | 371 presentation_frames_.get(request.render_frame_host_id()); |
| 373 if (presentation_frame) | 372 if (presentation_frame) |
| 374 presentation_frame->OnPresentationSessionStarted(session, route_id); | 373 presentation_frame->OnPresentationSessionStarted(session, route_id); |
| 375 | 374 |
| 376 if (default_presentation_request_ && | 375 if (default_presentation_request_ && |
| 377 default_presentation_request_->Equals(request)) { | 376 default_presentation_request_->Equals(request)) { |
| 378 default_presentation_started_callback_.Run(session); | 377 default_presentation_started_callback_.Run(session); |
| 379 } | 378 } |
| 380 } | 379 } |
| 381 | 380 |
| 382 void PresentationFrameManager::OnPresentationSessionClosed( | |
| 383 const RenderFrameHostId& render_frame_host_id, | |
| 384 const std::string& presentation_id) { | |
| 385 auto presentation_frame = presentation_frames_.get(render_frame_host_id); | |
| 386 if (presentation_frame) | |
| 387 presentation_frame->OnPresentationSessionClosed(presentation_id); | |
| 388 } | |
| 389 | |
| 390 const MediaRoute::Id PresentationFrameManager::GetRouteId( | 381 const MediaRoute::Id PresentationFrameManager::GetRouteId( |
| 391 const RenderFrameHostId& render_frame_host_id, | 382 const RenderFrameHostId& render_frame_host_id, |
| 392 const std::string& presentation_id) const { | 383 const std::string& presentation_id) const { |
| 393 auto presentation_frame = presentation_frames_.get(render_frame_host_id); | 384 auto presentation_frame = presentation_frames_.get(render_frame_host_id); |
| 394 return presentation_frame ? presentation_frame->GetRouteId(presentation_id) | 385 return presentation_frame ? presentation_frame->GetRouteId(presentation_id) |
| 395 : ""; | 386 : ""; |
| 396 } | 387 } |
| 397 | 388 |
| 398 const std::vector<MediaRoute::Id> PresentationFrameManager::GetRouteIds( | 389 const std::vector<MediaRoute::Id> PresentationFrameManager::GetRouteIds( |
| 399 const RenderFrameHostId& render_frame_host_id) const { | 390 const RenderFrameHostId& render_frame_host_id) const { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 420 } | 411 } |
| 421 | 412 |
| 422 bool PresentationFrameManager::HasScreenAvailabilityListenerForTest( | 413 bool PresentationFrameManager::HasScreenAvailabilityListenerForTest( |
| 423 const RenderFrameHostId& render_frame_host_id, | 414 const RenderFrameHostId& render_frame_host_id, |
| 424 const MediaSource::Id& source_id) const { | 415 const MediaSource::Id& source_id) const { |
| 425 auto presentation_frame = presentation_frames_.get(render_frame_host_id); | 416 auto presentation_frame = presentation_frames_.get(render_frame_host_id); |
| 426 return presentation_frame && | 417 return presentation_frame && |
| 427 presentation_frame->HasScreenAvailabilityListenerForTest(source_id); | 418 presentation_frame->HasScreenAvailabilityListenerForTest(source_id); |
| 428 } | 419 } |
| 429 | 420 |
| 430 void PresentationFrameManager::ListenForSessionStateChange( | 421 void PresentationFrameManager::ListenForConnectionStateChange( |
| 431 const RenderFrameHostId& render_frame_host_id, | 422 const RenderFrameHostId& render_frame_host_id, |
| 432 const content::SessionStateChangedCallback& state_changed_cb) { | 423 const content::PresentationSessionInfo& connection, |
| 433 PresentationFrame* presentation_frame = | 424 const content::PresentationConnectionStateChangedCallback& |
| 434 GetOrAddPresentationFrame(render_frame_host_id); | 425 state_changed_cb) { |
| 435 presentation_frame->ListenForSessionStateChange(state_changed_cb); | 426 auto presentation_frame = presentation_frames_.get(render_frame_host_id); |
| 427 if (presentation_frame) { |
| 428 presentation_frame->ListenForConnectionStateChange(connection, |
| 429 state_changed_cb); |
| 430 } |
| 436 } | 431 } |
| 437 | 432 |
| 438 void PresentationFrameManager::ListenForSessionMessages( | 433 void PresentationFrameManager::ListenForSessionMessages( |
| 439 const RenderFrameHostId& render_frame_host_id, | 434 const RenderFrameHostId& render_frame_host_id, |
| 440 const content::PresentationSessionInfo& session, | 435 const content::PresentationSessionInfo& session, |
| 441 const content::PresentationSessionMessageCallback& message_cb) { | 436 const content::PresentationSessionMessageCallback& message_cb) { |
| 442 PresentationFrame* presentation_frame = | 437 PresentationFrame* presentation_frame = |
| 443 presentation_frames_.get(render_frame_host_id); | 438 presentation_frames_.get(render_frame_host_id); |
| 444 if (!presentation_frame) { | 439 if (!presentation_frame) { |
| 445 DVLOG(2) << "ListenForSessionMessages: PresentationFrame does not exist " | 440 DVLOG(2) << "ListenForSessionMessages: PresentationFrame does not exist " |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 } | 754 } |
| 760 | 755 |
| 761 if (message->is_binary()) { | 756 if (message->is_binary()) { |
| 762 router_->SendRouteBinaryMessage(route_id, message->data.Pass(), | 757 router_->SendRouteBinaryMessage(route_id, message->data.Pass(), |
| 763 send_message_cb); | 758 send_message_cb); |
| 764 } else { | 759 } else { |
| 765 router_->SendRouteMessage(route_id, message->message, send_message_cb); | 760 router_->SendRouteMessage(route_id, message->message, send_message_cb); |
| 766 } | 761 } |
| 767 } | 762 } |
| 768 | 763 |
| 769 void PresentationServiceDelegateImpl::ListenForSessionStateChange( | 764 void PresentationServiceDelegateImpl::ListenForConnectionStateChange( |
| 770 int render_process_id, | 765 int render_process_id, |
| 771 int render_frame_id, | 766 int render_frame_id, |
| 772 const content::SessionStateChangedCallback& state_changed_cb) { | 767 const content::PresentationSessionInfo& connection, |
| 773 frame_manager_->ListenForSessionStateChange( | 768 const content::PresentationConnectionStateChangedCallback& |
| 774 RenderFrameHostId(render_process_id, render_frame_id), state_changed_cb); | 769 state_changed_cb) { |
| 770 frame_manager_->ListenForConnectionStateChange( |
| 771 RenderFrameHostId(render_process_id, render_frame_id), connection, |
| 772 state_changed_cb); |
| 775 } | 773 } |
| 776 | 774 |
| 777 void PresentationServiceDelegateImpl::OnRouteResponse( | 775 void PresentationServiceDelegateImpl::OnRouteResponse( |
| 778 const PresentationRequest& presentation_request, | 776 const PresentationRequest& presentation_request, |
| 779 const MediaRoute* route, | 777 const MediaRoute* route, |
| 780 const std::string& presentation_id, | 778 const std::string& presentation_id, |
| 781 const std::string& error) { | 779 const std::string& error) { |
| 782 if (!route) | 780 if (!route) |
| 783 return; | 781 return; |
| 784 | 782 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( | 820 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( |
| 823 int render_process_id, | 821 int render_process_id, |
| 824 int render_frame_id, | 822 int render_frame_id, |
| 825 const MediaSource::Id& source_id) const { | 823 const MediaSource::Id& source_id) const { |
| 826 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); | 824 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
| 827 return frame_manager_->HasScreenAvailabilityListenerForTest( | 825 return frame_manager_->HasScreenAvailabilityListenerForTest( |
| 828 render_frame_host_id, source_id); | 826 render_frame_host_id, source_id); |
| 829 } | 827 } |
| 830 | 828 |
| 831 } // namespace media_router | 829 } // namespace media_router |
| OLD | NEW |