Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / policy / user_network_configuration_updater_factory.cc
blobfed3c77197ef7f193150a2eda0bbd2d8ebbe1304
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.
5 #include "chrome/browser/chromeos/policy/user_network_configuration_updater_factory.h"
7 #include "base/memory/singleton.h"
8 #include "chrome/browser/chromeos/login/user.h"
9 #include "chrome/browser/chromeos/login/user_manager.h"
10 #include "chrome/browser/chromeos/policy/user_network_configuration_updater.h"
11 #include "chrome/browser/chromeos/profiles/profile_helper.h"
12 #include "chrome/browser/policy/profile_policy_connector.h"
13 #include "chrome/browser/policy/profile_policy_connector_factory.h"
14 #include "chrome/browser/profiles/incognito_helpers.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/common/pref_names.h"
17 #include "chromeos/network/network_handler.h"
18 #include "chromeos/network/onc/onc_certificate_importer_impl.h"
19 #include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
20 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
22 namespace policy {
24 // static
25 UserNetworkConfigurationUpdater*
26 UserNetworkConfigurationUpdaterFactory::GetForProfile(Profile* profile) {
27 return static_cast<UserNetworkConfigurationUpdater*>(
28 GetInstance()->GetServiceForBrowserContext(profile, true));
31 // static
32 UserNetworkConfigurationUpdaterFactory*
33 UserNetworkConfigurationUpdaterFactory::GetInstance() {
34 return Singleton<UserNetworkConfigurationUpdaterFactory>::get();
37 UserNetworkConfigurationUpdaterFactory::UserNetworkConfigurationUpdaterFactory()
38 : BrowserContextKeyedServiceFactory(
39 "UserNetworkConfigurationUpdater",
40 BrowserContextDependencyManager::GetInstance()) {
41 DependsOn(ProfilePolicyConnectorFactory::GetInstance());
44 UserNetworkConfigurationUpdaterFactory::
45 ~UserNetworkConfigurationUpdaterFactory() {}
47 content::BrowserContext*
48 UserNetworkConfigurationUpdaterFactory::GetBrowserContextToUse(
49 content::BrowserContext* context) const {
50 return chrome::GetBrowserContextRedirectedInIncognito(context);
53 bool
54 UserNetworkConfigurationUpdaterFactory::ServiceIsCreatedWithBrowserContext()
55 const {
56 return true;
59 bool UserNetworkConfigurationUpdaterFactory::ServiceIsNULLWhileTesting() const {
60 return true;
63 BrowserContextKeyedService*
64 UserNetworkConfigurationUpdaterFactory::BuildServiceInstanceFor(
65 content::BrowserContext* context) const {
66 Profile* profile = static_cast<Profile*>(context);
67 if (chromeos::ProfileHelper::IsSigninProfile(profile))
68 return NULL; // On the login screen only device network policies apply.
70 chromeos::UserManager* user_manager = chromeos::UserManager::Get();
71 chromeos::User* user = user_manager->GetUserByProfile(profile);
72 DCHECK(user);
73 // Currently, only the network policy of the primary user is supported. See
74 // also http://crbug.com/310685 .
75 if (user != user_manager->GetPrimaryUser())
76 return NULL;
78 const bool allow_trusted_certs_from_policy =
79 user->GetType() == chromeos::User::USER_TYPE_REGULAR;
81 ProfilePolicyConnector* profile_connector =
82 ProfilePolicyConnectorFactory::GetForProfile(profile);
84 return UserNetworkConfigurationUpdater::CreateForUserPolicy(
85 allow_trusted_certs_from_policy,
86 *user,
87 scoped_ptr<chromeos::onc::CertificateImporter>(
88 new chromeos::onc::CertificateImporterImpl),
89 profile_connector->policy_service(),
90 chromeos::NetworkHandler::Get()->managed_network_configuration_handler())
91 .release();
94 } // namespace policy