Commit 10feb240 authored by Ramin Halavati's avatar Ramin Halavati Committed by Commit Bot

Update presentation receiver window controller's OTR profile usage.

Independent OffTheRecord profile manager is getting deprecated.
PresentationReciverWindowController class is updated to use the newer
profile APIs instead of that.

Bug: 1033903
Change-Id: If2f664e01227a39be78c79c71eb2f5b02ea6b678
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2151448Reviewed-by: default avatarBrandon Tolsch <btolsch@chromium.org>
Commit-Queue: Ramin Halavati <rhalavati@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759939}
parent f336f3b7
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/media/router/presentation/receiver_presentation_service_delegate_impl.h" #include "chrome/browser/media/router/presentation/receiver_presentation_service_delegate_impl.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_destroyer.h"
#include "chrome/browser/ui/media_router/presentation_receiver_window.h" #include "chrome/browser/ui/media_router/presentation_receiver_window.h"
#include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h" #include "content/public/browser/navigation_entry.h"
...@@ -49,6 +50,11 @@ PresentationReceiverWindowController::CreateFromOriginalProfile( ...@@ -49,6 +50,11 @@ PresentationReceiverWindowController::CreateFromOriginalProfile(
PresentationReceiverWindowController::~PresentationReceiverWindowController() { PresentationReceiverWindowController::~PresentationReceiverWindowController() {
DCHECK(!web_contents_); DCHECK(!web_contents_);
DCHECK(!window_); DCHECK(!window_);
if (otr_profile_) {
otr_profile_->RemoveObserver(this);
ProfileDestroyer::DestroyProfileWhenAppropriate(otr_profile_);
}
} }
void PresentationReceiverWindowController::Start( void PresentationReceiverWindowController::Start(
...@@ -107,20 +113,16 @@ PresentationReceiverWindowController::PresentationReceiverWindowController( ...@@ -107,20 +113,16 @@ PresentationReceiverWindowController::PresentationReceiverWindowController(
const gfx::Rect& bounds, const gfx::Rect& bounds,
base::OnceClosure termination_callback, base::OnceClosure termination_callback,
TitleChangeCallback title_change_callback) TitleChangeCallback title_change_callback)
: otr_profile_registration_( : otr_profile_(
IndependentOTRProfileManager::GetInstance() profile->GetOffTheRecordProfile(Profile::OTRProfileID::CreateUnique(
->CreateFromOriginalProfile( "MediaRouter::PresentationReciever"))),
profile, web_contents_(WebContents::Create(CreateWebContentsParams(otr_profile_))),
base::BindOnce(&PresentationReceiverWindowController::
OriginalProfileDestroyed,
base::Unretained(this)))),
web_contents_(WebContents::Create(
CreateWebContentsParams(otr_profile_registration_->profile()))),
window_(PresentationReceiverWindow::Create(this, bounds)), window_(PresentationReceiverWindow::Create(this, bounds)),
termination_callback_(std::move(termination_callback)), termination_callback_(std::move(termination_callback)),
title_change_callback_(std::move(title_change_callback)) { title_change_callback_(std::move(title_change_callback)) {
DCHECK(otr_profile_registration_->profile()); DCHECK(otr_profile_);
DCHECK(otr_profile_registration_->profile()->IsOffTheRecord()); DCHECK(otr_profile_->IsOffTheRecord());
otr_profile_->AddObserver(this);
content::WebContentsObserver::Observe(web_contents_.get()); content::WebContentsObserver::Observe(web_contents_.get());
web_contents_->SetDelegate(this); web_contents_->SetDelegate(this);
} }
...@@ -130,11 +132,11 @@ void PresentationReceiverWindowController::WindowClosed() { ...@@ -130,11 +132,11 @@ void PresentationReceiverWindowController::WindowClosed() {
Terminate(); Terminate();
} }
void PresentationReceiverWindowController::OriginalProfileDestroyed( void PresentationReceiverWindowController::OnProfileWillBeDestroyed(
Profile* profile) { Profile* profile) {
DCHECK(profile == otr_profile_registration_->profile()); DCHECK(profile == otr_profile_);
web_contents_.reset(); web_contents_.reset();
otr_profile_registration_.reset(); otr_profile_ = nullptr;
Terminate(); Terminate();
} }
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/media/router/presentation/presentation_navigation_policy.h" #include "chrome/browser/media/router/presentation/presentation_navigation_policy.h"
#include "chrome/browser/media/router/providers/wired_display/wired_display_presentation_receiver.h" #include "chrome/browser/media/router/providers/wired_display/wired_display_presentation_receiver.h"
#include "chrome/browser/profiles/independent_otr_profile_manager.h" #include "chrome/browser/profiles/profile_observer.h"
#include "chrome/browser/ui/media_router/presentation_receiver_window_delegate.h" #include "chrome/browser/ui/media_router/presentation_receiver_window_delegate.h"
#include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
...@@ -38,7 +38,8 @@ class PresentationReceiverWindowController final ...@@ -38,7 +38,8 @@ class PresentationReceiverWindowController final
: public PresentationReceiverWindowDelegate, : public PresentationReceiverWindowDelegate,
public content::WebContentsObserver, public content::WebContentsObserver,
public content::WebContentsDelegate, public content::WebContentsDelegate,
public media_router::WiredDisplayPresentationReceiver { public media_router::WiredDisplayPresentationReceiver,
public ProfileObserver {
public: public:
using TitleChangeCallback = base::RepeatingCallback<void(const std::string&)>; using TitleChangeCallback = base::RepeatingCallback<void(const std::string&)>;
...@@ -68,7 +69,8 @@ class PresentationReceiverWindowController final ...@@ -68,7 +69,8 @@ class PresentationReceiverWindowController final
base::OnceClosure termination_callback, base::OnceClosure termination_callback,
TitleChangeCallback title_change_callback); TitleChangeCallback title_change_callback);
void OriginalProfileDestroyed(Profile* profile); // ProfileObserver:
void OnProfileWillBeDestroyed(Profile* profile) override;
// These methods are intended to be used by tests. // These methods are intended to be used by tests.
void CloseWindowForTest(); void CloseWindowForTest();
...@@ -101,8 +103,7 @@ class PresentationReceiverWindowController final ...@@ -101,8 +103,7 @@ class PresentationReceiverWindowController final
const GURL& target_url) override; const GURL& target_url) override;
// The profile used for the presentation. // The profile used for the presentation.
std::unique_ptr<IndependentOTRProfileManager::OTRProfileRegistration> Profile* otr_profile_;
otr_profile_registration_;
// WebContents for rendering the receiver page. // WebContents for rendering the receiver page.
std::unique_ptr<content::WebContents> web_contents_; std::unique_ptr<content::WebContents> web_contents_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment