Commit 364ac118 authored by jeremyim's avatar jeremyim Committed by Commit bot

Add DataReductionProxy IPC to determine if the Data Reduction Proxy was used.

The current mechanism is to create an instance of DataReductionProxyParams
inside of page_load_histogram, and to then check the proxy server inside of
DocumentState against DataReductionProxyParams. However, the plan is to make
the configuration dynamic, so we can no longer use DataReductionProxyParams.

BUG=452773

Review URL: https://codereview.chromium.org/966443002

Cr-Commit-Position: refs/heads/master@{#318917}
parent 0171e3cc
......@@ -232,6 +232,7 @@ static_library("browser") {
"//chrome/installer/util",
"//components/app_modal",
"//components/autofill/content/browser",
"//components/data_reduction_proxy/content/browser",
"//components/dom_distiller/content",
"//components/history/content/browser",
"//components/keyed_service/content",
......@@ -594,7 +595,6 @@ static_library("browser") {
deps += [
":jni_headers",
"//components/cdm/browser",
"//components/data_reduction_proxy/content/browser",
"//components/enhanced_bookmarks",
"//components/resources:components_resources",
"//components/web_contents_delegate_android",
......
......@@ -43,6 +43,8 @@
#include "chrome/browser/metrics/rappor/sampling.h"
#include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
#include "chrome/browser/net/chrome_net_log.h"
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h"
#include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_factory.h"
#include "chrome/browser/notifications/desktop_notification_service.h"
#include "chrome/browser/notifications/desktop_notification_service_factory.h"
#include "chrome/browser/notifications/platform_notification_service_impl.h"
......@@ -100,6 +102,7 @@
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/permission_request_id.h"
#include "components/data_reduction_proxy/content/browser/data_reduction_proxy_message_filter.h"
#include "components/dom_distiller/core/url_constants.h"
#include "components/google/core/browser/google_util.h"
#include "components/metrics/client_info.h"
......@@ -944,6 +947,13 @@ void ChromeContentBrowserClient::RenderProcessWillLaunch(
if (switches::IsEnableAccountConsistency())
host->AddFilter(new PrincipalsMessageFilter(id));
DataReductionProxyChromeSettings* data_reduction_proxy_settings =
DataReductionProxyChromeSettingsFactory::GetForBrowserContext(profile);
if (data_reduction_proxy_settings) {
host->AddFilter(new data_reduction_proxy::DataReductionProxyMessageFilter(
data_reduction_proxy_settings));
}
host->Send(new ChromeViewMsg_SetIsIncognitoProcess(
profile->IsOffTheRecord()));
......
......@@ -3003,6 +3003,7 @@
'../third_party/re2/re2.gyp:re2',
'../cc/cc.gyp:cc',
'../components/components.gyp:autofill_content_browser',
'../components/components.gyp:data_reduction_proxy_content_browser',
'../components/components.gyp:dom_distiller_content',
'../components/components.gyp:history_content_browser',
'../components/components.gyp:keyed_service_content',
......
......@@ -258,7 +258,7 @@
'../third_party/re2/re2.gyp:re2',
'../components/components.gyp:autofill_content_renderer',
'../components/components.gyp:cdm_renderer',
'../components/components.gyp:data_reduction_proxy_core_common',
'../components/components.gyp:data_reduction_proxy_content_common',
'../components/components.gyp:network_hints_renderer',
'../components/components.gyp:error_page_renderer',
'../components/components.gyp:startup_metric_utils',
......
......@@ -37,7 +37,7 @@ static_library("renderer") {
"//chrome:strings",
"//components/autofill/content/renderer",
"//components/cdm/renderer",
"//components/data_reduction_proxy/core/common",
"//components/data_reduction_proxy/content/common",
"//components/network_hints/renderer",
"//components/error_page/renderer",
"//components/password_manager/content/renderer",
......
......@@ -7,7 +7,7 @@ include_rules = [
"+components/cdm/renderer",
"+components/content_settings/core/common",
"+components/crx_file",
"+components/data_reduction_proxy/core/common",
"+components/data_reduction_proxy/content/common",
"+components/dom_distiller/core",
"+components/nacl/common",
"+components/nacl/renderer",
......
......@@ -18,7 +18,7 @@
#include "base/time/time.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/renderer/chrome_content_renderer_client.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h"
#include "components/data_reduction_proxy/content/common/data_reduction_proxy_messages.h"
#include "content/public/common/content_constants.h"
#include "content/public/renderer/document_state.h"
#include "content/public/renderer/render_thread.h"
......@@ -724,11 +724,7 @@ void DumpDeprecatedHistograms(const WebPerformance& performance,
} // namespace
PageLoadHistograms::PageLoadHistograms(content::RenderView* render_view)
: content::RenderViewObserver(render_view),
data_reduction_proxy_params_(
data_reduction_proxy::DataReductionProxyParams::kAllowed |
data_reduction_proxy::DataReductionProxyParams::kFallbackAllowed |
data_reduction_proxy::DataReductionProxyParams::kAlternativeAllowed) {
: content::RenderViewObserver(render_view) {
}
void PageLoadHistograms::Dump(WebFrame* frame) {
......@@ -750,9 +746,12 @@ void PageLoadHistograms::Dump(WebFrame* frame) {
DocumentState* document_state =
DocumentState::FromDataSource(frame->dataSource());
bool data_reduction_proxy_was_used =
data_reduction_proxy_params_.IsDataReductionProxy(
document_state->proxy_server(), NULL);
bool data_reduction_proxy_was_used = false;
if (!document_state->proxy_server().IsEmpty()) {
Send(new DataReductionProxyViewHostMsg_IsDataReductionProxy(
document_state->proxy_server(), &data_reduction_proxy_was_used));
}
bool came_from_websearch =
IsFromGoogleSearchResult(frame->document().url(),
GURL(frame->document().referrer()));
......
......@@ -6,7 +6,6 @@
#define CHROME_RENDERER_PAGE_LOAD_HISTOGRAMS_H_
#include "base/basictypes.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
#include "content/public/renderer/render_view_observer.h"
namespace content {
......@@ -46,8 +45,6 @@ class PageLoadHistograms : public content::RenderViewObserver {
void LogPageLoadTime(const content::DocumentState* load_times,
const blink::WebDataSource* ds) const;
data_reduction_proxy::DataReductionProxyParams data_reduction_proxy_params_;
DISALLOW_COPY_AND_ASSIGN(PageLoadHistograms);
};
......
......@@ -242,6 +242,7 @@ test("components_unittests") {
"//components/content_settings/core/browser:unit_tests",
"//components/content_settings/core/common:unit_tests",
"//components/crx_file:unit_tests",
"//components/data_reduction_proxy/content/browser:unit_tests",
"//components/data_reduction_proxy/core/browser:unit_tests",
"//components/data_reduction_proxy/core/common:unit_tests",
"//components/device_event_log:unit_tests",
......@@ -269,10 +270,6 @@ test("components_unittests") {
]
data_deps = [ ":components_tests_pak" ]
if (is_android) {
deps += [ "//components/data_reduction_proxy/content/browser:unit_tests" ]
}
# TODO(GYP) need this target.
#'breakpad/app/crash_keys_win_unittest.cc',
......
......@@ -490,6 +490,7 @@
['OS != "ios"', {
'sources': [
'autofill/content/renderer/renderer_save_password_progress_logger_unittest.cc',
'data_reduction_proxy/content/browser/data_reduction_proxy_message_filter_unittest.cc',
'dom_distiller/content/dom_distiller_viewer_source_unittest.cc',
'dom_distiller/content/web_contents_main_frame_observer_unittest.cc',
'error_page/renderer/net_error_helper_core_unittest.cc',
......@@ -505,6 +506,7 @@
'components.gyp:autofill_content_browser',
'components.gyp:autofill_content_renderer',
'components.gyp:autofill_content_test_support',
'components.gyp:data_reduction_proxy_content_browser',
'components.gyp:dom_distiller_content',
'components.gyp:error_page_renderer',
'components.gyp:history_content_browser',
......
......@@ -32,6 +32,39 @@
'data_reduction_proxy/content/browser/data_reduction_proxy_debug_ui_manager.h',
],
},
{
# GN version: //components/data_reduction_proxy/content/common
'target_name': 'data_reduction_proxy_content_common',
'type': 'static_library',
'dependencies': [
'../content/content.gyp:content_common',
'../ipc/ipc.gyp:ipc',
],
'include_dirs': [
'..',
],
'sources': [
'data_reduction_proxy/content/common/data_reduction_proxy_messages.cc',
'data_reduction_proxy/content/common/data_reduction_proxy_messages.h',
],
},
{
# GN version: //components/data_reduction_proxy/content/browser
'target_name': 'data_reduction_proxy_content_browser',
'type': 'static_library',
'dependencies': [
'../content/content.gyp:content_common',
'../ipc/ipc.gyp:ipc',
'data_reduction_proxy_content_common',
],
'include_dirs': [
'..',
],
'sources': [
'data_reduction_proxy/content/browser/data_reduction_proxy_message_filter.cc',
'data_reduction_proxy/content/browser/data_reduction_proxy_message_filter.h',
],
},
{
# GN version: //components/data_reduction_proxy/core/browser
'target_name': 'data_reduction_proxy_core_browser',
......@@ -181,6 +214,5 @@
},
],
},
],
}
......@@ -2,3 +2,17 @@ bengr@chromium.org
bolian@chromium.org
marq@chromium.org
sclittle@chromium.org
# Changes to IPC messages require a security review to avoid introducing
# new sandbox escapes.
per-file *_messages.*=set noparent
per-file *_messages.*=dcheng@chromium.org
per-file *_messages.*=inferno@chromium.org
per-file *_messages.*=jln@chromium.org
per-file *_messages.*=jschuh@chromium.org
per-file *_messages.*=kenrb@chromium.org
per-file *_messages.*=mkwst@chromium.org
per-file *_messages.*=nasko@chromium.org
per-file *_messages.*=palmer@chromium.org
per-file *_messages.*=tsepez@chromium.org
per-file *_messages.*=wfh@chromium.org
......@@ -4,40 +4,64 @@
static_library("browser") {
sources = [
"content_data_reduction_proxy_debug_ui_service.cc",
"content_data_reduction_proxy_debug_ui_service.h",
"data_reduction_proxy_debug_blocking_page.cc",
"data_reduction_proxy_debug_blocking_page.h",
"data_reduction_proxy_debug_resource_throttle.cc",
"data_reduction_proxy_debug_resource_throttle.h",
"data_reduction_proxy_debug_ui_manager.cc",
"data_reduction_proxy_debug_ui_manager.h",
"data_reduction_proxy_message_filter.cc",
"data_reduction_proxy_message_filter.h",
]
deps = [
"//base",
"//components/resources",
"//components/strings",
"//components/data_reduction_proxy/content/common",
"//content/public/browser",
"//skia",
"//ui/base",
"//ipc",
"//net",
]
if (is_android) {
sources += [
"content_data_reduction_proxy_debug_ui_service.cc",
"content_data_reduction_proxy_debug_ui_service.h",
"data_reduction_proxy_debug_blocking_page.cc",
"data_reduction_proxy_debug_blocking_page.h",
"data_reduction_proxy_debug_resource_throttle.cc",
"data_reduction_proxy_debug_resource_throttle.h",
"data_reduction_proxy_debug_ui_manager.cc",
"data_reduction_proxy_debug_ui_manager.h",
]
deps += [
"//components/resources",
"//components/strings",
"//skia",
"//ui/base",
]
}
}
if (is_android) {
source_set("unit_tests") {
testonly = true
sources = [
source_set("unit_tests") {
testonly = true
sources = [
"data_reduction_proxy_message_filter_unittest.cc",
]
deps = [
":browser",
"//base",
"//components/data_reduction_proxy/core/browser:test_support",
"//components/data_reduction_proxy/core/common:test_support",
"//net",
"//testing/gtest",
"//testing/gmock",
]
if (is_android) {
sources += [
"data_reduction_proxy_debug_blocking_page_unittest.cc",
"data_reduction_proxy_debug_resource_throttle_unittest.cc",
"data_reduction_proxy_debug_ui_manager_unittest.cc",
]
deps = [
":browser",
deps += [
"//skia",
"//testing/gtest",
"//testing/gmock",
"//third_party/mojo/src/mojo/public/cpp/bindings",
]
}
......
include_rules = [
"+ipc",
"+net",
]
\ No newline at end of file
// Copyright 2015 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 "components/data_reduction_proxy/content/browser/data_reduction_proxy_message_filter.h"
#include "components/data_reduction_proxy/content/common/data_reduction_proxy_messages.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_settings.h"
#include "content/public/browser/browser_thread.h"
#include "ipc/ipc_message_macros.h"
#include "net/base/host_port_pair.h"
namespace data_reduction_proxy {
DataReductionProxyMessageFilter::DataReductionProxyMessageFilter(
DataReductionProxySettings* settings)
: BrowserMessageFilter(DataReductionProxyStart),
config_(nullptr) {
DCHECK(settings);
config_ = settings->Config();
}
DataReductionProxyMessageFilter::~DataReductionProxyMessageFilter() {
}
bool DataReductionProxyMessageFilter::OnMessageReceived(
const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(DataReductionProxyMessageFilter, message)
IPC_MESSAGE_HANDLER(DataReductionProxyViewHostMsg_IsDataReductionProxy,
OnIsDataReductionProxy)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void DataReductionProxyMessageFilter::OverrideThreadForMessage(
const IPC::Message& message, content::BrowserThread::ID* thread) {
if (message.type() ==
DataReductionProxyViewHostMsg_IsDataReductionProxy::ID) {
*thread = content::BrowserThread::IO;
}
}
void DataReductionProxyMessageFilter::OnIsDataReductionProxy(
const net::HostPortPair& proxy_server, bool* response) {
if (config_)
*response = config_->IsDataReductionProxy(proxy_server, nullptr);
else
*response = false;
}
} // namespace data_reduction_proxy
// Copyright 2015 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 COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_BROWSER_DATA_REDUCTION_PROXY_MESSAGE_FILTER_H_
#define COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_BROWSER_DATA_REDUCTION_PROXY_MESSAGE_FILTER_H_
#include "base/macros.h"
#include "content/public/browser/browser_message_filter.h"
namespace net {
class HostPortPair;
}
namespace data_reduction_proxy {
class DataReductionProxyConfig;
class DataReductionProxySettings;
// An IPC listener to handle DataReductionProxy IPC messages from the renderer.
class DataReductionProxyMessageFilter
: public content::BrowserMessageFilter {
public:
DataReductionProxyMessageFilter(DataReductionProxySettings* settings);
// Sets |response| to true if the |proxy_server| corresponds to a Data
// Reduction Proxy.
void OnIsDataReductionProxy(const net::HostPortPair& proxy_server,
bool* response);
private:
~DataReductionProxyMessageFilter() override;
// BrowserMessageFilter implementation.
bool OnMessageReceived(const IPC::Message& message) override;
void OverrideThreadForMessage(const IPC::Message& message,
content::BrowserThread::ID* thread) override;
// Must outlive |this|.
DataReductionProxyConfig* config_;
DISALLOW_COPY_AND_ASSIGN(DataReductionProxyMessageFilter);
};
} // namespace data_reduction_proxy
#endif // COMPONENTS_DATA_REDUCTION_PROXY_CONTENT_BROWSER_DATA_REDUCTION_PROXY_MESSAGE_FILTER_H_
// Copyright 2015 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 "components/data_reduction_proxy/content/browser/data_reduction_proxy_message_filter.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h"
#include "net/base/host_port_pair.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace data_reduction_proxy {
class DataReductionProxyMessageFilterTest : public testing::Test {
public:
void SetUp() override {
test_context_ =
DataReductionProxyTestContext::Builder()
.WithParamsFlags(DataReductionProxyParams::kAllowed)
.WithParamsDefinitions(TestDataReductionProxyParams::HAS_EVERYTHING)
.WithMockConfig()
.Build();
message_filter_ = new DataReductionProxyMessageFilter(
test_context_->settings());
}
protected:
DataReductionProxyMessageFilter* message_filter() const {
return message_filter_.get();
}
MockDataReductionProxyConfig* config() const {
return test_context_->mock_config();
}
private:
scoped_ptr<DataReductionProxyTestContext> test_context_;
scoped_refptr<DataReductionProxyMessageFilter> message_filter_;
};
TEST_F(DataReductionProxyMessageFilterTest, TestOnIsDataReductionProxy) {
net::HostPortPair proxy_server =
net::HostPortPair::FromString("www.google.com:443");
bool is_data_reduction_proxy = false;
EXPECT_CALL(*config(), IsDataReductionProxy(testing::_, nullptr))
.Times(1)
.WillOnce(testing::Return(true));
message_filter()->OnIsDataReductionProxy(proxy_server,
&is_data_reduction_proxy);
EXPECT_TRUE(is_data_reduction_proxy);
EXPECT_CALL(*config(), IsDataReductionProxy(testing::_, nullptr))
.Times(1)
.WillOnce(testing::Return(false));
message_filter()->OnIsDataReductionProxy(proxy_server,
&is_data_reduction_proxy);
EXPECT_FALSE(is_data_reduction_proxy);
}
} // namespace data_reduction_proxy
# Copyright 2015 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.
static_library("common") {
sources = [
"data_reduction_proxy_messages.cc",
"data_reduction_proxy_messages.h",
]
deps = [
"//content/public/common",
"//ipc",
"//net",
]
}
include_rules = [
"+content/public/common",
"+ipc",
]
// Copyright (c) 2015 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.
// Get basic type definitions.
#define IPC_MESSAGE_IMPL
#include "components/data_reduction_proxy/content/common/data_reduction_proxy_messages.h"
// Generate constructors.
#include "ipc/struct_constructor_macros.h"
#include "components/data_reduction_proxy/content/common/data_reduction_proxy_messages.h"
// Generate destructors.
#include "ipc/struct_destructor_macros.h"
#include "components/data_reduction_proxy/content/common/data_reduction_proxy_messages.h"
// Generate param traits write methods.
#include "ipc/param_traits_write_macros.h"
namespace IPC {
#include "components/data_reduction_proxy/content/common/data_reduction_proxy_messages.h"
} // namespace IPC
// Generate param traits read methods.
#include "ipc/param_traits_read_macros.h"
namespace IPC {
#include "components/data_reduction_proxy/content/common/data_reduction_proxy_messages.h"
} // namespace IPC
// Generate param traits log methods.
#include "ipc/param_traits_log_macros.h"
namespace IPC {
#include "components/data_reduction_proxy/content/common/data_reduction_proxy_messages.h"
} // namespace IPC
// Copyright 2015 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.
// Multiply-included file, no traditional include guard.
#include "content/public/common/common_param_traits.h"
#include "ipc/ipc_message_macros.h"
#include "net/base/host_port_pair.h"
#define IPC_MESSAGE_START DataReductionProxyStart
IPC_SYNC_MESSAGE_CONTROL1_1(
DataReductionProxyViewHostMsg_IsDataReductionProxy,
net::HostPortPair /* proxy server */,
bool /* true iff the proxy server is a Data Reduction Proxy */)
......@@ -169,6 +169,12 @@ class DataReductionProxySettings {
return data_reduction_proxy_service_.get();
}
// Returns the |DataReductionProxyConfig| being used. May be null if
// InitDataReductionProxySettings has not been called.
DataReductionProxyConfig* Config() const {
return config_;
}
// Permits changing the underlying |DataReductionProxyConfig| without running
// the initialization loop.
void ResetConfigForTest(DataReductionProxyConfig* config) {
......@@ -176,12 +182,6 @@ class DataReductionProxySettings {
}
protected:
// Returns the |DataReductionProxyConfig| being used. May be null if
// InitDataReductionProxySettings has not been called.
DataReductionProxyConfig* Config() const {
return config_;
}
void InitPrefMembers();
void UpdateConfigValues();
......
......@@ -161,8 +161,8 @@ class CONTENT_EXPORT DocumentState
was_fetched_via_proxy_ = value;
}
net::HostPortPair proxy_server() const { return proxy_server_; }
void set_proxy_server(net::HostPortPair proxy_server) {
const net::HostPortPair& proxy_server() const { return proxy_server_; }
void set_proxy_server(const net::HostPortPair& proxy_server) {
proxy_server_ = proxy_server;
}
......
......@@ -118,6 +118,7 @@ enum IPCMessageStart {
// Note: CastCryptoMsgStart reserved for Chromecast internal code.
// Contact gunsch@ before changing/removing.
CastCryptoMsgStart,
DataReductionProxyStart,
LastIPCMsgStart // Must come last.
};
......
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