Commit 24fbb2b6 authored by Ramin Halavati's avatar Ramin Halavati Committed by Commit Bot

Update OffscreenTab's use of OTR profiles.

IndependentOTRProfileManager is deprecated. Usage of OTR profiles in
OffscreenTab is updated to use profile API instead of it.

Bug: 1033903
Change-Id: I792f1d5e16fcab56131d9fa74a2f4b4ed4c35400
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2153072
Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarSergey Ulanov <sergeyu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#760754}
parent 88b4d2f3
......@@ -12,6 +12,7 @@
#include "chrome/browser/media/router/presentation/presentation_navigation_policy.h"
#include "chrome/browser/media/router/presentation/receiver_presentation_service_delegate_impl.h" // nogncheck
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_destroyer.h"
#include "chrome/browser/ui/web_contents_sizer.h"
#include "content/public/browser/keyboard_event_processing_result.h"
#include "content/public/browser/navigation_handle.h"
......@@ -123,21 +124,21 @@ class OffscreenTab::WindowAdoptionAgent : protected aura::WindowObserver {
OffscreenTab::OffscreenTab(Owner* owner, content::BrowserContext* context)
: owner_(owner),
otr_profile_registration_(
IndependentOTRProfileManager::GetInstance()
->CreateFromOriginalProfile(
Profile::FromBrowserContext(context),
base::BindOnce(&OffscreenTab::DieIfOriginalProfileDestroyed,
base::Unretained(this)))),
otr_profile_(Profile::FromBrowserContext(context)->GetOffTheRecordProfile(
Profile::OTRProfileID::CreateUnique("Media::OffscreenTab"))),
content_capture_was_detected_(false),
navigation_policy_(
std::make_unique<media_router::DefaultNavigationPolicy>()) {
DCHECK(owner_);
DCHECK(otr_profile_registration_->profile());
otr_profile_->AddObserver(this);
}
OffscreenTab::~OffscreenTab() {
DVLOG(1) << "Destroying OffscreenTab for start_url=" << start_url_.spec();
if (otr_profile_) {
otr_profile_->RemoveObserver(this);
ProfileDestroyer::DestroyProfileWhenAppropriate(otr_profile_);
}
}
void OffscreenTab::Start(const GURL& start_url,
......@@ -149,7 +150,7 @@ void OffscreenTab::Start(const GURL& start_url,
<< initial_size.ToString() << " for start_url=" << start_url_.spec();
// Create the WebContents to contain the off-screen tab's page.
WebContents::CreateParams params(otr_profile_registration_->profile());
WebContents::CreateParams params(otr_profile_);
if (!optional_presentation_id.empty())
params.starting_sandbox_flags = content::kPresentationReceiverSandboxFlags;
......@@ -407,7 +408,8 @@ void OffscreenTab::DieIfContentCaptureEnded() {
base::Unretained(this)));
}
void OffscreenTab::DieIfOriginalProfileDestroyed(Profile* profile) {
DCHECK(profile == otr_profile_registration_->profile());
void OffscreenTab::OnProfileWillBeDestroyed(Profile* profile) {
DCHECK(profile == otr_profile_);
otr_profile_ = nullptr;
owner_->DestroyTab(this);
}
......@@ -13,7 +13,7 @@
#include "base/macros.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "chrome/browser/profiles/independent_otr_profile_manager.h"
#include "chrome/browser/profiles/profile_observer.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h"
#include "ui/gfx/geometry/size.h"
......@@ -43,7 +43,8 @@ class BrowserContext;
// 3. Automatically, when the associated profile is destroyed.
//
// This class operates exclusively on the UI thread and so is not thread-safe.
class OffscreenTab : protected content::WebContentsDelegate,
class OffscreenTab : public ProfileObserver,
protected content::WebContentsDelegate,
protected content::WebContentsObserver {
public:
class Owner {
......@@ -134,9 +135,10 @@ class OffscreenTab : protected content::WebContentsDelegate,
// when the capturer count returns to zero.
void DieIfContentCaptureEnded();
// Called if the profile that our OTR profile is based on is being destroyed
// and |this| therefore needs to be destroyed also.
void DieIfOriginalProfileDestroyed(Profile* profile);
// Called if OTR profile is being destroyed and |this| therefore needs to be
// destroyed also.
// ProfileObserver:
void OnProfileWillBeDestroyed(Profile* profile) override;
Owner* const owner_; // Outlives this class.
......@@ -146,8 +148,7 @@ class OffscreenTab : protected content::WebContentsDelegate,
// A non-shared off-the-record profile based on the profile of the extension
// background page.
const std::unique_ptr<IndependentOTRProfileManager::OTRProfileRegistration>
otr_profile_registration_;
Profile* otr_profile_;
// The WebContents containing the off-screen tab's page.
std::unique_ptr<content::WebContents> offscreen_tab_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