Commit a5c8cfea authored by John Abd-El-Malek's avatar John Abd-El-Malek Committed by Commit Bot

Run signin URLLoaderFactory proxy on the UI thread so we can simplify ProfileIOData.

Also remove all the now unused members of ProfileIOData.

Bug: 908955
Change-Id: I391673049673112feab970d7f24e0a6a2d7b4df4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1742844
Commit-Queue: John Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#685287}
parent 152baa90
......@@ -1610,8 +1610,6 @@ jumbo_split_static_library("browser") {
"signin/chrome_signin_url_loader_throttle.cc",
"signin/chrome_signin_url_loader_throttle.h",
"signin/header_modification_delegate.h",
"signin/header_modification_delegate_on_io_thread_impl.cc",
"signin/header_modification_delegate_on_io_thread_impl.h",
"signin/header_modification_delegate_on_ui_thread_impl.cc",
"signin/header_modification_delegate_on_ui_thread_impl.h",
"signin/identity_manager_factory.cc",
......
......@@ -128,7 +128,6 @@
#include "chrome/browser/sessions/session_tab_helper.h"
#include "chrome/browser/signin/chrome_signin_proxying_url_loader_factory.h"
#include "chrome/browser/signin/chrome_signin_url_loader_throttle.h"
#include "chrome/browser/signin/header_modification_delegate_on_io_thread_impl.h"
#include "chrome/browser/signin/header_modification_delegate_on_ui_thread_impl.h"
#include "chrome/browser/site_isolation/site_isolation_policy.h"
#include "chrome/browser/speech/chrome_speech_recognition_manager_delegate.h"
......
......@@ -48,7 +48,7 @@
using content::BrowserThread;
OffTheRecordProfileIOData::Handle::Handle(Profile* profile)
: io_data_(new OffTheRecordProfileIOData(profile->GetProfileType())),
: io_data_(new OffTheRecordProfileIOData),
profile_(profile),
initialized_(false) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
......@@ -87,18 +87,10 @@ void OffTheRecordProfileIOData::Handle::LazyInitialize() const {
profile_->GetPrefs());
io_data_->safe_browsing_enabled()->MoveToSequence(
base::CreateSingleThreadTaskRunner({BrowserThread::IO}));
#if BUILDFLAG(ENABLE_PLUGINS)
io_data_->always_open_pdf_externally()->Init(
prefs::kPluginsAlwaysOpenPdfExternally, profile_->GetPrefs());
io_data_->always_open_pdf_externally()->MoveToSequence(
base::CreateSingleThreadTaskRunner({BrowserThread::IO}));
#endif
io_data_->InitializeOnUIThread(profile_);
}
OffTheRecordProfileIOData::OffTheRecordProfileIOData(
Profile::ProfileType profile_type)
: ProfileIOData(profile_type) {}
OffTheRecordProfileIOData::OffTheRecordProfileIOData() = default;
OffTheRecordProfileIOData::~OffTheRecordProfileIOData() {
DestroyResourceContext();
......
......@@ -60,7 +60,7 @@ class OffTheRecordProfileIOData : public ProfileIOData {
};
private:
explicit OffTheRecordProfileIOData(Profile::ProfileType profile_type);
OffTheRecordProfileIOData();
~OffTheRecordProfileIOData() override;
DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileIOData);
......
......@@ -162,17 +162,10 @@ void ProfileImplIOData::Handle::LazyInitialize() const {
pref_service);
io_data_->safe_browsing_enabled()->MoveToSequence(
base::CreateSingleThreadTaskRunner({BrowserThread::IO}));
#if BUILDFLAG(ENABLE_PLUGINS)
io_data_->always_open_pdf_externally()->Init(
prefs::kPluginsAlwaysOpenPdfExternally, pref_service);
io_data_->always_open_pdf_externally()->MoveToSequence(
base::CreateSingleThreadTaskRunner({BrowserThread::IO}));
#endif
io_data_->InitializeOnUIThread(profile_);
}
ProfileImplIOData::ProfileImplIOData()
: ProfileIOData(Profile::REGULAR_PROFILE) {}
ProfileImplIOData::ProfileImplIOData() = default;
ProfileImplIOData::~ProfileImplIOData() {
DestroyResourceContext();
......
......@@ -36,7 +36,6 @@
#include "chrome/browser/net/profile_network_context_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/account_consistency_mode_manager.h"
#include "chrome/common/buildflags.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_features.h"
......@@ -53,8 +52,6 @@
#include "components/metrics/metrics_service.h"
#include "components/net_log/chrome_net_log.h"
#include "components/policy/core/common/cloud/user_cloud_policy_manager.h"
#include "components/prefs/pref_service.h"
#include "components/signin/public/base/account_consistency_method.h"
#include "components/signin/public/base/signin_pref_names.h"
#include "components/sync/base/pref_names.h"
#include "components/url_formatter/url_fixer.h"
......@@ -244,7 +241,6 @@ void StartNSSInitOnIOThread(const AccountId& account_id,
void ProfileIOData::InitializeOnUIThread(Profile* profile) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
PrefService* pref_service = profile->GetPrefs();
std::unique_ptr<ProfileParams> params(new ProfileParams);
params->path = profile->GetPath();
......@@ -258,9 +254,6 @@ void ProfileIOData::InitializeOnUIThread(Profile* profile) {
extensions::ExtensionSystem::Get(profile)->info_map();
#endif
params->account_consistency =
AccountConsistencyModeManager::GetMethodForProfile(profile);
ProtocolHandlerRegistry* protocol_handler_registry =
ProtocolHandlerRegistryFactory::GetForBrowserContext(profile);
DCHECK(protocol_handler_registry);
......@@ -315,48 +308,9 @@ void ProfileIOData::InitializeOnUIThread(Profile* profile) {
params->profile = profile;
profile_params_ = std::move(params);
signed_exchange_enabled_.Init(prefs::kSignedHTTPExchangeEnabled,
pref_service);
signed_exchange_enabled_.MoveToSequence(
base::CreateSingleThreadTaskRunner({BrowserThread::IO}));
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner =
base::CreateSingleThreadTaskRunner({BrowserThread::IO});
// These members are used only for sign in, which is not enabled in incognito
// and guest modes. So no need to initialize them.
if (!IsOffTheRecord()) {
google_services_user_account_id_.Init(prefs::kGoogleServicesUserAccountId,
pref_service);
google_services_user_account_id_.MoveToSequence(io_task_runner);
sync_requested_.Init(syncer::prefs::kSyncRequested, pref_service);
sync_requested_.MoveToSequence(io_task_runner);
sync_first_setup_complete_.Init(syncer::prefs::kSyncFirstSetupComplete,
pref_service);
sync_first_setup_complete_.MoveToSequence(io_task_runner);
}
#if !defined(OS_CHROMEOS)
signin_scoped_device_id_.Init(prefs::kGoogleServicesSigninScopedDeviceId,
pref_service);
signin_scoped_device_id_.MoveToSequence(io_task_runner);
#endif
network_prediction_options_.Init(prefs::kNetworkPredictionOptions,
pref_service);
network_prediction_options_.MoveToSequence(io_task_runner);
incognito_availibility_pref_.Init(prefs::kIncognitoModeAvailability,
pref_service);
incognito_availibility_pref_.MoveToSequence(io_task_runner);
#if defined(OS_CHROMEOS)
account_consistency_mirror_required_pref_.Init(
prefs::kAccountConsistencyMirrorRequired, pref_service);
account_consistency_mirror_required_pref_.MoveToSequence(io_task_runner);
#endif
// We need to make sure that content initializes its own data structures that
// are associated with each ResourceContext because we might post this
// object to the IO thread after this function.
......@@ -370,14 +324,12 @@ ProfileIOData::ProfileParams::ProfileParams() = default;
ProfileIOData::ProfileParams::~ProfileParams() = default;
ProfileIOData::ProfileIOData(Profile::ProfileType profile_type)
ProfileIOData::ProfileIOData()
: initialized_(false),
account_consistency_(signin::AccountConsistencyMethod::kDisabled),
#if defined(OS_CHROMEOS)
system_key_slot_use_type_(SystemKeySlotUseType::kNone),
#endif
resource_context_(new ResourceContext(this)),
profile_type_(profile_type) {
resource_context_(new ResourceContext(this)) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
}
......@@ -459,21 +411,6 @@ HostContentSettingsMap* ProfileIOData::GetHostContentSettingsMap() const {
return host_content_settings_map_.get();
}
bool ProfileIOData::IsSyncEnabled() const {
return sync_first_setup_complete_.GetValue() && sync_requested_.GetValue();
}
#if !defined(OS_CHROMEOS)
std::string ProfileIOData::GetSigninScopedDeviceId() const {
return signin_scoped_device_id_.GetValue();
}
#endif
bool ProfileIOData::IsOffTheRecord() const {
return profile_type() == Profile::INCOGNITO_PROFILE ||
profile_type() == Profile::GUEST_PROFILE;
}
std::unique_ptr<net::ClientCertStore> ProfileIOData::CreateClientCertStore() {
if (!client_cert_store_factory_.is_null())
return client_cert_store_factory_.Run();
......@@ -528,8 +465,6 @@ void ProfileIOData::Init() const {
DCHECK(!initialized_);
DCHECK(profile_params_.get());
account_consistency_ = profile_params_->account_consistency;
// Take ownership over these parameters.
cookie_settings_ = profile_params_->cookie_settings;
host_content_settings_map_ = profile_params_->host_content_settings_map;
......@@ -560,22 +495,7 @@ void ProfileIOData::Init() const {
void ProfileIOData::ShutdownOnUIThread() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
google_services_user_account_id_.Destroy();
sync_requested_.Destroy();
sync_first_setup_complete_.Destroy();
#if !defined(OS_CHROMEOS)
signin_scoped_device_id_.Destroy();
#endif
safe_browsing_enabled_.Destroy();
network_prediction_options_.Destroy();
incognito_availibility_pref_.Destroy();
signed_exchange_enabled_.Destroy();
#if BUILDFLAG(ENABLE_PLUGINS)
always_open_pdf_externally_.Destroy();
#endif
#if defined(OS_CHROMEOS)
account_consistency_mirror_required_pref_.Destroy();
#endif
bool posted = BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this);
if (!posted)
......
......@@ -25,7 +25,6 @@
#include "chrome/common/buildflags.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/prefs/pref_member.h"
#include "components/signin/public/base/account_consistency_method.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/resource_context.h"
#include "extensions/buildflags/buildflags.h"
......@@ -85,61 +84,16 @@ class ProfileIOData {
content_settings::CookieSettings* GetCookieSettings() const;
HostContentSettingsMap* GetHostContentSettingsMap() const;
StringPrefMember* google_services_account_id() const {
return &google_services_user_account_id_;
}
// Gets Sync state, for Dice account consistency.
bool IsSyncEnabled() const;
BooleanPrefMember* safe_browsing_enabled() const {
return &safe_browsing_enabled_;
}
IntegerPrefMember* network_prediction_options() const {
return &network_prediction_options_;
}
BooleanPrefMember* signed_exchange_enabled() const {
return &signed_exchange_enabled_;
}
signin::AccountConsistencyMethod account_consistency() const {
return account_consistency_;
}
#if !defined(OS_CHROMEOS)
std::string GetSigninScopedDeviceId() const;
#endif
#if defined(OS_CHROMEOS)
std::string username_hash() const {
return username_hash_;
}
#endif
Profile::ProfileType profile_type() const {
return profile_type_;
}
bool IsOffTheRecord() const;
IntegerPrefMember* incognito_availibility() const {
return &incognito_availibility_pref_;
}
#if BUILDFLAG(ENABLE_PLUGINS)
BooleanPrefMember* always_open_pdf_externally() const {
return &always_open_pdf_externally_;
}
#endif
#if defined(OS_CHROMEOS)
BooleanPrefMember* account_consistency_mirror_required() const {
return &account_consistency_mirror_required_pref_;
}
#endif
void set_client_cert_store_factory_for_testing(
const base::Callback<std::unique_ptr<net::ClientCertStore>()>& factory) {
client_cert_store_factory_ = factory;
......@@ -181,8 +135,6 @@ class ProfileIOData {
#if BUILDFLAG(ENABLE_EXTENSIONS)
scoped_refptr<extensions::InfoMap> extension_info_map;
#endif
signin::AccountConsistencyMethod account_consistency =
signin::AccountConsistencyMethod::kDisabled;
#if defined(OS_CHROMEOS)
std::string username_hash;
......@@ -196,7 +148,7 @@ class ProfileIOData {
void* profile = nullptr;
};
explicit ProfileIOData(Profile::ProfileType profile_type);
ProfileIOData();
void InitializeOnUIThread(Profile* profile);
......@@ -257,26 +209,8 @@ class ProfileIOData {
mutable base::Callback<std::unique_ptr<net::ClientCertStore>()>
client_cert_store_factory_;
mutable StringPrefMember google_services_user_account_id_;
mutable BooleanPrefMember sync_requested_;
mutable BooleanPrefMember sync_first_setup_complete_;
mutable signin::AccountConsistencyMethod account_consistency_;
#if !defined(OS_CHROMEOS)
mutable StringPrefMember signin_scoped_device_id_;
#endif
// Member variables which are pointed to by the various context objects.
mutable BooleanPrefMember safe_browsing_enabled_;
mutable IntegerPrefMember network_prediction_options_;
mutable IntegerPrefMember incognito_availibility_pref_;
mutable BooleanPrefMember signed_exchange_enabled_;
#if BUILDFLAG(ENABLE_PLUGINS)
mutable BooleanPrefMember always_open_pdf_externally_;
#endif
#if defined(OS_CHROMEOS)
mutable BooleanPrefMember account_consistency_mirror_required_pref_;
#endif
// Pointed to by URLRequestContext.
#if BUILDFLAG(ENABLE_EXTENSIONS)
......@@ -298,8 +232,6 @@ class ProfileIOData {
mutable scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
const Profile::ProfileType profile_type_;
DISALLOW_COPY_AND_ASSIGN(ProfileIOData);
};
......
......@@ -7,18 +7,15 @@
#include "base/barrier_closure.h"
#include "base/bind.h"
#include "base/supports_user_data.h"
#include "base/task/post_task.h"
#include "build/buildflag.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/chrome_signin_helper.h"
#include "chrome/browser/signin/header_modification_delegate.h"
#include "chrome/browser/signin/header_modification_delegate_on_io_thread_impl.h"
#include "chrome/browser/signin/header_modification_delegate_on_ui_thread_impl.h"
#include "components/signin/core/browser/signin_header_helper.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/resource_context.h"
#include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
#include "extensions/buildflags/buildflags.h"
#include "google_apis/gaia/gaia_auth_util.h"
......@@ -28,37 +25,32 @@ namespace signin {
namespace {
// User data key for ResourceContextData.
const void* const kResourceContextUserDataKey = &kResourceContextUserDataKey;
// User data key for BrowserContextData.
const void* const kBrowserContextUserDataKey = &kBrowserContextUserDataKey;
// Owns all of the ProxyingURLLoaderFactorys for a given Profile. Since these
// live on the IO thread this is done indirectly through the
// content::ResourceContext.
class ResourceContextData : public base::SupportsUserData::Data {
// Owns all of the ProxyingURLLoaderFactorys for a given Profile.
class BrowserContextData : public base::SupportsUserData::Data {
public:
~ResourceContextData() override {}
~BrowserContextData() override {}
static void StartProxying(
content::ResourceContext* resource_context,
Profile* profile,
content::WebContents::Getter web_contents_getter,
network::mojom::URLLoaderFactoryRequest request,
network::mojom::URLLoaderFactoryPtrInfo target_factory) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
auto* self = static_cast<ResourceContextData*>(
resource_context->GetUserData(kResourceContextUserDataKey));
auto* self = static_cast<BrowserContextData*>(
profile->GetUserData(kBrowserContextUserDataKey));
if (!self) {
self = new ResourceContextData();
resource_context->SetUserData(kResourceContextUserDataKey,
base::WrapUnique(self));
self = new BrowserContextData();
profile->SetUserData(kBrowserContextUserDataKey, base::WrapUnique(self));
}
auto delegate = std::make_unique<HeaderModificationDelegateOnIOThreadImpl>(
resource_context);
auto delegate =
std::make_unique<HeaderModificationDelegateOnUIThreadImpl>(profile);
auto proxy = std::make_unique<ProxyingURLLoaderFactory>(
std::move(delegate), std::move(web_contents_getter), std::move(request),
std::move(target_factory),
base::BindOnce(&ResourceContextData::RemoveProxy,
base::BindOnce(&BrowserContextData::RemoveProxy,
self->weak_factory_.GetWeakPtr()));
self->proxies_.emplace(std::move(proxy));
}
......@@ -70,14 +62,14 @@ class ResourceContextData : public base::SupportsUserData::Data {
}
private:
ResourceContextData() {}
BrowserContextData() {}
std::set<std::unique_ptr<ProxyingURLLoaderFactory>, base::UniquePtrComparator>
proxies_;
base::WeakPtrFactory<ResourceContextData> weak_factory_{this};
base::WeakPtrFactory<BrowserContextData> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(ResourceContextData);
DISALLOW_COPY_AND_ASSIGN(BrowserContextData);
};
} // namespace
......@@ -472,12 +464,9 @@ bool ProxyingURLLoaderFactory::MaybeProxyRequest(
base::BindRepeating(&content::WebContents::FromFrameTreeNodeId,
render_frame_host->GetFrameTreeNodeId());
base::PostTask(FROM_HERE, {content::BrowserThread::IO},
base::BindOnce(&ResourceContextData::StartProxying,
profile->GetResourceContext(),
std::move(web_contents_getter),
std::move(proxied_receiver),
std::move(target_factory_info)));
BrowserContextData::StartProxying(profile, std::move(web_contents_getter),
std::move(proxied_receiver),
std::move(target_factory_info));
return true;
}
......
// Copyright 2018 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/signin/header_modification_delegate_on_io_thread_impl.h"
#include "chrome/browser/profiles/profile_io_data.h"
#include "chrome/browser/renderer_host/chrome_navigation_ui_data.h"
#include "chrome/browser/signin/chrome_signin_helper.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/browser/extension_navigation_ui_data.h"
namespace signin {
HeaderModificationDelegateOnIOThreadImpl::
HeaderModificationDelegateOnIOThreadImpl(
content::ResourceContext* resource_context)
: io_data_(ProfileIOData::FromResourceContext(resource_context)) {}
HeaderModificationDelegateOnIOThreadImpl::
~HeaderModificationDelegateOnIOThreadImpl() = default;
bool HeaderModificationDelegateOnIOThreadImpl::ShouldInterceptNavigation(
content::NavigationUIData* navigation_ui_data) {
if (io_data_->IsOffTheRecord())
return false;
#if BUILDFLAG(ENABLE_EXTENSIONS)
// Note: InlineLoginUI uses an isolated request context and thus should
// bypass the account consistency flow. See http://crbug.com/428396
ChromeNavigationUIData* chrome_navigation_ui_data =
static_cast<ChromeNavigationUIData*>(navigation_ui_data);
if (chrome_navigation_ui_data) {
extensions::ExtensionNavigationUIData* extension_navigation_ui_data =
chrome_navigation_ui_data->GetExtensionNavigationUIData();
if (extension_navigation_ui_data &&
extension_navigation_ui_data->is_web_view()) {
return false;
}
}
#endif
return true;
}
void HeaderModificationDelegateOnIOThreadImpl::ProcessRequest(
ChromeRequestAdapter* request_adapter,
const GURL& redirect_url) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
FixAccountConsistencyRequestHeader(
request_adapter, redirect_url, io_data_->IsOffTheRecord(),
io_data_->incognito_availibility()->GetValue(),
io_data_->account_consistency(),
io_data_->google_services_account_id()->GetValue(),
#if defined(OS_CHROMEOS)
io_data_->account_consistency_mirror_required()->GetValue(),
#endif
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
io_data_->IsSyncEnabled(), io_data_->GetSigninScopedDeviceId(),
#endif
io_data_->GetCookieSettings());
}
void HeaderModificationDelegateOnIOThreadImpl::ProcessResponse(
ResponseAdapter* response_adapter,
const GURL& redirect_url) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
ProcessAccountConsistencyResponseHeaders(response_adapter, redirect_url,
io_data_->IsOffTheRecord());
}
} // namespace signin
// Copyright 2018 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.
#ifndef CHROME_BROWSER_SIGNIN_HEADER_MODIFICATION_DELEGATE_ON_IO_THREAD_IMPL_H_
#define CHROME_BROWSER_SIGNIN_HEADER_MODIFICATION_DELEGATE_ON_IO_THREAD_IMPL_H_
#include "chrome/browser/signin/header_modification_delegate.h"
class ProfileIOData;
namespace content {
class ResourceContext;
}
namespace signin {
// This class wraps the FixAccountConsistencyRequestHeader and
// ProcessAccountConsistencyResponseHeaders in the HeaderModificationDelegate
// interface.
class HeaderModificationDelegateOnIOThreadImpl
: public HeaderModificationDelegate {
public:
explicit HeaderModificationDelegateOnIOThreadImpl(
content::ResourceContext* resource_context);
~HeaderModificationDelegateOnIOThreadImpl() override;
// HeaderModificationDelegate
bool ShouldInterceptNavigation(
content::NavigationUIData* navigation_ui_data) override;
void ProcessRequest(ChromeRequestAdapter* request_adapter,
const GURL& redirect_url) override;
void ProcessResponse(ResponseAdapter* response_adapter,
const GURL& redirect_url) override;
private:
ProfileIOData* const io_data_;
DISALLOW_COPY_AND_ASSIGN(HeaderModificationDelegateOnIOThreadImpl);
};
} // namespace signin
#endif // CHROME_BROWSER_SIGNIN_HEADER_MODIFICATION_DELEGATE_ON_IO_THREAD_IMPL_H_
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