Commit f9987048 authored by Sophie Chang's avatar Sophie Chang Committed by Commit Bot

Add initial OptimizationGuideKeyedService behind a development flag

This initially introduces a subset of PreviewsHints logic into this new
service to incorporate the component hints and puts it into the store
without any mechanisms for retrieving it out of the store (that will
follow in subsequent CLs). Following this new path is subject to the new
"OptimizationGuideKeyedService" Feature being enabled.

Once this new path for loading and managing hints is fully landed, the logic
will be removed from PreviewsHints and PreviewsOptimizationGuide.

Bug: 969558
Change-Id: Ieebaf137e1b93dadc55dc381d3edad0606fe7b16
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1709652
Commit-Queue: Sophie Chang <sophiechang@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarDoug Arnett <dougarnett@chromium.org>
Reviewed-by: default avatarStefan Kuhne <skuhne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#681450}
parent e3f6e640
......@@ -919,6 +919,12 @@ jumbo_split_static_library("browser") {
"offline_items_collection/offline_content_aggregator_factory.cc",
"offline_items_collection/offline_content_aggregator_factory.h",
"omnibox/common/omnibox_features.h",
"optimization_guide/optimization_guide_hints_manager.cc",
"optimization_guide/optimization_guide_hints_manager.h",
"optimization_guide/optimization_guide_keyed_service.cc",
"optimization_guide/optimization_guide_keyed_service.h",
"optimization_guide/optimization_guide_keyed_service_factory.cc",
"optimization_guide/optimization_guide_keyed_service_factory.h",
"page_load_metrics/metrics_navigation_throttle.cc",
"page_load_metrics/metrics_navigation_throttle.h",
"page_load_metrics/metrics_web_contents_observer.cc",
......
file://components/optimization_guide/OWNERS
# COMPONENT: Blink>Previews
// Copyright 2019 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/optimization_guide/optimization_guide_hints_manager.h"
#include <utility>
#include "base/bind.h"
#include "base/logging.h"
#include "base/metrics/histogram_macros_local.h"
#include "base/sequenced_task_runner.h"
#include "base/task/post_task.h"
#include "base/task_runner_util.h"
#include "components/optimization_guide/hint_cache.h"
#include "components/optimization_guide/hint_cache_store.h"
#include "components/optimization_guide/hints_component_info.h"
#include "components/optimization_guide/hints_component_util.h"
#include "components/optimization_guide/hints_processing_util.h"
#include "components/optimization_guide/optimization_guide_service.h"
#include "components/optimization_guide/optimization_guide_switches.h"
#include "components/optimization_guide/proto/hints.pb.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/browser_thread.h"
namespace {
// The component version used with a manual config. This ensures that any hint
// component received from the OptimizationGuideService on a subsequent startup
// will have a newer version than it.
constexpr char kManualConfigComponentVersion[] = "0.0.0";
std::unique_ptr<optimization_guide::HintUpdateData> ProcessHintsComponent(
const optimization_guide::HintsComponentInfo& info,
std::unique_ptr<optimization_guide::HintUpdateData> update_data) {
// TODO(crbug/969558): Add the result here and record the histogram.
std::unique_ptr<optimization_guide::proto::Configuration> config =
optimization_guide::ProcessHintsComponent(info, /*out_result=*/nullptr);
if (!config)
return nullptr;
optimization_guide::ProcessHints(config->mutable_hints(), update_data.get());
return update_data;
}
void MaybeRunUpdateClosure(base::OnceClosure update_closure) {
if (update_closure)
std::move(update_closure).Run();
}
} // namespace
OptimizationGuideHintsManager::OptimizationGuideHintsManager(
optimization_guide::OptimizationGuideService* optimization_guide_service,
const base::FilePath& profile_path,
PrefService* pref_service,
leveldb_proto::ProtoDatabaseProvider* database_provider)
: optimization_guide_service_(optimization_guide_service),
background_task_runner_(base::CreateSequencedTaskRunnerWithTraits(
{base::MayBlock(), base::TaskPriority::BEST_EFFORT})),
pref_service_(pref_service),
hint_cache_(std::make_unique<optimization_guide::HintCache>(
std::make_unique<optimization_guide::HintCacheStore>(
database_provider,
profile_path,
pref_service_,
background_task_runner_))) {
DCHECK(optimization_guide_service_);
hint_cache_->Initialize(
optimization_guide::switches::ShouldPurgeHintCacheStoreOnStartup(),
base::BindOnce(&OptimizationGuideHintsManager::OnHintCacheInitialized,
ui_weak_ptr_factory_.GetWeakPtr()));
}
OptimizationGuideHintsManager::~OptimizationGuideHintsManager() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
optimization_guide_service_->RemoveObserver(this);
}
void OptimizationGuideHintsManager::Shutdown() {
optimization_guide_service_->RemoveObserver(this);
}
void OptimizationGuideHintsManager::OnHintsComponentAvailable(
const optimization_guide::HintsComponentInfo& info) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// Check for if hint component is disabled. This check is needed because the
// optimization guide still registers with the service as an observer for
// components as a signal during testing.
if (optimization_guide::switches::IsHintComponentProcessingDisabled()) {
MaybeRunUpdateClosure(std::move(next_update_closure_));
return;
}
std::unique_ptr<optimization_guide::HintUpdateData> update_data =
hint_cache_->MaybeCreateUpdateDataForComponentHints(info.version);
if (!update_data) {
MaybeRunUpdateClosure(std::move(next_update_closure_));
return;
}
// TODO(sophiechang): Check if we are mid-crash loop for processing this hint
// version.
// Processes the hints from the newly available component on a background
// thread, providing a HintUpdateData for component update from the hint
// cache, so that each hint within the component can be moved into it. In the
// case where the component's version is not newer than the hint cache store's
// component version, HintUpdateData will be a nullptr and hint
// processing will be skipped. After PreviewsHints::Create() returns the newly
// created PreviewsHints, it is initialized in UpdateHints() on the UI thread.
base::PostTaskAndReplyWithResult(
background_task_runner_.get(), FROM_HERE,
base::BindOnce(&ProcessHintsComponent, info, std::move(update_data)),
base::BindOnce(&OptimizationGuideHintsManager::UpdateComponentHints,
ui_weak_ptr_factory_.GetWeakPtr(),
std::move(next_update_closure_)));
}
void OptimizationGuideHintsManager::OnHintCacheInitialized() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// Check if there is a valid hint proto given on the command line first. We
// don't normally expect one, but if one is provided then use that and do not
// register as an observer as the opt_guide service.
std::unique_ptr<optimization_guide::proto::Configuration> manual_config =
optimization_guide::switches::ParseComponentConfigFromCommandLine();
if (manual_config) {
std::unique_ptr<optimization_guide::HintUpdateData> hint_update_data =
hint_cache_->MaybeCreateUpdateDataForComponentHints(
base::Version(kManualConfigComponentVersion));
optimization_guide::ProcessHints(manual_config->mutable_hints(),
hint_update_data.get());
// Allow |UpdateComponentHints| to block startup so that the first
// navigation gets the hints when a command line hint proto is provided.
UpdateComponentHints(base::DoNothing(), std::move(hint_update_data));
}
// Register as an observer regardless of hint proto override usage. This is
// needed as a signal during testing.
optimization_guide_service_->AddObserver(this);
}
void OptimizationGuideHintsManager::UpdateComponentHints(
base::OnceClosure update_closure,
std::unique_ptr<optimization_guide::HintUpdateData> hint_update_data) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (hint_update_data) {
hint_cache_->UpdateComponentHints(
std::move(hint_update_data),
base::BindOnce(&OptimizationGuideHintsManager::OnComponentHintsUpdated,
ui_weak_ptr_factory_.GetWeakPtr(),
std::move(update_closure),
/* hints_updated=*/true));
} else {
OnComponentHintsUpdated(std::move(update_closure), /*hints_updated=*/false);
}
}
void OptimizationGuideHintsManager::OnComponentHintsUpdated(
base::OnceClosure update_closure,
bool hints_updated) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// Record the result of updating the hints. This is used as a signal for the
// hints being fully processed in testing.
// TODO(sophiechang): Change this back to just a Result suffix once we
// have the flag to not record the histogram in Previews.
LOCAL_HISTOGRAM_BOOLEAN("OptimizationGuide.UpdateComponentHints.Result2",
hints_updated);
MaybeRunUpdateClosure(std::move(update_closure));
}
void OptimizationGuideHintsManager::ListenForNextUpdateForTesting(
base::OnceClosure next_update_closure) {
DCHECK(!next_update_closure_)
<< "Only one update closure is supported at a time";
next_update_closure_ = std::move(next_update_closure);
}
// Copyright 2019 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_OPTIMIZATION_GUIDE_OPTIMIZATION_GUIDE_HINTS_MANAGER_H_
#define CHROME_BROWSER_OPTIMIZATION_GUIDE_OPTIMIZATION_GUIDE_HINTS_MANAGER_H_
#include <memory>
#include "base/callback_forward.h"
#include "base/memory/weak_ptr.h"
#include "base/sequenced_task_runner.h"
#include "components/optimization_guide/optimization_guide_service_observer.h"
namespace base {
class FilePath;
} // namespace base
namespace leveldb_proto {
class ProtoDatabaseProvider;
} // namespace leveldb_proto
namespace optimization_guide {
class HintCache;
class HintUpdateData;
struct HintsComponentInfo;
class OptimizationGuideService;
} // namespace optimization_guide
class PrefService;
class OptimizationGuideHintsManager
: public optimization_guide::OptimizationGuideServiceObserver {
public:
OptimizationGuideHintsManager(
optimization_guide::OptimizationGuideService* optimization_guide_service,
const base::FilePath& profile_path,
PrefService* pref_service,
leveldb_proto::ProtoDatabaseProvider* database_provider);
~OptimizationGuideHintsManager() override;
// Unhooks the observer to |optimization_guide_service_|.
void Shutdown();
// optimization_guide::OptimizationGuideServiceObserver implementation:
void OnHintsComponentAvailable(
const optimization_guide::HintsComponentInfo& info) override;
// |next_update_closure| is called the next time OnHintsComponentAvailable()
// is called and the corresponding hints have been updated.
void ListenForNextUpdateForTesting(base::OnceClosure next_update_closure);
private:
// Callback run after the hint cache is fully initialized. At this point, the
// OptimizationGuideHintsManager is ready to process hints.
void OnHintCacheInitialized();
// Updates the cache with the latest hints sent by the Component Updater.
void UpdateComponentHints(
base::OnceClosure update_closure,
std::unique_ptr<optimization_guide::HintUpdateData> hint_update_data);
// Called when the hints have been fully updated with the latest hints from
// the Component Updater. This is used as a signal during tests.
void OnComponentHintsUpdated(base::OnceClosure update_closure,
bool hints_updated);
// The OptimizationGuideService that this guide is listening to. Not owned.
optimization_guide::OptimizationGuideService* const
optimization_guide_service_;
// Background thread where hints processing should be performed.
scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
// A reference to the PrefService for this profile. Not owned.
PrefService* pref_service_ = nullptr;
// The hint cache that holds both hints received from the component and
// fetched from the remote Optimization Guide Service.
std::unique_ptr<optimization_guide::HintCache> hint_cache_;
// Used in testing to subscribe to an update event in this class.
base::OnceClosure next_update_closure_;
// Used to get |weak_ptr_| to self on the UI thread.
base::WeakPtrFactory<OptimizationGuideHintsManager> ui_weak_ptr_factory_{
this};
DISALLOW_COPY_AND_ASSIGN(OptimizationGuideHintsManager);
};
#endif // CHROME_BROWSER_OPTIMIZATION_GUIDE_OPTIMIZATION_GUIDE_HINTS_MANAGER_H_
// Copyright 2019 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/optimization_guide/optimization_guide_keyed_service.h"
#include "base/files/file_path.h"
#include "chrome/browser/optimization_guide/optimization_guide_hints_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "components/leveldb_proto/public/proto_database_provider.h"
#include "components/optimization_guide/optimization_guide_service.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
OptimizationGuideKeyedService::OptimizationGuideKeyedService(
content::BrowserContext* browser_context)
: browser_context_(browser_context) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(!browser_context_->IsOffTheRecord());
}
OptimizationGuideKeyedService::~OptimizationGuideKeyedService() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
}
void OptimizationGuideKeyedService::Initialize(
optimization_guide::OptimizationGuideService* optimization_guide_service,
leveldb_proto::ProtoDatabaseProvider* database_provider,
const base::FilePath& profile_path) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(optimization_guide_service);
hints_manager_ = std::make_unique<OptimizationGuideHintsManager>(
optimization_guide_service, profile_path,
Profile::FromBrowserContext(browser_context_)->GetPrefs(),
database_provider);
}
void OptimizationGuideKeyedService::Shutdown() {
if (hints_manager_) {
hints_manager_->Shutdown();
hints_manager_ = nullptr;
}
}
// Copyright 2019 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_OPTIMIZATION_GUIDE_OPTIMIZATION_GUIDE_KEYED_SERVICE_H_
#define CHROME_BROWSER_OPTIMIZATION_GUIDE_OPTIMIZATION_GUIDE_KEYED_SERVICE_H_
#include <memory>
#include "base/macros.h"
#include "components/keyed_service/core/keyed_service.h"
namespace base {
class FilePath;
} // namespace base
namespace content {
class BrowserContext;
} // namespace content
namespace leveldb_proto {
class ProtoDatabaseProvider;
} // namespace leveldb_proto
namespace optimization_guide {
class OptimizationGuideService;
} // namespace optimization_guide
class OptimizationGuideHintsManager;
class OptimizationGuideKeyedService : public KeyedService {
public:
explicit OptimizationGuideKeyedService(
content::BrowserContext* browser_context);
~OptimizationGuideKeyedService() override;
// Initializes the service. |optimization_guide_service| is the
// Optimization Guide Service that is being listened to and is guaranteed to
// outlive |this|. |profile_path| is the path to user data on disk.
void Initialize(
optimization_guide::OptimizationGuideService* optimization_guide_service,
leveldb_proto::ProtoDatabaseProvider* database_provider,
const base::FilePath& profile_path);
OptimizationGuideHintsManager* GetHintsManager() {
return hints_manager_.get();
}
// KeyedService implementation.
void Shutdown() override;
private:
std::unique_ptr<OptimizationGuideHintsManager> hints_manager_;
content::BrowserContext* browser_context_;
DISALLOW_COPY_AND_ASSIGN(OptimizationGuideKeyedService);
};
#endif // CHROME_BROWSER_OPTIMIZATION_GUIDE_OPTIMIZATION_GUIDE_KEYED_SERVICE_H_
// Copyright 2019 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 "base/run_loop.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/optimization_guide/optimization_guide_hints_manager.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/optimization_guide/optimization_guide_features.h"
#include "components/optimization_guide/proto/hints.pb.h"
#include "components/optimization_guide/test_hints_component_creator.h"
#include "content/public/test/browser_test_utils.h"
using OptimizationGuideKeyedServiceDisabledBrowserTest = InProcessBrowserTest;
IN_PROC_BROWSER_TEST_F(OptimizationGuideKeyedServiceDisabledBrowserTest,
KeyedServiceNotEnabledButOptimizationHintsEnabled) {
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitWithFeatures(
{optimization_guide::features::kOptimizationHints},
{optimization_guide::features::kOptimizationGuideKeyedService});
EXPECT_EQ(nullptr, OptimizationGuideKeyedServiceFactory::GetForProfile(
browser()->profile()));
}
IN_PROC_BROWSER_TEST_F(OptimizationGuideKeyedServiceDisabledBrowserTest,
KeyedServiceEnabledButOptimizationHintsDisabled) {
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitWithFeatures(
{optimization_guide::features::kOptimizationGuideKeyedService},
{optimization_guide::features::kOptimizationHints});
EXPECT_EQ(nullptr, OptimizationGuideKeyedServiceFactory::GetForProfile(
browser()->profile()));
}
class OptimizationGuideKeyedServiceBrowserTest
: public OptimizationGuideKeyedServiceDisabledBrowserTest {
public:
OptimizationGuideKeyedServiceBrowserTest() = default;
~OptimizationGuideKeyedServiceBrowserTest() override = default;
void SetUp() override {
scoped_feature_list_.InitWithFeatures(
{optimization_guide::features::kOptimizationHints,
optimization_guide::features::kOptimizationGuideKeyedService},
{});
OptimizationGuideKeyedServiceDisabledBrowserTest::SetUp();
}
void PushHintsComponentAndWaitForCompletion() {
base::RunLoop run_loop;
OptimizationGuideKeyedServiceFactory::GetForProfile(browser()->profile())
->GetHintsManager()
->ListenForNextUpdateForTesting(run_loop.QuitClosure());
const optimization_guide::HintsComponentInfo& component_info =
test_hints_component_creator_.CreateHintsComponentInfoWithPageHints(
optimization_guide::proto::NOSCRIPT, {"somehost.com"}, "*", {});
g_browser_process->optimization_guide_service()->MaybeUpdateHintsComponent(
component_info);
run_loop.Run();
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
optimization_guide::testing::TestHintsComponentCreator
test_hints_component_creator_;
DISALLOW_COPY_AND_ASSIGN(OptimizationGuideKeyedServiceBrowserTest);
};
IN_PROC_BROWSER_TEST_F(OptimizationGuideKeyedServiceBrowserTest,
VerifyHintsReceivedWhenPushed) {
base::HistogramTester histogram_tester;
PushHintsComponentAndWaitForCompletion();
histogram_tester.ExpectUniqueSample(
"OptimizationGuide.UpdateComponentHints.Result2", true, 1);
}
// Copyright 2019 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/optimization_guide/optimization_guide_keyed_service_factory.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service.h"
#include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/optimization_guide/optimization_guide_features.h"
#include "content/public/browser/browser_context.h"
// static
OptimizationGuideKeyedService*
OptimizationGuideKeyedServiceFactory::GetForProfile(Profile* profile) {
if (optimization_guide::features::IsOptimizationHintsEnabled() &&
optimization_guide::features::IsOptimizationGuideKeyedServiceEnabled()) {
return static_cast<OptimizationGuideKeyedService*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
return nullptr;
}
// static
OptimizationGuideKeyedServiceFactory*
OptimizationGuideKeyedServiceFactory::GetInstance() {
static base::NoDestructor<OptimizationGuideKeyedServiceFactory> factory;
return factory.get();
}
OptimizationGuideKeyedServiceFactory::OptimizationGuideKeyedServiceFactory()
: BrowserContextKeyedServiceFactory(
"OptimizationGuideKeyedService",
BrowserContextDependencyManager::GetInstance()) {}
OptimizationGuideKeyedServiceFactory::~OptimizationGuideKeyedServiceFactory() =
default;
KeyedService* OptimizationGuideKeyedServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
return new OptimizationGuideKeyedService(context);
}
// Copyright 2019 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_OPTIMIZATION_GUIDE_OPTIMIZATION_GUIDE_KEYED_SERVICE_FACTORY_H_
#define CHROME_BROWSER_OPTIMIZATION_GUIDE_OPTIMIZATION_GUIDE_KEYED_SERVICE_FACTORY_H_
#include "base/macros.h"
#include "base/no_destructor.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
namespace content {
class BrowserContext;
} // namespace content
class OptimizationGuideKeyedService;
class Profile;
// LazyInstance that owns all OptimizationGuideKeyedServices and associates them
// with Profiles.
class OptimizationGuideKeyedServiceFactory
: public BrowserContextKeyedServiceFactory {
public:
// Gets the OptimizationGuideKeyedService for the profile.
//
// Returns null if the features that allow for this to provide useful
// information are disabled.
static OptimizationGuideKeyedService* GetForProfile(Profile* profile);
// Gets the LazyInstance that owns all OptimizationGuideKeyedService(s).
static OptimizationGuideKeyedServiceFactory* GetInstance();
private:
friend base::NoDestructor<OptimizationGuideKeyedServiceFactory>;
OptimizationGuideKeyedServiceFactory();
~OptimizationGuideKeyedServiceFactory() override;
// BrowserContextKeyedServiceFactory:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
DISALLOW_COPY_AND_ASSIGN(OptimizationGuideKeyedServiceFactory);
};
#endif // CHROME_BROWSER_OPTIMIZATION_GUIDE_OPTIMIZATION_GUIDE_KEYED_SERVICE_FACTORY_H_
......@@ -41,6 +41,8 @@
#include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings_factory.h"
#include "chrome/browser/download/download_core_service.h"
#include "chrome/browser/download/download_core_service_factory.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service_factory.h"
#include "chrome/browser/password_manager/password_store_factory.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/previews/previews_service.h"
......@@ -1262,6 +1264,16 @@ void ProfileManager::DoFinalInitForServices(Profile* profile,
leveldb_proto::ProtoDatabaseProviderFactory::GetInstance()->GetForKey(
profile->GetProfileKey());
// Creates the Optimization Guide Keyed Service and begins loading the
// hint cache from persistent memory.
auto* optimization_guide_keyed_service =
OptimizationGuideKeyedServiceFactory::GetForProfile(profile);
if (optimization_guide_keyed_service) {
optimization_guide_keyed_service->Initialize(
g_browser_process->optimization_guide_service(), proto_db_provider,
profile->GetPath());
}
// Create the Previews Service and begin loading opt out history from
// persistent memory.
PreviewsServiceFactory::GetForProfile(profile)->Initialize(
......
......@@ -969,6 +969,7 @@ if (!is_android) {
"../browser/no_best_effort_tasks_during_startup_browsertest.cc",
"../browser/ntp_snippets/content_suggestions_service_factory_browsertest.cc",
"../browser/ntp_tiles/ntp_tiles_browsertest.cc",
"../browser/optimization_guide/optimization_guide_keyed_service_browsertest.cc",
"../browser/page_load_metrics/observers/ad_metrics/ads_page_load_metrics_observer_browsertest.cc",
"../browser/page_load_metrics/observers/amp_page_load_metrics_observer_browsertest.cc",
"../browser/page_load_metrics/observers/data_saver_site_breakdown_metrics_observer_browsertest.cc",
......@@ -2934,6 +2935,7 @@ test("unit_tests") {
"../browser/notifications/stub_alert_dispatcher_mac.mm",
"../browser/notifications/stub_notification_center_mac.h",
"../browser/notifications/stub_notification_center_mac.mm",
"../browser/optimization_guide/optimization_guide_hints_manager_unittest.cc",
"../browser/page_load_metrics/metrics_web_contents_observer_unittest.cc",
"../browser/page_load_metrics/observers/aborts_page_load_metrics_observer_unittest.cc",
"../browser/page_load_metrics/observers/ad_metrics/ads_page_load_metrics_observer_unittest.cc",
......@@ -3370,6 +3372,7 @@ test("unit_tests") {
"//components/offline_items_collection/core/test_support",
"//components/offline_pages/task:test_support",
"//components/optimization_guide",
"//components/optimization_guide:test_support",
"//components/os_crypt:test_support",
"//components/resources",
"//components/safe_browsing:buildflags",
......
......@@ -11,7 +11,6 @@
#include "base/metrics/field_trial_params.h"
#include "build/build_config.h"
#include "components/optimization_guide/optimization_guide_constants.h"
#include "components/optimization_guide/optimization_guide_features.h"
#include "components/optimization_guide/optimization_guide_switches.h"
#include "google_apis/google_api_keys.h"
#include "net/base/url_util.h"
......@@ -50,6 +49,10 @@ const base::Feature kSlowPageTriggering{"PreviewsSlowPageTriggering",
const base::Feature kOptimizationHintsFetching{
"OptimizationHintsFetching", base::FEATURE_DISABLED_BY_DEFAULT};
// Enables the initialization of the Optimization Guide Keyed Service.
const base::Feature kOptimizationGuideKeyedService{
"OptimizationGuideKeyedService", base::FEATURE_DISABLED_BY_DEFAULT};
size_t MaxHintsFetcherTopHostBlacklistSize() {
// The blacklist will be limited to the most engaged hosts and will hold twice
// (2*N) as many hosts that the HintsFetcher request hints for. The extra N
......@@ -112,5 +115,9 @@ bool IsHintsFetchingEnabled() {
return base::FeatureList::IsEnabled(features::kOptimizationHintsFetching);
}
bool IsOptimizationGuideKeyedServiceEnabled() {
return base::FeatureList::IsEnabled(features::kOptimizationGuideKeyedService);
}
} // namespace features
} // namespace optimization_guide
......@@ -20,6 +20,7 @@ extern const base::Feature kOptimizationHintsExperiments;
constexpr char kOptimizationHintsExperimentNameParam[] = "experiment_name";
extern const base::Feature kSlowPageTriggering;
extern const base::Feature kOptimizationHintsFetching;
extern const base::Feature kOptimizationGuideKeyedService;
// The maximum number of hosts that can be stored in the
// |kHintsFetcherTopHostBlacklist| dictionary pref when initialized. The top
......@@ -49,6 +50,10 @@ bool IsOptimizationHintsEnabled();
// Service is enabled.
bool IsHintsFetchingEnabled();
// Returns true if the initialization of the Optimization Guide Keyed Service is
// enabled.
bool IsOptimizationGuideKeyedServiceEnabled();
} // namespace features
} // namespace optimization_guide
......
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