1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/prerender/prerender_link_manager_factory.h"
6
7#include "chrome/browser/prerender/prerender_link_manager.h"
8#include "chrome/browser/prerender/prerender_manager.h"
9#include "chrome/browser/prerender/prerender_manager_factory.h"
10#include "chrome/browser/profiles/incognito_helpers.h"
11#include "chrome/browser/profiles/profile.h"
12#include "components/keyed_service/content/browser_context_dependency_manager.h"
13
14namespace prerender {
15
16// static
17PrerenderLinkManager* PrerenderLinkManagerFactory::GetForProfile(
18    Profile* profile) {
19  return static_cast<PrerenderLinkManager*>(
20      GetInstance()->GetServiceForBrowserContext(profile, true));
21}
22
23// static
24PrerenderLinkManagerFactory* PrerenderLinkManagerFactory::GetInstance() {
25  return Singleton<PrerenderLinkManagerFactory>::get();
26}
27
28PrerenderLinkManagerFactory::PrerenderLinkManagerFactory()
29    : BrowserContextKeyedServiceFactory(
30        "PrerenderLinkmanager",
31        BrowserContextDependencyManager::GetInstance()) {
32  DependsOn(prerender::PrerenderManagerFactory::GetInstance());
33}
34
35KeyedService* PrerenderLinkManagerFactory::BuildServiceInstanceFor(
36    content::BrowserContext* profile) const {
37  PrerenderManager* prerender_manager =
38      PrerenderManagerFactory::GetForProfile(static_cast<Profile*>(profile));
39  if (!prerender_manager)
40    return NULL;
41  PrerenderLinkManager* prerender_link_manager =
42      new PrerenderLinkManager(prerender_manager);
43  return prerender_link_manager;
44}
45
46content::BrowserContext* PrerenderLinkManagerFactory::GetBrowserContextToUse(
47    content::BrowserContext* context) const {
48  return chrome::GetBrowserContextOwnInstanceInIncognito(context);
49}
50
51}  // namespace prerender
52