1 // Copyright (c) 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/policy/profile_policy_connector.h"
10 #include "base/logging.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/policy/browser_policy_connector.h"
13 #include "components/policy/core/common/cloud/cloud_policy_manager.h"
14 #include "components/policy/core/common/configuration_policy_provider.h"
15 #include "components/policy/core/common/forwarding_policy_provider.h"
16 #include "components/policy/core/common/policy_service_impl.h"
18 #if defined(OS_CHROMEOS)
19 #include "chrome/browser/chromeos/login/user.h"
20 #include "chrome/browser/chromeos/login/user_manager.h"
21 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
22 #include "chrome/browser/chromeos/policy/device_local_account_policy_provider.h"
23 #include "chrome/browser/chromeos/policy/login_profile_policy_provider.h"
28 ProfilePolicyConnector::ProfilePolicyConnector()
29 #if defined(OS_CHROMEOS)
30 : is_primary_user_(false)
34 ProfilePolicyConnector::~ProfilePolicyConnector() {}
36 void ProfilePolicyConnector::Init(
37 bool force_immediate_load
,
38 #if defined(OS_CHROMEOS)
39 const chromeos::User
* user
,
41 SchemaRegistry
* schema_registry
,
42 CloudPolicyManager
* user_cloud_policy_manager
) {
43 // |providers| contains a list of the policy providers available for the
44 // PolicyService of this connector, in decreasing order of priority.
46 // Note: all the providers appended to this vector must eventually become
47 // initialized for every policy domain, otherwise some subsystems will never
48 // use the policies exposed by the PolicyService!
49 // The default ConfigurationPolicyProvider::IsInitializationComplete()
50 // result is true, so take care if a provider overrides that.
51 std::vector
<ConfigurationPolicyProvider
*> providers
;
53 BrowserPolicyConnector
* connector
=
54 g_browser_process
->browser_policy_connector();
56 if (connector
->GetPlatformProvider()) {
57 forwarding_policy_provider_
.reset(
58 new ForwardingPolicyProvider(connector
->GetPlatformProvider()));
59 forwarding_policy_provider_
->Init(schema_registry
);
60 providers
.push_back(forwarding_policy_provider_
.get());
63 #if defined(OS_CHROMEOS)
64 if (connector
->GetDeviceCloudPolicyManager())
65 providers
.push_back(connector
->GetDeviceCloudPolicyManager());
68 if (user_cloud_policy_manager
)
69 providers
.push_back(user_cloud_policy_manager
);
71 #if defined(OS_CHROMEOS)
73 DCHECK(schema_registry
);
74 // This case occurs for the signin profile.
75 special_user_policy_provider_
.reset(
76 new LoginProfilePolicyProvider(connector
->GetPolicyService()));
77 special_user_policy_provider_
->Init(schema_registry
);
79 // |user| should never be NULL except for the signin profile.
80 is_primary_user_
= user
== chromeos::UserManager::Get()->GetPrimaryUser();
81 if (user
->GetType() == chromeos::User::USER_TYPE_PUBLIC_ACCOUNT
) {
82 InitializeDeviceLocalAccountPolicyProvider(user
->email(),
86 if (special_user_policy_provider_
)
87 providers
.push_back(special_user_policy_provider_
.get());
90 policy_service_
.reset(new PolicyServiceImpl(providers
));
92 #if defined(OS_CHROMEOS)
93 if (is_primary_user_
) {
94 if (user_cloud_policy_manager
)
95 connector
->SetUserPolicyDelegate(user_cloud_policy_manager
);
96 else if (special_user_policy_provider_
)
97 connector
->SetUserPolicyDelegate(special_user_policy_provider_
.get());
102 void ProfilePolicyConnector::InitForTesting(scoped_ptr
<PolicyService
> service
) {
103 policy_service_
= service
.Pass();
106 void ProfilePolicyConnector::Shutdown() {
107 #if defined(OS_CHROMEOS)
108 if (is_primary_user_
)
109 g_browser_process
->browser_policy_connector()->SetUserPolicyDelegate(NULL
);
110 if (special_user_policy_provider_
)
111 special_user_policy_provider_
->Shutdown();
113 if (forwarding_policy_provider_
)
114 forwarding_policy_provider_
->Shutdown();
117 #if defined(OS_CHROMEOS)
118 void ProfilePolicyConnector::InitializeDeviceLocalAccountPolicyProvider(
119 const std::string
& username
,
120 SchemaRegistry
* schema_registry
) {
121 BrowserPolicyConnector
* connector
=
122 g_browser_process
->browser_policy_connector();
123 DeviceLocalAccountPolicyService
* device_local_account_policy_service
=
124 connector
->GetDeviceLocalAccountPolicyService();
125 if (!device_local_account_policy_service
)
127 special_user_policy_provider_
.reset(new DeviceLocalAccountPolicyProvider(
128 username
, device_local_account_policy_service
));
129 special_user_policy_provider_
->Init(schema_registry
);
133 } // namespace policy