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/user_network_configuration_updater_fact ory.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/user_network_configuration_updater.h" | |
12 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
13 #include "chrome/browser/policy/browser_policy_connector.h" | |
14 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" | |
15 #include "chrome/browser/policy/profile_policy_connector.h" | |
16 #include "chrome/browser/policy/profile_policy_connector_factory.h" | |
17 #include "chrome/browser/profiles/incognito_helpers.h" | |
18 #include "chrome/browser/profiles/profile.h" | |
19 #include "chrome/common/pref_names.h" | |
20 #include "chromeos/network/network_handler.h" | |
21 #include "chromeos/network/onc/onc_certificate_importer_impl.h" | |
22 #include "components/browser_context_keyed_service/browser_context_dependency_ma nager.h" | |
23 | |
24 namespace policy { | |
25 | |
26 // static | |
27 UserNetworkConfigurationUpdater* | |
28 UserNetworkConfigurationUpdaterFactory::GetForProfile(Profile* profile) { | |
29 return static_cast<UserNetworkConfigurationUpdater*>( | |
30 GetInstance()->GetServiceForBrowserContext(profile, true)); | |
31 } | |
32 | |
33 // static | |
34 UserNetworkConfigurationUpdaterFactory* | |
35 UserNetworkConfigurationUpdaterFactory::GetInstance() { | |
36 return Singleton<UserNetworkConfigurationUpdaterFactory>::get(); | |
37 } | |
38 | |
39 UserNetworkConfigurationUpdaterFactory::UserNetworkConfigurationUpdaterFactory() | |
40 : BrowserContextKeyedServiceFactory( | |
41 "UserNetworkConfigurationUpdater", | |
42 BrowserContextDependencyManager::GetInstance()) { | |
43 DependsOn(ProfilePolicyConnectorFactory::GetInstance()); | |
44 } | |
45 | |
46 UserNetworkConfigurationUpdaterFactory:: | |
47 ~UserNetworkConfigurationUpdaterFactory() {} | |
48 | |
49 content::BrowserContext* | |
50 UserNetworkConfigurationUpdaterFactory::GetBrowserContextToUse( | |
51 content::BrowserContext* context) const { | |
52 return chrome::GetBrowserContextRedirectedInIncognito(context); | |
53 } | |
54 | |
55 bool | |
56 UserNetworkConfigurationUpdaterFactory::ServiceIsCreatedWithBrowserContext() | |
57 const { | |
58 return true; | |
59 } | |
60 | |
61 bool UserNetworkConfigurationUpdaterFactory::ServiceIsNULLWhileTesting() const { | |
62 return true; | |
63 } | |
64 | |
65 BrowserContextKeyedService* | |
66 UserNetworkConfigurationUpdaterFactory::BuildServiceInstanceFor( | |
67 content::BrowserContext* context) const { | |
68 Profile* profile = static_cast<Profile*>(context); | |
69 if (chromeos::ProfileHelper::IsSigninProfile(profile)) | |
70 return NULL; | |
Joao da Silva
2013/11/04 10:19:57
Document why this is so
pneubeck (no reviews)
2013/11/04 14:15:30
Done.
| |
71 | |
72 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); | |
73 chromeos::User* user = user_manager->GetUserByProfile(profile); | |
74 DCHECK(user); | |
75 if (user != user_manager->GetPrimaryUser()) | |
76 return NULL; | |
Joao da Silva
2013/11/04 10:19:57
Document why this is so
pneubeck (no reviews)
2013/11/04 14:15:30
Done.
| |
77 | |
78 BrowserPolicyConnector* browser_connector = | |
79 g_browser_process->browser_policy_connector(); | |
80 | |
81 // Allow trusted certs from policy only for accounts with managed user | |
82 // affiliation, i.e users that are managed by the same domain as the device. | |
83 bool allow_trusted_certs_from_policy = | |
84 browser_connector->GetUserAffiliation(user->email()) == | |
85 USER_AFFILIATION_MANAGED && | |
86 user->GetType() == chromeos::User::USER_TYPE_REGULAR; | |
87 | |
88 ProfilePolicyConnector* profile_connector = | |
89 ProfilePolicyConnectorFactory::GetForProfile(profile); | |
90 | |
91 return UserNetworkConfigurationUpdater::CreateForUserPolicy( | |
92 allow_trusted_certs_from_policy, | |
93 *user, | |
94 scoped_ptr<chromeos::onc::CertificateImporter>( | |
95 new chromeos::onc::CertificateImporterImpl), | |
96 profile_connector->policy_service(), | |
97 chromeos::NetworkHandler::Get()->managed_network_configuration_handler()) | |
98 .release(); | |
99 } | |
100 | |
101 } // namespace policy | |
OLD | NEW |