Commit a12b6d05 authored by Marc Treib's avatar Marc Treib Committed by Chromium LUCI CQ

Revert "Implement read-only mode for Optimization Guide when in incognito"

This reverts commit 84f1c409.

Reason for revert: Broke OverrideUnknownPerformanceHintsObserverTest.HintFetchingNotEnabled on Linux TSan, see crbug.com/1158739

Original change's description:
> Implement read-only mode for Optimization Guide when in incognito
>
> Bug: 1151087
> Change-Id: I4a6074a01793c5a97de7f07e14ccbd133ef6cb51
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2586246
> Reviewed-by: David Roger <droger@chromium.org>
> Reviewed-by: Tarun Bansal <tbansal@chromium.org>
> Reviewed-by: Michael Crouse <mcrouse@chromium.org>
> Commit-Queue: Sophie Chang <sophiechang@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#836442}

TBR=droger@chromium.org,tbansal@chromium.org,sophiechang@chromium.org,mcrouse@chromium.org,chromium-scoped@luci-project-accounts.iam.gserviceaccount.com

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 1151087, 1158739
Change-Id: Ic9c6142d2b1087010b75e9deaab3d0cfcb714762
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2592992Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Commit-Queue: Marc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837066}
parent 259e50fc
...@@ -1277,27 +1277,6 @@ IN_PROC_BROWSER_TEST_F(HintsFetcherBrowserTest, ...@@ -1277,27 +1277,6 @@ IN_PROC_BROWSER_TEST_F(HintsFetcherBrowserTest,
kRaceNavigationFetchHost, kRaceNavigationFetchHost,
1); 1);
} }
// Incognito page loads should not initiate any fetches.
{
base::HistogramTester incognito_histogram_tester;
// Instantiate off the record Optimization Guide Service.
OptimizationGuideKeyedServiceFactory::GetForProfile(
browser()->profile()->GetPrimaryOTRProfile())
->RegisterOptimizationTypes({optimization_guide::proto::NOSCRIPT});
Browser* otr_browser = CreateIncognitoBrowser(browser()->profile());
ui_test_utils::NavigateToURL(otr_browser, GURL(full_url));
// Make sure no additional hints requests were received.
RetryForHistogramUntilCountReached(
&incognito_histogram_tester,
optimization_guide::kLoadedHintLocalHistogramString, 1);
EXPECT_EQ(2u, count_hints_requests_received());
incognito_histogram_tester.ExpectTotalCount(
"OptimizationGuide.HintsManager.RaceNavigationFetchAttemptStatus", 0);
}
} }
// Test that the hints are fetched at the time of the navigation. // Test that the hints are fetched at the time of the navigation.
......
...@@ -291,6 +291,8 @@ OptimizationGuideHintsManager::OptimizationGuideHintsManager( ...@@ -291,6 +291,8 @@ OptimizationGuideHintsManager::OptimizationGuideHintsManager(
ExternalAppPackageNamesApprovedForFetch()), ExternalAppPackageNamesApprovedForFetch()),
top_host_provider_(top_host_provider), top_host_provider_(top_host_provider),
clock_(base::DefaultClock::GetInstance()) { clock_(base::DefaultClock::GetInstance()) {
DCHECK(optimization_guide_service_);
RegisterOptimizationTypes(optimization_types_at_initialization); RegisterOptimizationTypes(optimization_types_at_initialization);
g_browser_process->network_quality_tracker() g_browser_process->network_quality_tracker()
...@@ -304,27 +306,23 @@ OptimizationGuideHintsManager::OptimizationGuideHintsManager( ...@@ -304,27 +306,23 @@ OptimizationGuideHintsManager::OptimizationGuideHintsManager(
NavigationPredictorKeyedService* navigation_predictor_service = NavigationPredictorKeyedService* navigation_predictor_service =
NavigationPredictorKeyedServiceFactory::GetForProfile(profile_); NavigationPredictorKeyedServiceFactory::GetForProfile(profile_);
if (navigation_predictor_service) navigation_predictor_service->AddObserver(this);
navigation_predictor_service->AddObserver(this);
} }
OptimizationGuideHintsManager::~OptimizationGuideHintsManager() { OptimizationGuideHintsManager::~OptimizationGuideHintsManager() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (optimization_guide_service_) optimization_guide_service_->RemoveObserver(this);
optimization_guide_service_->RemoveObserver(this);
g_browser_process->network_quality_tracker() g_browser_process->network_quality_tracker()
->RemoveEffectiveConnectionTypeObserver(this); ->RemoveEffectiveConnectionTypeObserver(this);
NavigationPredictorKeyedService* navigation_predictor_service = NavigationPredictorKeyedService* navigation_predictor_service =
NavigationPredictorKeyedServiceFactory::GetForProfile(profile_); NavigationPredictorKeyedServiceFactory::GetForProfile(profile_);
if (navigation_predictor_service) navigation_predictor_service->RemoveObserver(this);
navigation_predictor_service->RemoveObserver(this);
} }
void OptimizationGuideHintsManager::Shutdown() { void OptimizationGuideHintsManager::Shutdown() {
if (optimization_guide_service_) optimization_guide_service_->RemoveObserver(this);
optimization_guide_service_->RemoveObserver(this);
g_browser_process->network_quality_tracker() g_browser_process->network_quality_tracker()
->RemoveEffectiveConnectionTypeObserver(this); ->RemoveEffectiveConnectionTypeObserver(this);
} }
...@@ -537,8 +535,7 @@ void OptimizationGuideHintsManager::OnHintCacheInitialized() { ...@@ -537,8 +535,7 @@ void OptimizationGuideHintsManager::OnHintCacheInitialized() {
// Register as an observer regardless of hint proto override usage. This is // Register as an observer regardless of hint proto override usage. This is
// needed as a signal during testing. // needed as a signal during testing.
if (optimization_guide_service_) optimization_guide_service_->AddObserver(this);
optimization_guide_service_->AddObserver(this);
} }
void OptimizationGuideHintsManager::UpdateComponentHints( void OptimizationGuideHintsManager::UpdateComponentHints(
...@@ -1234,7 +1231,6 @@ bool OptimizationGuideHintsManager::IsAllowedToFetchNavigationHints( ...@@ -1234,7 +1231,6 @@ bool OptimizationGuideHintsManager::IsAllowedToFetchNavigationHints(
if (!IsUserPermittedToFetchFromRemoteOptimizationGuide(profile_)) if (!IsUserPermittedToFetchFromRemoteOptimizationGuide(profile_))
return false; return false;
DCHECK(!profile_->IsOffTheRecord());
if (!url.is_valid() || !url.SchemeIsHTTPOrHTTPS()) if (!url.is_valid() || !url.SchemeIsHTTPOrHTTPS())
return false; return false;
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/optional.h" #include "base/optional.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/metrics/chrome_metrics_service_accessor.h" #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
#include "chrome/browser/optimization_guide/optimization_guide_hints_manager.h" #include "chrome/browser/optimization_guide/optimization_guide_hints_manager.h"
#include "chrome/browser/optimization_guide/optimization_guide_navigation_data.h" #include "chrome/browser/optimization_guide/optimization_guide_navigation_data.h"
...@@ -97,51 +96,37 @@ OptimizationGuideKeyedService::OptimizationGuideKeyedService( ...@@ -97,51 +96,37 @@ OptimizationGuideKeyedService::OptimizationGuideKeyedService(
content::BrowserContext* browser_context) content::BrowserContext* browser_context)
: browser_context_(browser_context) { : browser_context_(browser_context) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
Initialize(); DCHECK(!browser_context_->IsOffTheRecord());
} }
OptimizationGuideKeyedService::~OptimizationGuideKeyedService() { OptimizationGuideKeyedService::~OptimizationGuideKeyedService() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
} }
void OptimizationGuideKeyedService::Initialize() { 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_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK(optimization_guide_service);
Profile* profile = Profile::FromBrowserContext(browser_context_); Profile* profile = Profile::FromBrowserContext(browser_context_);
top_host_provider_ = GetTopHostProviderIfUserPermitted(browser_context_);
// Regardless of whether the profile is off the record or not, we initialize bool optimization_guide_fetching_enabled = top_host_provider_ != nullptr;
// the Optimization Guide with the database associated with the original UMA_HISTOGRAM_BOOLEAN("OptimizationGuide.RemoteFetchingEnabled",
// profile. optimization_guide_fetching_enabled);
auto* proto_db_provider = content::BrowserContext::GetDefaultStoragePartition( ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial(
profile->GetOriginalProfile()) "SyntheticOptimizationGuideRemoteFetching",
->GetProtoDatabaseProvider(); optimization_guide_fetching_enabled ? "Enabled" : "Disabled");
base::FilePath profile_path = profile->GetOriginalProfile()->GetPath(); scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory =
content::BrowserContext::GetDefaultStoragePartition(profile)
// We should not be fetching anything from the remote Optimization Guide ->GetURLLoaderFactoryForBrowserProcess();
// Service, only instantiate a URLLoaderFactory and TopHostProvider if the
// profile is a regular profile.
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory;
if (!profile->IsOffTheRecord()) {
url_loader_factory =
content::BrowserContext::GetDefaultStoragePartition(profile)
->GetURLLoaderFactoryForBrowserProcess();
top_host_provider_ = GetTopHostProviderIfUserPermitted(browser_context_);
bool optimization_guide_fetching_enabled = top_host_provider_ != nullptr;
UMA_HISTOGRAM_BOOLEAN("OptimizationGuide.RemoteFetchingEnabled",
optimization_guide_fetching_enabled);
ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial(
"SyntheticOptimizationGuideRemoteFetching",
optimization_guide_fetching_enabled ? "Enabled" : "Disabled");
}
hints_manager_ = std::make_unique<OptimizationGuideHintsManager>( hints_manager_ = std::make_unique<OptimizationGuideHintsManager>(
pre_initialized_optimization_types_, pre_initialized_optimization_types_, optimization_guide_service, profile,
g_browser_process->optimization_guide_service(), profile, profile_path, profile_path, profile->GetPrefs(), database_provider,
profile->GetPrefs(), proto_db_provider, top_host_provider_.get(), top_host_provider_.get(), url_loader_factory);
url_loader_factory);
prediction_manager_ = std::make_unique<optimization_guide::PredictionManager>( prediction_manager_ = std::make_unique<optimization_guide::PredictionManager>(
pre_initialized_optimization_targets_, profile_path, proto_db_provider, pre_initialized_optimization_targets_, profile_path, database_provider,
top_host_provider_.get(), url_loader_factory, profile->GetPrefs(), top_host_provider_.get(), url_loader_factory, profile->GetPrefs(),
profile); profile);
} }
......
...@@ -25,26 +25,24 @@ class BrowserContext; ...@@ -25,26 +25,24 @@ class BrowserContext;
class NavigationHandle; class NavigationHandle;
} // namespace content } // namespace content
namespace leveldb_proto {
class ProtoDatabaseProvider;
} // namespace leveldb_proto
namespace optimization_guide { namespace optimization_guide {
namespace android { namespace android {
class OptimizationGuideBridge; class OptimizationGuideBridge;
} // namespace android } // namespace android
class OptimizationGuideService;
class TopHostProvider;
class PredictionManager; class PredictionManager;
class PredictionManagerBrowserTestBase; class PredictionManagerBrowserTestBase;
class PredictionModelDownloadClient; class PredictionModelDownloadClient;
class TopHostProvider;
} // namespace optimization_guide } // namespace optimization_guide
class GURL; class GURL;
class OptimizationGuideHintsManager; class OptimizationGuideHintsManager;
// Keyed service that can be used to get information received from the remote
// Optimization Guide Service. For regular profiles, this will do the work to
// fetch the necessary information from the remote Optimization Guide Service
// in anticipation for when it is needed. For off the record profiles, this will
// act in a "read-only" mode where it will only serve information that was
// received from the remote Optimization Guide Service when not off the record
// and no information will be retrieved.
class OptimizationGuideKeyedService class OptimizationGuideKeyedService
: public KeyedService, : public KeyedService,
public optimization_guide::OptimizationGuideDecider { public optimization_guide::OptimizationGuideDecider {
...@@ -109,12 +107,18 @@ class OptimizationGuideKeyedService ...@@ -109,12 +107,18 @@ class OptimizationGuideKeyedService
friend class HintsFetcherBrowserTest; friend class HintsFetcherBrowserTest;
friend class OptimizationGuideKeyedServiceBrowserTest; friend class OptimizationGuideKeyedServiceBrowserTest;
friend class OptimizationGuideWebContentsObserver; friend class OptimizationGuideWebContentsObserver;
friend class ProfileManager;
friend class optimization_guide::PredictionModelDownloadClient; friend class optimization_guide::PredictionModelDownloadClient;
friend class optimization_guide::PredictionManagerBrowserTestBase; friend class optimization_guide::PredictionManagerBrowserTestBase;
friend class optimization_guide::android::OptimizationGuideBridge; friend class optimization_guide::android::OptimizationGuideBridge;
// Initializes |this|. // Initializes the service. |optimization_guide_service| is the
void Initialize(); // 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);
// Virtualized for testing. // Virtualized for testing.
virtual OptimizationGuideHintsManager* GetHintsManager(); virtual OptimizationGuideHintsManager* GetHintsManager();
......
...@@ -618,43 +618,6 @@ IN_PROC_BROWSER_TEST_F( ...@@ -618,43 +618,6 @@ IN_PROC_BROWSER_TEST_F(
#endif #endif
} }
// TODO(crbug/1158343): Re-enable when not flaky.
IN_PROC_BROWSER_TEST_F(
OptimizationGuideKeyedServiceDataSaverUserWithInfobarShownTest,
DISABLED_IncognitoCanStillReadFromComponentHints) {
// Instantiate off the record Optimization Guide Service.
OptimizationGuideKeyedServiceFactory::GetForProfile(
browser()->profile()->GetPrimaryOTRProfile())
->RegisterOptimizationTypes({optimization_guide::proto::NOSCRIPT});
// Wait until initialization logic finishes running and component pushed to
// both incognito and regular browsers.
PushHintsComponentAndWaitForCompletion();
base::RunLoop().RunUntilIdle();
// Set up incognito browser and incognito OptimizationGuideKeyedService
// consumer.
Browser* otr_browser = CreateIncognitoBrowser(browser()->profile());
auto otr_consumer =
std::make_unique<OptimizationGuideConsumerWebContentsObserver>(
otr_browser->tab_strip_model()->GetActiveWebContents());
std::unique_ptr<base::RunLoop> run_loop = std::make_unique<base::RunLoop>();
otr_consumer->set_callback(base::BindOnce(
[](base::RunLoop* run_loop,
optimization_guide::OptimizationGuideDecision decision,
const optimization_guide::OptimizationMetadata& metadata) {
// Should still get decision in incognito.
EXPECT_EQ(decision,
optimization_guide::OptimizationGuideDecision::kTrue);
run_loop->Quit();
},
run_loop.get()));
// Navigate to a URL that has a hint from a component.
ui_test_utils::NavigateToURL(otr_browser, url_with_hints());
run_loop->Run();
}
class OptimizationGuideKeyedServiceCommandLineOverridesTest class OptimizationGuideKeyedServiceCommandLineOverridesTest
: public OptimizationGuideKeyedServiceDataSaverUserWithInfobarShownTest { : public OptimizationGuideKeyedServiceDataSaverUserWithInfobarShownTest {
public: public:
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service_factory.h" #include "chrome/browser/optimization_guide/optimization_guide_keyed_service_factory.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service.h" #include "chrome/browser/optimization_guide/optimization_guide_keyed_service.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/optimization_guide/optimization_guide_features.h" #include "components/optimization_guide/optimization_guide_features.h"
...@@ -40,18 +39,3 @@ KeyedService* OptimizationGuideKeyedServiceFactory::BuildServiceInstanceFor( ...@@ -40,18 +39,3 @@ KeyedService* OptimizationGuideKeyedServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const { content::BrowserContext* context) const {
return new OptimizationGuideKeyedService(context); return new OptimizationGuideKeyedService(context);
} }
content::BrowserContext*
OptimizationGuideKeyedServiceFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextOwnInstanceInIncognito(context);
}
bool OptimizationGuideKeyedServiceFactory::ServiceIsCreatedWithBrowserContext()
const {
return optimization_guide::features::IsOptimizationHintsEnabled();
}
bool OptimizationGuideKeyedServiceFactory::ServiceIsNULLWhileTesting() const {
return true;
}
...@@ -39,10 +39,6 @@ class OptimizationGuideKeyedServiceFactory ...@@ -39,10 +39,6 @@ class OptimizationGuideKeyedServiceFactory
// BrowserContextKeyedServiceFactory: // BrowserContextKeyedServiceFactory:
KeyedService* BuildServiceInstanceFor( KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override; content::BrowserContext* context) const override;
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
bool ServiceIsCreatedWithBrowserContext() const override;
bool ServiceIsNULLWhileTesting() const override;
DISALLOW_COPY_AND_ASSIGN(OptimizationGuideKeyedServiceFactory); DISALLOW_COPY_AND_ASSIGN(OptimizationGuideKeyedServiceFactory);
}; };
......
...@@ -54,14 +54,14 @@ bool IsUserConsentedToAnonymousDataCollectionAndAllowedToFetchFromRemoteService( ...@@ -54,14 +54,14 @@ bool IsUserConsentedToAnonymousDataCollectionAndAllowedToFetchFromRemoteService(
} // namespace } // namespace
bool IsUserPermittedToFetchFromRemoteOptimizationGuide(Profile* profile) { bool IsUserPermittedToFetchFromRemoteOptimizationGuide(Profile* profile) {
if (profile->IsOffTheRecord())
return false;
if (optimization_guide::switches:: if (optimization_guide::switches::
ShouldOverrideCheckingUserPermissionsToFetchHintsForTesting()) { ShouldOverrideCheckingUserPermissionsToFetchHintsForTesting()) {
return true; return true;
} }
if (profile->IsOffTheRecord())
return false;
if (!optimization_guide::features::IsRemoteFetchingEnabled()) if (!optimization_guide::features::IsRemoteFetchingEnabled())
return false; return false;
......
...@@ -203,11 +203,6 @@ void OptimizationGuideTopHostProvider::MaybeUpdateTopHostBlacklist( ...@@ -203,11 +203,6 @@ void OptimizationGuideTopHostProvider::MaybeUpdateTopHostBlacklist(
Profile* profile = Profile::FromBrowserContext( Profile* profile = Profile::FromBrowserContext(
navigation_handle->GetWebContents()->GetBrowserContext()); navigation_handle->GetWebContents()->GetBrowserContext());
// Do not update the top host list if the profile is off the record.
if (profile->IsOffTheRecord())
return;
PrefService* pref_service = profile->GetPrefs(); PrefService* pref_service = profile->GetPrefs();
bool is_user_permitted_to_fetch_hints = bool is_user_permitted_to_fetch_hints =
......
...@@ -180,13 +180,6 @@ void RecordModelTypeChanged( ...@@ -180,13 +180,6 @@ void RecordModelTypeChanged(
changed); changed);
} }
// Returns whether models and host model features should be fetched from the
// remote Optimization Guide Service.
bool ShouldFetchModelsAndHostModelFeatures(Profile* profile) {
return optimization_guide::features::IsRemoteFetchingEnabled() &&
!profile->IsOffTheRecord();
}
} // namespace } // namespace
namespace optimization_guide { namespace optimization_guide {
...@@ -617,7 +610,7 @@ void PredictionManager::SetPredictionModelDownloadManagerForTesting( ...@@ -617,7 +610,7 @@ void PredictionManager::SetPredictionModelDownloadManagerForTesting(
void PredictionManager::FetchModelsAndHostModelFeatures() { void PredictionManager::FetchModelsAndHostModelFeatures() {
SEQUENCE_CHECKER(sequence_checker_); SEQUENCE_CHECKER(sequence_checker_);
if (!ShouldFetchModelsAndHostModelFeatures(profile_)) if (!features::IsRemoteFetchingEnabled())
return; return;
ScheduleModelsAndHostModelFeaturesFetch(); ScheduleModelsAndHostModelFeaturesFetch();
...@@ -1117,7 +1110,7 @@ bool PredictionManager::ProcessAndStoreHostModelFeatures( ...@@ -1117,7 +1110,7 @@ bool PredictionManager::ProcessAndStoreHostModelFeatures(
} }
void PredictionManager::MaybeScheduleModelAndHostModelFeaturesFetch() { void PredictionManager::MaybeScheduleModelAndHostModelFeaturesFetch() {
if (!ShouldFetchModelsAndHostModelFeatures(profile_)) if (!features::IsRemoteFetchingEnabled())
return; return;
if (optimization_guide::switches:: if (optimization_guide::switches::
......
...@@ -645,107 +645,6 @@ IN_PROC_BROWSER_TEST_F( ...@@ -645,107 +645,6 @@ IN_PROC_BROWSER_TEST_F(
1); 1);
} }
IN_PROC_BROWSER_TEST_F(PredictionManagerBrowserTest,
DISABLE_ON_WIN_MAC_CHROMEOS(IncognitoCanStillRead)) {
SetResponseType(PredictionModelsFetcherRemoteResponseType::
kSuccessfulWithModelsAndFeatures);
base::HistogramTester histogram_tester;
// Register with regular profile.
RegisterWithKeyedService();
// Wait until model has been fetched via regular profile.
RetryForHistogramUntilCountReached(
&histogram_tester,
"OptimizationGuide.PredictionManager.HostModelFeaturesStored", 1);
RetryForHistogramUntilCountReached(
&histogram_tester,
"OptimizationGuide.PredictionManager.PredictionModelsStored", 1);
RetryForHistogramUntilCountReached(
&histogram_tester,
"OptimizationGuide.PredictionModelLoadedVersion.PainfulPageLoad", 1);
// Set up incognito browser.
Browser* otr_browser = CreateIncognitoBrowser(browser()->profile());
// Register with off the record profile.
OptimizationGuideKeyedServiceFactory::GetForProfile(
browser()->profile()->GetPrimaryOTRProfile())
->RegisterOptimizationTargets(
{proto::OPTIMIZATION_TARGET_PAINFUL_PAGE_LOAD});
// Set up an OptimizationGuideKeyedService consumer.
auto otr_consumer =
std::make_unique<OptimizationGuideConsumerWebContentsObserver>(
otr_browser->tab_strip_model()->GetActiveWebContents());
std::unique_ptr<base::RunLoop> run_loop = std::make_unique<base::RunLoop>();
otr_consumer->set_callback(base::BindOnce(
[](base::RunLoop* run_loop,
optimization_guide::OptimizationGuideDecision decision) {
// We should have the model on the client so we have everything to make
// a decision.
EXPECT_NE(decision,
optimization_guide::OptimizationGuideDecision::kUnknown);
run_loop->Quit();
},
run_loop.get()));
// Navigate to a URL with a host model feature in incognito.
ui_test_utils::NavigateToURL(otr_browser, https_url_with_content());
run_loop->Run();
// The store should still be able to be read.
histogram_tester.ExpectUniqueSample(
"OptimizationGuide.PredictionManager.HasHostModelFeaturesForHost", true,
1);
}
IN_PROC_BROWSER_TEST_F(
PredictionManagerBrowserTest,
DISABLE_ON_WIN_MAC_CHROMEOS(IncognitoDoesntFetchModels)) {
SetResponseType(PredictionModelsFetcherRemoteResponseType::
kSuccessfulWithModelsAndFeatures);
base::HistogramTester histogram_tester;
// Set up incognito browser.
Browser* otr_browser = CreateIncognitoBrowser(browser()->profile());
// Register with off the record profile.
OptimizationGuideKeyedServiceFactory::GetForProfile(
browser()->profile()->GetPrimaryOTRProfile())
->RegisterOptimizationTargets(
{proto::OPTIMIZATION_TARGET_PAINFUL_PAGE_LOAD});
// Wait until logic finishes running.
base::RunLoop().RunUntilIdle();
// Ensure that GetModelsRequest did not go out.
histogram_tester.ExpectTotalCount(
"OptimizationGuide.PredictionModelFetcher.GetModelsRequest.HostCount", 0);
// Set up an OptimizationGuideKeyedService consumer.
auto otr_consumer =
std::make_unique<OptimizationGuideConsumerWebContentsObserver>(
otr_browser->tab_strip_model()->GetActiveWebContents());
std::unique_ptr<base::RunLoop> run_loop = std::make_unique<base::RunLoop>();
otr_consumer->set_callback(base::BindOnce(
[](base::RunLoop* run_loop,
optimization_guide::OptimizationGuideDecision decision) {
run_loop->Quit();
},
run_loop.get()));
// Navigate to a URL that would normally have a model had we not been in
// incognito.
ui_test_utils::NavigateToURL(otr_browser, https_url_with_content());
run_loop->Run();
// The model should not be available on the client.
histogram_tester.ExpectUniqueSample(
"OptimizationGuide.TargetDecision.PainfulPageLoad",
OptimizationTargetDecision::kModelNotAvailableOnClient, 1);
}
class PredictionManagerBrowserSameOriginTest class PredictionManagerBrowserSameOriginTest
: public PredictionManagerBrowserTest { : public PredictionManagerBrowserTest {
public: public:
......
...@@ -48,6 +48,8 @@ ...@@ -48,6 +48,8 @@
#include "chrome/browser/lite_video/lite_video_keyed_service.h" #include "chrome/browser/lite_video/lite_video_keyed_service.h"
#include "chrome/browser/lite_video/lite_video_keyed_service_factory.h" #include "chrome/browser/lite_video/lite_video_keyed_service_factory.h"
#include "chrome/browser/navigation_predictor/navigation_predictor_keyed_service_factory.h" #include "chrome/browser/navigation_predictor/navigation_predictor_keyed_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/password_manager/password_store_factory.h"
#include "chrome/browser/permissions/adaptive_quiet_notification_permission_ui_enabler.h" #include "chrome/browser/permissions/adaptive_quiet_notification_permission_ui_enabler.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/prefs/incognito_mode_prefs.h"
...@@ -1405,6 +1407,20 @@ void ProfileManager::DoFinalInitForServices(Profile* profile, ...@@ -1405,6 +1407,20 @@ void ProfileManager::DoFinalInitForServices(Profile* profile,
DataReductionProxyChromeSettingsFactory::GetForBrowserContext(profile)-> DataReductionProxyChromeSettingsFactory::GetForBrowserContext(profile)->
MaybeActivateDataReductionProxy(true); MaybeActivateDataReductionProxy(true);
auto* proto_db_provider =
content::BrowserContext::GetDefaultStoragePartition(profile)
->GetProtoDatabaseProvider();
// 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 // Create the Previews Service and begin loading opt out history from
// persistent memory. // persistent memory.
PreviewsServiceFactory::GetForProfile(profile)->Initialize( PreviewsServiceFactory::GetForProfile(profile)->Initialize(
......
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