OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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/chromeos/policy/policy_cert_service_factory.h" |
| 6 |
| 7 #include "base/memory/singleton.h" |
| 8 #include "chrome/browser/chromeos/policy/policy_cert_service.h" |
| 9 #include "chrome/browser/chromeos/policy/policy_cert_verifier.h" |
| 10 #include "chrome/browser/chromeos/policy/user_network_configuration_updater_fact
ory.h" |
| 11 #include "chrome/browser/profiles/incognito_helpers.h" |
| 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/common/pref_names.h" |
| 14 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" |
| 15 #include "components/user_prefs/pref_registry_syncable.h" |
| 16 |
| 17 namespace policy { |
| 18 |
| 19 // static |
| 20 PolicyCertService* PolicyCertServiceFactory::GetForProfile(Profile* profile) { |
| 21 return static_cast<PolicyCertService*>( |
| 22 GetInstance()->GetServiceForBrowserContext(profile, false)); |
| 23 } |
| 24 |
| 25 // static |
| 26 scoped_ptr<PolicyCertVerifier> PolicyCertServiceFactory::CreateForProfile( |
| 27 Profile* profile) { |
| 28 DCHECK(!GetInstance()->GetServiceForBrowserContext(profile, false)); |
| 29 PolicyCertService* service = static_cast<PolicyCertService*>( |
| 30 GetInstance()->GetServiceForBrowserContext(profile, true)); |
| 31 if (!service) |
| 32 return scoped_ptr<PolicyCertVerifier>(); |
| 33 return service->CreatePolicyCertVerifier(); |
| 34 } |
| 35 |
| 36 // static |
| 37 PolicyCertServiceFactory* PolicyCertServiceFactory::GetInstance() { |
| 38 return Singleton<PolicyCertServiceFactory>::get(); |
| 39 } |
| 40 |
| 41 PolicyCertServiceFactory::PolicyCertServiceFactory() |
| 42 : BrowserContextKeyedServiceFactory( |
| 43 "PolicyCertService", |
| 44 BrowserContextDependencyManager::GetInstance()) { |
| 45 DependsOn(UserNetworkConfigurationUpdaterFactory::GetInstance()); |
| 46 } |
| 47 |
| 48 PolicyCertServiceFactory::~PolicyCertServiceFactory() {} |
| 49 |
| 50 BrowserContextKeyedService* PolicyCertServiceFactory::BuildServiceInstanceFor( |
| 51 content::BrowserContext* context) const { |
| 52 Profile* profile = static_cast<Profile*>(context); |
| 53 UserNetworkConfigurationUpdater* net_conf_updater = |
| 54 UserNetworkConfigurationUpdaterFactory::GetForProfile(profile); |
| 55 if (!net_conf_updater) |
| 56 return NULL; |
| 57 |
| 58 // In case of usage of additional trust anchors from an incognito profile, the |
| 59 // prefs of the original profile have to be marked. |
| 60 return new PolicyCertService(net_conf_updater, |
| 61 profile->GetOriginalProfile()->GetPrefs()); |
| 62 } |
| 63 |
| 64 content::BrowserContext* PolicyCertServiceFactory::GetBrowserContextToUse( |
| 65 content::BrowserContext* context) const { |
| 66 return chrome::GetBrowserContextOwnInstanceInIncognito(context); |
| 67 } |
| 68 |
| 69 void PolicyCertServiceFactory::RegisterProfilePrefs( |
| 70 user_prefs::PrefRegistrySyncable* registry) { |
| 71 registry->RegisterBooleanPref( |
| 72 prefs::kUsedPolicyCertificatesOnce, |
| 73 false, |
| 74 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 75 } |
| 76 |
| 77 bool PolicyCertServiceFactory::ServiceIsNULLWhileTesting() const { |
| 78 return true; |
| 79 } |
| 80 |
| 81 } // namespace policy |
OLD | NEW |