Roll src/third_party/WebKit f298044:aa8346d (svn 202628:202629)
[chromium-blink-merge.git] / chrome / browser / prerender / prerender_manager_factory.cc
blob31052cf7d63e5cc3891b7f438b77b9b1899059ce
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.
5 #include "chrome/browser/prerender/prerender_manager_factory.h"
7 #include "base/sys_info.h"
8 #include "base/trace_event/trace_event.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/history/history_service_factory.h"
11 #include "chrome/browser/predictors/predictor_database_factory.h"
12 #include "chrome/browser/prerender/prerender_manager.h"
13 #include "chrome/browser/profiles/incognito_helpers.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/sync/profile_sync_service_factory.h"
16 #include "components/keyed_service/content/browser_context_dependency_manager.h"
18 #if defined(ENABLE_EXTENSIONS)
19 #include "extensions/browser/extension_system_provider.h"
20 #include "extensions/browser/extensions_browser_client.h"
21 #endif
23 namespace prerender {
25 // static
26 PrerenderManager* PrerenderManagerFactory::GetForProfile(
27 Profile* profile) {
28 TRACE_EVENT0("browser", "PrerenderManagerFactory::GetForProfile")
29 if (!PrerenderManager::IsPrerenderingPossible())
30 return NULL;
31 return static_cast<PrerenderManager*>(
32 GetInstance()->GetServiceForBrowserContext(profile, true));
35 // static
36 PrerenderManagerFactory* PrerenderManagerFactory::GetInstance() {
37 return base::Singleton<PrerenderManagerFactory>::get();
40 PrerenderManagerFactory::PrerenderManagerFactory()
41 : BrowserContextKeyedServiceFactory(
42 "PrerenderManager",
43 BrowserContextDependencyManager::GetInstance()) {
44 #if defined(ENABLE_EXTENSIONS)
45 DependsOn(
46 extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
47 #endif
48 // PrerenderLocalPredictor observers the history visit DB.
49 DependsOn(HistoryServiceFactory::GetInstance());
50 DependsOn(predictors::PredictorDatabaseFactory::GetInstance());
51 DependsOn(ProfileSyncServiceFactory::GetInstance());
54 PrerenderManagerFactory::~PrerenderManagerFactory() {
57 KeyedService* PrerenderManagerFactory::BuildServiceInstanceFor(
58 content::BrowserContext* browser_context) const {
59 Profile* profile = Profile::FromBrowserContext(browser_context);
60 if (base::SysInfo::IsLowEndDevice())
61 return NULL;
63 return new PrerenderManager(profile);
66 content::BrowserContext* PrerenderManagerFactory::GetBrowserContextToUse(
67 content::BrowserContext* context) const {
68 return chrome::GetBrowserContextOwnInstanceInIncognito(context);
71 } // namespace prerender