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/network_policy_service_factory.h" |
| 6 |
| 7 #include "base/memory/singleton.h" |
| 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/chromeos/login/user.h" |
| 10 #include "chrome/browser/chromeos/login/user_manager.h" |
| 11 #include "chrome/browser/chromeos/policy/network_policy_service.h" |
| 12 #include "chrome/browser/policy/browser_policy_connector.h" |
| 13 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" |
| 14 #include "chrome/browser/policy/profile_policy_connector.h" |
| 15 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 16 #include "chrome/browser/profiles/incognito_helpers.h" |
| 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/common/pref_names.h" |
| 19 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" |
| 20 #include "components/user_prefs/pref_registry_syncable.h" |
| 21 |
| 22 namespace policy { |
| 23 |
| 24 // static |
| 25 NetworkPolicyService* NetworkPolicyServiceFactory::GetForProfile( |
| 26 Profile* profile) { |
| 27 return static_cast<NetworkPolicyService*>( |
| 28 GetInstance()->GetServiceForBrowserContext(profile, true)); |
| 29 } |
| 30 |
| 31 // static |
| 32 NetworkPolicyServiceFactory* NetworkPolicyServiceFactory::GetInstance() { |
| 33 return Singleton<NetworkPolicyServiceFactory>::get(); |
| 34 } |
| 35 |
| 36 NetworkPolicyServiceFactory::NetworkPolicyServiceFactory() |
| 37 : BrowserContextKeyedServiceFactory( |
| 38 "NetworkPolicyService", |
| 39 BrowserContextDependencyManager::GetInstance()) { |
| 40 DependsOn(ProfilePolicyConnectorFactory::GetInstance()); |
| 41 } |
| 42 |
| 43 NetworkPolicyServiceFactory::~NetworkPolicyServiceFactory() {} |
| 44 |
| 45 content::BrowserContext* NetworkPolicyServiceFactory::GetBrowserContextToUse( |
| 46 content::BrowserContext* context) const { |
| 47 return chrome::GetBrowserContextRedirectedInIncognito(context); |
| 48 } |
| 49 |
| 50 BrowserContextKeyedService* |
| 51 NetworkPolicyServiceFactory::BuildServiceInstanceFor( |
| 52 content::BrowserContext* context) const { |
| 53 Profile* profile = static_cast<Profile*>(context); |
| 54 if (profile->IsLoginProfile()) |
| 55 return NULL; |
| 56 |
| 57 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); |
| 58 chromeos::User* user = user_manager->GetUserByProfile(profile); |
| 59 DCHECK(user); |
| 60 if (user != user_manager->GetPrimaryUser()) |
| 61 return NULL; |
| 62 |
| 63 BrowserPolicyConnector* browser_connector = |
| 64 g_browser_process->browser_policy_connector(); |
| 65 |
| 66 // Allow trusted certs from policy only for accounts with managed user |
| 67 // affiliation, i.e users that are managed by the same domain as the device. |
| 68 bool allow_trusted_certs_from_policy = |
| 69 browser_connector->GetUserAffiliation(user->email()) == |
| 70 USER_AFFILIATION_MANAGED && |
| 71 user->GetType() == chromeos::User::USER_TYPE_REGULAR; |
| 72 |
| 73 ProfilePolicyConnector* profile_connector = |
| 74 ProfilePolicyConnectorFactory::GetForProfile(profile); |
| 75 |
| 76 return new NetworkPolicyService(allow_trusted_certs_from_policy, |
| 77 *user, |
| 78 profile->GetPrefs(), |
| 79 profile_connector->policy_service()); |
| 80 } |
| 81 |
| 82 void NetworkPolicyServiceFactory::RegisterProfilePrefs( |
| 83 user_prefs::PrefRegistrySyncable* registry) { |
| 84 registry->RegisterBooleanPref( |
| 85 prefs::kUsedPolicyCertificatesOnce, |
| 86 false, |
| 87 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 88 } |
| 89 |
| 90 } // namespace policy |
OLD | NEW |