device_local_account_policy_store.h revision 8bcbed890bc3ce4d7a057a8f32cab53fa534672e
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 "chrome/browser/policy/cloud/cloud_policy_validator.h"
17#include "chrome/browser/policy/cloud/user_cloud_policy_store_base.h"
18
19namespace base {
20class SequencedTaskRunner;
21}
22
23namespace chromeos {
24class DeviceSettingsService;
25class SessionManagerClient;
26}
27
28namespace enterprise_management {
29class PolicyFetchResponse;
30}
31
32namespace policy {
33
34class DeviceLocalAccountPolicyBroker;
35
36// CloudPolicyStore implementation for device-local account policy. Stores/loads
37// policy to/from session_manager.
38class 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      scoped_ptr<enterprise_management::PolicyFetchResponse> policy,
73      const UserCloudPolicyValidator::CompletionCallback& callback);
74
75  // Triggers policy validation.
76  void Validate(
77      scoped_ptr<enterprise_management::PolicyFetchResponse> policy,
78      const UserCloudPolicyValidator::CompletionCallback& callback,
79      chromeos::DeviceSettingsService::OwnershipStatus ownership_status);
80
81  const std::string account_id_;
82  chromeos::SessionManagerClient* session_manager_client_;
83  chromeos::DeviceSettingsService* device_settings_service_;
84
85  scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
86
87  base::WeakPtrFactory<DeviceLocalAccountPolicyStore> weak_factory_;
88
89  DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyStore);
90};
91
92}  // namespace policy
93
94#endif  // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_STORE_H_
95