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/policy/user_network_configuration_updater.h"
9 #include "chrome/browser/chromeos/profiles/profile_helper.h"
10 #include "chrome/browser/policy/profile_policy_connector.h"
11 #include "chrome/browser/policy/profile_policy_connector_factory.h"
12 #include "chrome/browser/profiles/incognito_helpers.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chromeos/network/network_handler.h"
15 #include "components/keyed_service/content/browser_context_dependency_manager.h"
16 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
17 #include "components/user_manager/user.h"
18 #include "components/user_manager/user_manager.h"
23 UserNetworkConfigurationUpdater
*
24 UserNetworkConfigurationUpdaterFactory::GetForProfile(Profile
* profile
) {
25 return static_cast<UserNetworkConfigurationUpdater
*>(
26 GetInstance()->GetServiceForBrowserContext(profile
, true));
30 UserNetworkConfigurationUpdaterFactory
*
31 UserNetworkConfigurationUpdaterFactory::GetInstance() {
32 return base::Singleton
<UserNetworkConfigurationUpdaterFactory
>::get();
35 UserNetworkConfigurationUpdaterFactory::UserNetworkConfigurationUpdaterFactory()
36 : BrowserContextKeyedServiceFactory(
37 "UserNetworkConfigurationUpdater",
38 BrowserContextDependencyManager::GetInstance()) {
39 DependsOn(ProfilePolicyConnectorFactory::GetInstance());
42 UserNetworkConfigurationUpdaterFactory::
43 ~UserNetworkConfigurationUpdaterFactory() {}
45 content::BrowserContext
*
46 UserNetworkConfigurationUpdaterFactory::GetBrowserContextToUse(
47 content::BrowserContext
* context
) const {
48 return chrome::GetBrowserContextRedirectedInIncognito(context
);
52 UserNetworkConfigurationUpdaterFactory::ServiceIsCreatedWithBrowserContext()
57 bool UserNetworkConfigurationUpdaterFactory::ServiceIsNULLWhileTesting() const {
61 KeyedService
* UserNetworkConfigurationUpdaterFactory::BuildServiceInstanceFor(
62 content::BrowserContext
* context
) const {
63 Profile
* profile
= Profile::FromBrowserContext(context
);
64 if (chromeos::ProfileHelper::IsSigninProfile(profile
))
65 return NULL
; // On the login screen only device network policies apply.
67 const user_manager::User
* user
=
68 chromeos::ProfileHelper::Get()->GetUserByProfile(profile
);
70 // Currently, only the network policy of the primary user is supported. See
71 // also http://crbug.com/310685 .
72 if (user
!= user_manager::UserManager::Get()->GetPrimaryUser())
75 const bool allow_trusted_certs_from_policy
= user
->HasGaiaAccount();
77 ProfilePolicyConnector
* profile_connector
=
78 ProfilePolicyConnectorFactory::GetForBrowserContext(context
);
80 return UserNetworkConfigurationUpdater::CreateForUserPolicy(
82 allow_trusted_certs_from_policy
,
84 profile_connector
->policy_service(),
85 chromeos::NetworkHandler::Get()->managed_network_configuration_handler())