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

Unified Diff: chrome/browser/media/router/offscreen_presentation_manager.h

Issue 2343013002: [Presentation API] (MR side) 1-UA: notify receiver page when receiver connection becomes available (Closed)
Patch Set: resolve code review comments from Derek Created 4 years, 3 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
Index: chrome/browser/media/router/offscreen_presentation_manager.h
diff --git a/chrome/browser/media/router/offscreen_presentation_manager.h b/chrome/browser/media/router/offscreen_presentation_manager.h
new file mode 100644
index 0000000000000000000000000000000000000000..cdb40b2491693805de9f45481c67dbeaa71b50c8
--- /dev/null
+++ b/chrome/browser/media/router/offscreen_presentation_manager.h
@@ -0,0 +1,165 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_MEDIA_ROUTER_OFFSCREEN_PRESENTATION_MANAGER_H_
+#define CHROME_BROWSER_MEDIA_ROUTER_OFFSCREEN_PRESENTATION_MANAGER_H_
+
+#include <map>
+#include <memory>
+#include <set>
imcheng 2016/09/28 07:28:36 <set> and <vector> not used?
zhaobin 2016/09/29 17:20:43 Done.
+#include <string>
+#include <vector>
+
+#include "base/macros.h"
+#include "chrome/browser/media/router/render_frame_host_id.h"
+#include "components/keyed_service/core/keyed_service.h"
+#include "content/public/browser/presentation_service_delegate.h"
+
+namespace media_router {
+
+class OffscreenPresentation;
+
+// Instances of this class manages all offscreen presentations started in the
+// associated Profile and facilitates communication between the controllers and
+// the
+// receiver of an offscreen presentation.
imcheng 2016/09/28 07:28:36 nit: this can go in previous line.
zhaobin 2016/09/29 17:20:43 Done.
+//
+// Example usage:
+//
+// Receiver is created to host the offscreen presentation and registers itself
+// so that controller frames can connect to it:
+//
+// OffscreenPresentationManager* manager =
+// OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext(
+// context);
+// manager->RegisterOffscreenPresentationReceiver(presentation_id,
+// base::Bind(&OnReceiverConnectionAvailable));
+// ...
+// void OnReceiverConnectionAvailable(
+// const content::PresentationSessionInfo& session,
+// OffscreenPresentationClient* controller) {
+// [Connects controller PSImpl with receiver PSImpl to send/receive
+// messages in response to send()]
+// controller->SetOffscreenPresentationClient(receiver);
+// receiver->SetOffscreenPresentationClient(controller);
+// }
+//
+// Controller frame establishes connection with the receiver side, resulting
+// in a session with the two endpoints being the controller frame's PSImpl
+// (OffscreenPresentationClient) and the receiver frame's PSImpl
+// (OffscreenPresentationClient). Note calling this will trigger
+// |OnReceiverConnectionAvailable| on the receiver side.
+//
+// manager->RegisterOffscreenPresentationController(
+// presentation_id, controller_frame_id, controller_ptr);
+//
+// To send message from controller to receiver:
+//
+// In controll's PSImpl::SendSessionMessage() {
+// receiver.OnSessionMessage();
+// }
+//
+// A controller or receiver leaves the offscreen presentation (e.g.,
+// due to navigation) by unregistering themselves from
+// OffscreenPresentationConnection object.
+//
+// When the receiver is no longer associated with an offscreen presentation, it
+// shall remove itself from associated controllers and then unregister itself
+// with
imcheng 2016/09/28 07:28:36 nit: line wrap
zhaobin 2016/09/29 17:20:43 Done.
+// OffscreenPresentationManager. Unregistration will prevent additional
+// controllers from establishing a connection with the receiver:
+//
+// In receiver's PSImpl::Reset() {
+// for (controller : offscreen_presentation_observers_)
+// controller->RemoveOffscreenPresentationClient(receiver);
+// }
+// manager->UnregisterOffscreenPresentationReceiver(presentation_id);
+//
+// This class is not thread safe. All functions must be invoked on the UI
+// thread. All callbacks passed into this class will also be invoked on UI
+// thread.
+class OffscreenPresentationManager : public KeyedService {
+ public:
+ ~OffscreenPresentationManager() override;
+
+ // Register controller PSImpl to presentation with |presentation_id|,
+ // |render_frame_id|.
+ // Create a new presentation if no presentation with |presentation_id| exists.
+ // |controller| Not owned by this class.
+ void RegisterOffscreenPresentationController(
+ const std::string& presentation_id,
+ int render_frame_id,
imcheng 2016/09/28 07:28:36 Please use RenderFrameHostId here and below for al
zhaobin 2016/09/29 17:20:43 Done.
+ content::OffscreenPresentationClient* controller);
imcheng 2016/09/28 07:28:36 Can you forward declare OffscreenPresentationClien
zhaobin 2016/09/29 17:20:43 changed to content::PresentationConnectionPtr cont
+
+ // Unregister controller PSImpl to presentation with |presentation_id|,
+ // |render_frame_id|.
+ void UnregisterOffscreenPresentationController(
+ const std::string& presentation_id,
+ int render_frame_id);
+
+ // Register receiver PSImpl to presentation with |presentation_id|.
+ void RegisterOffscreenPresentationReceiver(
+ const std::string& presentation_id,
+ const content::ReceiverConnectionAvailableCallback& receiver_callback);
+
+ void UnregisterOffscreenPresentationReceiver(
+ const std::string& presentation_id);
+
+ private:
+ friend class OffscreenPresentationManagerFactory;
+ friend class OffscreenPresentationManagerTest;
+
+ // Used by OffscreenPresentationManagerFactory::GetOrCreateForBrowserContext.
+ OffscreenPresentationManager();
+
+ // Maps from presentation ID to OffscreenPresentation.
+ std::map<std::string, std::unique_ptr<OffscreenPresentation>>
+ offscreen_presentations_;
+
+ DISALLOW_COPY_AND_ASSIGN(OffscreenPresentationManager);
+};
+
+// Represents an offscreen presentation registered with
+// OffscreenPresentationManager.
+// Contains callback to the receiver to inform it of new sessions
+// established from a controller.
+// Contains set of controllers registered to OffscreenPresentationManager
+// before corresponding receiver.
+class OffscreenPresentation {
imcheng 2016/09/28 07:28:36 It looks like this class is not accessed from outs
zhaobin 2016/09/29 17:20:43 Done.
+ public:
+ explicit OffscreenPresentation(const std::string& presentation_id);
+ ~OffscreenPresentation();
+
+ void RegisterController(int render_frame_id,
+ content::OffscreenPresentationClient* controller);
+
+ void UnregisterController(int render_frame_id);
+
+ void RegisterReceiver(
+ const content::ReceiverConnectionAvailableCallback& receiver_callback);
+
+ private:
+ friend class OffscreenPresentationManagerTest;
+ friend class OffscreenPresentationManager;
+
+ // URL for current presentation
+ const std::string presentation_url_;
+
+ // presentation_id for current presentation
+ const std::string presentation_id_;
+
+ // proxy to receiver PSImpl
+ content::ReceiverConnectionAvailableCallback receiver_callback_;
+
+ // proxy to controller PSImpl
+ // It only contains controllers registered before receiver_callback_
+ // is set. This map will be cleared in RegisterReceiver().
+ std::map<int, content::OffscreenPresentationClient*> controllers_;
imcheng 2016/09/28 07:28:36 RenderFrameHostId
imcheng 2016/09/28 07:28:36 nit: I'd probably name it pending_controllers_ to
zhaobin 2016/09/29 17:20:43 Done.
zhaobin 2016/09/29 17:20:43 Done.
+
+ DISALLOW_COPY_AND_ASSIGN(OffscreenPresentation);
+};
+
+} // namespace media_router
+
+#endif // CHROME_BROWSER_MEDIA_ROUTER_OFFSCREEN_PRESENTATION_MANAGER_H_

Powered by Google App Engine
This is Rietveld 408576698