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

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

Issue 1243173003: [MediaRouter] Moved the code useful for Android to MediaRouterDialogController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@build-media-router-android
Patch Set: Fixed the unit test Created 5 years, 5 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/media_router_dialog_controller.cc
diff --git a/chrome/browser/media/router/media_router_dialog_controller.cc b/chrome/browser/media/router/media_router_dialog_controller.cc
index d9f80cc75805b71c733e0376807c6da84a604de5..e6c36dafaddf6ee54fa9782a04bcc204bd96271e 100644
--- a/chrome/browser/media/router/media_router_dialog_controller.cc
+++ b/chrome/browser/media/router/media_router_dialog_controller.cc
@@ -4,6 +4,10 @@
#include "chrome/browser/media/router/media_router_dialog_controller.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_delegate.h"
+
#if defined(OS_ANDROID)
#include "chrome/browser/media/android/router/media_router_dialog_controller_android.h"
#else
@@ -24,4 +28,96 @@ MediaRouterDialogController::GetOrCreateForWebContents(
#endif
}
+class MediaRouterDialogController::InitiatorWebContentsObserver
+ : public content::WebContentsObserver {
+ public:
+ InitiatorWebContentsObserver(
+ content::WebContents* web_contents,
+ MediaRouterDialogController* dialog_controller)
+ : content::WebContentsObserver(web_contents),
+ dialog_controller_(dialog_controller) {
+ DCHECK(dialog_controller_);
+ }
+
+ private:
+ void WebContentsDestroyed() override {
+ // NOTE: |this| is deleted after CloseMediaRouterDialog() returns.
+ dialog_controller_->CloseMediaRouterDialog();
+ }
+
+ void NavigationEntryCommitted(
+ const content::LoadCommittedDetails& load_details) override {
+ // NOTE: |this| is deleted after CloseMediaRouterDialog() returns.
+ dialog_controller_->CloseMediaRouterDialog();
+ }
+
+ void RenderProcessGone(base::TerminationStatus status) override {
+ // NOTE: |this| is deleted after CloseMediaRouterDialog() returns.
+ dialog_controller_->CloseMediaRouterDialog();
+ }
+
+ MediaRouterDialogController* const dialog_controller_;
+};
+
+MediaRouterDialogController::MediaRouterDialogController(
+ content::WebContents* initiator)
+ : initiator_(initiator) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ DCHECK(initiator_);
+ initiator_observer_.reset(new InitiatorWebContentsObserver(initiator_, this));
+}
+
+MediaRouterDialogController::~MediaRouterDialogController() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+}
+
+bool MediaRouterDialogController::ShowMediaRouterDialogForPresentation(
+ scoped_ptr<CreatePresentationSessionRequest> request) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ // Check if the media router dialog exists for |initiator| and return if so.
+ if (IsShowingMediaRouterDialog())
+ return false;
+
+ presentation_request_ = request.Pass();
+ CreateMediaRouterDialog();
+
+ // Show the initiator holding the existing media router dialog.
+ ActivateInitiatorWebContents();
+
+ return true;
+}
+
+bool MediaRouterDialogController::ShowMediaRouterDialog() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ // Don't create dialog if it already exists.
+ bool dialog_needs_creation = !IsShowingMediaRouterDialog();
+ if (dialog_needs_creation)
+ CreateMediaRouterDialog();
+
+ ActivateInitiatorWebContents();
+ return dialog_needs_creation;
+}
+
+void MediaRouterDialogController::HideMediaRouterDialog() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ CloseMediaRouterDialog();
+ Reset();
+}
+
+void MediaRouterDialogController::ActivateInitiatorWebContents() {
+ initiator_->GetDelegate()->ActivateContents(initiator_);
+}
+
+scoped_ptr<CreatePresentationSessionRequest>
+MediaRouterDialogController::PassPresentationRequest() {
+ return presentation_request_.Pass();
+}
+
+void MediaRouterDialogController::Reset() {
+ initiator_observer_.reset();
+ presentation_request_.reset();
+}
+
} // namespace media_router
« no previous file with comments | « chrome/browser/media/router/media_router_dialog_controller.h ('k') | chrome/browser/ui/toolbar/media_router_action.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698