Chromium Code Reviews| Index: content/browser/presentation/presentation_service_impl.h |
| diff --git a/content/browser/presentation/presentation_service_impl.h b/content/browser/presentation/presentation_service_impl.h |
| index 65e729f49bd85d0c73f5ba844c23837237dedf05..ba4bb42c50a0a841ce0124a99dd112ac7cc3aa05 100644 |
| --- a/content/browser/presentation/presentation_service_impl.h |
| +++ b/content/browser/presentation/presentation_service_impl.h |
| @@ -5,12 +5,15 @@ |
| #ifndef CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ |
| #define CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ |
| +#include <deque> |
| + |
| #include "base/basictypes.h" |
| #include "base/compiler_specific.h" |
| #include "base/containers/hash_tables.h" |
| #include "base/gtest_prod_util.h" |
| #include "base/macros.h" |
| #include "base/memory/linked_ptr.h" |
| +#include "base/memory/weak_ptr.h" |
| #include "content/common/content_export.h" |
| #include "content/common/presentation/presentation_service.mojom.h" |
| #include "content/common/presentation/presentation_session.mojom.h" |
| @@ -50,13 +53,14 @@ class CONTENT_EXPORT PresentationServiceImpl |
| mojo::InterfaceRequest<presentation::PresentationService> request); |
| private: |
| - using ScreenAvailabilityMojoCallback = mojo::Callback<void(bool)>; |
| + using ScreenAvailabilityMojoCallback = |
| + mojo::Callback<void(mojo::String, bool)>; |
| using NewSessionMojoCallback = |
| mojo::Callback<void(presentation::PresentationSessionInfoPtr, |
| presentation::PresentationErrorPtr)>; |
| friend class PresentationServiceImplTest; |
| - FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, RemoveAllListeners); |
| + FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, Reset); |
| FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
| DidNavigateThisFrame); |
| FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
| @@ -65,6 +69,12 @@ class CONTENT_EXPORT PresentationServiceImpl |
| ThisRenderFrameDeleted); |
| FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
| NotThisRenderFrameDeleted); |
| + FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
| + SetDefaultPresentationUrl); |
| + FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
| + SetSameDefaultPresentationUrl); |
| + FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
| + ClearDefaultPresentationUrl); |
| // |render_frame_host|: The RFH this instance is associated with. |
| // |web_contents|: The WebContents to observe. |
| @@ -79,7 +89,8 @@ class CONTENT_EXPORT PresentationServiceImpl |
| void GetScreenAvailability( |
| const mojo::String& presentation_url, |
| const ScreenAvailabilityMojoCallback& callback) override; |
| - void OnScreenAvailabilityListenerRemoved() override; |
| + void OnScreenAvailabilityListenerRemoved( |
| + const mojo::String& presentation_url) override; |
| void StartSession( |
| const mojo::String& presentation_url, |
| const mojo::String& presentation_id, |
| @@ -88,6 +99,9 @@ class CONTENT_EXPORT PresentationServiceImpl |
| const mojo::String& presentation_url, |
| const mojo::String& presentation_id, |
| const NewSessionMojoCallback& callback) override; |
| + void SetDefaultPresentationUrl( |
| + const mojo::String& default_presentation_url, |
| + const mojo::String& default_presentation_id) override; |
| // mojo::InterfaceImpl override. |
| // Note that this is called when the RenderFrameHost is deleted. |
| @@ -103,9 +117,35 @@ class CONTENT_EXPORT PresentationServiceImpl |
| // PresentationServiceDelegate::Observer |
| void OnDelegateDestroyed() override; |
| - // Removes all listeners on this instance and informs the |
| - // PresentationServiceDelegate of such. |
| - void RemoveAllListeners(); |
| + // Sets |default_presentation_url_| to |presentation_url| and informs the |
| + // delegate of new default presentation URL and ID. |
| + void DoSetDefaultPresentationUrl( |
| + const std::string& presentation_url, |
| + const std::string& presentation_id); |
| + |
| + // Removes all listeners and resets default presentation URL on this instance |
| + // and informs the PresentationServiceDelegate of such. |
| + void Reset(); |
| + |
| + // Callbacks from the embedder as a result of StartSession/JoinSession. |
| + void OnStartOrJoinSessionSucceeded( |
| + bool is_start_session, |
| + const NewSessionMojoCallback& callback, |
| + const PresentationSessionInfo& session_info); |
| + void OnStartOrJoinSessionError( |
| + bool is_start_session, |
| + const NewSessionMojoCallback& callback, |
| + const PresentationError& error); |
| + |
| + // Requests delegate to start a session. |
| + void DoStartSession( |
| + const std::string& presentation_url, |
| + const std::string& presentation_id, |
| + const NewSessionMojoCallback& callback); |
| + |
| + // Checks if there are any queued StartSession requests and if so, executes |
| + // the first one in the queue and remove it from the queue. |
|
whywhat
2015/03/13 17:44:35
nit: s/remove/removes
imcheng
2015/03/13 23:36:46
Done.
|
| + void HandleQueuedStartSessionRequests(); |
| RenderFrameHost* render_frame_host_; |
| PresentationServiceDelegate* delegate_; |
| @@ -144,17 +184,44 @@ class CONTENT_EXPORT PresentationServiceImpl |
| // |available|: New screen availability for the presentation URL. |
| void OnScreenAvailabilityChanged(bool available) override; |
| + // Gets the callback as a raw pointer. |
| + ScreenAvailabilityMojoCallback* callback() const { |
|
whywhat
2015/03/13 17:44:35
nit: I think since it's not a plain and simple "re
imcheng
2015/03/13 23:36:46
Done.
|
| + return callback_ptr_.get(); |
| + } |
| + |
| private: |
| std::string presentation_url_; |
| scoped_ptr<ScreenAvailabilityMojoCallback> callback_ptr_; |
| scoped_ptr<bool> available_ptr_; |
| }; |
| + // Context for a StartSession request. |
| + struct StartSessionRequest { |
| + StartSessionRequest(const std::string& presentation_url, |
| + const std::string& presentation_id, |
| + const NewSessionMojoCallback& callback); |
| + ~StartSessionRequest(); |
| + |
| + const std::string presentation_url; |
| + const std::string presentation_id; |
| + const NewSessionMojoCallback callback; |
| + }; |
| + |
| // Map from presentation URL to its ScreenAvailabilityContext state machine. |
| base::hash_map<std::string, linked_ptr<ScreenAvailabilityContext>> |
| availability_contexts_; |
| std::string default_presentation_url_; |
| + std::string default_presentation_id_; |
| + |
| + // This is set when there is a StartSession in progress. |
| + // Additional StartSession requests while one is in progress are queued for |
| + // later execution. |
| + bool start_session_in_progress_; |
| + std::deque<linked_ptr<StartSessionRequest>> queued_start_session_requests_; |
| + |
| + // NOTE: Weak pointers must be invalidated before all other member variables. |
| + base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; |
| DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); |
| }; |