Home | History | Annotate | Download | only in policy
      1 // Copyright (c) 2011 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_POLICY_DEVICE_POLICY_CACHE_H_
      6 #define CHROME_BROWSER_POLICY_DEVICE_POLICY_CACHE_H_
      7 #pragma once
      8 
      9 #include <string>
     10 
     11 #include "base/memory/scoped_callback_factory.h"
     12 #include "chrome/browser/chromeos/login/signed_settings.h"
     13 #include "chrome/browser/chromeos/login/signed_settings_helper.h"
     14 #include "chrome/browser/policy/cloud_policy_cache_base.h"
     15 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h"
     16 
     17 namespace policy {
     18 
     19 class DevicePolicyIdentityStrategy;
     20 class EnterpriseInstallAttributes;
     21 class PolicyMap;
     22 
     23 namespace em = enterprise_management;
     24 
     25 // CloudPolicyCacheBase implementation that persists policy information
     26 // to ChromeOS' session manager (via SignedSettingsHelper).
     27 class DevicePolicyCache : public CloudPolicyCacheBase,
     28                           public chromeos::SignedSettingsHelper::Callback {
     29  public:
     30   explicit DevicePolicyCache(DevicePolicyIdentityStrategy* identity_strategy,
     31                              EnterpriseInstallAttributes* install_attributes);
     32   virtual ~DevicePolicyCache();
     33 
     34   // CloudPolicyCacheBase implementation:
     35   virtual void Load() OVERRIDE;
     36   virtual void SetPolicy(const em::PolicyFetchResponse& policy) OVERRIDE;
     37   virtual void SetUnmanaged() OVERRIDE;
     38 
     39   // SignedSettingsHelper::Callback implementation:
     40   virtual void OnRetrievePolicyCompleted(
     41       chromeos::SignedSettings::ReturnCode code,
     42       const em::PolicyFetchResponse& policy) OVERRIDE;
     43 
     44  private:
     45   friend class DevicePolicyCacheTest;
     46 
     47   // Alternate c'tor allowing tests to mock out the SignedSettingsHelper
     48   // singleton.
     49   DevicePolicyCache(
     50       DevicePolicyIdentityStrategy* identity_strategy,
     51       EnterpriseInstallAttributes* install_attributes,
     52       chromeos::SignedSettingsHelper* signed_settings_helper);
     53 
     54   // CloudPolicyCacheBase implementation:
     55   virtual bool DecodePolicyData(const em::PolicyData& policy_data,
     56                                 PolicyMap* mandatory,
     57                                 PolicyMap* recommended) OVERRIDE;
     58 
     59   void PolicyStoreOpCompleted(chromeos::SignedSettings::ReturnCode code);
     60 
     61   // Checks with immutable attributes whether this is an enterprise device and
     62   // read the registration user if this is the case.
     63   void CheckImmutableAttributes();
     64 
     65   static void DecodeDevicePolicy(const em::ChromeDeviceSettingsProto& policy,
     66                                  PolicyMap* mandatory,
     67                                  PolicyMap* recommended);
     68 
     69   DevicePolicyIdentityStrategy* identity_strategy_;
     70   EnterpriseInstallAttributes* install_attributes_;
     71 
     72   chromeos::SignedSettingsHelper* signed_settings_helper_;
     73 
     74   bool starting_up_;
     75 
     76   base::ScopedCallbackFactory<DevicePolicyCache> callback_factory_;
     77 
     78   DISALLOW_COPY_AND_ASSIGN(DevicePolicyCache);
     79 };
     80 
     81 }  // namespace policy
     82 
     83 #endif  // CHROME_BROWSER_POLICY_DEVICE_POLICY_CACHE_H_
     84