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

Side by Side Diff: content/browser/presentation/presentation_service_impl.h

Issue 1073893003: [Presentation API] Implement ondefaultsessionstart in PSImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use RunLoopFor Created 5 years, 8 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
« no previous file with comments | « no previous file | content/browser/presentation/presentation_service_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ 5 #ifndef CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_
6 #define CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ 6 #define CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_
7 7
8 #include <deque> 8 #include <deque>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 102
103 // Indicates if this context has any pending callbacks. 103 // Indicates if this context has any pending callbacks.
104 bool HasPendingCallbacks() const; 104 bool HasPendingCallbacks() const;
105 105
106 private: 106 private:
107 std::string presentation_url_; 107 std::string presentation_url_;
108 ScopedVector<ScreenAvailabilityMojoCallback> callbacks_; 108 ScopedVector<ScreenAvailabilityMojoCallback> callbacks_;
109 scoped_ptr<bool> available_ptr_; 109 scoped_ptr<bool> available_ptr_;
110 }; 110 };
111 111
112 class CONTENT_EXPORT DefaultSessionStartContext {
113 public:
114 DefaultSessionStartContext();
115 ~DefaultSessionStartContext();
116
117 // Adds a callback. May invoke the callback immediately if |session| using
118 // default presentation URL was already started.
119 void AddCallback(const DefaultSessionMojoCallback& callback);
120
121 // Sets the session info. Maybe invoke callbacks queued with AddCallback().
122 void set_session(const PresentationSessionInfo& session);
123
124 private:
125 // Flush all queued callbacks by invoking them with null
126 // PresentationSessionInfoPtr.
127 void Reset();
128
129 ScopedVector<DefaultSessionMojoCallback> callbacks_;
130 scoped_ptr<PresentationSessionInfo> session_;
131 };
132
112 // Context for a StartSession request. 133 // Context for a StartSession request.
113 class CONTENT_EXPORT StartSessionRequest { 134 class CONTENT_EXPORT StartSessionRequest {
114 public: 135 public:
115 StartSessionRequest(const std::string& presentation_url, 136 StartSessionRequest(const std::string& presentation_url,
116 const std::string& presentation_id, 137 const std::string& presentation_id,
117 const NewSessionMojoCallback& callback); 138 const NewSessionMojoCallback& callback);
118 ~StartSessionRequest(); 139 ~StartSessionRequest();
119 140
120 // Retrieves the pending callback from this request, transferring ownership 141 // Retrieves the pending callback from this request, transferring ownership
121 // to the caller. 142 // to the caller.
(...skipping 17 matching lines...) Expand all
139 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, 160 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest,
140 ThisRenderFrameDeleted); 161 ThisRenderFrameDeleted);
141 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, 162 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest,
142 NotThisRenderFrameDeleted); 163 NotThisRenderFrameDeleted);
143 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, 164 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest,
144 SetDefaultPresentationUrl); 165 SetDefaultPresentationUrl);
145 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, 166 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest,
146 SetSameDefaultPresentationUrl); 167 SetSameDefaultPresentationUrl);
147 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, 168 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest,
148 ClearDefaultPresentationUrl); 169 ClearDefaultPresentationUrl);
170 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest,
171 ListenForDefaultSessionStart);
172 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest,
173 ListenForDefaultSessionStartAfterSet);
174 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest,
175 DefaultSessionStartReset);
149 176
150 // |render_frame_host|: The RFH this instance is associated with. 177 // |render_frame_host|: The RFH this instance is associated with.
151 // |web_contents|: The WebContents to observe. 178 // |web_contents|: The WebContents to observe.
152 // |delegate|: Where Presentation API requests are delegated to. Not owned 179 // |delegate|: Where Presentation API requests are delegated to. Not owned
153 // by this class. 180 // by this class.
154 PresentationServiceImpl( 181 PresentationServiceImpl(
155 RenderFrameHost* render_frame_host, 182 RenderFrameHost* render_frame_host,
156 WebContents* web_contents, 183 WebContents* web_contents,
157 PresentationServiceDelegate* delegate); 184 PresentationServiceDelegate* delegate);
158 185
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 217
191 // WebContentsObserver override. 218 // WebContentsObserver override.
192 void DidNavigateAnyFrame( 219 void DidNavigateAnyFrame(
193 content::RenderFrameHost* render_frame_host, 220 content::RenderFrameHost* render_frame_host,
194 const content::LoadCommittedDetails& details, 221 const content::LoadCommittedDetails& details,
195 const content::FrameNavigateParams& params) override; 222 const content::FrameNavigateParams& params) override;
196 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; 223 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
197 224
198 // PresentationServiceDelegate::Observer 225 // PresentationServiceDelegate::Observer
199 void OnDelegateDestroyed() override; 226 void OnDelegateDestroyed() override;
227 void OnDefaultPresentationStarted(const PresentationSessionInfo& session)
228 override;
200 229
201 // Finds the callback from |pending_session_cbs_| using |request_session_id|. 230 // Finds the callback from |pending_session_cbs_| using |request_session_id|.
202 // If it exists, invoke it with |session| and |error|, then erase it from 231 // If it exists, invoke it with |session| and |error|, then erase it from
203 // |pending_session_cbs_|. 232 // |pending_session_cbs_|.
204 void RunAndEraseNewSessionMojoCallback( 233 void RunAndEraseNewSessionMojoCallback(
205 int request_session_id, 234 int request_session_id,
206 presentation::PresentationSessionInfoPtr session, 235 presentation::PresentationSessionInfoPtr session,
207 presentation::PresentationErrorPtr error); 236 presentation::PresentationErrorPtr error);
208 237
209 // Sets |default_presentation_url_| to |presentation_url| and informs the 238 // Sets |default_presentation_url_| to |presentation_url| and informs the
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 278
250 // Invokes |callback| with an error. 279 // Invokes |callback| with an error.
251 static void InvokeNewSessionMojoCallbackWithError( 280 static void InvokeNewSessionMojoCallbackWithError(
252 const NewSessionMojoCallback& callback); 281 const NewSessionMojoCallback& callback);
253 282
254 // Gets the ScreenAvailabilityContext for |presentation_url|, or creates one 283 // Gets the ScreenAvailabilityContext for |presentation_url|, or creates one
255 // if it does not exist. 284 // if it does not exist.
256 ScreenAvailabilityContext* GetOrCreateAvailabilityContext( 285 ScreenAvailabilityContext* GetOrCreateAvailabilityContext(
257 const std::string& presentation_url); 286 const std::string& presentation_url);
258 287
259 RenderFrameHost* render_frame_host_; 288 // Returns true if this object is associated with |render_frame_host|.
289 bool FrameMatches(content::RenderFrameHost* render_frame_host) const;
290
260 PresentationServiceDelegate* delegate_; 291 PresentationServiceDelegate* delegate_;
261 292
262 // Map from presentation URL to its ScreenAvailabilityContext state machine. 293 // Map from presentation URL to its ScreenAvailabilityContext state machine.
263 base::hash_map<std::string, linked_ptr<ScreenAvailabilityContext>> 294 base::hash_map<std::string, linked_ptr<ScreenAvailabilityContext>>
264 availability_contexts_; 295 availability_contexts_;
265 296
266 std::string default_presentation_url_; 297 std::string default_presentation_url_;
267 std::string default_presentation_id_; 298 std::string default_presentation_id_;
268 299
269 // We only allow one StartSession request to be processed at a time. 300 // We only allow one StartSession request to be processed at a time.
270 // StartSession requests are queued here. When a request has been processed, 301 // StartSession requests are queued here. When a request has been processed,
271 // it is removed from head of the queue. 302 // it is removed from head of the queue.
272 std::deque<linked_ptr<StartSessionRequest>> queued_start_session_requests_; 303 std::deque<linked_ptr<StartSessionRequest>> queued_start_session_requests_;
273 304
274 // Indicates that a StartSession request is currently being processed. 305 // Indicates that a StartSession request is currently being processed.
275 bool is_start_session_pending_; 306 bool is_start_session_pending_;
276 307
277 int next_request_session_id_; 308 int next_request_session_id_;
278 base::hash_map<int, linked_ptr<NewSessionMojoCallback>> pending_session_cbs_; 309 base::hash_map<int, linked_ptr<NewSessionMojoCallback>> pending_session_cbs_;
279 310
311 scoped_ptr<DefaultSessionStartContext> default_session_start_context_;
312
280 // RAII binding of |this| to an Presentation interface request. 313 // RAII binding of |this| to an Presentation interface request.
281 // The binding is removed when binding_ is cleared or goes out of scope. 314 // The binding is removed when binding_ is cleared or goes out of scope.
282 scoped_ptr<mojo::Binding<presentation::PresentationService>> binding_; 315 scoped_ptr<mojo::Binding<presentation::PresentationService>> binding_;
283 316
317 // ID of the RenderFrameHost this object is associated with.
318 int render_process_id_;
319 int render_frame_id_;
320
284 // NOTE: Weak pointers must be invalidated before all other member variables. 321 // NOTE: Weak pointers must be invalidated before all other member variables.
285 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; 322 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_;
286 323
287 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); 324 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl);
288 }; 325 };
289 326
290 } // namespace content 327 } // namespace content
291 328
292 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ 329 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/presentation/presentation_service_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698