summaryrefslogtreecommitdiffstats
path: root/chrome/browser/prerender/prerender_manager_factory.cc
blob: d759df4f9bdb3376c4c4fcdcc70f4742a22c0fbb (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
51
52
53
54
// Copyright (c) 2011 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/prerender/prerender_manager_factory.h"

#include "chrome/browser/browser_process.h"
#include "chrome/browser/prerender/prerender_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_dependency_manager.h"

#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/prerender_condition_network.h"
#endif

namespace prerender {

// static
PrerenderManager* PrerenderManagerFactory::GetForProfile(
    Profile* profile) {
  if (!PrerenderManager::IsPrerenderingPossible())
    return NULL;
  return static_cast<PrerenderManager*>(
      GetInstance()->GetServiceForProfile(profile, true));
}

PrerenderManagerFactory* PrerenderManagerFactory::GetInstance() {
  return Singleton<PrerenderManagerFactory>::get();
}

PrerenderManagerFactory::PrerenderManagerFactory()
    : ProfileKeyedServiceFactory(ProfileDependencyManager::GetInstance()) {
}

PrerenderManagerFactory::~PrerenderManagerFactory() {
}

ProfileKeyedService* PrerenderManagerFactory::BuildServiceInstanceFor(
    Profile* profile) const {
  CHECK(g_browser_process->prerender_tracker());
  PrerenderManager* prerender_manager = new prerender::PrerenderManager(
      profile, g_browser_process->prerender_tracker());
#if defined(OS_CHROMEOS)
  if (chromeos::CrosLibrary::Get()) {
    prerender_manager->AddCondition(
        new chromeos::PrerenderConditionNetwork(
            chromeos::CrosLibrary::Get()->GetNetworkLibrary()));
  }
#endif
  return prerender_manager;
}

}  // end namespace prerender