Commit 3ce0ca47 authored by Tarun Bansal's avatar Tarun Bansal Committed by Commit Bot

Fix client hints crash in incognito profile

UINetworkQualityEstimatorService is not created by default in
incognito profile. This results in crashes in incogniro profile
when network quality metrics are queried by the client hints code.

This CL enables creation of UINetworkQualityEstimatorService
in incognito mode.

Bug: 855781
Change-Id: Ieafd5a853749dc00c2c8cd3c63c4ef7acd5ba215
Reviewed-on: https://chromium-review.googlesource.com/1114091
Commit-Queue: Tarun Bansal <tbansal@chromium.org>
Reviewed-by: default avatarRyan Sturm <ryansturm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570212}
parent 03f09dec
...@@ -1128,3 +1128,58 @@ IN_PROC_BROWSER_TEST_F(ClientHintsBrowserTest, ClientHintsHttpsIncognito) { ...@@ -1128,3 +1128,58 @@ IN_PROC_BROWSER_TEST_F(ClientHintsBrowserTest, ClientHintsHttpsIncognito) {
CloseBrowserSynchronously(incognito); CloseBrowserSynchronously(incognito);
} }
} }
// Verify that client hints are sent in the incognito profiles, and server
// client hint opt-ins are honored within the incognito profile.
IN_PROC_BROWSER_TEST_F(ClientHintsBrowserTest,
ClientHintsLifetimeFollowedByNoClientHintIncognito) {
base::HistogramTester histogram_tester;
Browser* incognito = CreateIncognitoBrowser();
ContentSettingsForOneType host_settings;
HostContentSettingsMapFactory::GetForProfile(incognito->profile())
->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_CLIENT_HINTS, std::string(),
&host_settings);
EXPECT_EQ(0u, host_settings.size());
// Fetching accept_ch_with_lifetime_url() should persist the request for
// client hints.
ui_test_utils::NavigateToURL(incognito, accept_ch_with_lifetime_url());
histogram_tester.ExpectUniqueSample("ClientHints.UpdateEventCount", 1, 1);
content::FetchHistogramsFromChildProcesses();
SubprocessMetricsProvider::MergeHistogramDeltasForTesting();
histogram_tester.ExpectUniqueSample("ClientHints.UpdateSize", 6, 1);
// accept_ch_with_lifetime_url() sets client hints persist duration to 3600
// seconds.
histogram_tester.ExpectUniqueSample("ClientHints.PersistDuration",
3600 * 1000, 1);
base::RunLoop().RunUntilIdle();
// Clients hints preferences for one origin should be persisted.
HostContentSettingsMapFactory::GetForProfile(incognito->profile())
->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_CLIENT_HINTS, std::string(),
&host_settings);
EXPECT_EQ(1u, host_settings.size());
SetClientHintExpectationsOnMainFrame(true);
SetClientHintExpectationsOnSubresources(true);
ui_test_utils::NavigateToURL(incognito,
without_accept_ch_without_lifetime_url());
// Six client hints are attached to the image request, and six to the main
// frame request.
EXPECT_EQ(12u, count_client_hints_headers_seen());
// Navigate using regular profile. Client hints should not be send.
SetClientHintExpectationsOnMainFrame(false);
SetClientHintExpectationsOnSubresources(false);
ui_test_utils::NavigateToURL(browser(),
without_accept_ch_without_lifetime_url());
// Six client hints are attached to the image request, and six to the main
// frame request.
EXPECT_EQ(12u, count_client_hints_headers_seen());
}
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/net/nqe/ui_network_quality_estimator_service_factory.h" #include "chrome/browser/net/nqe/ui_network_quality_estimator_service_factory.h"
#include "chrome/browser/net/nqe/ui_network_quality_estimator_service.h" #include "chrome/browser/net/nqe/ui_network_quality_estimator_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 "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
...@@ -43,3 +44,9 @@ KeyedService* UINetworkQualityEstimatorServiceFactory::BuildServiceInstanceFor( ...@@ -43,3 +44,9 @@ KeyedService* UINetworkQualityEstimatorServiceFactory::BuildServiceInstanceFor(
return new UINetworkQualityEstimatorService( return new UINetworkQualityEstimatorService(
Profile::FromBrowserContext(context)); Profile::FromBrowserContext(context));
} }
content::BrowserContext*
UINetworkQualityEstimatorServiceFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextOwnInstanceInIncognito(context);
}
...@@ -33,6 +33,9 @@ class UINetworkQualityEstimatorServiceFactory ...@@ -33,6 +33,9 @@ class UINetworkQualityEstimatorServiceFactory
// 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 ServiceIsCreatedWithBrowserContext() const override;
}; };
......
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