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

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

Issue 2343013002: [Presentation API] (MR side) 1-UA: notify receiver page when receiver connection becomes available (Closed)
Patch Set: 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.cc
diff --git a/chrome/browser/media/router/offscreen_presentation_manager.cc b/chrome/browser/media/router/offscreen_presentation_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4ba3b841f6543f080caa4f85b30230814c5edb0f
--- /dev/null
+++ b/chrome/browser/media/router/offscreen_presentation_manager.cc
@@ -0,0 +1,134 @@
+// Copyright 2015 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.
+
+#include "chrome/browser/media/router/offscreen_presentation_manager.h"
+
+#include "base/memory/ptr_util.h"
+#include "content/public/browser/render_frame_host.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/web_contents.h"
+
+namespace media_router {
+
+// OffscreenPresentationManager implementation. ////////////////////////////////
+OffscreenPresentationManager::OffscreenPresentationManager() {}
+OffscreenPresentationManager::~OffscreenPresentationManager() {}
+
+void OffscreenPresentationManager::RegisterOffscreenPresentationController(
+ const std::string& presentation_id,
+ content::OffscreenPresentationClient* controller) {
+ DVLOG(2)
+ << "OffscreenPresentationManager::RegisterOffscreenPresentationController"
+ << "[id]: " << presentation_id;
+
+ // Create a new presentation.
+ if (!base::ContainsKey(offscreen_presentations_, presentation_id))
+ offscreen_presentations_.insert(std::make_pair(
+ presentation_id,
+ base::WrapUnique(new OffscreenPresentation(presentation_id))));
imcheng 2016/09/19 23:01:17 base::MakeUnique<OffscreenPresentation>(presentati
zhaobin 2016/09/23 17:18:18 Done.
+
+ auto it = offscreen_presentations_.find(presentation_id);
imcheng 2016/09/19 23:01:17 The entry should already exist in offscreen_presen
zhaobin 2016/09/23 17:18:18 Done.
+ if (it != offscreen_presentations_.end())
+ it->second->RegisterController(controller);
+}
+
+void OffscreenPresentationManager::UnregisterOffscreenPresentationController(
+ const std::string& presentation_id,
+ content::OffscreenPresentationClient* controller) {
+ DVLOG(2) << "OffscreenPresentationManager::"
+ "UnRegisterOffscreenPresentationController";
+
+ auto it = offscreen_presentations_.find(presentation_id);
+ if (it == offscreen_presentations_.end())
+ return;
+
+ // Remove presentation if no controller.
+ it->second->UnregisterController(controller);
+ if (it->second->controllers_.size() == 0)
+ UnregisterOffscreenPresentationReceiver(presentation_id);
+}
+
+void OffscreenPresentationManager::RegisterOffscreenPresentationReceiver(
+ const std::string& presentation_id,
+ content::OffscreenPresentationClient* receiver) {
+ DVLOG(2)
+ << "OffscreenPresentationManager::RegisterOffscreenPresentationReceiver"
+ << "[id]: " << presentation_id;
+
+ auto it = offscreen_presentations_.find(presentation_id);
+ if (it != offscreen_presentations_.end())
+ it->second->RegisterReceiver(receiver);
+}
+
+void OffscreenPresentationManager::UnregisterOffscreenPresentationReceiver(
+ const std::string& presentation_id) {
+ DVLOG(2) << "OffscreenPresentationManager::"
+ "UnRegisterOffscreenPresentationReceiver";
+
+ auto it = offscreen_presentations_.find(presentation_id);
+ if (it != offscreen_presentations_.end())
+ it->second->UnregisterReceiver();
+
+ offscreen_presentations_.erase(presentation_id);
+}
+
+// OffscreenPresentation implementation. ///////////////////////////////////////
+OffscreenPresentation::OffscreenPresentation(const std::string& presentation_id)
+ : presentation_id_(presentation_id), receiver_(nullptr) {}
+
+OffscreenPresentation::~OffscreenPresentation() {}
+
+void OffscreenPresentation::RegisterController(
+ content::OffscreenPresentationClient* controller) {
+ // Connect controller PSImpl and receiver PSImpl.
+ if (receiver_)
+ AddOffscreenPresentationObserver(controller, receiver_);
+ controllers_.insert(controller);
+}
+
+void OffscreenPresentation::UnregisterController(
+ content::OffscreenPresentationClient* controller) {
+ if (receiver_)
+ RemoveOffscreenPresentationObserver(controller, receiver_);
+ controllers_.erase(controller);
+}
+
+void OffscreenPresentation::RegisterReceiver(
+ content::OffscreenPresentationClient* receiver) {
+ for (const auto& controller : controllers_)
+ AddOffscreenPresentationObserver(controller, receiver);
+ receiver_ = receiver;
+}
+
+void OffscreenPresentation::UnregisterReceiver() {
+ if (!receiver_)
+ return;
+
+ for (const auto& iter : controllers_)
+ RemoveOffscreenPresentationObserver(iter, receiver_);
+ receiver_ = nullptr;
+}
+
+void OffscreenPresentation::AddOffscreenPresentationObserver(
+ content::OffscreenPresentationClient* controller,
+ content::OffscreenPresentationClient* receiver) {
+ // Connect controller PSImpl and receiver PSImpl.
+ controller->AddOffscreenPresentationObserver(receiver);
+ receiver->AddOffscreenPresentationObserver(controller);
+
+ // Build a connection between controller and receiver and
+ // invoke on OnReceiverConnectionAvailable event.
+ receiver->OnReceiverConnectionAvailable(
+ content::PresentationSessionInfo(presentation_url_, presentation_id_));
+}
+
+void OffscreenPresentation::RemoveOffscreenPresentationObserver(
+ content::OffscreenPresentationClient* controller,
+ content::OffscreenPresentationClient* receiver) {
+ // Connect controller PSImpl and receiver PSImpl.
+ controller->RemoveOffscreenPresentationObserver(receiver);
+ receiver->RemoveOffscreenPresentationObserver(controller);
+}
+
+} // namespace media_router

Powered by Google App Engine
This is Rietveld 408576698