Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 <set> | |
|
imcheng
2016/09/28 07:28:36
<set> and <vector> not used?
zhaobin
2016/09/29 17:20:43
Done.
| |
| 11 #include <string> | |
| 12 #include <vector> | |
| 13 | |
| 14 #include "base/macros.h" | |
| 15 #include "chrome/browser/media/router/render_frame_host_id.h" | |
| 16 #include "components/keyed_service/core/keyed_service.h" | |
| 17 #include "content/public/browser/presentation_service_delegate.h" | |
| 18 | |
| 19 namespace media_router { | |
| 20 | |
| 21 class OffscreenPresentation; | |
| 22 | |
| 23 // Instances of this class manages all offscreen presentations started in the | |
| 24 // associated Profile and facilitates communication between the controllers and | |
| 25 // the | |
| 26 // receiver of an offscreen presentation. | |
|
imcheng
2016/09/28 07:28:36
nit: this can go in previous line.
zhaobin
2016/09/29 17:20:43
Done.
| |
| 27 // | |
| 28 // Example usage: | |
| 29 // | |
| 30 // Receiver is created to host the offscreen presentation and registers itself | |
| 31 // so that controller frames can connect to it: | |
| 32 // | |
| 33 // OffscreenPresentationManager* manager = | |
| 34 // OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext( | |
| 35 // context); | |
| 36 // manager->RegisterOffscreenPresentationReceiver(presentation_id, | |
| 37 // base::Bind(&OnReceiverConnectionAvailable)); | |
| 38 // ... | |
| 39 // void OnReceiverConnectionAvailable( | |
| 40 // const content::PresentationSessionInfo& session, | |
| 41 // OffscreenPresentationClient* controller) { | |
| 42 // [Connects controller PSImpl with receiver PSImpl to send/receive | |
| 43 // messages in response to send()] | |
| 44 // controller->SetOffscreenPresentationClient(receiver); | |
| 45 // receiver->SetOffscreenPresentationClient(controller); | |
| 46 // } | |
| 47 // | |
| 48 // Controller frame establishes connection with the receiver side, resulting | |
| 49 // in a session with the two endpoints being the controller frame's PSImpl | |
| 50 // (OffscreenPresentationClient) and the receiver frame's PSImpl | |
| 51 // (OffscreenPresentationClient). Note calling this will trigger | |
| 52 // |OnReceiverConnectionAvailable| on the receiver side. | |
| 53 // | |
| 54 // manager->RegisterOffscreenPresentationController( | |
| 55 // presentation_id, controller_frame_id, controller_ptr); | |
| 56 // | |
| 57 // To send message from controller to receiver: | |
| 58 // | |
| 59 // In controll's PSImpl::SendSessionMessage() { | |
| 60 // receiver.OnSessionMessage(); | |
| 61 // } | |
| 62 // | |
| 63 // A controller or receiver leaves the offscreen presentation (e.g., | |
| 64 // due to navigation) by unregistering themselves from | |
| 65 // OffscreenPresentationConnection object. | |
| 66 // | |
| 67 // When the receiver is no longer associated with an offscreen presentation, it | |
| 68 // shall remove itself from associated controllers and then unregister itself | |
| 69 // with | |
|
imcheng
2016/09/28 07:28:36
nit: line wrap
zhaobin
2016/09/29 17:20:43
Done.
| |
| 70 // OffscreenPresentationManager. Unregistration will prevent additional | |
| 71 // controllers from establishing a connection with the receiver: | |
| 72 // | |
| 73 // In receiver's PSImpl::Reset() { | |
| 74 // for (controller : offscreen_presentation_observers_) | |
| 75 // controller->RemoveOffscreenPresentationClient(receiver); | |
| 76 // } | |
| 77 // manager->UnregisterOffscreenPresentationReceiver(presentation_id); | |
| 78 // | |
| 79 // This class is not thread safe. All functions must be invoked on the UI | |
| 80 // thread. All callbacks passed into this class will also be invoked on UI | |
| 81 // thread. | |
| 82 class OffscreenPresentationManager : public KeyedService { | |
| 83 public: | |
| 84 ~OffscreenPresentationManager() override; | |
| 85 | |
| 86 // Register controller PSImpl to presentation with |presentation_id|, | |
| 87 // |render_frame_id|. | |
| 88 // Create a new presentation if no presentation with |presentation_id| exists. | |
| 89 // |controller| Not owned by this class. | |
| 90 void RegisterOffscreenPresentationController( | |
| 91 const std::string& presentation_id, | |
| 92 int render_frame_id, | |
|
imcheng
2016/09/28 07:28:36
Please use RenderFrameHostId here and below for al
zhaobin
2016/09/29 17:20:43
Done.
| |
| 93 content::OffscreenPresentationClient* controller); | |
|
imcheng
2016/09/28 07:28:36
Can you forward declare OffscreenPresentationClien
zhaobin
2016/09/29 17:20:43
changed to content::PresentationConnectionPtr cont
| |
| 94 | |
| 95 // Unregister controller PSImpl to presentation with |presentation_id|, | |
| 96 // |render_frame_id|. | |
| 97 void UnregisterOffscreenPresentationController( | |
| 98 const std::string& presentation_id, | |
| 99 int render_frame_id); | |
| 100 | |
| 101 // Register receiver PSImpl to presentation with |presentation_id|. | |
| 102 void RegisterOffscreenPresentationReceiver( | |
| 103 const std::string& presentation_id, | |
| 104 const content::ReceiverConnectionAvailableCallback& receiver_callback); | |
| 105 | |
| 106 void UnregisterOffscreenPresentationReceiver( | |
| 107 const std::string& presentation_id); | |
| 108 | |
| 109 private: | |
| 110 friend class OffscreenPresentationManagerFactory; | |
| 111 friend class OffscreenPresentationManagerTest; | |
| 112 | |
| 113 // Used by OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext. | |
| 114 OffscreenPresentationManager(); | |
| 115 | |
| 116 // Maps from presentation ID to OffscreenPresentation. | |
| 117 std::map<std::string, std::unique_ptr<OffscreenPresentation>> | |
| 118 offscreen_presentations_; | |
| 119 | |
| 120 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentationManager); | |
| 121 }; | |
| 122 | |
| 123 // Represents an offscreen presentation registered with | |
| 124 // OffscreenPresentationManager. | |
| 125 // Contains callback to the receiver to inform it of new sessions | |
| 126 // established from a controller. | |
| 127 // Contains set of controllers registered to OffscreenPresentationManager | |
| 128 // before corresponding receiver. | |
| 129 class OffscreenPresentation { | |
|
imcheng
2016/09/28 07:28:36
It looks like this class is not accessed from outs
zhaobin
2016/09/29 17:20:43
Done.
| |
| 130 public: | |
| 131 explicit OffscreenPresentation(const std::string& presentation_id); | |
| 132 ~OffscreenPresentation(); | |
| 133 | |
| 134 void RegisterController(int render_frame_id, | |
| 135 content::OffscreenPresentationClient* controller); | |
| 136 | |
| 137 void UnregisterController(int render_frame_id); | |
| 138 | |
| 139 void RegisterReceiver( | |
| 140 const content::ReceiverConnectionAvailableCallback& receiver_callback); | |
| 141 | |
| 142 private: | |
| 143 friend class OffscreenPresentationManagerTest; | |
| 144 friend class OffscreenPresentationManager; | |
| 145 | |
| 146 // URL for current presentation | |
| 147 const std::string presentation_url_; | |
| 148 | |
| 149 // presentation_id for current presentation | |
| 150 const std::string presentation_id_; | |
| 151 | |
| 152 // proxy to receiver PSImpl | |
| 153 content::ReceiverConnectionAvailableCallback receiver_callback_; | |
| 154 | |
| 155 // proxy to controller PSImpl | |
| 156 // It only contains controllers registered before receiver_callback_ | |
| 157 // is set. This map will be cleared in RegisterReceiver(). | |
| 158 std::map<int, content::OffscreenPresentationClient*> controllers_; | |
|
imcheng
2016/09/28 07:28:36
RenderFrameHostId
imcheng
2016/09/28 07:28:36
nit: I'd probably name it pending_controllers_ to
zhaobin
2016/09/29 17:20:43
Done.
zhaobin
2016/09/29 17:20:43
Done.
| |
| 159 | |
| 160 DISALLOW_COPY_AND_ASSIGN(OffscreenPresentation); | |
| 161 }; | |
| 162 | |
| 163 } // namespace media_router | |
| 164 | |
| 165 #endif // CHROME_BROWSER_MEDIA_ROUTER_OFFSCREEN_PRESENTATION_MANAGER_H_ | |
| OLD | NEW |