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_STORE_H_
      6 #define CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_STORE_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/settings/device_settings_service.h"
     16 #include "components/policy/core/common/cloud/cloud_policy_validator.h"
     17 #include "components/policy/core/common/cloud/user_cloud_policy_store_base.h"
     18 
     19 namespace base {
     20 class SequencedTaskRunner;
     21 }
     22 
     23 namespace chromeos {
     24 class DeviceSettingsService;
     25 class SessionManagerClient;
     26 }
     27 
     28 namespace enterprise_management {
     29 class PolicyFetchResponse;
     30 }
     31 
     32 namespace policy {
     33 
     34 class DeviceLocalAccountPolicyBroker;
     35 
     36 // CloudPolicyStore implementation for device-local account policy. Stores/loads
     37 // policy to/from session_manager.
     38 class DeviceLocalAccountPolicyStore
     39     : public UserCloudPolicyStoreBase {
     40  public:
     41   DeviceLocalAccountPolicyStore(
     42       const std::string& account_id,
     43       chromeos::SessionManagerClient* client,
     44       chromeos::DeviceSettingsService* device_settings_service,
     45       scoped_refptr<base::SequencedTaskRunner> background_task_runner);
     46   virtual ~DeviceLocalAccountPolicyStore();
     47 
     48   const std::string& account_id() const { return account_id_; }
     49 
     50   // CloudPolicyStore:
     51   virtual void Store(
     52       const enterprise_management::PolicyFetchResponse& policy) OVERRIDE;
     53   virtual void Load() OVERRIDE;
     54 
     55  private:
     56   // Called back by |session_manager_client_| after policy retrieval. Checks for
     57   // success and triggers policy validation.
     58   void ValidateLoadedPolicyBlob(const std::string& policy_blob);
     59 
     60   // Updates state after validation and notifies observers.
     61   void UpdatePolicy(UserCloudPolicyValidator* validator);
     62 
     63   // Sends the policy blob to session_manager for storing after validation.
     64   void StoreValidatedPolicy(UserCloudPolicyValidator* validator);
     65 
     66   // Called back when a store operation completes, updates state and reloads the
     67   // policy if applicable.
     68   void HandleStoreResult(bool result);
     69 
     70   // Gets the owner key and triggers policy validation.
     71   void CheckKeyAndValidate(
     72       bool valid_timestamp_required,
     73       scoped_ptr<enterprise_management::PolicyFetchResponse> policy,
     74       const UserCloudPolicyValidator::CompletionCallback& callback);
     75 
     76   // Triggers policy validation.
     77   void Validate(
     78       bool valid_timestamp_required,
     79       scoped_ptr<enterprise_management::PolicyFetchResponse> policy,
     80       const UserCloudPolicyValidator::CompletionCallback& callback,
     81       chromeos::DeviceSettingsService::OwnershipStatus ownership_status);
     82 
     83   const std::string account_id_;
     84   chromeos::SessionManagerClient* session_manager_client_;
     85   chromeos::DeviceSettingsService* device_settings_service_;
     86 
     87   scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
     88 
     89   base::WeakPtrFactory<DeviceLocalAccountPolicyStore> weak_factory_;
     90 
     91   DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyStore);
     92 };
     93 
     94 }  // namespace policy
     95 
     96 #endif  // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_STORE_H_
     97