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.
5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_STORE_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_STORE_H_
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"
20 class SequencedTaskRunner
;
24 class DeviceSettingsService
;
25 class SessionManagerClient
;
28 namespace enterprise_management
{
29 class PolicyFetchResponse
;
34 class DeviceLocalAccountPolicyBroker
;
36 // CloudPolicyStore implementation for device-local account policy. Stores/loads
37 // policy to/from session_manager.
38 class DeviceLocalAccountPolicyStore
39 : public UserCloudPolicyStoreBase
{
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();
48 const std::string
& account_id() const { return account_id_
; }
52 const enterprise_management::PolicyFetchResponse
& policy
) OVERRIDE
;
53 virtual void Load() OVERRIDE
;
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
);
60 // Updates state after validation and notifies observers.
61 void UpdatePolicy(UserCloudPolicyValidator
* validator
);
63 // Sends the policy blob to session_manager for storing after validation.
64 void StoreValidatedPolicy(UserCloudPolicyValidator
* validator
);
66 // Called back when a store operation completes, updates state and reloads the
67 // policy if applicable.
68 void HandleStoreResult(bool result
);
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
);
76 // Triggers policy validation.
78 bool valid_timestamp_required
,
79 scoped_ptr
<enterprise_management::PolicyFetchResponse
> policy
,
80 const UserCloudPolicyValidator::CompletionCallback
& callback
,
81 chromeos::DeviceSettingsService::OwnershipStatus ownership_status
);
83 const std::string account_id_
;
84 chromeos::SessionManagerClient
* session_manager_client_
;
85 chromeos::DeviceSettingsService
* device_settings_service_
;
87 scoped_refptr
<base::SequencedTaskRunner
> background_task_runner_
;
89 base::WeakPtrFactory
<DeviceLocalAccountPolicyStore
> weak_factory_
;
91 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountPolicyStore
);
96 #endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_LOCAL_ACCOUNT_POLICY_STORE_H_