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
......@@ -1340,17 +1340,6 @@ IN_PROC_BROWSER_TEST_P(PreviewsLitePageRedirectServerBrowserTest,
VerifyPreviewLoaded();
}
{
// Verify the preview is not triggered when the server responds with 403.
base::HistogramTester histogram_tester;
ui_test_utils::NavigateToURL(browser(), HttpsLitePageURL(kAuthFailure));
VerifyPreviewNotLoaded();
ClearDeciderState();
histogram_tester.ExpectBucketCount(
"Previews.ServerLitePage.ServerResponse",
previews::LitePageRedirectServerResponse::kAuthFailure, 1);
}
{
// Verify the preview is not triggered when the server responds with 503.
base::HistogramTester histogram_tester;
......@@ -1363,6 +1352,27 @@ IN_PROC_BROWSER_TEST_P(PreviewsLitePageRedirectServerBrowserTest,
}
}
IN_PROC_BROWSER_TEST_P(
PreviewsLitePageRedirectServerBrowserTest,
DISABLE_ON_WIN_MAC_CHROMESOS(LitePagePreviewsAuthFailure)) {
// Verify the preview is not triggered when the server responds with 403.
base::HistogramTester histogram_tester;
ui_test_utils::NavigateToURL(browser(), HttpsLitePageURL(kAuthFailure));
VerifyPreviewNotLoaded();
ClearDeciderState();
histogram_tester.ExpectBucketCount(
"Previews.ServerLitePage.ServerResponse",
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,
DISABLE_ON_WIN_MAC_CHROMESOS(LitePagePreviewsLoadshed)) {
PreviewsService* previews_service =
......
......@@ -20,11 +20,15 @@
#include "base/task/task_traits.h"
#include "base/threading/thread_task_runner_handle.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_url_loader_interceptor.h"
#include "chrome/browser/previews/previews_service.h"
#include "chrome/browser/previews/previews_service_factory.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/previews/core/previews_experiments.h"
#include "components/previews/core/previews_lite_page_redirect.h"
......@@ -114,6 +118,35 @@ void ReportDataSavings(int64_t network_bytes,
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 net::NetworkTrafficAnnotationTag kPreviewsTrafficAnnotation =
......@@ -271,6 +304,11 @@ void PreviewsLitePageRedirectServingURLLoader::OnReceiveResponse(
UMA_HISTOGRAM_ENUMERATION(
"Previews.ServerLitePage.ServerResponse",
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 {
UMA_HISTOGRAM_ENUMERATION(
"Previews.ServerLitePage.ServerResponse",
......
......@@ -243,6 +243,22 @@ void DataReductionProxyConfigServiceClient::SetEnabled(bool 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() {
DCHECK(thread_checker_.CalledOnValidThread());
if (!enabled_)
......
......@@ -29,7 +29,7 @@ class HttpRequestHeaders;
class HttpResponseHeaders;
struct LoadTimingInfo;
class ProxyServer;
}
} // namespace net
namespace network {
class SharedURLLoaderFactory;
......@@ -106,6 +106,10 @@ class DataReductionProxyConfigServiceClient
// operation takes place asynchronously.
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
// current Data Reduction Proxy configuration. If a remote configuration has
// 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