Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / chromeos / policy / user_policy_disk_cache.h
blobb22ad90a46ab296a7872bfcbcf8db23306ce13c5
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_USER_POLICY_DISK_CACHE_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_USER_POLICY_DISK_CACHE_H_
8 #include "base/basictypes.h"
9 #include "base/files/file_path.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/weak_ptr.h"
13 namespace base {
14 class SequencedTaskRunner;
17 namespace enterprise_management {
18 class CachedCloudPolicyResponse;
21 namespace policy {
23 // Handles the on-disk cache file used by UserPolicyCache. This class handles
24 // the necessary thread switching and may outlive the associated UserPolicyCache
25 // instance.
26 class UserPolicyDiskCache
27 : public base::RefCountedThreadSafe<UserPolicyDiskCache> {
28 public:
29 // Indicates the status of a completed load operation.
30 enum LoadResult {
31 // Policy was loaded successfully.
32 LOAD_RESULT_SUCCESS,
33 // Cache file missing.
34 LOAD_RESULT_NOT_FOUND,
35 // Failed to read cache file.
36 LOAD_RESULT_READ_ERROR,
37 // Failed to parse cache file.
38 LOAD_RESULT_PARSE_ERROR,
41 // Delegate interface for observing loads operations.
42 class Delegate {
43 public:
44 virtual ~Delegate();
45 virtual void OnDiskCacheLoaded(
46 LoadResult result,
47 const enterprise_management::CachedCloudPolicyResponse& policy) = 0;
50 UserPolicyDiskCache(
51 const base::WeakPtr<Delegate>& delegate,
52 const base::FilePath& backing_file_path,
53 scoped_refptr<base::SequencedTaskRunner> background_task_runner);
55 // Starts reading the policy cache from disk. Passes the read policy
56 // information back to the hosting UserPolicyCache after a successful cache
57 // load through UserPolicyCache::OnDiskCacheLoaded().
58 void Load();
60 // Triggers a write operation to the disk cache on the FILE thread.
61 void Store(const enterprise_management::CachedCloudPolicyResponse& policy);
63 private:
64 friend class base::RefCountedThreadSafe<UserPolicyDiskCache>;
65 ~UserPolicyDiskCache();
67 // Tries to load the cache file on the FILE thread.
68 void LoadOnFileThread();
70 // Forwards the result to the UI thread.
71 void LoadDone(LoadResult result,
72 const enterprise_management::CachedCloudPolicyResponse& policy);
74 // Passes back the successfully read policy to the cache on the UI thread.
75 void ReportResultOnUIThread(
76 LoadResult result,
77 const enterprise_management::CachedCloudPolicyResponse& policy);
79 // Saves a policy blob on the FILE thread.
80 void StoreOnFileThread(
81 const enterprise_management::CachedCloudPolicyResponse& policy);
83 base::WeakPtr<Delegate> delegate_;
84 const base::FilePath backing_file_path_;
85 scoped_refptr<base::SequencedTaskRunner> origin_task_runner_;
86 scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
88 DISALLOW_COPY_AND_ASSIGN(UserPolicyDiskCache);
91 } // namespace policy
93 #endif // CHROME_BROWSER_CHROMEOS_POLICY_USER_POLICY_DISK_CACHE_H_