Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(338)

Side by Side Diff: chrome/browser/media/router/offscreen_presentation_manager.cc

Issue 2343013002: [Presentation API] (MR side) 1-UA: notify receiver page when receiver connection becomes available (Closed)
Patch Set: resolve code review comments from Derek Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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. ////////////////////////////////
17 OffscreenPresentationManager::OffscreenPresentationManager() {}
18
19 OffscreenPresentationManager::~OffscreenPresentationManager() {}
20
21 void OffscreenPresentationManager::RegisterOffscreenPresentationController(
22 const std::string& presentation_id,
23 int render_frame_id,
24 content::OffscreenPresentationClient* controller) {
25 DVLOG(2) << __FUNCTION__ << " [presentation_id]: " << presentation_id
26 << ", [render_frame_id]: " << render_frame_id;
27
28 auto it = offscreen_presentations_.find(presentation_id);
29 // Create a new presentation.
30 if (it == offscreen_presentations_.end()) {
31 it = offscreen_presentations_
32 .insert(std::make_pair(
33 presentation_id,
34 base::MakeUnique<OffscreenPresentation>(presentation_id)))
35 .first;
36 }
37 it->second->RegisterController(render_frame_id, controller);
38 }
39
40 void OffscreenPresentationManager::UnregisterOffscreenPresentationController(
41 const std::string& presentation_id,
42 int render_frame_id) {
43 DVLOG(2) << __FUNCTION__ << " [presentation_id]: " << presentation_id
44 << ", [render_frame_id]: " << render_frame_id;
45
46 auto it = offscreen_presentations_.find(presentation_id);
47 if (it == offscreen_presentations_.end())
48 return;
49
50 // Remove presentation if no controller and receiver.
51 it->second->UnregisterController(render_frame_id);
52 if (it->second->controllers_.size() == 0 &&
53 it->second->receiver_callback_.is_null())
54 offscreen_presentations_.erase(presentation_id);
55 }
56
57 void OffscreenPresentationManager::RegisterOffscreenPresentationReceiver(
58 const std::string& presentation_id,
59 const content::ReceiverConnectionAvailableCallback& receiver_callback) {
60 DVLOG(2) << __FUNCTION__ << " [presentation_id]: " << presentation_id;
61
62 auto it = offscreen_presentations_.find(presentation_id);
63 if (it != offscreen_presentations_.end())
imcheng 2016/09/28 07:28:35 Does the first RegisterOffscreenPresentationContro
zhaobin 2016/09/29 17:20:43 They are async so they can occur in any order. Gen
64 it->second->RegisterReceiver(receiver_callback);
65 }
66
67 void OffscreenPresentationManager::UnregisterOffscreenPresentationReceiver(
68 const std::string& presentation_id) {
69 DVLOG(2) << __FUNCTION__ << " [presentation_id]: " << presentation_id;
70 offscreen_presentations_.erase(presentation_id);
imcheng 2016/09/28 07:28:35 question: how do we inform controllers that the re
zhaobin 2016/09/29 17:20:42 Receiver PSImpl should have controller's PSImpl (o
71 }
72
73 // OffscreenPresentation implementation. ///////////////////////////////////////
74 OffscreenPresentation::OffscreenPresentation(const std::string& presentation_id)
75 : presentation_id_(presentation_id), receiver_callback_(nullptr) {}
76
77 OffscreenPresentation::~OffscreenPresentation() {}
78
79 void OffscreenPresentation::RegisterController(
80 int render_frame_id,
81 content::OffscreenPresentationClient* controller) {
82 // Connect controller PSImpl and receiver PSImpl.
83 if (receiver_callback_) {
84 receiver_callback_.Run(
85 content::PresentationSessionInfo(presentation_url_, presentation_id_),
imcheng 2016/09/28 07:28:35 Looks like we also need to pass in presentation_ur
zhaobin 2016/09/29 17:20:43 Done.
86 controller);
87 } else {
88 controllers_.insert(std::make_pair(render_frame_id, controller));
89 }
90 }
91
92 void OffscreenPresentation::UnregisterController(int render_frame_id) {
93 controllers_.erase(render_frame_id);
94 }
95
96 void OffscreenPresentation::RegisterReceiver(
97 const content::ReceiverConnectionAvailableCallback& receiver_callback) {
98 for (const auto& controller : controllers_) {
99 receiver_callback.Run(
100 content::PresentationSessionInfo(presentation_url_, presentation_id_),
101 controller.second);
102 }
103 receiver_callback_ = receiver_callback;
104 controllers_.clear();
105 }
106
107 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698