| 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/cloud/component_cloud_policy_service.h" | |
| 18 #include "components/policy/core/common/cloud/resource_cache.h" | |
| 19 #include "components/policy/core/common/configuration_policy_provider.h" | 17 #include "components/policy/core/common/configuration_policy_provider.h" |
| 20 | 18 |
| 21 namespace policy { | 19 namespace policy { |
| 22 | 20 |
| 23 class PolicyMap; | 21 class PolicyMap; |
| 24 | 22 |
| 25 // Policy provider for a device-local account. Pulls policy from | 23 // Policy provider for a device-local account. Pulls policy from |
| 26 // DeviceLocalAccountPolicyService. Note that this implementation keeps | 24 // DeviceLocalAccountPolicyService. Note that this implementation keeps |
| 27 // functioning when the device-local account disappears from | 25 // functioning when the device-local account disappears from |
| 28 // DeviceLocalAccountPolicyService. The current policy will be kept in that case | 26 // DeviceLocalAccountPolicyService. The current policy will be kept in that case |
| 29 // and RefreshPolicies becomes a no-op. | 27 // and RefreshPolicies becomes a no-op. |
| 30 class DeviceLocalAccountPolicyProvider | 28 class DeviceLocalAccountPolicyProvider |
| 31 : public ConfigurationPolicyProvider, | 29 : public ConfigurationPolicyProvider, |
| 32 public DeviceLocalAccountPolicyService::Observer, | 30 public DeviceLocalAccountPolicyService::Observer { |
| 33 public ComponentCloudPolicyService::Delegate { | |
| 34 public: | 31 public: |
| 35 DeviceLocalAccountPolicyProvider( | 32 DeviceLocalAccountPolicyProvider( |
| 36 const std::string& user_id, | 33 const std::string& user_id, |
| 37 DeviceLocalAccountPolicyService* service, | 34 DeviceLocalAccountPolicyService* service, |
| 38 scoped_ptr<PolicyMap> chrome_policy_overrides); | 35 scoped_ptr<PolicyMap> chrome_policy_overrides); |
| 39 virtual ~DeviceLocalAccountPolicyProvider(); | 36 virtual ~DeviceLocalAccountPolicyProvider(); |
| 40 | 37 |
| 41 // Factory function to create and initialize a provider for |user_id|. Returns | 38 // Factory function to create and initialize a provider for |user_id|. Returns |
| 42 // NULL if |user_id| is not a device-local account or user policy isn't | 39 // NULL if |user_id| is not a device-local account or user policy isn't |
| 43 // applicable for user_id's user type. | 40 // applicable for user_id's user type. |
| 44 static scoped_ptr<DeviceLocalAccountPolicyProvider> Create( | 41 static scoped_ptr<DeviceLocalAccountPolicyProvider> Create( |
| 45 const std::string& user_id, | 42 const std::string& user_id, |
| 46 DeviceLocalAccountPolicyService* service); | 43 DeviceLocalAccountPolicyService* service); |
| 47 | 44 |
| 48 // ConfigurationPolicyProvider: | 45 // ConfigurationPolicyProvider: |
| 49 virtual void Init(SchemaRegistry* registry) OVERRIDE; | |
| 50 virtual bool IsInitializationComplete(PolicyDomain domain) const OVERRIDE; | 46 virtual bool IsInitializationComplete(PolicyDomain domain) const OVERRIDE; |
| 51 virtual void RefreshPolicies() OVERRIDE; | 47 virtual void RefreshPolicies() OVERRIDE; |
| 52 virtual void Shutdown() OVERRIDE; | |
| 53 | 48 |
| 54 // DeviceLocalAccountPolicyService::Observer: | 49 // DeviceLocalAccountPolicyService::Observer: |
| 55 virtual void OnPolicyUpdated(const std::string& user_id) OVERRIDE; | 50 virtual void OnPolicyUpdated(const std::string& user_id) OVERRIDE; |
| 56 virtual void OnDeviceLocalAccountsChanged() OVERRIDE; | 51 virtual void OnDeviceLocalAccountsChanged() OVERRIDE; |
| 57 virtual void OnBrokerShutdown( | |
| 58 DeviceLocalAccountPolicyBroker* broker) OVERRIDE; | |
| 59 | |
| 60 // ComponentCloudPolicyService::Delegate: | |
| 61 virtual void OnComponentCloudPolicyUpdated() OVERRIDE; | |
| 62 | 52 |
| 63 private: | 53 private: |
| 64 // Returns the broker for |user_id_| or NULL if not available. | 54 // Returns the broker for |user_id_| or NULL if not available. |
| 65 DeviceLocalAccountPolicyBroker* GetBroker(); | 55 DeviceLocalAccountPolicyBroker* GetBroker(); |
| 66 | 56 |
| 67 // Handles completion of policy refreshes and triggers the update callback. | 57 // Handles completion of policy refreshes and triggers the update callback. |
| 68 // |success| is true if the policy refresh was successful. | 58 // |success| is true if the policy refresh was successful. |
| 69 void ReportPolicyRefresh(bool success); | 59 void ReportPolicyRefresh(bool success); |
| 70 | 60 |
| 71 // Unless |waiting_for_policy_refresh_|, calls UpdatePolicy(), using the | 61 // Unless |waiting_for_policy_refresh_|, calls UpdatePolicy(), using the |
| 72 // policy from the broker if available or keeping the current policy. | 62 // policy from the broker if available or keeping the current policy. |
| 73 void UpdateFromBroker(); | 63 void UpdateFromBroker(); |
| 74 | 64 |
| 75 // Creates the |component_policy_service_| if it hasn't been created yet | |
| 76 // and all the dependencies are in place. | |
| 77 void MaybeCreateComponentPolicyService(); | |
| 78 | |
| 79 const std::string user_id_; | 65 const std::string user_id_; |
| 80 scoped_refptr<DeviceLocalAccountExternalDataManager> external_data_manager_; | 66 scoped_refptr<DeviceLocalAccountExternalDataManager> external_data_manager_; |
| 81 | 67 |
| 82 DeviceLocalAccountPolicyService* service_; | 68 DeviceLocalAccountPolicyService* service_; |
| 83 | 69 |
| 84 // A policy map providing overrides to apply on top of the Chrome policy | 70 // A policy map providing overrides to apply on top of the Chrome policy |
| 85 // received from |service_|. This is used to fix certain policies for public | 71 // received from |service_|. This is used to fix certain policies for public |
| 86 // sessions regardless of what's actually specified in policy. | 72 // sessions regardless of what's actually specified in policy. |
| 87 scoped_ptr<PolicyMap> chrome_policy_overrides_; | 73 scoped_ptr<PolicyMap> chrome_policy_overrides_; |
| 88 | 74 |
| 89 bool store_initialized_; | 75 bool store_initialized_; |
| 90 bool waiting_for_policy_refresh_; | 76 bool waiting_for_policy_refresh_; |
| 91 | 77 |
| 92 scoped_ptr<ComponentCloudPolicyService> component_policy_service_; | |
| 93 | |
| 94 base::WeakPtrFactory<DeviceLocalAccountPolicyProvider> weak_factory_; | 78 base::WeakPtrFactory<DeviceLocalAccountPolicyProvider> weak_factory_; |
| 95 | 79 |
| 96 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyProvider); | 80 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyProvider); |
| 97 }; | 81 }; |
| 98 | 82 |
| 99 } // namespace policy | 83 } // namespace policy |
| 100 | 84 |
| 101 #endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_PROVIDER_H
_ | 85 #endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_PROVIDER_H
_ |
| OLD | NEW |