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"
26 PrerenderManager
* PrerenderManagerFactory::GetForProfile(
28 TRACE_EVENT0("browser", "PrerenderManagerFactory::GetForProfile")
29 if (!PrerenderManager::IsPrerenderingPossible())
31 return static_cast<PrerenderManager
*>(
32 GetInstance()->GetServiceForBrowserContext(profile
, true));
36 PrerenderManagerFactory
* PrerenderManagerFactory::GetInstance() {
37 return base::Singleton
<PrerenderManagerFactory
>::get();
40 PrerenderManagerFactory::PrerenderManagerFactory()
41 : BrowserContextKeyedServiceFactory(
43 BrowserContextDependencyManager::GetInstance()) {
44 #if defined(ENABLE_EXTENSIONS)
46 extensions::ExtensionsBrowserClient::Get()->GetExtensionSystemFactory());
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())
63 return new PrerenderManager(profile
);
66 content::BrowserContext
* PrerenderManagerFactory::GetBrowserContextToUse(
67 content::BrowserContext
* context
) const {
68 return chrome::GetBrowserContextOwnInstanceInIncognito(context
);
71 } // namespace prerender