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