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 #if defined(OS_ANDROID)
8 #include "base/android/sys_utils.h"
11 #include "base/debug/trace_event.h"
12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/extensions/extension_system_factory.h"
14 #include "chrome/browser/history/history_service_factory.h"
15 #include "chrome/browser/predictors/predictor_database_factory.h"
16 #include "chrome/browser/prerender/prerender_manager.h"
17 #include "chrome/browser/profiles/incognito_helpers.h"
18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/sync/profile_sync_service_factory.h"
20 #include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
22 #if defined(OS_CHROMEOS)
23 #include "chrome/browser/chromeos/prerender_condition_network.h"
24 #include "chromeos/network/network_handler.h"
27 #if defined(OS_ANDROID)
28 #include "chrome/browser/android/prerender_condition_platform.h"
34 PrerenderManager
* PrerenderManagerFactory::GetForProfile(
36 TRACE_EVENT0("browser", "PrerenderManagerFactory::GetForProfile")
37 if (!PrerenderManager::IsPrerenderingPossible())
39 return static_cast<PrerenderManager
*>(
40 GetInstance()->GetServiceForBrowserContext(profile
, true));
44 PrerenderManagerFactory
* PrerenderManagerFactory::GetInstance() {
45 return Singleton
<PrerenderManagerFactory
>::get();
48 PrerenderManagerFactory::PrerenderManagerFactory()
49 : BrowserContextKeyedServiceFactory(
51 BrowserContextDependencyManager::GetInstance()) {
52 DependsOn(extensions::ExtensionSystemFactory::GetInstance());
53 // PrerenderLocalPredictor observers the history visit DB.
54 DependsOn(HistoryServiceFactory::GetInstance());
55 DependsOn(predictors::PredictorDatabaseFactory::GetInstance());
56 DependsOn(ProfileSyncServiceFactory::GetInstance());
59 PrerenderManagerFactory::~PrerenderManagerFactory() {
62 BrowserContextKeyedService
* PrerenderManagerFactory::BuildServiceInstanceFor(
63 content::BrowserContext
* browser_context
) const {
64 Profile
* profile
= Profile::FromBrowserContext(browser_context
);
65 CHECK(g_browser_process
->prerender_tracker());
66 #if defined(OS_ANDROID)
67 if (base::android::SysUtils::IsLowEndDevice())
71 PrerenderManager
* prerender_manager
= new PrerenderManager(
72 profile
, g_browser_process
->prerender_tracker());
73 #if defined(OS_CHROMEOS)
74 if (chromeos::NetworkHandler::IsInitialized())
75 prerender_manager
->AddCondition(new chromeos::PrerenderConditionNetwork
);
77 #if defined(OS_ANDROID)
78 prerender_manager
->AddCondition(new android::PrerenderConditionPlatform(
81 return prerender_manager
;
84 content::BrowserContext
* PrerenderManagerFactory::GetBrowserContextToUse(
85 content::BrowserContext
* context
) const {
86 return chrome::GetBrowserContextOwnInstanceInIncognito(context
);
89 } // namespace prerender