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 dd4ac02193db5457222ab8068a92d4177717385a..d86474fa6490350480ab6809e6536b13fa4ba2a5 100644 |
| --- a/content/browser/presentation/presentation_service_impl.h |
| +++ b/content/browser/presentation/presentation_service_impl.h |
| @@ -11,6 +11,7 @@ |
| #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" |
| @@ -56,7 +57,7 @@ class CONTENT_EXPORT PresentationServiceImpl |
| 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 +66,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. |
| @@ -88,6 +95,8 @@ class CONTENT_EXPORT PresentationServiceImpl |
| const mojo::String& presentation_url, |
| const mojo::String& presentation_id, |
| const NewSessionMojoCallback& callback) override; |
| + void SetDefaultPresentationUrl( |
| + const mojo::String& presentation_url) override; |
| // mojo::InterfaceImpl override. |
| // Note that this is called when the RenderFrameHost is deleted. |
| @@ -103,76 +112,18 @@ class CONTENT_EXPORT PresentationServiceImpl |
| // PresentationServiceDelegate::Observer |
| void OnDelegateDestroyed() override; |
| - // Removes all listeners on this instance and informs the |
| - // PresentationServiceDelegate of such. |
| - void RemoveAllListeners(); |
| - |
| - 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_; |
| + // Sets |default_presentation_url_| to |presentation_url| and informs the |
| + // delegate of such. |
| + void DoSetDefaultPresentationUrl(const std::string& presentation_url); |
| - // mojo::InterfaceImpl override. |
| - // Note that this is called when the RenderFrameHost is deleted. |
| - void OnConnectionError() override; |
| + // Removes all listeners and resets default presentation URL on this instance |
| + // and informs the PresentationServiceDelegate of such. |
| + void Reset(); |
| - // WebContentsObserver override. |
| - void DidNavigateAnyFrame( |
| - content::RenderFrameHost* render_frame_host, |
| - const content::LoadCommittedDetails& details, |
| - const content::FrameNavigateParams& params) override; |
| - void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; |
| - |
| - // PresentationServiceDelegate::Observer |
| - void OnDelegateDestroyed() override; |
| - |
| - // Removes all listeners on this instance and informs the |
| - // PresentationServiceDelegate of such. |
| - void RemoveAllListeners(); |
| + // Callbacks from the embedder as a result of StartSession/JoinSession. |
| + void OnStartOrJoinSessionSucceeded( |
| + const PresentationSessionInfo& session_info); |
| + void OnStartOrJoinSessionError(const PresentationError& error); |
| RenderFrameHost* render_frame_host_; |
| PresentationServiceDelegate* delegate_; |
| @@ -211,6 +162,11 @@ 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 { |
| + return callback_ptr_.get(); |
| + } |
| + |
| private: |
| std::string presentation_url_; |
| scoped_ptr<ScreenAvailabilityMojoCallback> callback_ptr_; |
| @@ -223,6 +179,16 @@ class CONTENT_EXPORT PresentationServiceImpl |
| std::string default_presentation_url_; |
| + // This is set when there is a StartSession/JoinSession in progress. |
| + // Additional StartSession/JoinSession calls are ignored while this is |
|
whywhat
2015/03/10 17:05:04
Is this a temporary limitation? What if the frame
imcheng
2015/03/10 18:31:15
For StartSession, we can only process one at a tim
|
| + // set. |
| + // When embedder returns with a result, this callback will be invoked and then |
| + // reset. |
| + scoped_ptr<NewSessionMojoCallback> start_or_join_session_cb_; |
| + |
| + // NOTE: Weak pointers must be invalidated before all other member variables. |
| + base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); |
| }; |