Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / prerender / prerender_manager_factory.cc
blobf7dc4d0f8a7ce19a1b83fe98bc7e109e8fb8100f
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"
9 #endif
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"
25 #endif
27 #if defined(OS_ANDROID)
28 #include "chrome/browser/android/prerender_condition_platform.h"
29 #endif
31 namespace prerender {
33 // static
34 PrerenderManager* PrerenderManagerFactory::GetForProfile(
35 Profile* profile) {
36 TRACE_EVENT0("browser", "PrerenderManagerFactory::GetForProfile")
37 if (!PrerenderManager::IsPrerenderingPossible())
38 return NULL;
39 return static_cast<PrerenderManager*>(
40 GetInstance()->GetServiceForBrowserContext(profile, true));
43 // static
44 PrerenderManagerFactory* PrerenderManagerFactory::GetInstance() {
45 return Singleton<PrerenderManagerFactory>::get();
48 PrerenderManagerFactory::PrerenderManagerFactory()
49 : BrowserContextKeyedServiceFactory(
50 "PrerenderManager",
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())
68 return NULL;
69 #endif
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);
76 #endif
77 #if defined(OS_ANDROID)
78 prerender_manager->AddCondition(new android::PrerenderConditionPlatform(
79 browser_context));
80 #endif
81 return prerender_manager;
84 content::BrowserContext* PrerenderManagerFactory::GetBrowserContextToUse(
85 content::BrowserContext* context) const {
86 return chrome::GetBrowserContextOwnInstanceInIncognito(context);
89 } // namespace prerender