summaryrefslogtreecommitdiffstats
path: root/chrome/browser/prefetch/prefetch.cc
blob: ccf13e22a1522b185ea993ffc464afa54df85b2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// 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 "chrome/browser/prefetch/prefetch.h"

#include <string>

#include "base/metrics/field_trial.h"
#include "base/strings/string_util.h"
#include "chrome/browser/prefetch/prefetch_field_trial.h"
#include "chrome/browser/profiles/profile_io_data.h"
#include "net/base/network_change_notifier.h"

namespace prefetch {

bool IsPrefetchEnabled(content::ResourceContext* resource_context) {
  DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));

  // TODO(jkarlin): Eventually tie this to a new Chrome preference to predict
  // network actions when on cellular connections.  See crbug.com/370454.
  if (net::NetworkChangeNotifier::IsConnectionCellular(
          net::NetworkChangeNotifier::GetConnectionType()))
    return false;

  ProfileIOData* io_data = ProfileIOData::FromResourceContext(resource_context);
  if (io_data != NULL && io_data->network_prediction_enabled()->GetValue())
    return IsPrefetchFieldTrialEnabled();
  return false;
}

}  // namespace prefetch