| OLD | NEW |
| 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 Loading... |
| 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 | |
| 133 // Context for a StartSession request. | 112 // Context for a StartSession request. |
| 134 class CONTENT_EXPORT StartSessionRequest { | 113 class CONTENT_EXPORT StartSessionRequest { |
| 135 public: | 114 public: |
| 136 StartSessionRequest(const std::string& presentation_url, | 115 StartSessionRequest(const std::string& presentation_url, |
| 137 const std::string& presentation_id, | 116 const std::string& presentation_id, |
| 138 const NewSessionMojoCallback& callback); | 117 const NewSessionMojoCallback& callback); |
| 139 ~StartSessionRequest(); | 118 ~StartSessionRequest(); |
| 140 | 119 |
| 141 // Retrieves the pending callback from this request, transferring ownership | 120 // Retrieves the pending callback from this request, transferring ownership |
| 142 // to the caller. | 121 // to the caller. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 160 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 139 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
| 161 ThisRenderFrameDeleted); | 140 ThisRenderFrameDeleted); |
| 162 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 141 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
| 163 NotThisRenderFrameDeleted); | 142 NotThisRenderFrameDeleted); |
| 164 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 143 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
| 165 SetDefaultPresentationUrl); | 144 SetDefaultPresentationUrl); |
| 166 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 145 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
| 167 SetSameDefaultPresentationUrl); | 146 SetSameDefaultPresentationUrl); |
| 168 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 147 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
| 169 ClearDefaultPresentationUrl); | 148 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); | |
| 176 | 149 |
| 177 // |render_frame_host|: The RFH this instance is associated with. | 150 // |render_frame_host|: The RFH this instance is associated with. |
| 178 // |web_contents|: The WebContents to observe. | 151 // |web_contents|: The WebContents to observe. |
| 179 // |delegate|: Where Presentation API requests are delegated to. Not owned | 152 // |delegate|: Where Presentation API requests are delegated to. Not owned |
| 180 // by this class. | 153 // by this class. |
| 181 PresentationServiceImpl( | 154 PresentationServiceImpl( |
| 182 RenderFrameHost* render_frame_host, | 155 RenderFrameHost* render_frame_host, |
| 183 WebContents* web_contents, | 156 WebContents* web_contents, |
| 184 PresentationServiceDelegate* delegate); | 157 PresentationServiceDelegate* delegate); |
| 185 | 158 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 190 |
| 218 // WebContentsObserver override. | 191 // WebContentsObserver override. |
| 219 void DidNavigateAnyFrame( | 192 void DidNavigateAnyFrame( |
| 220 content::RenderFrameHost* render_frame_host, | 193 content::RenderFrameHost* render_frame_host, |
| 221 const content::LoadCommittedDetails& details, | 194 const content::LoadCommittedDetails& details, |
| 222 const content::FrameNavigateParams& params) override; | 195 const content::FrameNavigateParams& params) override; |
| 223 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; | 196 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; |
| 224 | 197 |
| 225 // PresentationServiceDelegate::Observer | 198 // PresentationServiceDelegate::Observer |
| 226 void OnDelegateDestroyed() override; | 199 void OnDelegateDestroyed() override; |
| 227 void OnDefaultPresentationStarted(const PresentationSessionInfo& session) | |
| 228 override; | |
| 229 | 200 |
| 230 // Finds the callback from |pending_session_cbs_| using |request_session_id|. | 201 // Finds the callback from |pending_session_cbs_| using |request_session_id|. |
| 231 // If it exists, invoke it with |session| and |error|, then erase it from | 202 // If it exists, invoke it with |session| and |error|, then erase it from |
| 232 // |pending_session_cbs_|. | 203 // |pending_session_cbs_|. |
| 233 void RunAndEraseNewSessionMojoCallback( | 204 void RunAndEraseNewSessionMojoCallback( |
| 234 int request_session_id, | 205 int request_session_id, |
| 235 presentation::PresentationSessionInfoPtr session, | 206 presentation::PresentationSessionInfoPtr session, |
| 236 presentation::PresentationErrorPtr error); | 207 presentation::PresentationErrorPtr error); |
| 237 | 208 |
| 238 // Sets |default_presentation_url_| to |presentation_url| and informs the | 209 // Sets |default_presentation_url_| to |presentation_url| and informs the |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 | 249 |
| 279 // Invokes |callback| with an error. | 250 // Invokes |callback| with an error. |
| 280 static void InvokeNewSessionMojoCallbackWithError( | 251 static void InvokeNewSessionMojoCallbackWithError( |
| 281 const NewSessionMojoCallback& callback); | 252 const NewSessionMojoCallback& callback); |
| 282 | 253 |
| 283 // Gets the ScreenAvailabilityContext for |presentation_url|, or creates one | 254 // Gets the ScreenAvailabilityContext for |presentation_url|, or creates one |
| 284 // if it does not exist. | 255 // if it does not exist. |
| 285 ScreenAvailabilityContext* GetOrCreateAvailabilityContext( | 256 ScreenAvailabilityContext* GetOrCreateAvailabilityContext( |
| 286 const std::string& presentation_url); | 257 const std::string& presentation_url); |
| 287 | 258 |
| 288 // Returns true if this object is associated with |render_frame_host|. | 259 RenderFrameHost* render_frame_host_; |
| 289 bool FrameMatches(content::RenderFrameHost* render_frame_host) const; | |
| 290 | |
| 291 PresentationServiceDelegate* delegate_; | 260 PresentationServiceDelegate* delegate_; |
| 292 | 261 |
| 293 // Map from presentation URL to its ScreenAvailabilityContext state machine. | 262 // Map from presentation URL to its ScreenAvailabilityContext state machine. |
| 294 base::hash_map<std::string, linked_ptr<ScreenAvailabilityContext>> | 263 base::hash_map<std::string, linked_ptr<ScreenAvailabilityContext>> |
| 295 availability_contexts_; | 264 availability_contexts_; |
| 296 | 265 |
| 297 std::string default_presentation_url_; | 266 std::string default_presentation_url_; |
| 298 std::string default_presentation_id_; | 267 std::string default_presentation_id_; |
| 299 | 268 |
| 300 // We only allow one StartSession request to be processed at a time. | 269 // We only allow one StartSession request to be processed at a time. |
| 301 // StartSession requests are queued here. When a request has been processed, | 270 // StartSession requests are queued here. When a request has been processed, |
| 302 // it is removed from head of the queue. | 271 // it is removed from head of the queue. |
| 303 std::deque<linked_ptr<StartSessionRequest>> queued_start_session_requests_; | 272 std::deque<linked_ptr<StartSessionRequest>> queued_start_session_requests_; |
| 304 | 273 |
| 305 // Indicates that a StartSession request is currently being processed. | 274 // Indicates that a StartSession request is currently being processed. |
| 306 bool is_start_session_pending_; | 275 bool is_start_session_pending_; |
| 307 | 276 |
| 308 int next_request_session_id_; | 277 int next_request_session_id_; |
| 309 base::hash_map<int, linked_ptr<NewSessionMojoCallback>> pending_session_cbs_; | 278 base::hash_map<int, linked_ptr<NewSessionMojoCallback>> pending_session_cbs_; |
| 310 | 279 |
| 311 scoped_ptr<DefaultSessionStartContext> default_session_start_context_; | |
| 312 | |
| 313 // RAII binding of |this| to an Presentation interface request. | 280 // RAII binding of |this| to an Presentation interface request. |
| 314 // The binding is removed when binding_ is cleared or goes out of scope. | 281 // The binding is removed when binding_ is cleared or goes out of scope. |
| 315 scoped_ptr<mojo::Binding<presentation::PresentationService>> binding_; | 282 scoped_ptr<mojo::Binding<presentation::PresentationService>> binding_; |
| 316 | 283 |
| 317 // ID of the RenderFrameHost this object is associated with. | |
| 318 int render_process_id_; | |
| 319 int render_frame_id_; | |
| 320 | |
| 321 // NOTE: Weak pointers must be invalidated before all other member variables. | 284 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 322 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; | 285 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; |
| 323 | 286 |
| 324 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); | 287 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); |
| 325 }; | 288 }; |
| 326 | 289 |
| 327 } // namespace content | 290 } // namespace content |
| 328 | 291 |
| 329 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ | 292 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ |
| OLD | NEW |