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 | |
14 namespace media_router { | |
15 | |
16 // OffscreenPresentationManager implementation. //////////////////////////////// | |
mark a. foltz
2016/10/06 03:13:54
I don't think the trailing slashes are needed.
zhaobin
2016/10/07 01:07:03
Done.
| |
17 OffscreenPresentationManager::OffscreenPresentationManager() {} | |
18 | |
19 OffscreenPresentationManager::~OffscreenPresentationManager() {} | |
20 | |
21 void OffscreenPresentationManager::RegisterOffscreenPresentationController( | |
22 const std::string& presentation_id, | |
23 const std::string& presentation_url, | |
24 const RenderFrameHostId& render_frame_host_id, | |
25 content::PresentationConnectionPtr controller) { | |
26 DVLOG(2) << __FUNCTION__ << " [presentation_id]: " << presentation_id | |
27 << ", [render_frame_host_id]: " << render_frame_host_id.second; | |
28 | |
29 auto it = offscreen_presentations_.find(presentation_id); | |
30 // Create a new presentation. | |
mark a. foltz
2016/10/06 03:13:54
It's not clear to me why registering an offscreen
zhaobin
2016/10/07 01:07:03
RegisterController() and RegisterReceiver() are as
| |
31 if (it == offscreen_presentations_.end()) { | |
32 it = offscreen_presentations_ | |
33 .insert(std::make_pair(presentation_id, | |
34 base::MakeUnique<OffscreenPresentation>( | |
35 presentation_id, presentation_url))) | |
36 .first; | |
37 } | |
mark a. foltz
2016/10/06 03:13:54
This logic is duplicated here and in RegisterOffsc
zhaobin
2016/10/07 01:07:03
Extract a RegisterOffscreenPresentation(id, url) f
| |
38 it->second->RegisterController(render_frame_host_id, std::move(controller)); | |
39 } | |
40 | |
41 void OffscreenPresentationManager::UnregisterOffscreenPresentationController( | |
42 const std::string& presentation_id, | |
43 const RenderFrameHostId& render_frame_host_id) { | |
44 DVLOG(2) << __FUNCTION__ << " [presentation_id]: " << presentation_id | |
45 << ", [render_frame_host_id]: " << render_frame_host_id.second; | |
46 | |
47 auto it = offscreen_presentations_.find(presentation_id); | |
48 if (it == offscreen_presentations_.end()) | |
49 return; | |
50 | |
51 // Remove presentation if no controller and receiver. | |
52 it->second->UnregisterController(render_frame_host_id); | |
53 if (it->second->pending_controllers_.size() == 0 && | |
mark a. foltz
2016/10/06 03:13:54
Even if the last controller connection is closed,
zhaobin
2016/10/07 01:07:03
We only remove presentation if no there no control
| |
54 it->second->receiver_callback_.is_null()) | |
55 offscreen_presentations_.erase(presentation_id); | |
56 } | |
57 | |
58 void OffscreenPresentationManager::RegisterOffscreenPresentationReceiver( | |
59 const std::string& presentation_id, | |
60 const std::string& presentation_url, | |
61 const content::ReceiverConnectionAvailableCallback& receiver_callback) { | |
62 DVLOG(2) << __FUNCTION__ << " [presentation_id]: " << presentation_id; | |
63 | |
64 auto it = offscreen_presentations_.find(presentation_id); | |
65 if (it == offscreen_presentations_.end()) { | |
66 it = offscreen_presentations_ | |
67 .insert(std::make_pair(presentation_id, | |
68 base::MakeUnique<OffscreenPresentation>( | |
69 presentation_id, presentation_url))) | |
70 .first; | |
71 } | |
72 it->second->RegisterReceiver(receiver_callback); | |
73 } | |
74 | |
75 void OffscreenPresentationManager::UnregisterOffscreenPresentationReceiver( | |
76 const std::string& presentation_id) { | |
77 DVLOG(2) << __FUNCTION__ << " [presentation_id]: " << presentation_id; | |
78 offscreen_presentations_.erase(presentation_id); | |
79 } | |
80 | |
81 // OffscreenPresentation implementation. /////////////////////////////////////// | |
mark a. foltz
2016/10/06 03:13:54
Omit trailing slashes
zhaobin
2016/10/07 01:07:03
Done.
| |
82 OffscreenPresentationManager::OffscreenPresentation::OffscreenPresentation( | |
83 const std::string& presentation_id, | |
84 const std::string& presentation_url) | |
85 : presentation_id_(presentation_id), | |
86 presentation_url_(presentation_url), | |
87 receiver_callback_(nullptr) {} | |
88 | |
89 OffscreenPresentationManager::OffscreenPresentation::~OffscreenPresentation() {} | |
90 | |
91 void OffscreenPresentationManager::OffscreenPresentation::RegisterController( | |
92 const RenderFrameHostId& render_frame_host_id, | |
93 content::PresentationConnectionPtr controller) { | |
94 // Connect controller PSImpl and receiver PSImpl. | |
mark a. foltz
2016/10/06 03:13:54
It may be difficult for those unfamiliar with our
zhaobin
2016/10/07 01:07:03
Outdated comments. Updated.
| |
95 if (receiver_callback_) { | |
96 receiver_callback_.Run( | |
97 content::PresentationSessionInfo(presentation_url_, presentation_id_), | |
98 std::move(controller)); | |
99 } else { | |
100 pending_controllers_.insert( | |
101 std::make_pair(render_frame_host_id, std::move(controller))); | |
102 } | |
103 } | |
104 | |
105 void OffscreenPresentationManager::OffscreenPresentation::UnregisterController( | |
106 const RenderFrameHostId& render_frame_host_id) { | |
107 pending_controllers_.erase(render_frame_host_id); | |
108 } | |
109 | |
110 void OffscreenPresentationManager::OffscreenPresentation::RegisterReceiver( | |
111 const content::ReceiverConnectionAvailableCallback& receiver_callback) { | |
112 for (auto& controller : pending_controllers_) { | |
mark a. foltz
2016/10/06 03:13:54
This must be called only once per receiver, correc
zhaobin
2016/10/07 01:07:03
Done.
| |
113 receiver_callback.Run( | |
114 content::PresentationSessionInfo(presentation_url_, presentation_id_), | |
115 std::move(controller.second)); | |
116 } | |
117 receiver_callback_ = receiver_callback; | |
118 pending_controllers_.clear(); | |
119 } | |
120 | |
121 } // namespace media_router | |
OLD | NEW |