| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/renderer/net/prescient_networking_dispatcher.h" | 5 #include "chrome/renderer/net/prescient_networking_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/metrics/field_trial.h" | 7 #include "base/metrics/field_trial.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/common/render_messages.h" | 9 #include "chrome/common/render_messages.h" |
| 10 #include "content/public/renderer/render_thread.h" | 10 #include "content/public/renderer/render_thread.h" |
| 11 | 11 |
| 12 using WebKit::WebPrescientNetworking; | 12 using blink::WebPrescientNetworking; |
| 13 | 13 |
| 14 const char kMouseEventPreconnectFieldTrialName[] = "MouseEventPreconnect"; | 14 const char kMouseEventPreconnectFieldTrialName[] = "MouseEventPreconnect"; |
| 15 const char kMouseEventPreconnectFieldTrialMouseDownGroup[] = "MouseDown"; | 15 const char kMouseEventPreconnectFieldTrialMouseDownGroup[] = "MouseDown"; |
| 16 const char kMouseEventPreconnectFieldTrialMouseOverGroup[] = "MouseOver"; | 16 const char kMouseEventPreconnectFieldTrialMouseOverGroup[] = "MouseOver"; |
| 17 const char kMouseEventPreconnectFieldTrialTapUnconfirmedGroup[] = | 17 const char kMouseEventPreconnectFieldTrialTapUnconfirmedGroup[] = |
| 18 "TapUnconfirmed"; | 18 "TapUnconfirmed"; |
| 19 const char kMouseEventPreconnectFieldTrialTapDownGroup[] = "TapDown"; | 19 const char kMouseEventPreconnectFieldTrialTapDownGroup[] = "TapDown"; |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 // Returns true if preconnect is enabled for given motivation. | 23 // Returns true if preconnect is enabled for given motivation. |
| 24 // The preconnect via {mouse,gesture} event is enabled for limited userbase | 24 // The preconnect via {mouse,gesture} event is enabled for limited userbase |
| 25 // for Finch field trial. | 25 // for Finch field trial. |
| 26 bool isPreconnectEnabledForMotivation( | 26 bool isPreconnectEnabledForMotivation( |
| 27 WebKit::WebPreconnectMotivation motivation) { | 27 blink::WebPreconnectMotivation motivation) { |
| 28 std::string group = | 28 std::string group = |
| 29 base::FieldTrialList::FindFullName(kMouseEventPreconnectFieldTrialName); | 29 base::FieldTrialList::FindFullName(kMouseEventPreconnectFieldTrialName); |
| 30 | 30 |
| 31 switch (motivation) { | 31 switch (motivation) { |
| 32 case WebKit::WebPreconnectMotivationLinkMouseDown: | 32 case blink::WebPreconnectMotivationLinkMouseDown: |
| 33 return group == kMouseEventPreconnectFieldTrialMouseDownGroup; | 33 return group == kMouseEventPreconnectFieldTrialMouseDownGroup; |
| 34 case WebKit::WebPreconnectMotivationLinkMouseOver: | 34 case blink::WebPreconnectMotivationLinkMouseOver: |
| 35 return group == kMouseEventPreconnectFieldTrialMouseOverGroup; | 35 return group == kMouseEventPreconnectFieldTrialMouseOverGroup; |
| 36 case WebKit::WebPreconnectMotivationLinkTapUnconfirmed: | 36 case blink::WebPreconnectMotivationLinkTapUnconfirmed: |
| 37 return group == kMouseEventPreconnectFieldTrialTapUnconfirmedGroup; | 37 return group == kMouseEventPreconnectFieldTrialTapUnconfirmedGroup; |
| 38 case WebKit::WebPreconnectMotivationLinkTapDown: | 38 case blink::WebPreconnectMotivationLinkTapDown: |
| 39 return group == kMouseEventPreconnectFieldTrialTapDownGroup; | 39 return group == kMouseEventPreconnectFieldTrialTapDownGroup; |
| 40 default: | 40 default: |
| 41 return false; | 41 return false; |
| 42 } | 42 } |
| 43 } | 43 } |
| 44 | 44 |
| 45 } // namespace | 45 } // namespace |
| 46 | 46 |
| 47 PrescientNetworkingDispatcher::PrescientNetworkingDispatcher() { | 47 PrescientNetworkingDispatcher::PrescientNetworkingDispatcher() { |
| 48 } | 48 } |
| 49 | 49 |
| 50 PrescientNetworkingDispatcher::~PrescientNetworkingDispatcher() { | 50 PrescientNetworkingDispatcher::~PrescientNetworkingDispatcher() { |
| 51 } | 51 } |
| 52 | 52 |
| 53 void PrescientNetworkingDispatcher::prefetchDNS( | 53 void PrescientNetworkingDispatcher::prefetchDNS( |
| 54 const WebKit::WebString& hostname) { | 54 const blink::WebString& hostname) { |
| 55 if (hostname.isEmpty()) | 55 if (hostname.isEmpty()) |
| 56 return; | 56 return; |
| 57 | 57 |
| 58 std::string hostname_utf8 = UTF16ToUTF8(hostname); | 58 std::string hostname_utf8 = UTF16ToUTF8(hostname); |
| 59 net_predictor_.Resolve(hostname_utf8.data(), hostname_utf8.length()); | 59 net_predictor_.Resolve(hostname_utf8.data(), hostname_utf8.length()); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void PrescientNetworkingDispatcher::preconnect( | 62 void PrescientNetworkingDispatcher::preconnect( |
| 63 const WebKit::WebURL& url, | 63 const blink::WebURL& url, |
| 64 WebKit::WebPreconnectMotivation motivation) { | 64 blink::WebPreconnectMotivation motivation) { |
| 65 if (isPreconnectEnabledForMotivation(motivation)) | 65 if (isPreconnectEnabledForMotivation(motivation)) |
| 66 content::RenderThread::Get()->Send(new ChromeViewHostMsg_Preconnect(url)); | 66 content::RenderThread::Get()->Send(new ChromeViewHostMsg_Preconnect(url)); |
| 67 } | 67 } |
| 68 | 68 |
| OLD | NEW |