alloy: Remove optimization/prediction service usage (see issue #3352)

This service is required by the "PermissionOnDeviceNotificationPredictions"
feature which is enabled by default in https://crbug.com/1350956. It uses a
Google backend service as described at https://go.dev/solutions/google/chrome.

This change removes the usage of PredictionBasedPermissionUiSelector, which
triggered this dependency, along with related startup complexity that was added
to support the optimization/prediction service in the M106 update.
This commit is contained in:
Marshall Greenblatt 2022-08-23 12:20:45 -04:00
parent 7659dd60ba
commit 5dc69c6cdb
16 changed files with 29 additions and 135 deletions

View File

@ -20,14 +20,12 @@
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/strings/string_util.h"
#include "base/threading/thread_restrictions.h"
#include "chrome/browser/font_family_cache.h"
#include "chrome/browser/media/media_device_id_salt.h"
#include "chrome/browser/permissions/permission_manager_factory.h"
#include "chrome/browser/plugins/chrome_plugin_service_filter.h"
#include "chrome/browser/profiles/profile_key.h"
#include "chrome/browser/reduce_accept_language/reduce_accept_language_factory.h"
#include "chrome/browser/transition_manager/full_browser_transition_manager.h"
#include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
#include "chrome/common/pref_names.h"
#include "components/guest_view/browser/guest_view_manager.h"
@ -141,17 +139,11 @@ void AlloyBrowserContext::Initialize() {
pref_service_ = browser_prefs::CreatePrefService(
this, cache_path_, !!settings_.persist_user_preferences);
FullBrowserTransitionManager::Get()->OnProfileCreated(this);
{
base::ScopedAllowBlockingForTesting allow_blocking;
// This must be called before creating any services to avoid hitting
// DependencyManager::AssertContextWasntDestroyed when creating/destroying
// multiple browser contexts (due to pointer address reuse).
BrowserContextDependencyManager::GetInstance()
->CreateBrowserContextServices(this);
}
// This must be called before creating any services to avoid hitting
// DependencyManager::AssertContextWasntDestroyed when creating/destroying
// multiple browser contexts (due to pointer address reuse).
BrowserContextDependencyManager::GetInstance()->CreateBrowserContextServices(
this);
const bool extensions_enabled = extensions::ExtensionsEnabled();
if (extensions_enabled) {
@ -194,9 +186,6 @@ void AlloyBrowserContext::Initialize() {
ChromePluginServiceFilter::GetInstance()->RegisterProfile(this);
auto* db_provider = GetDefaultStoragePartition()->GetProtoDatabaseProvider();
key_->SetProtoDatabaseProvider(db_provider);
media_device_id_salt_ = new MediaDeviceIDSalt(pref_service);
}
@ -207,7 +196,6 @@ void AlloyBrowserContext::Shutdown() {
MaybeSendDestroyedNotification();
ChromePluginServiceFilter::GetInstance()->UnregisterProfile(this);
FullBrowserTransitionManager::Get()->OnProfileDestroyed(this);
// Remove any BrowserContextKeyedServiceFactory associations. This must be
// called before the ProxyService owned by AlloyBrowserContext is destroyed.

View File

@ -282,6 +282,10 @@ int AlloyBrowserMainParts::PreMainMessageLoopRun() {
// Create the global RequestContext.
global_request_context_ =
CefRequestContextImpl::CreateGlobalRequestContext(settings);
auto browser_context =
global_request_context_->GetBrowserContext()->AsBrowserContext();
CefDevToolsManagerDelegate::StartHttpHandler(browser_context);
#if BUILDFLAG(IS_WIN)
// Windows parental controls calls can be slow, so we do an early init here
@ -322,19 +326,6 @@ int AlloyBrowserMainParts::PreMainMessageLoopRun() {
return content::RESULT_CODE_NORMAL_EXIT;
}
void AlloyBrowserMainParts::OnContextInitialized() {
CEF_REQUIRE_UIT();
// Initialize the global RequestContext. This needs to occur on the UI thread
// after the CEF context is initialized because it indirectly accesses the
// ProfileManager.
global_request_context_->InitializeGlobalContext();
auto browser_context =
global_request_context_->GetBrowserContext()->AsBrowserContext();
CefDevToolsManagerDelegate::StartHttpHandler(browser_context);
}
void AlloyBrowserMainParts::PostMainMessageLoopRun() {
// NOTE: Destroy objects in reverse order of creation.
CefDevToolsManagerDelegate::StopHttpHandler();

View File

@ -44,7 +44,6 @@ class AlloyBrowserMainParts : public content::BrowserMainParts {
void PostCreateMainMessageLoop() override;
int PreCreateThreads() override;
int PreMainMessageLoopRun() override;
void OnContextInitialized();
void PostMainMessageLoopRun() override;
void PostDestroyThreads() override;

View File

@ -1449,10 +1449,6 @@ bool AlloyContentBrowserClient::IsFindInPageDisabledForOrigin(
return IsPdfExtensionOrigin(origin);
}
void AlloyContentBrowserClient::OnContextInitialized() {
browser_main_parts_->OnContextInitialized();
}
CefRefPtr<CefRequestContextImpl> AlloyContentBrowserClient::request_context()
const {
return browser_main_parts_->request_context();

View File

@ -248,8 +248,6 @@ class AlloyContentBrowserClient : public content::ContentBrowserClient {
void OnWebContentsCreated(content::WebContents* web_contents) override;
bool IsFindInPageDisabledForOrigin(const url::Origin& origin) override;
void OnContextInitialized();
CefRefPtr<CefRequestContextImpl> request_context() const;
CefDevToolsDelegate* devtools_delegate() const;

View File

@ -17,7 +17,6 @@
#include "base/command_line.h"
#include "chrome/browser/component_updater/chrome_component_updater_configurator.h"
#include "chrome/browser/metrics/chrome_metrics_services_manager_client.h"
#include "chrome/browser/net/system_network_context_manager.h"
#include "chrome/browser/permissions/chrome_permissions_client.h"
#include "chrome/browser/policy/chrome_browser_policy_connector.h"
@ -27,8 +26,6 @@
#include "chrome/browser/ui/prefs/pref_watcher.h"
#include "components/component_updater/component_updater_service.h"
#include "components/component_updater/timer_update_scheduler.h"
#include "components/metrics_services_manager/metrics_services_manager.h"
#include "components/metrics_services_manager/metrics_services_manager_client.h"
#include "components/net_log/chrome_net_log.h"
#include "components/prefs/pref_service.h"
#include "content/browser/startup_helper.h"
@ -104,8 +101,6 @@ void ChromeBrowserProcessAlloy::CleanupOnUIThread() {
print_job_manager_.reset(nullptr);
print_preview_dialog_controller_ = nullptr;
metrics_services_manager_.reset();
profile_manager_.reset();
event_router_forwarder_ = nullptr;
@ -130,7 +125,6 @@ void ChromeBrowserProcessAlloy::CleanupOnUIThread() {
}
local_state_.reset();
network_quality_tracker_.reset();
browser_policy_connector_.reset();
background_printing_manager_.reset();
field_trial_list_.reset();
@ -150,19 +144,13 @@ void ChromeBrowserProcessAlloy::FlushLocalStateAndReply(
metrics_services_manager::MetricsServicesManager*
ChromeBrowserProcessAlloy::GetMetricsServicesManager() {
if (!metrics_services_manager_) {
auto client =
std::make_unique<ChromeMetricsServicesManagerClient>(local_state());
metrics_services_manager_client_ = client.get();
metrics_services_manager_ =
std::make_unique<metrics_services_manager::MetricsServicesManager>(
std::move(client));
}
return metrics_services_manager_.get();
NOTREACHED();
return nullptr;
}
metrics::MetricsService* ChromeBrowserProcessAlloy::metrics_service() {
return GetMetricsServicesManager()->GetMetricsService();
NOTREACHED();
return nullptr;
}
SystemNetworkContextManager*
@ -173,11 +161,8 @@ ChromeBrowserProcessAlloy::system_network_context_manager() {
network::NetworkQualityTracker*
ChromeBrowserProcessAlloy::network_quality_tracker() {
if (!network_quality_tracker_) {
network_quality_tracker_ = std::make_unique<network::NetworkQualityTracker>(
base::BindRepeating(&content::GetNetworkService));
}
return network_quality_tracker_.get();
NOTREACHED();
return nullptr;
}
ProfileManager* ChromeBrowserProcessAlloy::profile_manager() {

View File

@ -16,14 +16,12 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/event_router_forwarder.h"
#include "media/media_buildflags.h"
#include "services/network/public/cpp/network_quality_tracker.h"
namespace extensions {
class ExtensionsBrowserClient;
class ExtensionsClient;
} // namespace extensions
class ChromeMetricsServicesManagerClient;
class ChromeProfileManagerAlloy;
class BackgroundModeManager {
@ -131,16 +129,6 @@ class ChromeBrowserProcessAlloy : public BrowserProcess {
background_printing_manager_;
std::unique_ptr<PrefService> local_state_;
// |metrics_services_manager_| owns this.
raw_ptr<ChromeMetricsServicesManagerClient> metrics_services_manager_client_ =
nullptr;
// Must be destroyed before |local_state_| and |profile_manager_|.
std::unique_ptr<metrics_services_manager::MetricsServicesManager>
metrics_services_manager_;
std::unique_ptr<network::NetworkQualityTracker> network_quality_tracker_;
// Must be destroyed after |local_state_|.
std::unique_ptr<policy::ChromeBrowserPolicyConnector>
browser_policy_connector_;

View File

@ -14,17 +14,12 @@
#include "chrome/browser/spellchecker/spellcheck_factory.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/ui/prefs/prefs_tab_helper.h"
#include "components/optimization_guide/machine_learning_tflite_buildflags.h"
#include "components/permissions/features.h"
#include "extensions/browser/api/alarms/alarm_manager.h"
#include "extensions/browser/api/storage/storage_frontend.h"
#include "extensions/browser/renderer_startup_helper.h"
#include "services/network/public/cpp/features.h"
#if BUILDFLAG(BUILD_WITH_TFLITE_LIB)
#include "chrome/browser/permissions/prediction_model_handler_factory.h"
#endif
namespace cef {
void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
@ -45,13 +40,6 @@ void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
if (base::FeatureList::IsEnabled(network::features::kReduceAcceptLanguage)) {
ReduceAcceptLanguageFactory::GetInstance();
}
#if BUILDFLAG(BUILD_WITH_TFLITE_LIB)
if (base::FeatureList::IsEnabled(
permissions::features::kPermissionOnDeviceNotificationPredictions)) {
PredictionModelHandlerFactory::GetInstance();
}
#endif // BUILDFLAG(BUILD_WITH_TFLITE_LIB)
}
} // namespace cef

View File

@ -27,7 +27,6 @@ void ChromeBrowserMainExtraPartsCef::PostProfileInit(Profile* profile,
// Create the global RequestContext.
global_request_context_ =
CefRequestContextImpl::CreateGlobalRequestContext(settings);
global_request_context_->InitializeGlobalContext();
}
void ChromeBrowserMainExtraPartsCef::PreMainMessageLoopRun() {

View File

@ -23,7 +23,6 @@
#include "chrome/browser/media/media_device_id_salt.h"
#include "chrome/browser/media/router/media_router_feature.h"
#include "chrome/browser/media/webrtc/permission_bubble_media_access_handler.h"
#include "chrome/browser/metrics/chrome_metrics_service_client.h"
#include "chrome/browser/net/profile_network_context_service.h"
#include "chrome/browser/net/system_network_context_manager.h"
#include "chrome/browser/plugins/plugin_info_host_impl.h"
@ -47,7 +46,6 @@
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/language/core/browser/language_prefs.h"
#include "components/language/core/browser/pref_names.h"
#include "components/optimization_guide/core/optimization_guide_prefs.h"
#include "components/permissions/permission_actions_history.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/json_pref_store.h"
@ -60,7 +58,6 @@
#include "components/spellcheck/browser/pref_names.h"
#include "components/sync_preferences/pref_service_syncable.h"
#include "components/sync_preferences/pref_service_syncable_factory.h"
#include "components/unified_consent/unified_consent_service.h"
#include "components/update_client/update_client.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/browser/extension_prefs.h"
@ -226,7 +223,6 @@ std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
// Default preferences.
CefMediaCaptureDevicesDispatcher::RegisterPrefs(registry.get());
certificate_transparency::prefs::RegisterPrefs(registry.get());
ChromeMetricsServiceClient::RegisterPrefs(registry.get());
flags_ui::PrefServiceFlagsStorage::RegisterPrefs(registry.get());
media_router::RegisterLocalStatePrefs(registry.get());
PluginInfoHostImpl::RegisterUserPrefs(registry.get());
@ -273,13 +269,11 @@ std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
language::LanguagePrefs::RegisterProfilePrefs(registry.get());
media_router::RegisterProfilePrefs(registry.get());
MediaDeviceIDSalt::RegisterProfilePrefs(registry.get());
optimization_guide::prefs::RegisterProfilePrefs(registry.get());
PermissionBubbleMediaAccessHandler::RegisterProfilePrefs(registry.get());
permissions::PermissionActionsHistory::RegisterProfilePrefs(registry.get());
prefetch::RegisterPredictionOptionsProfilePrefs(registry.get());
ProfileNetworkContextService::RegisterProfilePrefs(registry.get());
safe_browsing::RegisterProfilePrefs(registry.get());
unified_consent::UnifiedConsentService::RegisterPrefs(registry.get());
RegisterProfilePrefs(registry.get());
const std::string& locale =

View File

@ -183,6 +183,7 @@ CefRequestContextImpl::CreateGlobalRequestContext(
config.is_global = true;
config.settings = settings;
CefRefPtr<CefRequestContextImpl> impl = new CefRequestContextImpl(config);
impl->Initialize();
return impl;
}
@ -201,11 +202,6 @@ CefRequestContextImpl::GetOrCreateForRequestContext(
return CefRequestContextImpl::GetOrCreateRequestContext(config);
}
void CefRequestContextImpl::InitializeGlobalContext() {
DCHECK(IsGlobal());
Initialize();
}
bool CefRequestContextImpl::VerifyBrowserContext() const {
if (!CEF_CURRENTLY_ON_UIT()) {
NOTREACHED() << "called on invalid thread";

View File

@ -29,8 +29,7 @@ class CefRequestContextImpl : public CefRequestContext {
// Creates the singleton global RequestContext. Called from
// AlloyBrowserMainParts::PreMainMessageLoopRun and
// ChromeBrowserMainExtraPartsCef::PostProfileInit. Must be followed by a call
// to InitializeGlobalContext on the UI thread.
// ChromeBrowserMainExtraPartsCef::PostProfileInit.
static CefRefPtr<CefRequestContextImpl> CreateGlobalRequestContext(
const CefRequestContextSettings& settings);
@ -39,8 +38,6 @@ class CefRequestContextImpl : public CefRequestContext {
static CefRefPtr<CefRequestContextImpl> GetOrCreateForRequestContext(
CefRefPtr<CefRequestContext> request_context);
void InitializeGlobalContext();
// Verify that the browser context can be directly accessed (e.g. on the UI
// thread and initialized).
bool VerifyBrowserContext() const;

View File

@ -5,10 +5,8 @@
#include "libcef/common/alloy/alloy_main_runner_delegate.h"
#include "libcef/browser/alloy/alloy_content_browser_client.h"
#include "libcef/browser/alloy/chrome_browser_process_alloy.h"
#include "libcef/common/alloy/alloy_main_delegate.h"
#include "libcef/common/app_manager.h"
#include "libcef/renderer/alloy/alloy_content_renderer_client.h"
#include "content/public/browser/render_process_host.h"
@ -41,10 +39,6 @@ void AlloyMainRunnerDelegate::BeforeMainThreadRun() {
void AlloyMainRunnerDelegate::AfterUIThreadInitialize() {
static_cast<ChromeBrowserProcessAlloy*>(g_browser_process)
->OnContextInitialized();
static_cast<AlloyContentBrowserClient*>(
CefAppManager::Get()->GetContentClient()->browser())
->OnContextInitialized();
}
void AlloyMainRunnerDelegate::AfterUIThreadShutdown() {

View File

@ -256,14 +256,6 @@ patches = [
# https://bitbucket.org/chromiumembedded/cef/issues/2830
'name': 'chrome_browser_net_proxy',
},
{
# alloy: Don't create an optimization model downloads directory when
# cache_path is empty. This is related to Chrome permissions and the
# "PermissionOnDeviceNotificationPredictions" feature which is enabled by
# default in https://crbug.com/1350956.
# https://bitbucket.org/chromiumembedded/cef/issues/3352
'name': 'chrome_browser_optimization_guide',
},
{
# Support override of CreatePermissionPrompt.
# https://bitbucket.org/chromiumembedded/cef/issues/3352

View File

@ -1,22 +0,0 @@
diff --git chrome/browser/optimization_guide/optimization_guide_keyed_service.cc chrome/browser/optimization_guide/optimization_guide_keyed_service.cc
index bd928f4422f99..f0124ab225b6f 100644
--- chrome/browser/optimization_guide/optimization_guide_keyed_service.cc
+++ chrome/browser/optimization_guide/optimization_guide_keyed_service.cc
@@ -269,7 +269,7 @@ void OptimizationGuideKeyedService::Initialize() {
MaybeCreatePushNotificationManager(profile),
optimization_guide_logger_.get());
base::FilePath model_downloads_dir;
- if (!profile->IsOffTheRecord()) {
+ if (!profile->IsOffTheRecord() && !profile_path.empty()) {
// Do not explicitly hand off the model downloads directory to
// off-the-record profiles. Underneath the hood, this variable is only used
// in non off-the-record profiles to know where to download the model files
@@ -281,7 +281,7 @@ void OptimizationGuideKeyedService::Initialize() {
prediction_manager_ = std::make_unique<optimization_guide::PredictionManager>(
prediction_model_and_features_store, url_loader_factory,
- profile->GetPrefs(), profile->IsOffTheRecord(),
+ profile->GetPrefs(), /*is_off_the_record=*/model_downloads_dir.empty(),
g_browser_process->GetApplicationLocale(), model_downloads_dir,
optimization_guide_logger_.get(),
base::BindOnce(

View File

@ -1,5 +1,5 @@
diff --git chrome/browser/permissions/chrome_permissions_client.cc chrome/browser/permissions/chrome_permissions_client.cc
index 994b78d94de26..b64c1a7506a23 100644
index 994b78d94de26..e51f6f6162f02 100644
--- chrome/browser/permissions/chrome_permissions_client.cc
+++ chrome/browser/permissions/chrome_permissions_client.cc
@@ -12,6 +12,7 @@
@ -20,6 +20,17 @@ index 994b78d94de26..b64c1a7506a23 100644
return site_engagement::SiteEngagementService::Get(
Profile::FromBrowserContext(browser_context))
->GetScore(origin);
@@ -300,8 +304,10 @@ ChromePermissionsClient::CreatePermissionUiSelectors(
std::make_unique<ContextualNotificationPermissionUiSelector>());
selectors.emplace_back(std::make_unique<PrefNotificationPermissionUiSelector>(
Profile::FromBrowserContext(browser_context)));
+ if (!cef::IsAlloyRuntimeEnabled()) {
selectors.emplace_back(std::make_unique<PredictionBasedPermissionUiSelector>(
Profile::FromBrowserContext(browser_context)));
+ }
return selectors;
}
diff --git chrome/browser/permissions/permission_manager_factory.cc chrome/browser/permissions/permission_manager_factory.cc
index 5efee36a48397..bb683b88c5bd6 100644
--- chrome/browser/permissions/permission_manager_factory.cc