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

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

Issue 2379703002: [Presentation API] (alternative) 1-UA: send message between controller and receiver page (Closed)
Patch Set: rebase with master Created 4 years, 2 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 2016 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 #ifndef CHROME_BROWSER_MEDIA_ROUTER_OFFSCREEN_PRESENTATION_MANAGER_H_
6 #define CHROME_BROWSER_MEDIA_ROUTER_OFFSCREEN_PRESENTATION_MANAGER_H_
7
8 #include <map>
9 #include <memory>
10 #include <string>
11
12 #include "base/macros.h"
13 #include "chrome/browser/media/router/render_frame_host_id.h"
14 #include "components/keyed_service/core/keyed_service.h"
15 #include "content/public/browser/presentation_service_delegate.h"
16
17 namespace media_router {
18
19 // Instances of this class manages all offscreen presentations started in the
20 // associated Profile and facilitates communication between the controllers and
21 // the receiver of an offscreen presentation.
22 //
23 // Example usage:
24 //
25 // Receiver is created to host the offscreen presentation and registers itself
26 // so that controller frames can connect to it:
27 //
28 // OffscreenPresentationManager* manager =
29 // OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext(
30 // context);
mark a. foltz 2016/10/06 03:13:55 Is |context| the one that has the controller frame
zhaobin 2016/10/07 01:07:03 context is browserContext (profile). offscreen_pr
31 // manager->RegisterOffscreenPresentationReceiver(presentation_id,
32 // base::Bind(&OnReceiverConnectionAvailable));
33 // ...
34 // void OnReceiverConnectionAvailable(
mark a. foltz 2016/10/06 03:13:55 Is this called when a connection is available to t
zhaobin 2016/10/07 01:07:04 receiver PSImpl::onReceiverConnectionAvailable() i
35 // const content::PresentationSessionInfo& session,
36 // OffscreenPresentationClient* controller) {
37 // [Connects controller PSImpl with receiver PSImpl to send/receive
38 // messages in response to send()]
39 // controller->SetOffscreenPresentationClient(receiver);
40 // receiver->SetOffscreenPresentationClient(controller);
41 // }
42 //
43 // Controller frame establishes connection with the receiver side, resulting
44 // in a session with the two endpoints being the controller frame's PSImpl
45 // (OffscreenPresentationClient) and the receiver frame's PSImpl
46 // (OffscreenPresentationClient). Note calling this will trigger
47 // |OnReceiverConnectionAvailable| on the receiver side.
48 //
49 // manager->RegisterOffscreenPresentationController(
50 // presentation_id, controller_frame_id, controller_ptr);
51 //
52 // To send message from controller to receiver:
mark a. foltz 2016/10/06 03:13:54 It looks like this is the same for the other direc
zhaobin 2016/10/07 01:07:04 Done.
53 //
54 // In controll's PSImpl::SendSessionMessage() {
mark a. foltz 2016/10/06 03:13:55 contoller's
zhaobin 2016/10/07 01:07:04 Done.
55 // receiver.OnSessionMessage();
56 // }
57 //
58 // A controller or receiver leaves the offscreen presentation (e.g.,
59 // due to navigation) by unregistering themselves from
60 // OffscreenPresentationConnection object.
mark a. foltz 2016/10/06 03:13:54 If the receiver navigates, the offscreen tab shoul
zhaobin 2016/10/07 01:07:04 UnregisterReceiver() called in ReceiverPSDImpl::Re
61 //
62 // When the receiver is no longer associated with an offscreen presentation, it
mark a. foltz 2016/10/06 03:13:55 I believe there are five ways to terminate an offs
zhaobin 2016/10/07 01:07:04 (Not implemented yet) for #4, it will close the c
63 // shall remove itself from associated controllers and then unregister itself
64 // with OffscreenPresentationManager. Unregistration will prevent additional
65 // controllers from establishing a connection with the receiver:
66 //
67 // In receiver's PSImpl::Reset() {
68 // for (controller : offscreen_presentation_observers_)
69 // controller->RemoveOffscreenPresentationClient(receiver);
70 // }
71 // manager->UnregisterOffscreenPresentationReceiver(presentation_id);
72 //
73 // This class is not thread safe. All functions must be invoked on the UI
mark a. foltz 2016/10/06 03:13:54 Is this called by another thread or code outside o
zhaobin 2016/10/07 01:07:04 Done.
74 // thread. All callbacks passed into this class will also be invoked on UI
75 // thread.
76 class OffscreenPresentationManager : public KeyedService {
77 public:
78 ~OffscreenPresentationManager() override;
79
80 // Register controller PSImpl to presentation with |presentation_id|,
mark a. foltz 2016/10/06 03:13:55 Nit: Registers, Creates, Unregisters, etc. in func
zhaobin 2016/10/07 01:07:03 Done.
81 // |render_frame_id|.
82 // Create a new presentation if no presentation with |presentation_id| exists.
83 // |controller| Not owned by this class.
84 void RegisterOffscreenPresentationController(
85 const std::string& presentation_id,
86 const std::string& presentation_url,
mark a. foltz 2016/10/06 03:13:54 const GURL&
zhaobin 2016/10/07 01:07:03 Merge GURL changes after https://codereview.chromi
87 const RenderFrameHostId& render_frame_id,
88 content::PresentationConnectionPtr controller);
89
90 // Unregister controller PSImpl to presentation with |presentation_id|,
91 // |render_frame_id|.
92 void UnregisterOffscreenPresentationController(
93 const std::string& presentation_id,
94 const RenderFrameHostId& render_frame_id);
mark a. foltz 2016/10/06 03:13:55 Should this take a content::PresentationConnection
zhaobin 2016/10/07 01:07:03 content::PresentationConnectionPtr disallows copy
95
96 // Register receiver PSImpl to presentation with |presentation_id|.
mark a. foltz 2016/10/06 03:13:54 This function doesn't have a PSImpl parameter.
zhaobin 2016/10/07 01:07:03 Done.
97 void RegisterOffscreenPresentationReceiver(
mark a. foltz 2016/10/06 03:13:55 OnOffscreenPresentationReceiverCreated(id, url, ca
zhaobin 2016/10/07 01:07:04 Done.
98 const std::string& presentation_id,
99 const std::string& presentation_url,
mark a. foltz 2016/10/06 03:13:54 const GURL&
zhaobin 2016/10/07 01:07:04 Done.
100 const content::ReceiverConnectionAvailableCallback& receiver_callback);
101
102 void UnregisterOffscreenPresentationReceiver(
mark a. foltz 2016/10/06 03:13:54 OnOffscreenPresentationReceiverTerminated(presenta
zhaobin 2016/10/07 01:07:03 Done.
zhaobin 2016/10/07 01:07:03 Done.
103 const std::string& presentation_id);
104
105 private:
106 // Represents an offscreen presentation registered with
107 // OffscreenPresentationManager.
108 // Contains callback to the receiver to inform it of new sessions
mark a. foltz 2016/10/06 03:13:55 nit: s/sessions/connections/
zhaobin 2016/10/07 01:07:04 Done.
109 // established from a controller.
110 // Contains set of controllers registered to OffscreenPresentationManager
111 // before corresponding receiver.
112 class OffscreenPresentation {
113 public:
114 explicit OffscreenPresentation(const std::string& presentation_id,
115 const std::string& presentation_url);
mark a. foltz 2016/10/06 03:13:55 const GURL&
zhaobin 2016/10/07 01:07:03 Done.
116 ~OffscreenPresentation();
117
118 void RegisterController(const RenderFrameHostId& render_frame_id,
119 content::PresentationConnectionPtr controller);
120
121 void UnregisterController(const RenderFrameHostId& render_frame_id);
122
123 void RegisterReceiver(
124 const content::ReceiverConnectionAvailableCallback& receiver_callback);
125
126 private:
127 friend class OffscreenPresentationManagerTest;
128 friend class OffscreenPresentationManager;
129
130 // presentation_id for current presentation
mark a. foltz 2016/10/06 03:13:55 Nit: comments should end in period, here and below
zhaobin 2016/10/07 01:07:04 Done.
131 const std::string presentation_id_;
132
133 // URL for current presentation
134 const std::string presentation_url_;
mark a. foltz 2016/10/06 03:13:55 const GURL
zhaobin 2016/10/07 01:07:04 Done.
135
136 // proxy to receiver PSImpl
mark a. foltz 2016/10/06 03:13:54 I don't think this comment matches the code; the m
zhaobin 2016/10/07 01:07:04 Done.
137 content::ReceiverConnectionAvailableCallback receiver_callback_;
138
139 // proxy to controller PSImpl
140 // It only contains controllers registered before receiver_callback_
141 // is set. This map will be cleared in RegisterReceiver().
142 std::unordered_map<RenderFrameHostId,
mark a. foltz 2016/10/06 03:13:55 Is it necessary to be a map, or would a vector<Pen
zhaobin 2016/10/07 01:07:04 It needs to be a map. We cannot pass content::Pres
143 content::PresentationConnectionPtr,
144 RenderFrameHostIdHasher>
145 pending_controllers_;
146
147 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentation);
148 };
149
150 private:
151 friend class OffscreenPresentationManagerFactory;
152 friend class OffscreenPresentationManagerTest;
153
154 // Used by OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext.
155 OffscreenPresentationManager();
156
157 // Maps from presentation ID to OffscreenPresentation.
158 std::map<std::string, std::unique_ptr<OffscreenPresentation>>
159 offscreen_presentations_;
160
161 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentationManager);
162 };
163
164 } // namespace media_router
165
166 #endif // CHROME_BROWSER_MEDIA_ROUTER_OFFSCREEN_PRESENTATION_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698