summaryrefslogtreecommitdiffstats
path: root/chrome/browser/predictors/resource_prefetch_predictor_factory.cc
blob: 415cbf5a2eca40feac72031148e2eeadca89929f (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) 2012 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/predictors/resource_prefetch_predictor_factory.h"

#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/predictors/predictor_database_factory.h"
#include "chrome/browser/predictors/resource_prefetch_common.h"
#include "chrome/browser/predictors/resource_prefetch_predictor.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_dependency_manager.h"

namespace predictors {

// static
ResourcePrefetchPredictor* ResourcePrefetchPredictorFactory::GetForProfile(
    Profile* profile) {
  return static_cast<ResourcePrefetchPredictor*>(
      GetInstance()->GetServiceForProfile(profile, true));
}

// static
ResourcePrefetchPredictorFactory*
ResourcePrefetchPredictorFactory::GetInstance() {
  return Singleton<ResourcePrefetchPredictorFactory>::get();
}

ResourcePrefetchPredictorFactory::ResourcePrefetchPredictorFactory()
    : ProfileKeyedServiceFactory("ResourcePrefetchPredictor",
                                 ProfileDependencyManager::GetInstance()) {
  DependsOn(HistoryServiceFactory::GetInstance());
  DependsOn(PredictorDatabaseFactory::GetInstance());
}

ResourcePrefetchPredictorFactory::~ResourcePrefetchPredictorFactory() {}

ProfileKeyedService*
    ResourcePrefetchPredictorFactory::BuildServiceInstanceFor(
        content::BrowserContext* context) const {
  Profile* profile = static_cast<Profile*>(context);

  ResourcePrefetchPredictorConfig config;
  if (!IsSpeculativeResourcePrefetchingEnabled(profile, &config))
    return NULL;

  return new ResourcePrefetchPredictor(config, profile);
}

}  // namespace predictors