1 // Copyright 2013 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 COMPONENTS_POLICY_CORE_COMMON_CLOUD_USER_CLOUD_POLICY_STORE_H_
6 #define COMPONENTS_POLICY_CORE_COMMON_CLOUD_USER_CLOUD_POLICY_STORE_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/files/file_path.h"
13 #include "base/memory/weak_ptr.h"
14 #include "components/policy/core/common/cloud/user_cloud_policy_store_base.h"
15 #include "components/policy/policy_export.h"
18 class SequencedTaskRunner;
23 // Implements a cloud policy store that is stored in a simple file in the user's
24 // profile directory. This is used on (non-chromeos) platforms that do not have
25 // a secure storage implementation.
26 class POLICY_EXPORT UserCloudPolicyStore : public UserCloudPolicyStoreBase {
28 // Creates a policy store associated with a signed-in (or in the progress of
31 const base::FilePath& policy_file,
32 scoped_refptr<base::SequencedTaskRunner> background_task_runner);
33 virtual ~UserCloudPolicyStore();
35 // Factory method for creating a UserCloudPolicyStore for a profile with path
37 static scoped_ptr<UserCloudPolicyStore> Create(
38 const base::FilePath& profile_path,
39 scoped_refptr<base::SequencedTaskRunner> background_task_runner);
41 // Sets the username from signin for validation of the policy.
42 void SetSigninUsername(const std::string& username);
44 // Loads policy immediately on the current thread. Virtual for mocks.
45 virtual void LoadImmediately();
47 // Deletes any existing policy blob and notifies observers via OnStoreLoaded()
48 // that the blob has changed. Virtual for mocks.
51 // CloudPolicyStore implementation.
52 virtual void Load() OVERRIDE;
54 const enterprise_management::PolicyFetchResponse& policy) OVERRIDE;
57 std::string signin_username_;
60 // Callback invoked when a new policy has been loaded from disk. If
61 // |validate_in_background| is true, then policy is validated via a background
63 void PolicyLoaded(bool validate_in_background,
64 struct PolicyLoadResult policy_load_result);
66 // Starts policy blob validation. |callback| is invoked once validation is
67 // complete. If |validate_in_background| is true, then the validation work
68 // occurs on a background thread (results are sent back to the calling
71 scoped_ptr<enterprise_management::PolicyFetchResponse> policy,
72 bool validate_in_background,
73 const UserCloudPolicyValidator::CompletionCallback& callback);
75 // Callback invoked to install a just-loaded policy after validation has
77 void InstallLoadedPolicyAfterValidation(UserCloudPolicyValidator* validator);
79 // Callback invoked to store the policy after validation has finished.
80 void StorePolicyAfterValidation(UserCloudPolicyValidator* validator);
82 // WeakPtrFactory used to create callbacks for validating and storing policy.
83 base::WeakPtrFactory<UserCloudPolicyStore> weak_factory_;
85 // Path to file where we store persisted policy.
86 base::FilePath backing_file_path_;
88 DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyStore);
93 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_USER_CLOUD_POLICY_STORE_H_