Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/media/router/offscreen_presentation_manager.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "base/memory/ptr_util.h" | |
| 10 #include "content/public/browser/render_frame_host.h" | |
| 11 #include "content/public/browser/render_process_host.h" | |
| 12 #include "content/public/browser/web_contents.h" | |
| 13 #include "url/gurl.h" | |
| 14 | |
| 15 namespace media_router { | |
| 16 | |
| 17 // OffscreenPresentationManager implementation. | |
| 18 OffscreenPresentationManager::OffscreenPresentationManager() {} | |
| 19 | |
| 20 OffscreenPresentationManager::~OffscreenPresentationManager() {} | |
| 21 | |
| 22 OffscreenPresentationManager::OffscreenPresentationMap::iterator | |
|
imcheng
2016/11/01 17:20:28
it looks like you can just return OffscreenPresent
zhaobin
2016/11/02 03:55:47
Done.
| |
| 23 OffscreenPresentationManager::GetOrCreateOffscreenPresentation( | |
| 24 const std::string& presentation_id, | |
| 25 const GURL& presentation_url) { | |
| 26 auto it = offscreen_presentations_.find(presentation_id); | |
| 27 if (it == offscreen_presentations_.end()) { | |
| 28 it = offscreen_presentations_ | |
| 29 .insert(std::make_pair(presentation_id, | |
| 30 base::WrapUnique(new OffscreenPresentation( | |
| 31 presentation_id, presentation_url)))) | |
| 32 .first; | |
|
imcheng
2016/11/01 17:20:29
add ->second
zhaobin
2016/11/02 03:55:47
Done.
| |
| 33 } | |
| 34 return it; | |
| 35 } | |
| 36 | |
| 37 void OffscreenPresentationManager::RegisterOffscreenPresentationController( | |
| 38 const std::string& presentation_id, | |
| 39 const GURL& presentation_url, | |
| 40 const RenderFrameHostId& render_frame_host_id, | |
| 41 content::PresentationConnectionPtr controller) { | |
| 42 DVLOG(2) << __FUNCTION__ << " [presentation_id]: " << presentation_id | |
| 43 << ", [render_frame_host_id]: " << render_frame_host_id.second; | |
| 44 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 45 | |
| 46 auto presentation = | |
| 47 GetOrCreateOffscreenPresentation(presentation_id, presentation_url); | |
| 48 presentation->second->RegisterController(render_frame_host_id, | |
| 49 std::move(controller)); | |
| 50 } | |
| 51 | |
| 52 void OffscreenPresentationManager::UnregisterOffscreenPresentationController( | |
| 53 const std::string& presentation_id, | |
| 54 const RenderFrameHostId& render_frame_host_id) { | |
| 55 DVLOG(2) << __FUNCTION__ << " [presentation_id]: " << presentation_id | |
| 56 << ", [render_frame_host_id]: " << render_frame_host_id.second; | |
| 57 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 58 | |
| 59 auto it = offscreen_presentations_.find(presentation_id); | |
| 60 if (it == offscreen_presentations_.end()) | |
| 61 return; | |
| 62 | |
| 63 // Remove presentation if no controller and receiver. | |
| 64 it->second->UnregisterController(render_frame_host_id); | |
| 65 if (it->second->pending_controllers_.size() == 0 && | |
|
imcheng
2016/11/01 17:20:28
nit: define a IsValid method in OffscreenPresentat
zhaobin
2016/11/02 03:55:47
Done.
| |
| 66 it->second->receiver_callback_.is_null()) | |
| 67 offscreen_presentations_.erase(presentation_id); | |
| 68 } | |
| 69 | |
| 70 void OffscreenPresentationManager::OnOffscreenPresentationReceiverCreated( | |
| 71 const std::string& presentation_id, | |
| 72 const GURL& presentation_url, | |
| 73 const content::ReceiverConnectionAvailableCallback& receiver_callback) { | |
| 74 DVLOG(2) << __FUNCTION__ << " [presentation_id]: " << presentation_id; | |
| 75 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 76 auto presentation = | |
| 77 GetOrCreateOffscreenPresentation(presentation_id, presentation_url); | |
| 78 presentation->second->RegisterReceiver(receiver_callback); | |
| 79 } | |
| 80 | |
| 81 void OffscreenPresentationManager::OnOffscreenPresentationReceiverTerminated( | |
|
imcheng
2016/11/01 17:20:28
how will the controllers be informed that the Pres
zhaobin
2016/11/02 03:55:46
Not implemented yet. Controller connection should
| |
| 82 const std::string& presentation_id) { | |
| 83 DVLOG(2) << __FUNCTION__ << " [presentation_id]: " << presentation_id; | |
| 84 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 85 | |
| 86 offscreen_presentations_.erase(presentation_id); | |
| 87 } | |
| 88 | |
| 89 // OffscreenPresentation implementation. | |
| 90 OffscreenPresentationManager::OffscreenPresentation::OffscreenPresentation( | |
| 91 const std::string& presentation_id, | |
| 92 const GURL& presentation_url) | |
| 93 : presentation_id_(presentation_id), | |
| 94 presentation_url_(presentation_url), | |
| 95 receiver_callback_(nullptr) {} | |
|
imcheng
2016/11/01 17:20:28
is it necessary to initialize receiver_callback_?
zhaobin
2016/11/02 03:55:47
Done.
| |
| 96 | |
| 97 OffscreenPresentationManager::OffscreenPresentation::~OffscreenPresentation() {} | |
| 98 | |
| 99 void OffscreenPresentationManager::OffscreenPresentation::RegisterController( | |
| 100 const RenderFrameHostId& render_frame_host_id, | |
| 101 content::PresentationConnectionPtr controller) { | |
| 102 if (receiver_callback_) { | |
| 103 // Create a receiver PresentationConnectionPtr, and connect it with | |
|
imcheng
2016/11/01 17:20:28
It sounds like this comment belongs in the definit
zhaobin
2016/11/02 03:55:47
Done.
| |
| 104 // controller PresentationConnectionPtr. | |
| 105 receiver_callback_.Run( | |
| 106 content::PresentationSessionInfo(presentation_url_, presentation_id_), | |
| 107 std::move(controller)); | |
| 108 } else { | |
| 109 pending_controllers_.insert( | |
| 110 std::make_pair(render_frame_host_id, std::move(controller))); | |
| 111 } | |
| 112 } | |
| 113 | |
| 114 void OffscreenPresentationManager::OffscreenPresentation::UnregisterController( | |
| 115 const RenderFrameHostId& render_frame_host_id) { | |
| 116 pending_controllers_.erase(render_frame_host_id); | |
| 117 } | |
| 118 | |
| 119 void OffscreenPresentationManager::OffscreenPresentation::RegisterReceiver( | |
| 120 const content::ReceiverConnectionAvailableCallback& receiver_callback) { | |
| 121 DCHECK(!receiver_callback_); | |
| 122 | |
| 123 for (auto& controller : pending_controllers_) { | |
| 124 receiver_callback.Run( | |
| 125 content::PresentationSessionInfo(presentation_url_, presentation_id_), | |
| 126 std::move(controller.second)); | |
| 127 } | |
| 128 receiver_callback_ = receiver_callback; | |
| 129 pending_controllers_.clear(); | |
| 130 } | |
| 131 | |
| 132 } // namespace media_router | |
| OLD | NEW |