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_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_SERVICE_H_ |
6 #define CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_SERVICE_H_ | 6 #define CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_SERVICE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/callback_forward.h" | |
13 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
14 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" |
15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
16 #include "chrome/browser/chromeos/settings/device_settings_service.h" | |
17 #include "chrome/browser/policy/cloud/cloud_policy_core.h" | 16 #include "chrome/browser/policy/cloud/cloud_policy_core.h" |
18 #include "chrome/browser/policy/cloud/cloud_policy_store.h" | 17 #include "chrome/browser/policy/cloud/cloud_policy_store.h" |
| 18 #include "content/public/browser/notification_observer.h" |
19 | 19 |
20 namespace chromeos { | 20 namespace chromeos { |
| 21 class CrosSettings; |
| 22 class DeviceSettingsService; |
21 class SessionManagerClient; | 23 class SessionManagerClient; |
22 } | 24 } |
23 | 25 |
24 namespace policy { | 26 namespace policy { |
25 | 27 |
26 class CloudPolicyClient; | 28 class CloudPolicyClient; |
27 class DeviceLocalAccountPolicyStore; | 29 class DeviceLocalAccountPolicyStore; |
28 class DeviceManagementService; | 30 class DeviceManagementService; |
29 | 31 |
30 // The main switching central that downloads, caches, refreshes, etc. policy for | 32 // The main switching central that downloads, caches, refreshes, etc. policy for |
31 // a single device-local account. | 33 // a single device-local account. |
32 class DeviceLocalAccountPolicyBroker { | 34 class DeviceLocalAccountPolicyBroker { |
33 public: | 35 public: |
34 explicit DeviceLocalAccountPolicyBroker( | 36 explicit DeviceLocalAccountPolicyBroker( |
| 37 const std::string& user_id, |
35 scoped_ptr<DeviceLocalAccountPolicyStore> store); | 38 scoped_ptr<DeviceLocalAccountPolicyStore> store); |
36 ~DeviceLocalAccountPolicyBroker(); | 39 ~DeviceLocalAccountPolicyBroker(); |
37 | 40 |
38 const std::string& account_id() const; | 41 const std::string& user_id() const { return user_id_; } |
39 | 42 |
40 CloudPolicyCore* core() { return &core_; } | 43 CloudPolicyCore* core() { return &core_; } |
41 const CloudPolicyCore* core() const { return &core_; } | 44 const CloudPolicyCore* core() const { return &core_; } |
42 | 45 |
43 // Establish a cloud connection for the service. | 46 // Establish a cloud connection for the service. |
44 void Connect(scoped_ptr<CloudPolicyClient> client); | 47 void Connect(scoped_ptr<CloudPolicyClient> client); |
45 | 48 |
46 // Destroy the cloud connection, stopping policy refreshes. | 49 // Destroy the cloud connection, stopping policy refreshes. |
47 void Disconnect(); | 50 void Disconnect(); |
48 | 51 |
49 // Reads the refresh delay from policy and configures the refresh scheduler. | 52 // Reads the refresh delay from policy and configures the refresh scheduler. |
50 void UpdateRefreshDelay(); | 53 void UpdateRefreshDelay(); |
51 | 54 |
52 // Retrieves the display name for the account as stored in policy. Returns an | 55 // Retrieves the display name for the account as stored in policy. Returns an |
53 // empty string if the policy is not present. | 56 // empty string if the policy is not present. |
54 std::string GetDisplayName() const; | 57 std::string GetDisplayName() const; |
55 | 58 |
56 private: | 59 private: |
57 const std::string account_id_; | 60 const std::string user_id_; |
58 scoped_ptr<DeviceLocalAccountPolicyStore> store_; | 61 scoped_ptr<DeviceLocalAccountPolicyStore> store_; |
59 CloudPolicyCore core_; | 62 CloudPolicyCore core_; |
60 | 63 |
61 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyBroker); | 64 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyBroker); |
62 }; | 65 }; |
63 | 66 |
64 // Manages user policy blobs for device-local accounts present on the device. | 67 // Manages user policy blobs for device-local accounts present on the device. |
65 // The actual policy blobs are brokered by session_manager (to prevent file | 68 // The actual policy blobs are brokered by session_manager (to prevent file |
66 // manipulation), and we're making signature checks on the policy blobs to | 69 // manipulation), and we're making signature checks on the policy blobs to |
67 // ensure they're issued by the device owner. | 70 // ensure they're issued by the device owner. |
68 class DeviceLocalAccountPolicyService | 71 class DeviceLocalAccountPolicyService : public content::NotificationObserver, |
69 : public chromeos::DeviceSettingsService::Observer, | 72 public CloudPolicyStore::Observer { |
70 public CloudPolicyStore::Observer { | |
71 public: | 73 public: |
72 // Interface for interested parties to observe policy changes. | 74 // Interface for interested parties to observe policy changes. |
73 class Observer { | 75 class Observer { |
74 public: | 76 public: |
75 virtual ~Observer() {} | 77 virtual ~Observer() {} |
76 | 78 |
77 // Policy for the given account has changed. | 79 // Policy for the given |user_id| has changed. |
78 virtual void OnPolicyUpdated(const std::string& account_id) = 0; | 80 virtual void OnPolicyUpdated(const std::string& user_id) = 0; |
79 | 81 |
80 // The list of accounts has been updated. | 82 // The list of accounts has been updated. |
81 virtual void OnDeviceLocalAccountsChanged() = 0; | 83 virtual void OnDeviceLocalAccountsChanged() = 0; |
82 }; | 84 }; |
83 | 85 |
84 DeviceLocalAccountPolicyService( | 86 DeviceLocalAccountPolicyService( |
85 chromeos::SessionManagerClient* session_manager_client, | 87 chromeos::SessionManagerClient* session_manager_client, |
86 chromeos::DeviceSettingsService* device_settings_service); | 88 chromeos::DeviceSettingsService* device_settings_service, |
| 89 chromeos::CrosSettings* cros_settings); |
87 virtual ~DeviceLocalAccountPolicyService(); | 90 virtual ~DeviceLocalAccountPolicyService(); |
88 | 91 |
89 // Initializes the cloud policy service connection. | 92 // Initializes the cloud policy service connection. |
90 void Connect(DeviceManagementService* device_management_service); | 93 void Connect(DeviceManagementService* device_management_service); |
91 | 94 |
92 // Prevents further policy fetches from the cloud. | 95 // Prevents further policy fetches from the cloud. |
93 void Disconnect(); | 96 void Disconnect(); |
94 | 97 |
95 // Get the policy broker for a given account. Returns NULL if that account is | 98 // Get the policy broker for a given |user_id|. Returns NULL if that |user_id| |
96 // not valid. | 99 // does not belong to an existing device-local account. |
97 DeviceLocalAccountPolicyBroker* GetBrokerForAccount( | 100 DeviceLocalAccountPolicyBroker* GetBrokerForUser(const std::string& user_id); |
98 const std::string& account_id); | |
99 | 101 |
100 // Indicates whether policy has been successfully fetched for the given | 102 // Indicates whether policy has been successfully fetched for the given |
101 // account. | 103 // |user_id|. |
102 bool IsPolicyAvailableForAccount(const std::string& account_id); | 104 bool IsPolicyAvailableForUser(const std::string& user_id); |
103 | 105 |
104 void AddObserver(Observer* observer); | 106 void AddObserver(Observer* observer); |
105 void RemoveObserver(Observer* observer); | 107 void RemoveObserver(Observer* observer); |
106 | 108 |
107 // DeviceSettingsService::Observer: | 109 // NotificationObserver: |
108 virtual void OwnershipStatusChanged() OVERRIDE; | 110 virtual void Observe(int type, |
109 virtual void DeviceSettingsUpdated() OVERRIDE; | 111 const content::NotificationSource& source, |
| 112 const content::NotificationDetails& details) OVERRIDE; |
110 | 113 |
111 // CloudPolicyStore::Observer: | 114 // CloudPolicyStore::Observer: |
112 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE; | 115 virtual void OnStoreLoaded(CloudPolicyStore* store) OVERRIDE; |
113 virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE; | 116 virtual void OnStoreError(CloudPolicyStore* store) OVERRIDE; |
114 | 117 |
115 private: | 118 private: |
116 typedef std::map<std::string, DeviceLocalAccountPolicyBroker*> | 119 struct PolicyBrokerWrapper { |
117 PolicyBrokerMap; | 120 PolicyBrokerWrapper(); |
| 121 |
| 122 // Return the |broker|, creating it first if necessary. |
| 123 DeviceLocalAccountPolicyBroker* GetBroker(); |
| 124 |
| 125 // Fire up the cloud connection for fetching policy for the account from the |
| 126 // cloud if this is an enterprise-managed device. |
| 127 void ConnectIfPossible(); |
| 128 |
| 129 // Destroy the cloud connection. |
| 130 void Disconnect(); |
| 131 |
| 132 // Delete the broker. |
| 133 void DeleteBroker(); |
| 134 |
| 135 std::string user_id; |
| 136 std::string account_id; |
| 137 DeviceLocalAccountPolicyService* parent; |
| 138 DeviceLocalAccountPolicyBroker* broker; |
| 139 }; |
| 140 |
| 141 typedef std::map<std::string, PolicyBrokerWrapper> PolicyBrokerMap; |
118 | 142 |
119 // Re-queries the list of defined device-local accounts from device settings | 143 // Re-queries the list of defined device-local accounts from device settings |
120 // and updates |policy_brokers_| to match that list. | 144 // and updates |policy_brokers_| to match that list. |
121 void UpdateAccountList( | 145 void UpdateAccountList(); |
122 const enterprise_management::ChromeDeviceSettingsProto& device_settings); | |
123 | |
124 // Creates a broker for the given account ID. | |
125 scoped_ptr<DeviceLocalAccountPolicyBroker> CreateBroker( | |
126 const std::string& account_id); | |
127 | 146 |
128 // Deletes brokers in |map| and clears it. | 147 // Deletes brokers in |map| and clears it. |
129 void DeleteBrokers(PolicyBrokerMap* map); | 148 void DeleteBrokers(PolicyBrokerMap* map); |
130 | 149 |
131 // Find the broker for a given |store|. Returns NULL if |store| is unknown. | 150 // Find the broker for a given |store|. Returns NULL if |store| is unknown. |
132 DeviceLocalAccountPolicyBroker* GetBrokerForStore(CloudPolicyStore* store); | 151 DeviceLocalAccountPolicyBroker* GetBrokerForStore(CloudPolicyStore* store); |
133 | 152 |
134 // Creates and initializes a cloud policy client for |account_id|. Returns | |
135 // NULL if the device doesn't have credentials in device settings (i.e. is not | |
136 // enterprise-enrolled). | |
137 scoped_ptr<CloudPolicyClient> CreateClientForAccount( | |
138 const std::string& account_id); | |
139 | |
140 chromeos::SessionManagerClient* session_manager_client_; | 153 chromeos::SessionManagerClient* session_manager_client_; |
141 chromeos::DeviceSettingsService* device_settings_service_; | 154 chromeos::DeviceSettingsService* device_settings_service_; |
| 155 chromeos::CrosSettings* cros_settings_; |
142 | 156 |
143 DeviceManagementService* device_management_service_; | 157 DeviceManagementService* device_management_service_; |
144 | 158 |
145 // The device-local account policy brokers, keyed by account ID. | 159 // The device-local account policy brokers, keyed by user ID. |
146 PolicyBrokerMap policy_brokers_; | 160 PolicyBrokerMap policy_brokers_; |
147 | 161 |
148 ObserverList<Observer, true> observers_; | 162 ObserverList<Observer, true> observers_; |
149 | 163 |
| 164 // Weak pointer factory for cros_settings_->PrepareTrustedValues() callbacks. |
| 165 base::WeakPtrFactory<DeviceLocalAccountPolicyService> |
| 166 cros_settings_callback_factory_; |
| 167 |
150 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyService); | 168 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyService); |
151 }; | 169 }; |
152 | 170 |
153 } // namespace policy | 171 } // namespace policy |
154 | 172 |
155 #endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_SERVICE_H_ | 173 #endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_SERVICE_H_ |
OLD | NEW |