diff options
author | pmeenan <pmeenan@chromium.org> | 2015-01-30 13:59:59 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-30 22:00:53 +0000 |
commit | ed4b6f8b7392eb64fc664aa49f2627ecb5fdc073 (patch) | |
tree | c41b78ef68d5d37d5ec28ecaaa4037607524060d /components | |
parent | 7a47c4214a06aa1778ced28dc6c57658326bbf3d (diff) | |
download | chromium_src-ed4b6f8b7392eb64fc664aa49f2627ecb5fdc073.zip chromium_src-ed4b6f8b7392eb64fc664aa49f2627ecb5fdc073.tar.gz chromium_src-ed4b6f8b7392eb64fc664aa49f2627ecb5fdc073.tar.bz2 |
Renamed the dns_prefetch component to network_predictor
This is in preparation for adding preconnect support which goes through
the same underlying plumbing. dns_prefetch was too restrictive of a
component name and was only exposing the single method.
There are no functionality changes in this CL, just the rename (the namespace was also renamed)
BUG=450682
Review URL: https://codereview.chromium.org/848303005
Cr-Commit-Position: refs/heads/master@{#314001}
Diffstat (limited to 'components')
-rw-r--r-- | components/OWNERS | 4 | ||||
-rw-r--r-- | components/components.gyp | 2 | ||||
-rw-r--r-- | components/components_tests.gyp | 8 | ||||
-rw-r--r-- | components/dns_prefetch.gypi | 70 | ||||
-rw-r--r-- | components/dns_prefetch/common/BUILD.gn | 19 | ||||
-rw-r--r-- | components/dns_prefetch/common/prefetch_messages.cc | 42 | ||||
-rw-r--r-- | components/network_hints.gypi | 70 | ||||
-rw-r--r-- | components/network_hints/OWNERS (renamed from components/dns_prefetch/OWNERS) | 0 | ||||
-rw-r--r-- | components/network_hints/browser/BUILD.gn (renamed from components/dns_prefetch/browser/BUILD.gn) | 6 | ||||
-rw-r--r-- | components/network_hints/browser/DEPS (renamed from components/dns_prefetch/browser/DEPS) | 0 | ||||
-rw-r--r-- | components/network_hints/browser/network_hints_message_filter.cc (renamed from components/dns_prefetch/browser/net_message_filter.cc) | 22 | ||||
-rw-r--r-- | components/network_hints/browser/network_hints_message_filter.h (renamed from components/dns_prefetch/browser/net_message_filter.h) | 18 | ||||
-rw-r--r-- | components/network_hints/common/BUILD.gn | 19 | ||||
-rw-r--r-- | components/network_hints/common/DEPS (renamed from components/dns_prefetch/common/DEPS) | 0 | ||||
-rw-r--r-- | components/network_hints/common/network_hints_common.cc (renamed from components/dns_prefetch/common/prefetch_common.cc) | 6 | ||||
-rw-r--r-- | components/network_hints/common/network_hints_common.h (renamed from components/dns_prefetch/common/prefetch_common.h) | 10 | ||||
-rw-r--r-- | components/network_hints/common/network_hints_message_generator.cc (renamed from components/dns_prefetch/common/prefetch_message_generator.cc) | 12 | ||||
-rw-r--r-- | components/network_hints/common/network_hints_message_generator.h (renamed from components/dns_prefetch/common/prefetch_message_generator.h) | 2 | ||||
-rw-r--r-- | components/network_hints/common/network_hints_messages.cc | 42 | ||||
-rw-r--r-- | components/network_hints/common/network_hints_messages.h (renamed from components/dns_prefetch/common/prefetch_messages.h) | 14 | ||||
-rw-r--r-- | components/network_hints/renderer/BUILD.gn (renamed from components/dns_prefetch/renderer/BUILD.gn) | 12 | ||||
-rw-r--r-- | components/network_hints/renderer/DEPS (renamed from components/dns_prefetch/renderer/DEPS) | 2 | ||||
-rw-r--r-- | components/network_hints/renderer/dns_prefetch_queue.cc (renamed from components/dns_prefetch/renderer/predictor_queue.cc) | 6 | ||||
-rw-r--r-- | components/network_hints/renderer/dns_prefetch_queue.h (renamed from components/dns_prefetch/renderer/predictor_queue.h) | 12 | ||||
-rw-r--r-- | components/network_hints/renderer/dns_prefetch_queue_unittest.cc (renamed from components/dns_prefetch/renderer/predictor_queue_unittest.cc) | 6 | ||||
-rw-r--r-- | components/network_hints/renderer/prescient_networking_dispatcher.cc (renamed from components/dns_prefetch/renderer/prescient_networking_dispatcher.cc) | 8 | ||||
-rw-r--r-- | components/network_hints/renderer/prescient_networking_dispatcher.h (renamed from components/dns_prefetch/renderer/prescient_networking_dispatcher.h) | 16 | ||||
-rw-r--r-- | components/network_hints/renderer/renderer_dns_prefetch.cc (renamed from components/dns_prefetch/renderer/renderer_net_predictor.cc) | 34 | ||||
-rw-r--r-- | components/network_hints/renderer/renderer_dns_prefetch.h (renamed from components/dns_prefetch/renderer/renderer_net_predictor.h) | 28 | ||||
-rw-r--r-- | components/network_hints/renderer/renderer_dns_prefetch_unittest.cc (renamed from components/dns_prefetch/renderer/renderer_net_predictor_unittest.cc) | 12 |
30 files changed, 255 insertions, 247 deletions
diff --git a/components/OWNERS b/components/OWNERS index 73dd507..e40e825 100644 --- a/components/OWNERS +++ b/components/OWNERS @@ -47,8 +47,8 @@ per-file data_reduction_proxy*=bolian@chromium.org per-file devtools_bridge.gyp=mnaganov@chromium.org per-file devtools_bridge.gyp=serya@chromium.org -per-file dns_prefetch*=jar@chromium.org -per-file dns_prefetch*=ttuttle@chromium.org +per-file network_hints*=jar@chromium.org +per-file network_hints*=ttuttle@chromium.org per-file dom_distiller*=bengr@chromium.org per-file dom_distiller*=cjhopman@chromium.org diff --git a/components/components.gyp b/components/components.gyp index 0972d45..1eb533c 100644 --- a/components/components.gyp +++ b/components/components.gyp @@ -21,7 +21,7 @@ 'cronet.gypi', 'crx_file.gypi', 'data_reduction_proxy.gypi', - 'dns_prefetch.gypi', + 'network_hints.gypi', 'dom_distiller.gypi', 'domain_reliability.gypi', 'enhanced_bookmarks.gypi', diff --git a/components/components_tests.gyp b/components/components_tests.gyp index 5088ba3..3809893 100644 --- a/components/components_tests.gyp +++ b/components/components_tests.gyp @@ -471,8 +471,8 @@ ['OS != "ios"', { 'sources': [ 'autofill/content/renderer/renderer_save_password_progress_logger_unittest.cc', - 'dns_prefetch/renderer/predictor_queue_unittest.cc', - 'dns_prefetch/renderer/renderer_net_predictor_unittest.cc', + 'network_hints/renderer/dns_prefetch_queue_unittest.cc', + 'network_hints/renderer/renderer_dns_prefetch_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', @@ -485,12 +485,12 @@ 'components.gyp:autofill_content_browser', 'components.gyp:autofill_content_renderer', 'components.gyp:autofill_content_test_support', - 'components.gyp:dns_prefetch_renderer', 'components.gyp:dom_distiller_content', 'components.gyp:error_page_renderer', 'components.gyp:history_content_browser', 'components.gyp:keyed_service_content', 'components.gyp:navigation_interception', + 'components.gyp:network_hints_renderer', 'components.gyp:password_manager_content_browser', 'components.gyp:password_manager_content_common', 'components.gyp:power', @@ -1047,7 +1047,7 @@ }], ['OS=="mac"', { 'dependencies': [ - '../content/content_shell_and_tests.gyp:content_shell', # Needed for Content Shell.app's Helper. + '../content/content_shell_and_tests.gyp:content_shell', # Needed for Content Shell.app's Helper. ], }], ], diff --git a/components/dns_prefetch.gypi b/components/dns_prefetch.gypi deleted file mode 100644 index 3328faa..0000000 --- a/components/dns_prefetch.gypi +++ /dev/null @@ -1,70 +0,0 @@ -# Copyright 2014 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. - -{ - 'targets': [ - { - # GN version: //components/dns_prefetch/common - 'target_name': 'dns_prefetch_common', - 'type': 'static_library', - 'include_dirs': [ - '..', - ], - 'dependencies': [ - '../base/base.gyp:base', - ], - 'sources': [ - 'dns_prefetch/common/prefetch_common.cc', - 'dns_prefetch/common/prefetch_common.h', - 'dns_prefetch/common/prefetch_message_generator.cc', - 'dns_prefetch/common/prefetch_message_generator.h', - 'dns_prefetch/common/prefetch_messages.cc', - 'dns_prefetch/common/prefetch_messages.h', - ], - }, - { - # GN version: //components/dns_prefetch/browser - 'target_name': 'dns_prefetch_browser', - 'type': 'static_library', - 'include_dirs': [ - '..', - ], - 'dependencies': [ - '../content/content.gyp:content_browser', - '../net/net.gyp:net', - ], - 'sources': [ - 'dns_prefetch/browser/net_message_filter.cc', - 'dns_prefetch/browser/net_message_filter.h', - ], - }, - ], - 'conditions': [ - ['OS!="ios"', { - 'targets': [ - { - # GN version: //components/dns_prefetch/renderer - 'target_name': 'dns_prefetch_renderer', - 'type': 'static_library', - 'include_dirs': [ - '..', - ], - 'dependencies': [ - 'dns_prefetch_common', - '../content/content.gyp:content_renderer', - '../third_party/WebKit/public/blink.gyp:blink', - ], - 'sources': [ - 'dns_prefetch/renderer/predictor_queue.cc', - 'dns_prefetch/renderer/predictor_queue.h', - 'dns_prefetch/renderer/prescient_networking_dispatcher.cc', - 'dns_prefetch/renderer/prescient_networking_dispatcher.h', - 'dns_prefetch/renderer/renderer_net_predictor.cc', - 'dns_prefetch/renderer/renderer_net_predictor.h', - ], - }, - ], - }], - ], -} diff --git a/components/dns_prefetch/common/BUILD.gn b/components/dns_prefetch/common/BUILD.gn deleted file mode 100644 index 82a02ac..0000000 --- a/components/dns_prefetch/common/BUILD.gn +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright 2014 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. - -# GYP version: components/dns_prefetch.gypi:predictor -source_set("common") { - sources = [ - "prefetch_common.cc", - "prefetch_common.h", - "prefetch_message_generator.cc", - "prefetch_message_generator.h", - "prefetch_messages.cc", - "prefetch_messages.h", - ] - - deps = [ - "//base", - ] -} diff --git a/components/dns_prefetch/common/prefetch_messages.cc b/components/dns_prefetch/common/prefetch_messages.cc deleted file mode 100644 index 315ed92..0000000 --- a/components/dns_prefetch/common/prefetch_messages.cc +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2014 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/dns_prefetch/common/prefetch_messages.h" - -#include "base/strings/string_number_conversions.h" -#include "components/dns_prefetch/common/prefetch_common.h" - -namespace IPC { - -void ParamTraits<dns_prefetch::LookupRequest>::Write( - Message* m, const dns_prefetch::LookupRequest& request) { - IPC::WriteParam(m, request.hostname_list); -} - -bool ParamTraits<dns_prefetch::LookupRequest>::Read( - const Message* m, - PickleIterator* iter, - dns_prefetch::LookupRequest* request) { - // Verify the hostname limits after deserialization success. - if (IPC::ReadParam(m, iter, &request->hostname_list)) { - dns_prefetch::NameList& hostnames = request->hostname_list; - if (hostnames.size() > dns_prefetch::kMaxDnsHostnamesPerRequest) - return false; - - for (const auto& hostname : hostnames) { - if (hostname.length() > dns_prefetch::kMaxDnsHostnameLength) - return false; - } - } - return true; -} - -void ParamTraits<dns_prefetch::LookupRequest>::Log( - const dns_prefetch::LookupRequest& p, std::string* l) { - l->append("<dns_prefetch::LookupRequest: "); - l->append(base::SizeTToString(p.hostname_list.size())); - l->append(" hostnames>"); -} - -} // namespace IPC diff --git a/components/network_hints.gypi b/components/network_hints.gypi new file mode 100644 index 0000000..b6944f1 --- /dev/null +++ b/components/network_hints.gypi @@ -0,0 +1,70 @@ +# Copyright 2014 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. + +{ + 'targets': [ + { + # GN version: //components/network_hints/common + 'target_name': 'network_hints_common', + 'type': 'static_library', + 'include_dirs': [ + '..', + ], + 'dependencies': [ + '../base/base.gyp:base', + ], + 'sources': [ + 'network_hints/common/network_hints_common.cc', + 'network_hints/common/network_hints_common.h', + 'network_hints/common/network_hints_message_generator.cc', + 'network_hints/common/network_hints_message_generator.h', + 'network_hints/common/network_hints_messages.cc', + 'network_hints/common/network_hints_messages.h', + ], + }, + { + # GN version: //components/network_hints/browser + 'target_name': 'network_hints_browser', + 'type': 'static_library', + 'include_dirs': [ + '..', + ], + 'dependencies': [ + '../content/content.gyp:content_browser', + '../net/net.gyp:net', + ], + 'sources': [ + 'network_hints/browser/network_hints_message_filter.cc', + 'network_hints/browser/network_hints_message_filter.h', + ], + }, + ], + 'conditions': [ + ['OS!="ios"', { + 'targets': [ + { + # GN version: //components/network_hints/renderer + 'target_name': 'network_hints_renderer', + 'type': 'static_library', + 'include_dirs': [ + '..', + ], + 'dependencies': [ + 'network_hints_common', + '../content/content.gyp:content_renderer', + '../third_party/WebKit/public/blink.gyp:blink', + ], + 'sources': [ + 'network_hints/renderer/dns_prefetch_queue.cc', + 'network_hints/renderer/dns_prefetch_queue.h', + 'network_hints/renderer/prescient_networking_dispatcher.cc', + 'network_hints/renderer/prescient_networking_dispatcher.h', + 'network_hints/renderer/renderer_dns_prefetch.cc', + 'network_hints/renderer/renderer_dns_prefetch.h', + ], + }, + ], + }], + ], +} diff --git a/components/dns_prefetch/OWNERS b/components/network_hints/OWNERS index 1535646..1535646 100644 --- a/components/dns_prefetch/OWNERS +++ b/components/network_hints/OWNERS diff --git a/components/dns_prefetch/browser/BUILD.gn b/components/network_hints/browser/BUILD.gn index f6cdd83..aafe3eb 100644 --- a/components/dns_prefetch/browser/BUILD.gn +++ b/components/network_hints/browser/BUILD.gn @@ -2,11 +2,11 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -# GYP version: components/dns_prefetch.gypi:dns_prefetch_browser +# GYP version: components/network_hints.gypi:network_hints_browser source_set("browser") { sources = [ - "net_message_filter.cc", - "net_message_filter.h", + "network_hints_message_filter.cc", + "network_hints_message_filter.h", ] public_deps = [ diff --git a/components/dns_prefetch/browser/DEPS b/components/network_hints/browser/DEPS index 9883d79..9883d79 100644 --- a/components/dns_prefetch/browser/DEPS +++ b/components/network_hints/browser/DEPS diff --git a/components/dns_prefetch/browser/net_message_filter.cc b/components/network_hints/browser/network_hints_message_filter.cc index 268dc2e..5541747 100644 --- a/components/dns_prefetch/browser/net_message_filter.cc +++ b/components/network_hints/browser/network_hints_message_filter.cc @@ -2,11 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "components/dns_prefetch/browser/net_message_filter.h" +#include "components/network_hints/browser/network_hints_message_filter.h" #include "base/logging.h" -#include "components/dns_prefetch/common/prefetch_common.h" -#include "components/dns_prefetch/common/prefetch_messages.h" +#include "components/network_hints/common/network_hints_common.h" +#include "components/network_hints/common/network_hints_messages.h" #include "ipc/ipc_message_macros.h" #include "net/base/address_list.h" #include "net/base/net_errors.h" @@ -14,7 +14,7 @@ #include "net/dns/single_request_host_resolver.h" #include "url/gurl.h" -namespace dns_prefetch { +namespace network_hints { namespace { @@ -62,25 +62,27 @@ class DnsLookupRequest { } // namespace -NetMessageFilter::NetMessageFilter(net::HostResolver* host_resolver) +NetworkHintsMessageFilter::NetworkHintsMessageFilter( + net::HostResolver* host_resolver) : content::BrowserMessageFilter(DnsPrefetchMsgStart), host_resolver_(host_resolver) { DCHECK(host_resolver_); } -NetMessageFilter::~NetMessageFilter() { +NetworkHintsMessageFilter::~NetworkHintsMessageFilter() { } -bool NetMessageFilter::OnMessageReceived(const IPC::Message& message) { +bool NetworkHintsMessageFilter::OnMessageReceived(const IPC::Message& message) { bool handled = true; - IPC_BEGIN_MESSAGE_MAP(NetMessageFilter, message) + IPC_BEGIN_MESSAGE_MAP(NetworkHintsMessageFilter, message) IPC_MESSAGE_HANDLER(DnsPrefetchMsg_RequestPrefetch, OnDnsPrefetch) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() return handled; } -void NetMessageFilter::OnDnsPrefetch(const LookupRequest& lookup_request) { +void NetworkHintsMessageFilter::OnDnsPrefetch( + const LookupRequest& lookup_request) { DCHECK(host_resolver_); for (const std::string& hostname : lookup_request.hostname_list) { DnsLookupRequest* request = new DnsLookupRequest(host_resolver_, hostname); @@ -90,4 +92,4 @@ void NetMessageFilter::OnDnsPrefetch(const LookupRequest& lookup_request) { } } -} // namespace dns_prefetch +} // namespace network_hints diff --git a/components/dns_prefetch/browser/net_message_filter.h b/components/network_hints/browser/network_hints_message_filter.h index 610f1ab..f30216e 100644 --- a/components/dns_prefetch/browser/net_message_filter.h +++ b/components/network_hints/browser/network_hints_message_filter.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef COMPONENTS_DNS_PREFETCH_BROWSER_NET_MESSAGE_FILTER_H_ -#define COMPONENTS_DNS_PREFETCH_BROWSER_NET_MESSAGE_FILTER_H_ +#ifndef COMPONENTS_NETWORK_HINTS_BROWSER_NETWORK_HINTS_MESSAGE_FILTER_H_ +#define COMPONENTS_NETWORK_HINTS_BROWSER_NETWORK_HINTS_MESSAGE_FILTER_H_ #include "base/macros.h" #include "content/public/browser/browser_message_filter.h" @@ -12,29 +12,29 @@ namespace net { class HostResolver; } -namespace dns_prefetch { +namespace network_hints { struct LookupRequest; // Simple browser-side handler for DNS prefetch requests. // Passes prefetch requests to the provided net::HostResolver. // Each renderer process requires its own filter. -class NetMessageFilter : public content::BrowserMessageFilter { +class NetworkHintsMessageFilter : public content::BrowserMessageFilter { public: - explicit NetMessageFilter(net::HostResolver* host_resolver); + explicit NetworkHintsMessageFilter(net::HostResolver* host_resolver); // content::BrowserMessageFilter implementation: bool OnMessageReceived(const IPC::Message& message) override; private: - ~NetMessageFilter() override; + ~NetworkHintsMessageFilter() override; void OnDnsPrefetch(const LookupRequest& lookup_request); net::HostResolver* host_resolver_; - DISALLOW_COPY_AND_ASSIGN(NetMessageFilter); + DISALLOW_COPY_AND_ASSIGN(NetworkHintsMessageFilter); }; -} // namespace dns_prefetch +} // namespace network_hints -#endif // COMPONENTS_DNS_PREFETCH_BROWSER_NET_MESSAGE_FILTER_H_ +#endif // COMPONENTS_NETWORK_HINTS_BROWSER_NETWORK_HINTS_MESSAGE_FILTER_H_ diff --git a/components/network_hints/common/BUILD.gn b/components/network_hints/common/BUILD.gn new file mode 100644 index 0000000..1e06117 --- /dev/null +++ b/components/network_hints/common/BUILD.gn @@ -0,0 +1,19 @@ +# Copyright 2014 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. + +# GYP version: components/network_hints.gypi:predictor +source_set("common") { + sources = [ + "network_hints_common.cc", + "network_hints_common.h", + "network_hints_message_generator.cc", + "network_hints_message_generator.h", + "network_hints_messages.cc", + "network_hints_messages.h", + ] + + deps = [ + "//base", + ] +} diff --git a/components/dns_prefetch/common/DEPS b/components/network_hints/common/DEPS index 1c40d98..1c40d98 100644 --- a/components/dns_prefetch/common/DEPS +++ b/components/network_hints/common/DEPS diff --git a/components/dns_prefetch/common/prefetch_common.cc b/components/network_hints/common/network_hints_common.cc index 04d5ff2..c6d64ae 100644 --- a/components/dns_prefetch/common/prefetch_common.cc +++ b/components/network_hints/common/network_hints_common.cc @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "components/dns_prefetch/common/prefetch_common.h" +#include "components/network_hints/common/network_hints_common.h" -namespace dns_prefetch { +namespace network_hints { const size_t kMaxDnsHostnamesPerRequest = 30; const size_t kMaxDnsHostnameLength = 255; @@ -15,4 +15,4 @@ LookupRequest::LookupRequest() { LookupRequest::~LookupRequest() { } -} // namespace dns_prefetch +} // namespace network_hints diff --git a/components/dns_prefetch/common/prefetch_common.h b/components/network_hints/common/network_hints_common.h index 84b2a0c..701b003 100644 --- a/components/dns_prefetch/common/prefetch_common.h +++ b/components/network_hints/common/network_hints_common.h @@ -2,15 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef COMPONENTS_DNS_PREFETCH_COMMON_PREFETCH_COMMON_H_ -#define COMPONENTS_DNS_PREFETCH_COMMON_PREFETCH_COMMON_H_ +#ifndef COMPONENTS_NETWORK_HINTS_COMMON_NETWORK_HINTS_COMMON_H_ +#define COMPONENTS_NETWORK_HINTS_COMMON_NETWORK_HINTS_COMMON_H_ #include <string> #include <vector> #include "url/gurl.h" -namespace dns_prefetch { +namespace network_hints { // IPC messages are passed from the renderer to the browser in the form of // Namelist instances. @@ -36,6 +36,6 @@ extern const size_t kMaxDnsHostnamesPerRequest; // The maximum length for a given DNS hostname to resolve. extern const size_t kMaxDnsHostnameLength; -} +} // namespace network_hints -#endif // COMPONENTS_DNS_PREFETCH_COMMON_PREFETCH_COMMON_H_ +#endif // COMPONENTS_NETWORK_HINTS_COMMON_NETWORK_HINTS_COMMON_H_ diff --git a/components/dns_prefetch/common/prefetch_message_generator.cc b/components/network_hints/common/network_hints_message_generator.cc index 81b93f0..f315e98 100644 --- a/components/dns_prefetch/common/prefetch_message_generator.cc +++ b/components/network_hints/common/network_hints_message_generator.cc @@ -4,30 +4,30 @@ // Get basic type definitions. #define IPC_MESSAGE_IMPL -#include "components/dns_prefetch/common/prefetch_message_generator.h" +#include "components/network_hints/common/network_hints_message_generator.h" // Generate constructors. #include "ipc/struct_constructor_macros.h" -#include "components/dns_prefetch/common/prefetch_message_generator.h" +#include "components/network_hints/common/network_hints_message_generator.h" // Generate destructors. #include "ipc/struct_destructor_macros.h" -#include "components/dns_prefetch/common/prefetch_message_generator.h" +#include "components/network_hints/common/network_hints_message_generator.h" // Generate param traits write methods. #include "ipc/param_traits_write_macros.h" namespace IPC { -#include "components/dns_prefetch/common/prefetch_message_generator.h" +#include "components/network_hints/common/network_hints_message_generator.h" } // namespace IPC // Generate param traits read methods. #include "ipc/param_traits_read_macros.h" namespace IPC { -#include "components/dns_prefetch/common/prefetch_message_generator.h" +#include "components/network_hints/common/network_hints_message_generator.h" } // namespace IPC // Generate param traits log methods. #include "ipc/param_traits_log_macros.h" namespace IPC { -#include "components/dns_prefetch/common/prefetch_message_generator.h" +#include "components/network_hints/common/network_hints_message_generator.h" } // namespace IPC diff --git a/components/dns_prefetch/common/prefetch_message_generator.h b/components/network_hints/common/network_hints_message_generator.h index 92240c4..246cd4b 100644 --- a/components/dns_prefetch/common/prefetch_message_generator.h +++ b/components/network_hints/common/network_hints_message_generator.h @@ -4,4 +4,4 @@ // Multiply-included file, no traditional include guard. -#include "components/dns_prefetch/common/prefetch_messages.h" +#include "components/network_hints/common/network_hints_messages.h" diff --git a/components/network_hints/common/network_hints_messages.cc b/components/network_hints/common/network_hints_messages.cc new file mode 100644 index 0000000..e97e1a2 --- /dev/null +++ b/components/network_hints/common/network_hints_messages.cc @@ -0,0 +1,42 @@ +// Copyright 2014 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/network_hints/common/network_hints_messages.h" + +#include "base/strings/string_number_conversions.h" +#include "components/network_hints/common/network_hints_common.h" + +namespace IPC { + +void ParamTraits<network_hints::LookupRequest>::Write( + Message* m, const network_hints::LookupRequest& request) { + IPC::WriteParam(m, request.hostname_list); +} + +bool ParamTraits<network_hints::LookupRequest>::Read( + const Message* m, + PickleIterator* iter, + network_hints::LookupRequest* request) { + // Verify the hostname limits after deserialization success. + if (IPC::ReadParam(m, iter, &request->hostname_list)) { + network_hints::NameList& hostnames = request->hostname_list; + if (hostnames.size() > network_hints::kMaxDnsHostnamesPerRequest) + return false; + + for (const auto& hostname : hostnames) { + if (hostname.length() > network_hints::kMaxDnsHostnameLength) + return false; + } + } + return true; +} + +void ParamTraits<network_hints::LookupRequest>::Log( + const network_hints::LookupRequest& p, std::string* l) { + l->append("<network_hints::LookupRequest: "); + l->append(base::SizeTToString(p.hostname_list.size())); + l->append(" hostnames>"); +} + +} // namespace IPC diff --git a/components/dns_prefetch/common/prefetch_messages.h b/components/network_hints/common/network_hints_messages.h index d12ac74..9c52c3a 100644 --- a/components/dns_prefetch/common/prefetch_messages.h +++ b/components/network_hints/common/network_hints_messages.h @@ -6,19 +6,19 @@ #include <string> #include <vector> -#include "components/dns_prefetch/common/prefetch_common.h" +#include "components/network_hints/common/network_hints_common.h" #include "ipc/ipc_message_macros.h" #include "ipc/ipc_message_utils.h" // Singly-included section for custom IPC traits. -#ifndef COMPONENTS_DNS_PREFETCH_COMMON_PREFETCH_MESSAGES_H_ -#define COMPONENTS_DNS_PREFETCH_COMMON_PREFETCH_MESSAGES_H_ +#ifndef COMPONENTS_NETWORK_HINTS_COMMON_NETWORK_HINTS_MESSAGES_H_ +#define COMPONENTS_NETWORK_HINTS_COMMON_NETWORK_HINTS_MESSAGES_H_ namespace IPC { template <> -struct ParamTraits<dns_prefetch::LookupRequest> { - typedef dns_prefetch::LookupRequest param_type; +struct ParamTraits<network_hints::LookupRequest> { + typedef network_hints::LookupRequest param_type; static void Write(Message* m, const param_type& p); static bool Read(const Message* m, PickleIterator* iter, param_type* r); static void Log(const param_type& p, std::string* l); @@ -26,7 +26,7 @@ struct ParamTraits<dns_prefetch::LookupRequest> { } // namespace IPC -#endif // COMPONENTS_DNS_PREFETCH_COMMON_PREFETCH_MESSAGES_H_ +#endif // COMPONENTS_NETWORK_HINTS_COMMON_NETWORK_HINTS_MESSAGES_H_ #define IPC_MESSAGE_START DnsPrefetchMsgStart @@ -37,4 +37,4 @@ struct ParamTraits<dns_prefetch::LookupRequest> { // Request for a DNS prefetch of the names in the array. // NameList is typedef'ed std::vector<std::string> IPC_MESSAGE_CONTROL1(DnsPrefetchMsg_RequestPrefetch, - dns_prefetch::LookupRequest) + network_hints::LookupRequest) diff --git a/components/dns_prefetch/renderer/BUILD.gn b/components/network_hints/renderer/BUILD.gn index cc7350d..8c56754 100644 --- a/components/dns_prefetch/renderer/BUILD.gn +++ b/components/network_hints/renderer/BUILD.gn @@ -2,19 +2,19 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -# GYP version: components/dns_prefetch.gypi:predictor_renderer +# GYP version: components/network_hints.gypi:predictor_renderer source_set("renderer") { sources = [ - "predictor_queue.cc", - "predictor_queue.h", + "dns_prefetch_queue.cc", + "dns_prefetch_queue.h", "prescient_networking_dispatcher.cc", "prescient_networking_dispatcher.h", - "renderer_net_predictor.cc", - "renderer_net_predictor.h", + "renderer_dns_prefetch.cc", + "renderer_dns_prefetch.h", ] public_deps = [ - "//components/dns_prefetch/common", + "//components/network_hints/common", "//content/public/renderer", "//third_party/WebKit/public:blink", ] diff --git a/components/dns_prefetch/renderer/DEPS b/components/network_hints/renderer/DEPS index 5a47d5f..d6ea0c4 100644 --- a/components/dns_prefetch/renderer/DEPS +++ b/components/network_hints/renderer/DEPS @@ -1,5 +1,5 @@ include_rules = [ - "+components/dns_prefetch/common", + "+components/network_hints/common", "+content/public/renderer", "+third_party/WebKit/public", ] diff --git a/components/dns_prefetch/renderer/predictor_queue.cc b/components/network_hints/renderer/dns_prefetch_queue.cc index 1691108..8328df9 100644 --- a/components/dns_prefetch/renderer/predictor_queue.cc +++ b/components/network_hints/renderer/dns_prefetch_queue.cc @@ -4,12 +4,12 @@ // See header file for description of DnsQueue class -#include "components/dns_prefetch/renderer/predictor_queue.h" +#include "components/network_hints/renderer/dns_prefetch_queue.h" #include "base/logging.h" #include "base/metrics/stats_counters.h" -namespace dns_prefetch { +namespace network_hints { DnsQueue::DnsQueue(BufferSize size) : buffer_(new char[size + 2]), @@ -153,4 +153,4 @@ bool DnsQueue::Validate() { ((0 == size_) == (readable_ == writeable_)); } -} // namespace dns_prefetch +} // namespace network_hints diff --git a/components/dns_prefetch/renderer/predictor_queue.h b/components/network_hints/renderer/dns_prefetch_queue.h index cb0c17a..72b4fad 100644 --- a/components/dns_prefetch/renderer/predictor_queue.h +++ b/components/network_hints/renderer/dns_prefetch_queue.h @@ -21,16 +21,18 @@ // rendering, the supplier is the renderer (typically), and the consumer // is a thread that sends messages to an async DNS resolver. -#ifndef COMPONENTS_DNS_PREFETCH_RENDERER_PREDICTOR_QUEUE_H__ -#define COMPONENTS_DNS_PREFETCH_RENDERER_PREDICTOR_QUEUE_H__ +#ifndef COMPONENTS_NETWORK_HINTS_RENDERER_DNS_PREFETCH_QUEUE_H__ +#define COMPONENTS_NETWORK_HINTS_RENDERER_DNS_PREFETCH_QUEUE_H__ #include <string> #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" -namespace dns_prefetch { +namespace network_hints { +// A queue of DNS lookup requests for internal use within the network_hints +// component. class DnsQueue { public: // BufferSize is a signed type used for indexing into a buffer. @@ -86,6 +88,6 @@ class DnsQueue { DISALLOW_COPY_AND_ASSIGN(DnsQueue); }; // class DnsQueue -} // namespace dns_prefetch +} // namespace network_hints -#endif // COMPONENTS_DNS_PREFETCH_RENDERER_PREDICTOR_QUEUE_H__ +#endif // COMPONENTS_NETWORK_HINTS_RENDERER_DNS_PREFETCH_QUEUE_H__ diff --git a/components/dns_prefetch/renderer/predictor_queue_unittest.cc b/components/network_hints/renderer/dns_prefetch_queue_unittest.cc index af2ea04..cb808c1 100644 --- a/components/dns_prefetch/renderer/predictor_queue_unittest.cc +++ b/components/network_hints/renderer/dns_prefetch_queue_unittest.cc @@ -4,12 +4,12 @@ #include <sstream> -#include "components/dns_prefetch/renderer/predictor_queue.h" +#include "components/network_hints/renderer/dns_prefetch_queue.h" #include "testing/gtest/include/gtest/gtest.h" // Single threaded tests of DnsQueue functionality. -namespace dns_prefetch { +namespace network_hints { class DnsQueueTest : public testing::Test { }; @@ -259,4 +259,4 @@ TEST(DnsQueueTest, WrapOnVariousSubstrings) { EXPECT_FALSE(tester.Pop()); } -}; // namespace dns_prefetch +}; // namespace network_hints diff --git a/components/dns_prefetch/renderer/prescient_networking_dispatcher.cc b/components/network_hints/renderer/prescient_networking_dispatcher.cc index 6ce8b66..ee02f019 100644 --- a/components/dns_prefetch/renderer/prescient_networking_dispatcher.cc +++ b/components/network_hints/renderer/prescient_networking_dispatcher.cc @@ -2,11 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "components/dns_prefetch/renderer/prescient_networking_dispatcher.h" +#include "components/network_hints/renderer/prescient_networking_dispatcher.h" #include "base/logging.h" -namespace dns_prefetch { +namespace network_hints { PrescientNetworkingDispatcher::PrescientNetworkingDispatcher() { } @@ -21,7 +21,7 @@ void PrescientNetworkingDispatcher::prefetchDNS( return; std::string hostname_utf8 = hostname.utf8(); - net_predictor_.Resolve(hostname_utf8.data(), hostname_utf8.length()); + dns_prefetch_.Resolve(hostname_utf8.data(), hostname_utf8.length()); } -} // namespace dns_prefetch +} // namespace network_hints diff --git a/components/dns_prefetch/renderer/prescient_networking_dispatcher.h b/components/network_hints/renderer/prescient_networking_dispatcher.h index fbb383c..9b10739 100644 --- a/components/dns_prefetch/renderer/prescient_networking_dispatcher.h +++ b/components/network_hints/renderer/prescient_networking_dispatcher.h @@ -2,15 +2,17 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef COMPONENTS_DNS_PREFETCH_RENDERER_PRESCIENT_NETWORKING_DISPATCHER_H_ -#define COMPONENTS_DNS_PREFETCH_RENDERER_PRESCIENT_NETWORKING_DISPATCHER_H_ +#ifndef COMPONENTS_NETWORK_HINTS_RENDERER_PRESCIENT_NETWORKING_DISPATCHER_H_ +#define COMPONENTS_NETWORK_HINTS_RENDERER_PRESCIENT_NETWORKING_DISPATCHER_H_ #include "base/macros.h" -#include "components/dns_prefetch/renderer/renderer_net_predictor.h" +#include "components/network_hints/renderer/renderer_dns_prefetch.h" #include "third_party/WebKit/public/platform/WebPrescientNetworking.h" -namespace dns_prefetch { +namespace network_hints { +// The main entry point from blink for sending DNS prefetch requests to the +// network stack. class PrescientNetworkingDispatcher : public blink::WebPrescientNetworking { public: PrescientNetworkingDispatcher(); @@ -19,11 +21,11 @@ class PrescientNetworkingDispatcher : public blink::WebPrescientNetworking { void prefetchDNS(const blink::WebString& hostname) override; private: - dns_prefetch::RendererNetPredictor net_predictor_; + network_hints::RendererDnsPrefetch dns_prefetch_; DISALLOW_COPY_AND_ASSIGN(PrescientNetworkingDispatcher); }; -} // namespace dns_prefetch +} // namespace network_hints -#endif // COMPONENTS_DNS_PREFETCH_RENDERER_PRESCIENT_NETWORKING_DISPATCHER_H_ +#endif // COMPONENTS_NETWORK_HINTS_RENDERER_PRESCIENT_NETWORKING_DISPATCHER_H_ diff --git a/components/dns_prefetch/renderer/renderer_net_predictor.cc b/components/network_hints/renderer/renderer_dns_prefetch.cc index 273e3e1..7098037 100644 --- a/components/dns_prefetch/renderer/renderer_net_predictor.cc +++ b/components/network_hints/renderer/renderer_dns_prefetch.cc @@ -2,34 +2,34 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// See header file for description of RendererNetPredictor class +// See header file for description of RendererDnsPrefetch class -#include "components/dns_prefetch/renderer/renderer_net_predictor.h" +#include "components/network_hints/renderer/renderer_dns_prefetch.h" #include <ctype.h> #include "base/bind.h" #include "base/logging.h" #include "base/message_loop/message_loop.h" -#include "components/dns_prefetch/common/prefetch_common.h" -#include "components/dns_prefetch/common/prefetch_messages.h" -#include "components/dns_prefetch/renderer/predictor_queue.h" +#include "components/network_hints/common/network_hints_common.h" +#include "components/network_hints/common/network_hints_messages.h" +#include "components/network_hints/renderer/dns_prefetch_queue.h" #include "content/public/renderer/render_thread.h" using content::RenderThread; -namespace dns_prefetch { +namespace network_hints { -RendererNetPredictor::RendererNetPredictor() +RendererDnsPrefetch::RendererDnsPrefetch() : c_string_queue_(1000), weak_factory_(this) { Reset(); } -RendererNetPredictor::~RendererNetPredictor() { +RendererDnsPrefetch::~RendererDnsPrefetch() { } -void RendererNetPredictor::Reset() { +void RendererDnsPrefetch::Reset() { domain_map_.clear(); c_string_queue_.Clear(); buffer_full_discard_count_ = 0; @@ -38,7 +38,7 @@ void RendererNetPredictor::Reset() { } // Push names into queue quickly! -void RendererNetPredictor::Resolve(const char* name, size_t length) { +void RendererDnsPrefetch::Resolve(const char* name, size_t length) { if (!length) return; // Don't store empty strings in buffer. if (is_numeric_ip(name, length)) @@ -53,7 +53,7 @@ void RendererNetPredictor::Resolve(const char* name, size_t length) { return; // Overkill safety net: Don't send too many InvokeLater's. weak_factory_.InvalidateWeakPtrs(); RenderThread::Get()->GetTaskRunner()->PostDelayedTask( - FROM_HERE, base::Bind(&RendererNetPredictor::SubmitHostnames, + FROM_HERE, base::Bind(&RendererDnsPrefetch::SubmitHostnames, weak_factory_.GetWeakPtr()), base::TimeDelta::FromMilliseconds(10)); } @@ -68,7 +68,7 @@ void RendererNetPredictor::Resolve(const char* name, size_t length) { // Extract data from the Queue, and then send it off the the Browser process // to be resolved. -void RendererNetPredictor::SubmitHostnames() { +void RendererDnsPrefetch::SubmitHostnames() { // Get all names out of the C_string_queue (into our map) ExtractBufferedNames(); // TBD: IT could be that we should only extract about as many names as we are @@ -88,7 +88,7 @@ void RendererNetPredictor::SubmitHostnames() { if (new_name_count_ > 0 || 0 < c_string_queue_.Size()) { weak_factory_.InvalidateWeakPtrs(); RenderThread::Get()->GetTaskRunner()->PostDelayedTask( - FROM_HERE, base::Bind(&RendererNetPredictor::SubmitHostnames, + FROM_HERE, base::Bind(&RendererDnsPrefetch::SubmitHostnames, weak_factory_.GetWeakPtr()), base::TimeDelta::FromMilliseconds(10)); } else { @@ -98,7 +98,7 @@ void RendererNetPredictor::SubmitHostnames() { } // Pull some hostnames from the queue, and add them to our map. -void RendererNetPredictor::ExtractBufferedNames(size_t size_goal) { +void RendererDnsPrefetch::ExtractBufferedNames(size_t size_goal) { size_t count(0); // Number of entries to find (0 means find all). if (size_goal > 0) { if (size_goal <= domain_map_.size()) @@ -126,7 +126,7 @@ void RendererNetPredictor::ExtractBufferedNames(size_t size_goal) { } } -void RendererNetPredictor::DnsPrefetchNames(size_t max_count) { +void RendererDnsPrefetch::DnsPrefetchNames(size_t max_count) { // We are on the renderer thread, and just need to send things to the browser. NameList names; for (DomainUseMap::iterator it = domain_map_.begin(); @@ -144,7 +144,7 @@ void RendererNetPredictor::DnsPrefetchNames(size_t max_count) { DCHECK_GE(new_name_count_, names.size()); new_name_count_ -= names.size(); - dns_prefetch::LookupRequest request; + network_hints::LookupRequest request; request.hostname_list = names; RenderThread::Get()->Send(new DnsPrefetchMsg_RequestPrefetch(request)); } @@ -152,7 +152,7 @@ void RendererNetPredictor::DnsPrefetchNames(size_t max_count) { // is_numeric_ip() checks to see if all characters in name are either numeric, // or dots. Such a name will not actually be passed to DNS, as it is an IP // address. -bool RendererNetPredictor::is_numeric_ip(const char* name, size_t length) { +bool RendererDnsPrefetch::is_numeric_ip(const char* name, size_t length) { // Scan for a character outside our lookup list. while (length-- > 0) { if (!isdigit(*name) && '.' != *name) diff --git a/components/dns_prefetch/renderer/renderer_net_predictor.h b/components/network_hints/renderer/renderer_dns_prefetch.h index 74a148e..9ee4f61 100644 --- a/components/dns_prefetch/renderer/renderer_net_predictor.h +++ b/components/network_hints/renderer/renderer_dns_prefetch.h @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// A RendererNetPredictor instance is maintained for each RenderThread. +// A RendererDnsPrefetch instance is maintained for each RenderThread. // URL strings are typically added to the embedded queue during rendering. // The first addition to the queue (transitioning from empty to having // some names) causes a processing task to be added to the Renderer Thread. @@ -18,22 +18,24 @@ // sent names. If the entire queue is processed, then the list of "sent names" // is cleared so that future gatherings might again pass along the same names. -#ifndef COMPONENTS_DNS_PREFETCH_RENDERER_RENDERER_NET_PREDICTOR_H_ -#define COMPONENTS_DNS_PREFETCH_RENDERER_RENDERER_NET_PREDICTOR_H_ +#ifndef COMPONENTS_NETWORK_HINTS_RENDERER_RENDERER_DNS_PREFETCH_H_ +#define COMPONENTS_NETWORK_HINTS_RENDERER_RENDERER_DNS_PREFETCH_H_ #include <map> #include <string> #include "base/basictypes.h" #include "base/memory/weak_ptr.h" -#include "components/dns_prefetch/renderer/predictor_queue.h" +#include "components/network_hints/renderer/dns_prefetch_queue.h" -namespace dns_prefetch { +namespace network_hints { -class RendererNetPredictor { +// An internal interface to the network_hints component for efficiently sending +// DNS prefetch requests to the net stack. +class RendererDnsPrefetch { public: - RendererNetPredictor(); - ~RendererNetPredictor(); + RendererDnsPrefetch(); + ~RendererDnsPrefetch(); // Push a name into the queue to be resolved. void Resolve(const char* name, size_t length); @@ -97,11 +99,11 @@ class RendererNetPredictor { int buffer_full_discard_count_; int numeric_ip_discard_count_; - base::WeakPtrFactory<RendererNetPredictor> weak_factory_; + base::WeakPtrFactory<RendererDnsPrefetch> weak_factory_; - DISALLOW_COPY_AND_ASSIGN(RendererNetPredictor); -}; // class RendererNetPredictor + DISALLOW_COPY_AND_ASSIGN(RendererDnsPrefetch); +}; // class RendererDnsPrefetch -} // namespace dns_prefetch +} // namespace network_hints -#endif // COMPONENTS_DNS_PREFETCH_RENDERER_RENDERER_NET_PREDICTOR_H_ +#endif // COMPONENTS_NETWORK_HINTS_RENDERER_RENDERER_DNS_PREFETCH_H_ diff --git a/components/dns_prefetch/renderer/renderer_net_predictor_unittest.cc b/components/network_hints/renderer/renderer_dns_prefetch_unittest.cc index 03a4f2e..588383c 100644 --- a/components/dns_prefetch/renderer/renderer_net_predictor_unittest.cc +++ b/components/network_hints/renderer/renderer_dns_prefetch_unittest.cc @@ -2,15 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// Single threaded tests of RendererNetPredictor functionality. +// Single threaded tests of RendererDnsPrefetch functionality. -#include "components/dns_prefetch/renderer/renderer_net_predictor.h" +#include "components/network_hints/renderer/renderer_dns_prefetch.h" #include <algorithm> #include "testing/gtest/include/gtest/gtest.h" -namespace dns_prefetch { +namespace network_hints { class RenderDnsMasterTest : public testing::Test { }; @@ -21,8 +21,8 @@ TEST(RenderDnsMasterTest, NumericIpDiscardCheck) { // Combination of digits plus dots. const std::string N1("1.3."), N2("5.5.7.12"); -#define TESTNAME(string) RendererNetPredictor::is_numeric_ip((string.data()), \ - (string).size()) +#define TESTNAME(string) RendererDnsPrefetch::is_numeric_ip((string.data()), \ + (string).size()) EXPECT_TRUE(TESTNAME(N1)); EXPECT_TRUE(TESTNAME(N2)); @@ -34,4 +34,4 @@ TEST(RenderDnsMasterTest, NumericIpDiscardCheck) { #undef TESTNAME } -} // namespace dns_prefetch +} // namespace network_hints |