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

Side by Side Diff: content/renderer/presentation/presentation_dispatcher.h

Issue 2598063002: [Presentation API] Handle multiple Presentation URLs in PresentationRequest::getAvailability() (Closed)
Patch Set: seperate AvailabilityStatus from ListeningStatus and simplify book keeping code Created 3 years, 11 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ 5 #ifndef CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_
6 #define CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ 6 #define CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 29 matching lines...) Expand all
40 // Blink. It forwards the calls to the Mojo PresentationService. 40 // Blink. It forwards the calls to the Mojo PresentationService.
41 class CONTENT_EXPORT PresentationDispatcher 41 class CONTENT_EXPORT PresentationDispatcher
42 : public RenderFrameObserver, 42 : public RenderFrameObserver,
43 public NON_EXPORTED_BASE(blink::WebPresentationClient), 43 public NON_EXPORTED_BASE(blink::WebPresentationClient),
44 public NON_EXPORTED_BASE(blink::mojom::PresentationServiceClient) { 44 public NON_EXPORTED_BASE(blink::mojom::PresentationServiceClient) {
45 public: 45 public:
46 explicit PresentationDispatcher(RenderFrame* render_frame); 46 explicit PresentationDispatcher(RenderFrame* render_frame);
47 ~PresentationDispatcher() override; 47 ~PresentationDispatcher() override;
48 48
49 private: 49 private:
50 friend class PresentationDispatcherTest;
50 struct SendMessageRequest { 51 struct SendMessageRequest {
51 SendMessageRequest(blink::mojom::PresentationSessionInfoPtr session_info, 52 SendMessageRequest(blink::mojom::PresentationSessionInfoPtr session_info,
52 blink::mojom::ConnectionMessagePtr message); 53 blink::mojom::ConnectionMessagePtr message);
53 ~SendMessageRequest(); 54 ~SendMessageRequest();
54 55
55 blink::mojom::PresentationSessionInfoPtr session_info; 56 blink::mojom::PresentationSessionInfoPtr session_info;
56 blink::mojom::ConnectionMessagePtr message; 57 blink::mojom::ConnectionMessagePtr message;
57 }; 58 };
58 59
59 static SendMessageRequest* CreateSendTextMessageRequest( 60 static SendMessageRequest* CreateSendTextMessageRequest(
(...skipping 27 matching lines...) Expand all
87 size_t length) override; 88 size_t length) override;
88 void sendBlobData(const blink::WebURL& presentationUrl, 89 void sendBlobData(const blink::WebURL& presentationUrl,
89 const blink::WebString& presentationId, 90 const blink::WebString& presentationId,
90 const uint8_t* data, 91 const uint8_t* data,
91 size_t length) override; 92 size_t length) override;
92 void closeSession(const blink::WebURL& presentationUrl, 93 void closeSession(const blink::WebURL& presentationUrl,
93 const blink::WebString& presentationId) override; 94 const blink::WebString& presentationId) override;
94 void terminateSession(const blink::WebURL& presentationUrl, 95 void terminateSession(const blink::WebURL& presentationUrl,
95 const blink::WebString& presentationId) override; 96 const blink::WebString& presentationId) override;
96 void getAvailability( 97 void getAvailability(
97 const blink::WebVector<blink::WebURL>& availabilityUrl, 98 const blink::WebVector<blink::WebURL>& availabilityUrls,
98 std::unique_ptr<blink::WebPresentationAvailabilityCallbacks> callbacks) 99 std::unique_ptr<blink::WebPresentationAvailabilityCallbacks> callbacks)
99 override; 100 override;
100 void startListening(blink::WebPresentationAvailabilityObserver*) override; 101 void startListening(blink::WebPresentationAvailabilityObserver*) override;
101 void stopListening(blink::WebPresentationAvailabilityObserver*) override; 102 void stopListening(blink::WebPresentationAvailabilityObserver*) override;
102 void setDefaultPresentationUrls( 103 void setDefaultPresentationUrls(
103 const blink::WebVector<blink::WebURL>& presentationUrls) override; 104 const blink::WebVector<blink::WebURL>& presentationUrls) override;
104 105
105 // RenderFrameObserver implementation. 106 // RenderFrameObserver implementation.
106 void DidCommitProvisionalLoad( 107 void DidCommitProvisionalLoad(
107 bool is_new_navigation, 108 bool is_new_navigation,
(...skipping 23 matching lines...) Expand all
131 void OnReceiverConnectionAvailable( 132 void OnReceiverConnectionAvailable(
132 blink::mojom::PresentationSessionInfoPtr) override; 133 blink::mojom::PresentationSessionInfoPtr) override;
133 134
134 // Call to PresentationService to send the message in |request|. 135 // Call to PresentationService to send the message in |request|.
135 // |session_info| and |message| of |reuqest| will be consumed. 136 // |session_info| and |message| of |reuqest| will be consumed.
136 // |HandleSendMessageRequests| will be invoked after the send is attempted. 137 // |HandleSendMessageRequests| will be invoked after the send is attempted.
137 void DoSendMessage(SendMessageRequest* request); 138 void DoSendMessage(SendMessageRequest* request);
138 void HandleSendMessageRequests(bool success); 139 void HandleSendMessageRequests(bool success);
139 140
140 void ConnectToPresentationServiceIfNeeded(); 141 void ConnectToPresentationServiceIfNeeded();
142 void SetPresentationServiceForTest(
143 blink::mojom::PresentationServicePtr presentation_service);
141 144
142 void UpdateListeningState(); 145 void UpdateListeningState();
143 146
144 // Used as a weak reference. Can be null since lifetime is bound to the frame. 147 // Used as a weak reference. Can be null since lifetime is bound to the frame.
145 blink::WebPresentationController* controller_; 148 blink::WebPresentationController* controller_;
146 blink::WebPresentationReceiver* receiver_; 149 blink::WebPresentationReceiver* receiver_;
147 blink::mojom::PresentationServicePtr presentation_service_; 150 blink::mojom::PresentationServicePtr presentation_service_;
148 mojo::Binding<blink::mojom::PresentationServiceClient> binding_; 151 mojo::Binding<blink::mojom::PresentationServiceClient> binding_;
149 152
150 // Message requests are queued here and only one message at a time is sent 153 // Message requests are queued here and only one message at a time is sent
151 // over mojo channel. 154 // over mojo channel.
152 using MessageRequestQueue = std::queue<std::unique_ptr<SendMessageRequest>>; 155 using MessageRequestQueue = std::queue<std::unique_ptr<SendMessageRequest>>;
153 MessageRequestQueue message_request_queue_; 156 MessageRequestQueue message_request_queue_;
154 157
155 enum class ListeningState { 158 enum class ListeningState {
156 INACTIVE, 159 INACTIVE,
157 WAITING, 160 WAITING,
158 ACTIVE, 161 ACTIVE,
159 }; 162 };
160 163
164 enum class ScreenAvailability {
165 UNKNOWN,
166 AVAILABLE,
167 UNAVAILABLE,
168 UNSUPPORTED
169 };
170
161 using AvailabilityCallbacksMap = 171 using AvailabilityCallbacksMap =
162 IDMap<std::unique_ptr<blink::WebPresentationAvailabilityCallbacks>>; 172 IDMap<std::unique_ptr<blink::WebPresentationAvailabilityCallbacks>>;
163 using AvailabilityObserversSet = 173 using AvailabilityObserversSet =
164 std::set<blink::WebPresentationAvailabilityObserver*>; 174 std::set<blink::WebPresentationAvailabilityObserver*>;
165 175
166 // Tracks status of presentation displays availability for |availability_url|. 176 // Tracks status of presentation displays availability for
177 // |availability_urls|.
167 struct AvailabilityStatus { 178 struct AvailabilityStatus {
168 explicit AvailabilityStatus(const GURL& availability_url); 179 AvailabilityStatus(const std::vector<GURL>& availability_urls);
169 ~AvailabilityStatus(); 180 ~AvailabilityStatus();
170 181
171 const GURL url; 182 std::vector<GURL> urls;
172 bool last_known_availability;
173 ListeningState listening_state;
174 AvailabilityCallbacksMap availability_callbacks; 183 AvailabilityCallbacksMap availability_callbacks;
175 AvailabilityObserversSet availability_observers; 184 AvailabilityObserversSet availability_observers;
176 }; 185 };
177 186
178 // Map of AvailabilityStatus for known URLs. 187 // Tracks listening status of |availability_url|.
179 std::map<GURL, std::unique_ptr<AvailabilityStatus>> 188 struct ListeningStatus {
180 availability_status_; 189 explicit ListeningStatus(const GURL& availability_url);
190 ~ListeningStatus();
181 191
182 // Updates the listening state of availability for |status| and notifies the 192 const GURL url;
183 // client. 193 ScreenAvailability last_known_availability;
184 void UpdateListeningState(AvailabilityStatus* status); 194 ListeningState listening_state;
195 };
196
197 // Map of ListeningStatus for known URLs.
198 std::map<GURL, std::unique_ptr<ListeningStatus>> listening_status_;
199
200 // Map of AvailabilityStatus for known PresentationRequest.
mark a. foltz 2017/01/11 00:06:03 s/Map/Set/
zhaobin 2017/01/12 03:02:12 Done.
201 std::set<std::unique_ptr<AvailabilityStatus>> availability_set_;
202
203 // Starts listening to |url|.
204 void StartListening(const GURL& url);
205
206 // Stops listening to |url| if no PresentationAvailability is observing |url|.
mark a. foltz 2017/01/11 00:06:02 Document that StartListening() must have been call
zhaobin 2017/01/12 03:02:12 Done.
207 void StopListening(const GURL& url);
208
209 ListeningStatus* GetListeningStatus(const GURL& url);
mark a. foltz 2017/01/11 00:06:02 Document that this method returns nullptr if there
zhaobin 2017/01/12 03:02:12 Done.
210
211 // Returns AVAILABLE if any url in |urls| has screen availability AVAILABLE;
212 // Returns UNSUPPORTED if any url in |urls| have screen availability
213 // UNSUPPORTED, and no url has screen availability AVAILABLE;
214 // Returns UNAVAILABLE if at least one url in |urls| has screen availability
215 // UNAVAILABLE, and no url has screen availability AVAILABLE or UNSUPPORTED;
216 // Returns UNKNOWN if all urls in |urls| have screen availability
217 // UNKNOWN.
218 PresentationDispatcher::ScreenAvailability GetScreenAvailability(
mark a. foltz 2017/01/11 00:06:03 I don't think you need PresentationDispatcher:: he
zhaobin 2017/01/12 03:02:12 Done.
219 const std::vector<GURL>& urls);
185 220
186 DISALLOW_COPY_AND_ASSIGN(PresentationDispatcher); 221 DISALLOW_COPY_AND_ASSIGN(PresentationDispatcher);
187 }; 222 };
188 223
189 } // namespace content 224 } // namespace content
190 225
191 #endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ 226 #endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698