Commit e4de4a08 authored by Gavin Williams's avatar Gavin Williams Committed by Commit Bot

Use correct BrowserContext in guest mode for CupsPrintersManagerFactory

First this change gives CupsPrintersManagerFactory access to the both
the OffTheRecord(OTR) and non-OTR guest profile when logged into Guest
mode. Before, using GetBrowserContextRedirectedInIncognito, only the
non-OTR recording guest profile was available to
BuildServiceInstanceFor.

Second, this change filters to only create CupsPrintersManager with the
OTR profile when in Guest mode. The OTR profile is needed by the
UsbPrinterNotificationController to open the System Web App(SWA)
Settings page to configure USB printers. There is a check
(https://osscs.corp.google.com/chromium/chromium/src/+/master:chrome/browser/ui/browser.cc;l=471)
that only OTR guest profiles are allowed to open SWAs.

For the other profile users in CupsPrintersManager, there's no impact
for using the OTR guest profile vs. the non-OTR guest profile.

Fixed: 1116062
Change-Id: Icbc000f36f178cbf30f1a85dbbe94b16cfe1f3b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2368234
Commit-Queue: Gavin Williams <gavinwill@chromium.org>
Reviewed-by: default avatarBailey Berro <baileyberro@chromium.org>
Reviewed-by: default avatarRamin Halavati <rhalavati@chromium.org>
Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#800636}
parent ad68fed2
...@@ -51,6 +51,12 @@ KeyedService* CupsPrintersManagerFactory::BuildServiceInstanceFor( ...@@ -51,6 +51,12 @@ KeyedService* CupsPrintersManagerFactory::BuildServiceInstanceFor(
ProfileHelper::IsSigninProfile(profile)) { ProfileHelper::IsSigninProfile(profile)) {
return nullptr; return nullptr;
} }
// In Guest Mode, only use the OffTheRecord profile.
if (profile->IsGuestSession() && !profile->IsOffTheRecord()) {
return nullptr;
}
auto manager = CupsPrintersManager::Create(profile); auto manager = CupsPrintersManager::Create(profile);
if (ProfileHelper::IsPrimaryProfile(profile)) { if (ProfileHelper::IsPrimaryProfile(profile)) {
proxy_->SetManager(manager.get()); proxy_->SetManager(manager.get());
...@@ -71,7 +77,7 @@ void CupsPrintersManagerFactory::BrowserContextShutdown( ...@@ -71,7 +77,7 @@ void CupsPrintersManagerFactory::BrowserContextShutdown(
content::BrowserContext* CupsPrintersManagerFactory::GetBrowserContextToUse( content::BrowserContext* CupsPrintersManagerFactory::GetBrowserContextToUse(
content::BrowserContext* context) const { content::BrowserContext* context) const {
return chrome::GetBrowserContextRedirectedInIncognito(context); return chrome::GetBrowserContextOwnInstanceInIncognito(context);
} }
bool CupsPrintersManagerFactory::ServiceIsCreatedWithBrowserContext() const { bool CupsPrintersManagerFactory::ServiceIsCreatedWithBrowserContext() const {
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
namespace chromeos { namespace chromeos {
...@@ -70,6 +71,11 @@ class UsbPrinterNotificationControllerImpl ...@@ -70,6 +71,11 @@ class UsbPrinterNotificationControllerImpl
std::unique_ptr<UsbPrinterNotificationController> std::unique_ptr<UsbPrinterNotificationController>
UsbPrinterNotificationController::Create(Profile* profile) { UsbPrinterNotificationController::Create(Profile* profile) {
// If we are in guest mode, the new profile should be an OffTheRecord profile.
// Otherwise, this may later hit a check (same condition as this one) in
// Browser::Browser when opening attempting to open the Printer Settings page.
DCHECK(!profile->IsGuestSession() || profile->IsOffTheRecord())
<< "Guest mode must use OffTheRecord profile";
return std::make_unique<UsbPrinterNotificationControllerImpl>(profile); return std::make_unique<UsbPrinterNotificationControllerImpl>(profile);
} }
......
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