Skip to content

Commit

Permalink
Speculatively launch Service Workers on mouse/touch events. [2/5]
Browse files Browse the repository at this point in the history
1/5: Introduce NavigationHintSender.
     https://codereview.chromium.org/2043863003/
2/5: Pipe NavigationHints from NavigationHintSender to ChromeRenderMessageFilter
     Thic CL.
3/5: Call StartServiceWorkerForNavigationHint() from ChromeRenderMessageFilter
     https://codereview.chromium.org/2052613003/
4/5: Measure the precision of the speculative launch of Service Workers for NavigationHints
     https://codereview.chromium.org/2045153003/
5/5: Add flags to enable SupeculativeLaunchServiceWorker
     https://codereview.chromium.org/2053573002/

NavigationHints are sent from NavigationHintSender to ChromeRenderMessageFilter.

NavigationHintSender::maybeSendNavigationHint()
-> sendNavigationHint()
-> WebPrescientNetworking::sendNavigationHint()
-> PrescientNetworkingDispatcher::sendNavigationHint()
-> IPC (NetworkHintsMsg_NavigationHint)

In the browser process, ChromeRenderMessageFilter receives the IPC message.

BUG=616502

Review-Url: https://codereview.chromium.org/2043083002
Cr-Commit-Position: refs/heads/master@{#407399}
  • Loading branch information
horo-t authored and Commit bot committed Jul 25, 2016
1 parent 9461cb3 commit 133f8c0
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 10 deletions.
9 changes: 9 additions & 0 deletions chrome/browser/renderer_host/chrome_render_message_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ bool ChromeRenderMessageFilter::OnMessageReceived(const IPC::Message& message) {
IPC_BEGIN_MESSAGE_MAP(ChromeRenderMessageFilter, message)
IPC_MESSAGE_HANDLER(NetworkHintsMsg_DNSPrefetch, OnDnsPrefetch)
IPC_MESSAGE_HANDLER(NetworkHintsMsg_Preconnect, OnPreconnect)
IPC_MESSAGE_HANDLER(NetworkHintsMsg_NavigationHint, OnNavigationHint)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_UpdatedCacheStats,
OnUpdatedCacheStats)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_AllowDatabase, OnAllowDatabase)
Expand Down Expand Up @@ -128,6 +129,14 @@ void ChromeRenderMessageFilter::OnPreconnect(const GURL& url,
}
}

void ChromeRenderMessageFilter::OnNavigationHint(
const GURL& url,
blink::WebNavigationHintType type) {
// TODO(horo): We don't need to have this method in //chrome. Move it to
// //content while mojoifing network_hints. (crbug.com/610750)
// TODO(horo): Implement this.
}

