Commit fd3b3753 authored by Robert Ogden's avatar Robert Ogden Committed by Commit Bot

Invalidate DRP config on Previews auth failure

Bug: 1011457
Change-Id: I39016ea24cd296b3ed0ed95a2556e7941fdb9390
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1845937Reviewed-by: default avatarTarun Bansal <tbansal@chromium.org>
Commit-Queue: Robert Ogden <robertogden@chromium.org>
Cr-Commit-Position: refs/heads/master@{#703788}
parent a7fc3445
...@@ -1341,26 +1341,36 @@ IN_PROC_BROWSER_TEST_P(PreviewsLitePageRedirectServerBrowserTest, ...@@ -1341,26 +1341,36 @@ IN_PROC_BROWSER_TEST_P(PreviewsLitePageRedirectServerBrowserTest,
} }
{ {
// Verify the preview is not triggered when the server responds with 403. // Verify the preview is not triggered when the server responds with 503.
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
ui_test_utils::NavigateToURL(browser(), HttpsLitePageURL(kAuthFailure)); ui_test_utils::NavigateToURL(browser(), HttpsLitePageURL(kLoadshed));
VerifyPreviewNotLoaded(); VerifyPreviewNotLoaded();
ClearDeciderState(); ClearDeciderState();
histogram_tester.ExpectBucketCount( histogram_tester.ExpectBucketCount(
"Previews.ServerLitePage.ServerResponse", "Previews.ServerLitePage.ServerResponse",
previews::LitePageRedirectServerResponse::kAuthFailure, 1); previews::LitePageRedirectServerResponse::kServiceUnavailable, 1);
} }
}
{ IN_PROC_BROWSER_TEST_P(
// Verify the preview is not triggered when the server responds with 503. PreviewsLitePageRedirectServerBrowserTest,
DISABLE_ON_WIN_MAC_CHROMESOS(LitePagePreviewsAuthFailure)) {
// Verify the preview is not triggered when the server responds with 403.
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
ui_test_utils::NavigateToURL(browser(), HttpsLitePageURL(kLoadshed)); ui_test_utils::NavigateToURL(browser(), HttpsLitePageURL(kAuthFailure));
VerifyPreviewNotLoaded(); VerifyPreviewNotLoaded();
ClearDeciderState(); ClearDeciderState();
histogram_tester.ExpectBucketCount( histogram_tester.ExpectBucketCount(
"Previews.ServerLitePage.ServerResponse", "Previews.ServerLitePage.ServerResponse",
previews::LitePageRedirectServerResponse::kServiceUnavailable, 1); previews::LitePageRedirectServerResponse::kAuthFailure, 1);
}
// DRP config is invalid, a subsequent preview page load should fail.
ui_test_utils::NavigateToURL(browser(), HttpsLitePageURL(kSuccess));
VerifyPreviewNotLoaded();
histogram_tester.ExpectBucketCount(
"Previews.ServerLitePage.IneligibleReasons",
previews::LitePageRedirectIneligibleReason::kInvalidProxyHeaders, 1);
} }
IN_PROC_BROWSER_TEST_P(PreviewsLitePageRedirectServerBrowserTest, IN_PROC_BROWSER_TEST_P(PreviewsLitePageRedirectServerBrowserTest,
......
...@@ -20,11 +20,15 @@ ...@@ -20,11 +20,15 @@
#include "base/task/task_traits.h" #include "base/task/task_traits.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings.h"
#include "chrome/browser/data_reduction_proxy/data_reduction_proxy_chrome_settings_factory.h"
#include "chrome/browser/previews/previews_lite_page_redirect_decider.h" #include "chrome/browser/previews/previews_lite_page_redirect_decider.h"
#include "chrome/browser/previews/previews_lite_page_redirect_url_loader_interceptor.h" #include "chrome/browser/previews/previews_lite_page_redirect_url_loader_interceptor.h"
#include "chrome/browser/previews/previews_service.h" #include "chrome/browser/previews/previews_service.h"
#include "chrome/browser/previews/previews_service_factory.h" #include "chrome/browser/previews/previews_service_factory.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config_service_client.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_service.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h"
#include "components/previews/core/previews_experiments.h" #include "components/previews/core/previews_experiments.h"
#include "components/previews/core/previews_lite_page_redirect.h" #include "components/previews/core/previews_lite_page_redirect.h"
...@@ -114,6 +118,35 @@ void ReportDataSavings(int64_t network_bytes, ...@@ -114,6 +118,35 @@ void ReportDataSavings(int64_t network_bytes,
original_bytes, std::move(host), frame_tree_node_id)); original_bytes, std::move(host), frame_tree_node_id));
} }
void InvalidateDRPConfigOnUIThread(int frame_tree_node_id) {
auto* web_contents =
content::WebContents::FromFrameTreeNodeId(frame_tree_node_id);
// If the WebContents has been closed this may be null.
if (!web_contents)
return;
DataReductionProxyChromeSettings* drp_settings =
DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
web_contents->GetBrowserContext());
if (!drp_settings)
return;
if (!drp_settings->data_reduction_proxy_service())
return;
if (!drp_settings->data_reduction_proxy_service()->config_client())
return;
drp_settings->data_reduction_proxy_service()
->config_client()
->InvalidateAndRetrieveNewConfig();
}
void InvalidateDRPConfig(int frame_tree_node_id) {
base::PostTask(
FROM_HERE, {content::BrowserThread::UI, base::TaskPriority::USER_VISIBLE},
base::BindOnce(&InvalidateDRPConfigOnUIThread, frame_tree_node_id));
}
const base::TimeDelta kBlacklistDuration = base::TimeDelta::FromDays(30); const base::TimeDelta kBlacklistDuration = base::TimeDelta::FromDays(30);
const net::NetworkTrafficAnnotationTag kPreviewsTrafficAnnotation = const net::NetworkTrafficAnnotationTag kPreviewsTrafficAnnotation =
...@@ -271,6 +304,11 @@ void PreviewsLitePageRedirectServingURLLoader::OnReceiveResponse( ...@@ -271,6 +304,11 @@ void PreviewsLitePageRedirectServingURLLoader::OnReceiveResponse(
UMA_HISTOGRAM_ENUMERATION( UMA_HISTOGRAM_ENUMERATION(
"Previews.ServerLitePage.ServerResponse", "Previews.ServerLitePage.ServerResponse",
previews::LitePageRedirectServerResponse::kAuthFailure); previews::LitePageRedirectServerResponse::kAuthFailure);
// This should disable future preview attempts until a new DRP Session Key
// is retrieved since the PreviewsLitePageRedirectDecider checks for valid
// session keys before triggering the preview.
InvalidateDRPConfig(frame_tree_node_id_);
} else { } else {
UMA_HISTOGRAM_ENUMERATION( UMA_HISTOGRAM_ENUMERATION(
"Previews.ServerLitePage.ServerResponse", "Previews.ServerLitePage.ServerResponse",
......
...@@ -243,6 +243,22 @@ void DataReductionProxyConfigServiceClient::SetEnabled(bool enabled) { ...@@ -243,6 +243,22 @@ void DataReductionProxyConfigServiceClient::SetEnabled(bool enabled) {
enabled_ = enabled; enabled_ = enabled;
} }
void DataReductionProxyConfigServiceClient::InvalidateAndRetrieveNewConfig() {
DCHECK(thread_checker_.CalledOnValidThread());
InvalidateConfig();
DCHECK(config_->GetProxiesForHttp().empty());
if (fetch_in_progress_) {
// If a client config fetch is already in progress, then do not start
// another fetch since starting a new fetch will cause extra data
// usage, and also cancel the ongoing fetch.
return;
}
RetrieveConfig();
}
void DataReductionProxyConfigServiceClient::RetrieveConfig() { void DataReductionProxyConfigServiceClient::RetrieveConfig() {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
if (!enabled_) if (!enabled_)
......
...@@ -29,7 +29,7 @@ class HttpRequestHeaders; ...@@ -29,7 +29,7 @@ class HttpRequestHeaders;
class HttpResponseHeaders; class HttpResponseHeaders;
struct LoadTimingInfo; struct LoadTimingInfo;
class ProxyServer; class ProxyServer;
} } // namespace net
namespace network { namespace network {
class SharedURLLoaderFactory; class SharedURLLoaderFactory;
...@@ -106,6 +106,10 @@ class DataReductionProxyConfigServiceClient ...@@ -106,6 +106,10 @@ class DataReductionProxyConfigServiceClient
// operation takes place asynchronously. // operation takes place asynchronously.
void RetrieveConfig(); void RetrieveConfig();
// Invalidates the current Data Reduction Proxy configuration and requests the
// retrieval of the Data Reduction Proxy configuration
void InvalidateAndRetrieveNewConfig();
// Takes a serialized Data Reduction Proxy configuration and sets it as the // Takes a serialized Data Reduction Proxy configuration and sets it as the
// current Data Reduction Proxy configuration. If a remote configuration has // current Data Reduction Proxy configuration. If a remote configuration has
// already been retrieved, the remote configuration takes precedence. // already been retrieved, the remote configuration takes precedence.
......
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