// Copyright 2013 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 "chrome/renderer/net/prescient_networking_dispatcher.h"

#include "chrome/common/render_messages.h"
#include "content/public/renderer/render_thread.h"

using WebKit::WebPrescientNetworking;

PrescientNetworkingDispatcher::~PrescientNetworkingDispatcher() {
}

void PrescientNetworkingDispatcher::preconnect(
    const WebKit::WebURL& url,
    WebKit::WebPreconnectMotivation motivation) {
  // FIXME(kouhei) actual pre-connecting is currently disabled.
  // This should shortly be enabled via Finch field trials in upcoming patch.
  // content::RenderThread::Get()->Send(new ChromeViewHostMsg_Preconnect(url));
}


// Copyright 2013 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 "chrome/renderer/net/prescient_networking_dispatcher.h"

#include "base/metrics/field_trial.h"
#include "chrome/common/render_messages.h"
#include "content/public/renderer/render_thread.h"

using WebKit::WebPrescientNetworking;

const char kMouseEventPreconnectFieldTrialName[] = "MouseEventPreconnect";
const char kMouseEventPreconnectFieldTrialMouseDownGroup[] = "MouseDown";
const char kMouseEventPreconnectFieldTrialMouseOverGroup[] = "MouseOver";
const char kMouseEventPreconnectFieldTrialTapUnconfirmedGroup[] =
    "TapUnconfirmed";
const char kMouseEventPreconnectFieldTrialTapDownGroup[] = "TapDown";

namespace {

// Returns true if preconnect is enabled for given motivation.
// The preconnect via {mouse,gesture} event is enabled for limited userbase
// for Finch field trial.
bool isPreconnectEnabledForMotivation(
    WebKit::WebPreconnectMotivation motivation) {
  std::string group =
      base::FieldTrialList::FindFullName(kMouseEventPreconnectFieldTrialName);

  switch (motivation) {
    case WebKit::WebPreconnectMotivationLinkMouseDown:
      return group == kMouseEventPreconnectFieldTrialMouseDownGroup;
    case WebKit::WebPreconnectMotivationLinkMouseOver:
      return group == kMouseEventPreconnectFieldTrialMouseOverGroup;
    case WebKit::WebPreconnectMotivationLinkTapUnconfirmed:
      return group == kMouseEventPreconnectFieldTrialTapUnconfirmedGroup;
    case WebKit::WebPreconnectMotivationLinkTapDown:
      return group == kMouseEventPreconnectFieldTrialTapDownGroup;
    default:
      return false;
  }
}

} // namespace

PrescientNetworkingDispatcher::~PrescientNetworkingDispatcher() {
}

void PrescientNetworkingDispatcher::preconnect(
    const WebKit::WebURL& url,
    WebKit::WebPreconnectMotivation motivation) {
  if (isPreconnectEnabledForMotivation(motivation))
    content::RenderThread::Get()->Send(new ChromeViewHostMsg_Preconnect(url));
}


Enable pre-connect via {mouse,gesture}-event triggers to limited users controlled by Finch.
Enable pre-connect via {mouse,gesture}-event triggers to limited users controlled by Finch.

BUG=240959

Review URL: https://chromiumcodereview.appspot.com/15725006

git-svn-id: de016e52bd170d2d4f2344f9bf92d50478b649e0@203120 0039d316-1c4b-4281-b951-d872f2087c98
