4dc7e248b1f53a304bb567d173f31c6424f1a60d
[platform/framework/web/crosswalk.git] / src / components / policy / core / common / cloud / user_cloud_policy_store.h
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.
4
5 #ifndef COMPONENTS_POLICY_CORE_COMMON_CLOUD_USER_CLOUD_POLICY_STORE_H_
6 #define COMPONENTS_POLICY_CORE_COMMON_CLOUD_USER_CLOUD_POLICY_STORE_H_
7
8 #include <string>
9
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"
16
17 namespace base {
18 class SequencedTaskRunner;
19 }
20
21 namespace policy {
22
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 {
27  public:
28   // Creates a policy store associated with a signed-in (or in the progress of
29   // it) user.
30   UserCloudPolicyStore(
31       const base::FilePath& policy_file,
32       scoped_refptr<base::SequencedTaskRunner> background_task_runner);
33   virtual ~UserCloudPolicyStore();
34
35   // Factory method for creating a UserCloudPolicyStore for a profile with path
36   // |profile_path|.
37   static scoped_ptr<UserCloudPolicyStore> Create(
38       const base::FilePath& profile_path,
39       scoped_refptr<base::SequencedTaskRunner> background_task_runner);
40
41   // Sets the username from signin for validation of the policy.
42   void SetSigninUsername(const std::string& username);
43
44   // Loads policy immediately on the current thread. Virtual for mocks.
45   virtual void LoadImmediately();
46
47   // Deletes any existing policy blob and notifies observers via OnStoreLoaded()
48   // that the blob has changed. Virtual for mocks.
49   virtual void Clear();
50
51   // CloudPolicyStore implementation.
52   virtual void Load() OVERRIDE;
53   virtual void Store(
54       const enterprise_management::PolicyFetchResponse& policy) OVERRIDE;
55
56  protected:
57   std::string signin_username_;
58
59  private:
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
62   // thread.
63   void PolicyLoaded(bool validate_in_background,
64                     struct PolicyLoadResult policy_load_result);
65
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
69   // thread).
70   void Validate(
71       scoped_ptr<enterprise_management::PolicyFetchResponse> policy,
72       bool validate_in_background,
73       const UserCloudPolicyValidator::CompletionCallback& callback);
74
75   // Callback invoked to install a just-loaded policy after validation has
76   // finished.
77   void InstallLoadedPolicyAfterValidation(UserCloudPolicyValidator* validator);
78
79   // Callback invoked to store the policy after validation has finished.
80   void StorePolicyAfterValidation(UserCloudPolicyValidator* validator);
81
82   // WeakPtrFactory used to create callbacks for validating and storing policy.
83   base::WeakPtrFactory<UserCloudPolicyStore> weak_factory_;
84
85   // Path to file where we store persisted policy.
86   base::FilePath backing_file_path_;
87
88   DISALLOW_COPY_AND_ASSIGN(UserCloudPolicyStore);
89 };
90
91 }  // namespace policy
92
93 #endif  // COMPONENTS_POLICY_CORE_COMMON_CLOUD_USER_CLOUD_POLICY_STORE_H_