Home | History | Annotate | Download | only in policy
      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 
     19 namespace policy {
     20 
     21 class 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. Policies for any installed extensions
     28 // will be kept as well in that case.
     29 class DeviceLocalAccountPolicyProvider
     30     : public ConfigurationPolicyProvider,
     31       public DeviceLocalAccountPolicyService::Observer {
     32  public:
     33   DeviceLocalAccountPolicyProvider(
     34       const std::string& user_id,
     35       DeviceLocalAccountPolicyService* service,
     36       scoped_ptr<PolicyMap> chrome_policy_overrides);
     37   virtual ~DeviceLocalAccountPolicyProvider();
     38 
     39   // 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   // applicable for user_id's user type.
     42   static scoped_ptr<DeviceLocalAccountPolicyProvider> Create(
     43       const std::string& user_id,
     44       DeviceLocalAccountPolicyService* service);
     45 
     46   // ConfigurationPolicyProvider:
     47   virtual bool IsInitializationComplete(PolicyDomain domain) const OVERRIDE;
     48   virtual void RefreshPolicies() OVERRIDE;
     49 
     50   // DeviceLocalAccountPolicyService::Observer:
     51   virtual void OnPolicyUpdated(const std::string& user_id) OVERRIDE;
     52   virtual void OnDeviceLocalAccountsChanged() OVERRIDE;
     53 
     54  private:
     55   // Returns the broker for |user_id_| or NULL if not available.
     56   DeviceLocalAccountPolicyBroker* GetBroker() const;
     57 
     58   // Handles completion of policy refreshes and triggers the update callback.
     59   // |success| is true if the policy refresh was successful.
     60   void ReportPolicyRefresh(bool success);
     61 
     62   // Unless |waiting_for_policy_refresh_|, calls UpdatePolicy(), using the
     63   // policy from the broker if available or keeping the current policy.
     64   void UpdateFromBroker();
     65 
     66   const std::string user_id_;
     67   scoped_refptr<DeviceLocalAccountExternalDataManager> external_data_manager_;
     68 
     69   DeviceLocalAccountPolicyService* service_;
     70 
     71   // 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   // sessions regardless of what's actually specified in policy.
     74   scoped_ptr<PolicyMap> chrome_policy_overrides_;
     75 
     76   bool store_initialized_;
     77   bool waiting_for_policy_refresh_;
     78 
     79   base::WeakPtrFactory<DeviceLocalAccountPolicyProvider> weak_factory_;
     80 
     81   DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyProvider);
     82 };
     83 
     84 }  // namespace policy
     85 
     86 #endif  // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_PROVIDER_H_
     87