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 bc1e0ef9ce9b8462f36fb0d688be76917e7e4509..fed1fe8ef0d12061f7410fe6fbd2c9cf15e701c4 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,15 +53,71 @@ 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)>; |
| using DefaultSessionMojoCallback = |
| mojo::Callback<void(presentation::PresentationSessionInfoPtr)>; |
| + // A helper data class used by PresentationServiceImpl to do bookkeeping |
| + // of currently registered screen availability listeners. |
| + // An instance of this class is a simple state machine that waits for both |
| + // the available bit and the Mojo callback to become available. |
| + // Once this happens, the Mojo callback will be invoked with the available |
| + // bit, and the state machine will reset. |
| + // The available bit is obtained from the embedder's media router. |
| + // The callback is obtained from the renderer via PresentationServiceImpl's |
| + // GetScreenAvailability(). |
| + class CONTENT_EXPORT ScreenAvailabilityContext |
|
mark a. foltz
2015/03/18 00:10:58
Is CONTENT_EXPORT only for unit testing?
It is od
imcheng
2015/03/18 00:56:53
Yeah unfortunately this is needed otherwise unit t
|
| + : public PresentationScreenAvailabilityListener { |
| + public: |
| + explicit ScreenAvailabilityContext( |
| + const std::string& presentation_url); |
| + ~ScreenAvailabilityContext() override; |
| + |
| + // If available bit exists, |callback| will be invoked with the bit and |
| + // this state machine will reset. |
| + // Otherwise |callback| is saved for later use. |
| + // |callback|: Callback to the client of PresentationService |
| + // (i.e. the renderer) that screen availability has changed, via Mojo. |
| + void CallbackReceived(const ScreenAvailabilityMojoCallback& callback); |
| + |
| + // Clears both callback and available bit. |
| + void Reset(); |
| + |
| + // PresentationScreenAvailabilityListener implementation. |
| + std::string GetPresentationUrl() const override; |
| + // If callback exists, it will be invoked with |available| and |
|
mark a. foltz
2015/03/18 00:10:58
Add a blank line before to help readability of the
imcheng
2015/03/18 00:56:53
Done.
|
| + // this state machine will reset. |
| + // Otherwise |available| is saved for later use. |
| + // |available|: New screen availability for the presentation URL. |
| + void OnScreenAvailabilityChanged(bool available) override; |
| + |
| + // Gets the callback as a raw pointer. |
| + ScreenAvailabilityMojoCallback* GetCallback() const; |
| + |
| + private: |
| + std::string presentation_url_; |
| + scoped_ptr<ScreenAvailabilityMojoCallback> callback_ptr_; |
| + scoped_ptr<bool> available_ptr_; |
| + }; |
| + |
| + // Context for a StartSession request. |
| + struct CONTENT_EXPORT StartSessionRequest { |
|
mark a. foltz
2015/03/18 00:10:58
Similar comment about CONTENT_EXPORT.
imcheng
2015/03/18 00:56:53
Ditto
|
| + 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; |
| + }; |
| + |
| 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, |
| @@ -67,6 +126,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. |
| @@ -111,58 +176,60 @@ 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. |
|
mark a. foltz
2015/03/18 00:10:58
I don't quite follow this comment - this is in con
imcheng
2015/03/18 00:56:53
I clarified the comments here.
What I mean is tha
|
| + 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); |
| + |
| + // Removes the head of the queue (which represents the request that has just |
| + // been processed). |
| + // Checks if there are any queued StartSession requests and if so, executes |
| + // the first one in the queue. |
| + void HandleQueuedStartSessionRequests(); |
| + |
| + // Gets the ScreenAvailabilityContext for |presentation_url|, or creates one |
| + // if it does not exist. |
| + ScreenAvailabilityContext* GetOrCreateAvailabilityContext( |
| + const std::string& presentation_url); |
| RenderFrameHost* render_frame_host_; |
| PresentationServiceDelegate* delegate_; |
| - // A helper data class used by PresentationServiceImpl to do bookkeeping |
| - // of currently registered screen availability listeners. |
| - // An instance of this class is a simple state machine that waits for both |
| - // the available bit and the Mojo callback to become available. |
| - // Once this happens, the Mojo callback will be invoked with the available |
| - // bit, and the state machine will reset. |
| - // The available bit is obtained from the embedder's media router. |
| - // The callback is obtained from the renderer via PresentationServiceImpl's |
| - // GetScreenAvailability(). |
| - class ScreenAvailabilityContext |
| - : public PresentationScreenAvailabilityListener { |
| - public: |
| - explicit ScreenAvailabilityContext( |
| - const std::string& presentation_url); |
| - ~ScreenAvailabilityContext() override; |
| - |
| - // If available bit exists, |callback| will be invoked with the bit and |
| - // this state machine will reset. |
| - // Otherwise |callback| is saved for later use. |
| - // |callback|: Callback to the client of PresentationService |
| - // (i.e. the renderer) that screen availability has changed, via Mojo. |
| - void CallbackReceived(const ScreenAvailabilityMojoCallback& callback); |
| - |
| - // Clears both callback and available bit. |
| - void Reset(); |
| - |
| - // PresentationScreenAvailabilityListener implementation. |
| - std::string GetPresentationUrl() const override; |
| - // If callback exists, it will be invoked with |available| and |
| - // this state machine will reset. |
| - // Otherwise |available| is saved for later use. |
| - // |available|: New screen availability for the presentation URL. |
| - void OnScreenAvailabilityChanged(bool available) override; |
| - |
| - private: |
| - std::string presentation_url_; |
| - scoped_ptr<ScreenAvailabilityMojoCallback> callback_ptr_; |
| - scoped_ptr<bool> available_ptr_; |
| - }; |
| - |
| // 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_; |
| + |
| + // We only allow one StartSession request to be processed at a time. |
| + // StartSession requests are queued here. When a request has been processed, |
| + // it is removed from head of the queue. |
| + 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); |
| }; |