blob: 555524cea968546d6385276ea2358c54faa2afd5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_POLICY_USER_POLICY_DISK_CACHE_H_
#define CHROME_BROWSER_POLICY_USER_POLICY_DISK_CACHE_H_
#pragma once
#include "base/basictypes.h"
#include "base/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
namespace em = enterprise_management;
namespace enterprise_management {
class CachedCloudPolicyResponse;
}
namespace policy {
// Handles the on-disk cache file used by UserPolicyCache. This class handles
// the necessary thread switching and may outlive the associated UserPolicyCache
// instance.
class UserPolicyDiskCache
: public base::RefCountedThreadSafe<UserPolicyDiskCache> {
public:
// Delegate interface for observing loads operations.
class Delegate {
public:
virtual ~Delegate();
virtual void OnDiskCacheLoaded(
const em::CachedCloudPolicyResponse& policy) = 0;
};
UserPolicyDiskCache(const base::WeakPtr<Delegate>& delegate,
const FilePath& backing_file_path);
// Starts reading the policy cache from disk. Passes the read policy
// information back to the hosting UserPolicyCache after a successful cache
// load through UserPolicyCache::OnDiskCacheLoaded().
void Load();
// Triggers a write operation to the disk cache on the FILE thread.
void Store(const em::CachedCloudPolicyResponse& policy);
private:
friend class base::RefCountedThreadSafe<UserPolicyDiskCache>;
~UserPolicyDiskCache();
// Tries to load the cache file on the FILE thread.
void LoadOnFileThread();
// Passes back the successfully read policy to the cache on the UI thread.
void FinishLoadOnUIThread(const em::CachedCloudPolicyResponse& policy);
// Saves a policy blob on the FILE thread.
void StoreOnFileThread(const em::CachedCloudPolicyResponse& policy);
base::WeakPtr<Delegate> delegate_;
const FilePath backing_file_path_;
DISALLOW_COPY_AND_ASSIGN(UserPolicyDiskCache);
};
} // namespace policy
#endif // CHROME_BROWSER_POLICY_USER_POLICY_DISK_CACHE_H_
|