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_manager_factory.h" 6 7 #include "base/debug/trace_event.h" 8 #include "base/sys_info.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" 17 18 #if defined(ENABLE_EXTENSIONS) 19 #include "extensions/browser/extension_system_provider.h" 20 #include "extensions/browser/extensions_browser_client.h" 21 #endif 22 23 namespace prerender { 24 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)); 33 } 34 35 // static 36 PrerenderManagerFactory* PrerenderManagerFactory::GetInstance() { 37 return Singleton<PrerenderManagerFactory>::get(); 38 } 39 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()); 52 } 53 54 PrerenderManagerFactory::~PrerenderManagerFactory() { 55 } 56 57 KeyedService* PrerenderManagerFactory::BuildServiceInstanceFor( 58 content::BrowserContext* browser_context) const { 59 Profile* profile = Profile::FromBrowserContext(browser_context); 60 CHECK(g_browser_process->prerender_tracker()); 61 if (base::SysInfo::IsLowEndDevice()) 62 return NULL; 63 64 PrerenderManager* prerender_manager = new PrerenderManager( 65 profile, g_browser_process->prerender_tracker()); 66 return prerender_manager; 67 } 68 69 content::BrowserContext* PrerenderManagerFactory::GetBrowserContextToUse( 70 content::BrowserContext* context) const { 71 return chrome::GetBrowserContextOwnInstanceInIncognito(context); 72 } 73 74 } // namespace prerender 75