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 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_PROVIDER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_PROVIDER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_PROVIDER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "chrome/browser/chromeos/policy/device_local_account_external_data_mana
ger.h" | 15 #include "chrome/browser/chromeos/policy/device_local_account_external_data_mana
ger.h" |
16 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" | 16 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" |
17 #include "components/policy/core/common/configuration_policy_provider.h" | 17 #include "components/policy/core/common/configuration_policy_provider.h" |
| 18 #include "components/user_manager/user_id.h" |
18 | 19 |
19 namespace policy { | 20 namespace policy { |
20 | 21 |
21 class PolicyMap; | 22 class PolicyMap; |
22 | 23 |
23 // Policy provider for a device-local account. Pulls policy from | 24 // Policy provider for a device-local account. Pulls policy from |
24 // DeviceLocalAccountPolicyService. Note that this implementation keeps | 25 // DeviceLocalAccountPolicyService. Note that this implementation keeps |
25 // functioning when the device-local account disappears from | 26 // functioning when the device-local account disappears from |
26 // DeviceLocalAccountPolicyService. The current policy will be kept in that case | 27 // DeviceLocalAccountPolicyService. The current policy will be kept in that case |
27 // and RefreshPolicies becomes a no-op. Policies for any installed extensions | 28 // and RefreshPolicies becomes a no-op. Policies for any installed extensions |
28 // will be kept as well in that case. | 29 // will be kept as well in that case. |
29 class DeviceLocalAccountPolicyProvider | 30 class DeviceLocalAccountPolicyProvider |
30 : public ConfigurationPolicyProvider, | 31 : public ConfigurationPolicyProvider, |
31 public DeviceLocalAccountPolicyService::Observer { | 32 public DeviceLocalAccountPolicyService::Observer { |
32 public: | 33 public: |
33 DeviceLocalAccountPolicyProvider( | 34 DeviceLocalAccountPolicyProvider( |
34 const std::string& user_id, | 35 const user_manager::UserID& user_id, |
35 DeviceLocalAccountPolicyService* service, | 36 DeviceLocalAccountPolicyService* service, |
36 scoped_ptr<PolicyMap> chrome_policy_overrides); | 37 scoped_ptr<PolicyMap> chrome_policy_overrides); |
37 ~DeviceLocalAccountPolicyProvider() override; | 38 ~DeviceLocalAccountPolicyProvider() override; |
38 | 39 |
39 // Factory function to create and initialize a provider for |user_id|. Returns | 40 // Factory function to create and initialize a provider for |user_id|. Returns |
40 // NULL if |user_id| is not a device-local account or user policy isn't | 41 // NULL if |user_id| is not a device-local account or user policy isn't |
41 // applicable for user_id's user type. | 42 // applicable for user_id's user type. |
42 static scoped_ptr<DeviceLocalAccountPolicyProvider> Create( | 43 static scoped_ptr<DeviceLocalAccountPolicyProvider> Create( |
43 const std::string& user_id, | 44 const user_manager::UserID& user_id, |
44 DeviceLocalAccountPolicyService* service); | 45 DeviceLocalAccountPolicyService* service); |
45 | 46 |
46 // ConfigurationPolicyProvider: | 47 // ConfigurationPolicyProvider: |
47 bool IsInitializationComplete(PolicyDomain domain) const override; | 48 bool IsInitializationComplete(PolicyDomain domain) const override; |
48 void RefreshPolicies() override; | 49 void RefreshPolicies() override; |
49 | 50 |
50 // DeviceLocalAccountPolicyService::Observer: | 51 // DeviceLocalAccountPolicyService::Observer: |
51 void OnPolicyUpdated(const std::string& user_id) override; | 52 void OnPolicyUpdated(const user_manager::UserID& user_id) override; |
52 void OnDeviceLocalAccountsChanged() override; | 53 void OnDeviceLocalAccountsChanged() override; |
53 | 54 |
54 private: | 55 private: |
55 // Returns the broker for |user_id_| or NULL if not available. | 56 // Returns the broker for |user_id_| or NULL if not available. |
56 DeviceLocalAccountPolicyBroker* GetBroker() const; | 57 DeviceLocalAccountPolicyBroker* GetBroker() const; |
57 | 58 |
58 // Handles completion of policy refreshes and triggers the update callback. | 59 // Handles completion of policy refreshes and triggers the update callback. |
59 // |success| is true if the policy refresh was successful. | 60 // |success| is true if the policy refresh was successful. |
60 void ReportPolicyRefresh(bool success); | 61 void ReportPolicyRefresh(bool success); |
61 | 62 |
62 // Unless |waiting_for_policy_refresh_|, calls UpdatePolicy(), using the | 63 // Unless |waiting_for_policy_refresh_|, calls UpdatePolicy(), using the |
63 // policy from the broker if available or keeping the current policy. | 64 // policy from the broker if available or keeping the current policy. |
64 void UpdateFromBroker(); | 65 void UpdateFromBroker(); |
65 | 66 |
66 const std::string user_id_; | 67 const user_manager::UserID user_id_; |
67 scoped_refptr<DeviceLocalAccountExternalDataManager> external_data_manager_; | 68 scoped_refptr<DeviceLocalAccountExternalDataManager> external_data_manager_; |
68 | 69 |
69 DeviceLocalAccountPolicyService* service_; | 70 DeviceLocalAccountPolicyService* service_; |
70 | 71 |
71 // A policy map providing overrides to apply on top of the Chrome policy | 72 // A policy map providing overrides to apply on top of the Chrome policy |
72 // received from |service_|. This is used to fix certain policies for public | 73 // received from |service_|. This is used to fix certain policies for public |
73 // sessions regardless of what's actually specified in policy. | 74 // sessions regardless of what's actually specified in policy. |
74 scoped_ptr<PolicyMap> chrome_policy_overrides_; | 75 scoped_ptr<PolicyMap> chrome_policy_overrides_; |
75 | 76 |
76 bool store_initialized_; | 77 bool store_initialized_; |
77 bool waiting_for_policy_refresh_; | 78 bool waiting_for_policy_refresh_; |
78 | 79 |
79 base::WeakPtrFactory<DeviceLocalAccountPolicyProvider> weak_factory_; | 80 base::WeakPtrFactory<DeviceLocalAccountPolicyProvider> weak_factory_; |
80 | 81 |
81 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyProvider); | 82 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyProvider); |
82 }; | 83 }; |
83 | 84 |
84 } // namespace policy | 85 } // namespace policy |
85 | 86 |
86 #endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_PROVIDER_H
_ | 87 #endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_PROVIDER_H
_ |
OLD | NEW |