device_local_account_policy_provider.h revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
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/weak_ptr.h" 14#include "chrome/browser/chromeos/policy/device_local_account_external_data_manager.h" 15#include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" 16#include "components/policy/core/common/configuration_policy_provider.h" 17 18namespace policy { 19 20// Policy provider for a device-local account. Pulls policy from 21// DeviceLocalAccountPolicyService. Note that this implementation keeps 22// functioning when the device-local account disappears from 23// DeviceLocalAccountPolicyService. The current policy will be kept in that case 24// and RefreshPolicies becomes a no-op. 25class DeviceLocalAccountPolicyProvider 26 : public ConfigurationPolicyProvider, 27 public DeviceLocalAccountPolicyService::Observer { 28 public: 29 DeviceLocalAccountPolicyProvider(const std::string& user_id, 30 DeviceLocalAccountPolicyService* service); 31 virtual ~DeviceLocalAccountPolicyProvider(); 32 33 // ConfigurationPolicyProvider: 34 virtual bool IsInitializationComplete(PolicyDomain domain) const OVERRIDE; 35 virtual void RefreshPolicies() OVERRIDE; 36 37 // DeviceLocalAccountPolicyService::Observer: 38 virtual void OnPolicyUpdated(const std::string& user_id) OVERRIDE; 39 virtual void OnDeviceLocalAccountsChanged() OVERRIDE; 40 41 private: 42 // Returns the broker for |user_id_| or NULL if not available. 43 DeviceLocalAccountPolicyBroker* GetBroker(); 44 45 // Handles completion of policy refreshes and triggers the update callback. 46 // |success| is true if the policy refresh was successful. 47 void ReportPolicyRefresh(bool success); 48 49 // Unless |waiting_for_policy_refresh_|, calls UpdatePolicy(), using the 50 // policy from the broker if available or keeping the current policy. 51 void UpdateFromBroker(); 52 53 const std::string user_id_; 54 scoped_refptr<DeviceLocalAccountExternalDataManager> external_data_manager_; 55 56 DeviceLocalAccountPolicyService* service_; 57 58 bool store_initialized_; 59 bool waiting_for_policy_refresh_; 60 61 base::WeakPtrFactory<DeviceLocalAccountPolicyProvider> weak_factory_; 62 63 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyProvider); 64}; 65 66} // namespace policy 67 68#endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_PROVIDER_H_ 69