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

Unified Diff: content/browser/presentation/presentation_service_impl.h

Issue 979413002: [Presentation API] Additional plumbing for PresentationServiceImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@REAL-NEW-MASTER
Patch Set: rm presentation_session.mojom Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/browser/presentation/presentation_service_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..38ba4129448ff6681bc591d18659f8689e47c27a 100644
--- a/content/browser/presentation/presentation_service_impl.h
+++ b/content/browser/presentation/presentation_service_impl.h
@@ -5,15 +5,17 @@
#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"
#include "content/public/browser/navigation_details.h"
#include "content/public/browser/presentation_screen_availability_listener.h"
#include "content/public/browser/presentation_service_delegate.h"
@@ -50,15 +52,72 @@ 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
+ : 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;
+
+ // 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 {
+ 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,62 @@ 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();
+
+ // These two functions are bound as base::Callbacks and passed to
+ // embedder's implementation of PresentationServiceDelegate for later
+ // invocation.
+ 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);
};
« 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