OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/policy/device_local_account_policy_provider.h" | 5 #include "chrome/browser/chromeos/policy/device_local_account_policy_provider.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/chromeos/policy/device_local_account.h" | 9 #include "chrome/browser/chromeos/policy/device_local_account.h" |
10 #include "chrome/browser/chromeos/policy/device_local_account_external_data_mana
ger.h" | 10 #include "chrome/browser/chromeos/policy/device_local_account_external_data_mana
ger.h" |
11 #include "chromeos/dbus/power_policy_controller.h" | 11 #include "chromeos/dbus/power_policy_controller.h" |
12 #include "components/policy/core/common/cloud/cloud_policy_core.h" | 12 #include "components/policy/core/common/cloud/cloud_policy_core.h" |
13 #include "components/policy/core/common/cloud/cloud_policy_service.h" | 13 #include "components/policy/core/common/cloud/cloud_policy_service.h" |
14 #include "components/policy/core/common/cloud/component_cloud_policy_service.h" | 14 #include "components/policy/core/common/cloud/component_cloud_policy_service.h" |
15 #include "components/policy/core/common/policy_bundle.h" | 15 #include "components/policy/core/common/policy_bundle.h" |
16 #include "components/policy/core/common/policy_map.h" | 16 #include "components/policy/core/common/policy_map.h" |
17 #include "components/policy/core/common/policy_namespace.h" | 17 #include "components/policy/core/common/policy_namespace.h" |
18 #include "policy/policy_constants.h" | 18 #include "policy/policy_constants.h" |
19 | 19 |
20 namespace policy { | 20 namespace policy { |
21 | 21 |
22 DeviceLocalAccountPolicyProvider::DeviceLocalAccountPolicyProvider( | 22 DeviceLocalAccountPolicyProvider::DeviceLocalAccountPolicyProvider( |
23 const std::string& user_id, | 23 const user_manager::UserID& user_id, |
24 DeviceLocalAccountPolicyService* service, | 24 DeviceLocalAccountPolicyService* service, |
25 scoped_ptr<PolicyMap> chrome_policy_overrides) | 25 scoped_ptr<PolicyMap> chrome_policy_overrides) |
26 : user_id_(user_id), | 26 : user_id_(user_id), |
27 service_(service), | 27 service_(service), |
28 chrome_policy_overrides_(chrome_policy_overrides.Pass()), | 28 chrome_policy_overrides_(chrome_policy_overrides.Pass()), |
29 store_initialized_(false), | 29 store_initialized_(false), |
30 waiting_for_policy_refresh_(false), | 30 waiting_for_policy_refresh_(false), |
31 weak_factory_(this) { | 31 weak_factory_(this) { |
32 service_->AddObserver(this); | 32 service_->AddObserver(this); |
33 UpdateFromBroker(); | 33 UpdateFromBroker(); |
34 } | 34 } |
35 | 35 |
36 DeviceLocalAccountPolicyProvider::~DeviceLocalAccountPolicyProvider() { | 36 DeviceLocalAccountPolicyProvider::~DeviceLocalAccountPolicyProvider() { |
37 service_->RemoveObserver(this); | 37 service_->RemoveObserver(this); |
38 } | 38 } |
39 | 39 |
40 // static | 40 // static |
41 scoped_ptr<DeviceLocalAccountPolicyProvider> | 41 scoped_ptr<DeviceLocalAccountPolicyProvider> |
42 DeviceLocalAccountPolicyProvider::Create( | 42 DeviceLocalAccountPolicyProvider::Create( |
43 const std::string& user_id, | 43 const user_manager::UserID& user_id, |
44 DeviceLocalAccountPolicyService* device_local_account_policy_service) { | 44 DeviceLocalAccountPolicyService* device_local_account_policy_service) { |
45 DeviceLocalAccount::Type type; | 45 DeviceLocalAccount::Type type; |
46 if (!device_local_account_policy_service || | 46 if (!device_local_account_policy_service || |
47 !IsDeviceLocalAccountUser(user_id, &type)) { | 47 !IsDeviceLocalAccountUser(user_id, &type)) { |
48 return scoped_ptr<DeviceLocalAccountPolicyProvider>(); | 48 return scoped_ptr<DeviceLocalAccountPolicyProvider>(); |
49 } | 49 } |
50 | 50 |
51 scoped_ptr<PolicyMap> chrome_policy_overrides; | 51 scoped_ptr<PolicyMap> chrome_policy_overrides; |
52 if (type == DeviceLocalAccount::TYPE_PUBLIC_SESSION) { | 52 if (type == DeviceLocalAccount::TYPE_PUBLIC_SESSION) { |
53 chrome_policy_overrides.reset(new PolicyMap()); | 53 chrome_policy_overrides.reset(new PolicyMap()); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 waiting_for_policy_refresh_ = true; | 112 waiting_for_policy_refresh_ = true; |
113 broker->core()->service()->RefreshPolicy( | 113 broker->core()->service()->RefreshPolicy( |
114 base::Bind(&DeviceLocalAccountPolicyProvider::ReportPolicyRefresh, | 114 base::Bind(&DeviceLocalAccountPolicyProvider::ReportPolicyRefresh, |
115 weak_factory_.GetWeakPtr())); | 115 weak_factory_.GetWeakPtr())); |
116 } else { | 116 } else { |
117 UpdateFromBroker(); | 117 UpdateFromBroker(); |
118 } | 118 } |
119 } | 119 } |
120 | 120 |
121 void DeviceLocalAccountPolicyProvider::OnPolicyUpdated( | 121 void DeviceLocalAccountPolicyProvider::OnPolicyUpdated( |
122 const std::string& user_id) { | 122 const user_manager::UserID& user_id) { |
123 if (user_id == user_id_) | 123 if (user_id == user_id_) |
124 UpdateFromBroker(); | 124 UpdateFromBroker(); |
125 } | 125 } |
126 | 126 |
127 void DeviceLocalAccountPolicyProvider::OnDeviceLocalAccountsChanged() { | 127 void DeviceLocalAccountPolicyProvider::OnDeviceLocalAccountsChanged() { |
128 UpdateFromBroker(); | 128 UpdateFromBroker(); |
129 } | 129 } |
130 | 130 |
131 DeviceLocalAccountPolicyBroker* DeviceLocalAccountPolicyProvider::GetBroker() | 131 DeviceLocalAccountPolicyBroker* DeviceLocalAccountPolicyProvider::GetBroker() |
132 const { | 132 const { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 const PolicyMap::Entry& entry = it->second; | 172 const PolicyMap::Entry& entry = it->second; |
173 chrome_policy.Set( | 173 chrome_policy.Set( |
174 it->first, entry.level, entry.scope, entry.value->DeepCopy(), NULL); | 174 it->first, entry.level, entry.scope, entry.value->DeepCopy(), NULL); |
175 } | 175 } |
176 } | 176 } |
177 | 177 |
178 UpdatePolicy(bundle.Pass()); | 178 UpdatePolicy(bundle.Pass()); |
179 } | 179 } |
180 | 180 |
181 } // namespace policy | 181 } // namespace policy |
OLD | NEW |