Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(491)

Side by Side Diff: chrome/browser/chromeos/policy/user_network_configuration_updater_factory.cc

Issue 53923004: policy: Make UserNetworkConfigurationUpdater a BCKS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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; // On the login screen only device network policies apply.
71
72 chromeos::UserManager* user_manager = chromeos::UserManager::Get();
73 chromeos::User* user = user_manager->GetUserByProfile(profile);
74 DCHECK(user);
75 // Currently, only the network policy of the primary user is supported. See
76 // also http://crbug.com/310685 .
77 if (user != user_manager->GetPrimaryUser())
78 return NULL;
79
80 BrowserPolicyConnector* browser_connector =
81 g_browser_process->browser_policy_connector();
82
83 // Allow trusted certs from policy only for accounts with managed user
84 // affiliation, i.e users that are managed by the same domain as the device.
85 bool allow_trusted_certs_from_policy =
86 browser_connector->GetUserAffiliation(user->email()) ==
87 USER_AFFILIATION_MANAGED &&
88 user->GetType() == chromeos::User::USER_TYPE_REGULAR;
89
90 ProfilePolicyConnector* profile_connector =
91 ProfilePolicyConnectorFactory::GetForProfile(profile);
92
93 return UserNetworkConfigurationUpdater::CreateForUserPolicy(
94 allow_trusted_certs_from_policy,
95 *user,
96 scoped_ptr<chromeos::onc::CertificateImporter>(
97 new chromeos::onc::CertificateImporterImpl),
98 profile_connector->policy_service(),
99 chromeos::NetworkHandler::Get()->managed_network_configuration_handler())
100 .release();
101 }
102
103 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698