void ChromeRenderMessageFilter::OnUpdatedCacheStats(
uint64_t min_dead_capacity,
uint64_t max_dead_capacity,
Expand Down
5 changes: 5 additions & 0 deletions chrome/browser/renderer_host/chrome_render_message_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
class GURL;
class Profile;

namespace blink {
enum class WebNavigationHintType;
}

namespace chrome_browser_net {
class Predictor;
}
Expand Down Expand Up @@ -51,6 +55,7 @@ class ChromeRenderMessageFilter : public content::BrowserMessageFilter {

void OnDnsPrefetch(const network_hints::LookupRequest& request);
void OnPreconnect(const GURL& url, bool allow_credentials, int count);
void OnNavigationHint(const GURL& url, blink::WebNavigationHintType type);
void OnUpdatedCacheStats(uint64_t min_capacity,
uint64_t max_capacity,
uint64_t capacity,
Expand Down
2 changes: 2 additions & 0 deletions components/network_hints/common/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
per-file *_messages*.h=set noparent
per-file *_messages*.h=file://ipc/SECURITY_OWNERS
9 changes: 9 additions & 0 deletions components/network_hints/common/network_hints_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "components/network_hints/common/network_hints_common.h"
#include "ipc/ipc_message_macros.h"
#include "ipc/ipc_message_utils.h"
#include "third_party/WebKit/public/platform/WebNavigationHintType.h"
#include "url/ipc/url_param_traits.h"

// Singly-included section for custom IPC traits.
Expand All @@ -33,6 +34,9 @@ struct ParamTraits<network_hints::LookupRequest> {

#define IPC_MESSAGE_START NetworkHintsMsgStart

IPC_ENUM_TRAITS_MAX_VALUE(blink::WebNavigationHintType,
blink::WebNavigationHintType::Last)

//-----------------------------------------------------------------------------
// Host messages
// These are messages sent from the renderer process to the browser process.
Expand All @@ -48,3 +52,8 @@ IPC_MESSAGE_CONTROL3(NetworkHintsMsg_Preconnect,
GURL /* preconnect target url */,
bool /* Does connection have its credentials flag set */,
int /* number of connections */)

// Request to trigger possible optimizations for navigation.
IPC_MESSAGE_CONTROL2(NetworkHintsMsg_NavigationHint,
GURL /* document url */,
blink::WebNavigationHintType /* navigation hint type */)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include "components/network_hints/renderer/prescient_networking_dispatcher.h"

#include "base/logging.h"
#include "components/network_hints/common/network_hints_messages.h"
#include "content/public/renderer/render_thread.h"

using content::RenderThread;

namespace network_hints {

Expand All @@ -30,4 +34,12 @@ void PrescientNetworkingDispatcher::preconnect(const blink::WebURL& url,
preconnect_.Preconnect(url, allow_credentials);
}

void PrescientNetworkingDispatcher::sendNavigationHint(
const blink::WebURL& url,
blink::WebNavigationHintType type) {
if (!url.isValid())
return;
RenderThread::Get()->Send(new NetworkHintsMsg_NavigationHint(url, type));
}

} // namespace network_hints
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#include "components/network_hints/renderer/renderer_preconnect.h"
#include "third_party/WebKit/public/platform/WebPrescientNetworking.h"

namespace blink {
enum class WebNavigationHintType;
}

namespace network_hints {

// The main entry point from blink for sending DNS prefetch requests to the
Expand All @@ -22,6 +26,8 @@ class PrescientNetworkingDispatcher : public blink::WebPrescientNetworking {
void prefetchDNS(const blink::WebString& hostname) override;
void preconnect(const blink::WebURL& url,
const bool allow_credentials) override;
void sendNavigationHint(const blink::WebURL& url,
blink::WebNavigationHintType type) override;

private:
network_hints::RendererDnsPrefetch dns_prefetch_;
Expand Down
12 changes: 2 additions & 10 deletions third_party/WebKit/Source/core/html/HTMLAnchorElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,14 @@
#include "core/page/ChromeClient.h"
#include "platform/network/NetworkHints.h"
#include "platform/weborigin/SecurityPolicy.h"
#include "public/platform/WebNavigationHintType.h"

namespace blink {

using namespace HTMLNames;

class HTMLAnchorElement::NavigationHintSender : public GarbageCollected<HTMLAnchorElement::NavigationHintSender> {
public:
// TODO(horo): Move WebNavigationHintType to public/ directory.
enum class WebNavigationHintType {
Unknown,
LinkMouseDown,
LinkTapUnconfirmed,
LinkTapDown,
Last = LinkTapDown
};

static NavigationHintSender* create(HTMLAnchorElement* anchorElement)
{
return new NavigationHintSender(anchorElement);
Expand Down Expand Up @@ -116,7 +108,7 @@ void HTMLAnchorElement::NavigationHintSender::maybeSendNavigationHint(WebNavigat
if (!shouldSendNavigationHint())
return;

// TODO(horo): Send the navigation hint message to the browser process.
sendNavigationHint(m_anchorElement->href(), type);
}

HTMLAnchorElement::HTMLAnchorElement(const QualifiedName& tagName, Document& document)
Expand Down
7 changes: 7 additions & 0 deletions third_party/WebKit/Source/platform/network/NetworkHints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,11 @@ void preconnect(const KURL& url, const CrossOriginAttributeValue crossOrigin)
}
}

void sendNavigationHint(const KURL& url, WebNavigationHintType type)
{
if (WebPrescientNetworking* prescientNetworking = Platform::current()->prescientNetworking()) {
prescientNetworking->sendNavigationHint(url, type);
}
}

} // namespace blink
3 changes: 3 additions & 0 deletions third_party/WebKit/Source/platform/network/NetworkHints.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@

namespace blink {

enum class WebNavigationHintType;

PLATFORM_EXPORT void prefetchDNS(const String& hostname);
PLATFORM_EXPORT void preconnect(const KURL&, const CrossOriginAttributeValue);
PLATFORM_EXPORT void sendNavigationHint(const KURL&, WebNavigationHintType);

} // namespace blink

Expand Down
1 change: 1 addition & 0 deletions third_party/WebKit/public/blink_headers.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
"platform/WebMixedContent.h",
"platform/WebMockClipboard.h",
"platform/WebNativeScrollBehavior.h",
"platform/WebNavigationHintType.h",
"platform/WebNonCopyable.h",
"platform/WebOriginTrialTokenStatus.h",
"platform/WebPageVisibilityState.h",
Expand Down
19 changes: 19 additions & 0 deletions third_party/WebKit/public/platform/WebNavigationHintType.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2016 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 WebNavigationHintType_h
#define WebNavigationHintType_h

namespace blink {

enum class WebNavigationHintType {
LinkMouseDown,
LinkTapUnconfirmed,
LinkTapDown,
Last = LinkTapDown
};

} // namespace blink

#endif // WebNavigationHintType_h
5 changes: 5 additions & 0 deletions third_party/WebKit/public/platform/WebPrescientNetworking.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

namespace blink {

enum class WebNavigationHintType;

class WebPrescientNetworking {
public:
virtual ~WebPrescientNetworking() { }
Expand All @@ -46,6 +48,9 @@ class WebPrescientNetworking {
virtual void prefetchDNS(const WebString& hostname) { }

virtual void preconnect(const WebURL& url, const bool allowCredentials) { }

// Send a hint that a navigation to |url| is likely to happen.
virtual void sendNavigationHint(const WebURL& url, WebNavigationHintType) {}
};

} // namespace blink
Expand Down

0 comments on commit 133f8c0

Please sign in to comment.