summaryrefslogtreecommitdiffstats
path: root/chrome/browser/policy/user_policy_cache.h
blob: 45eb3d05e9d762c9fc9bd5a049a7b9f741e31c8d (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
69
70
71
72
73
74
75
76
// 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_CACHE_H_
#define CHROME_BROWSER_POLICY_USER_POLICY_CACHE_H_
#pragma once

#include <string>

#include "base/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/policy/cloud_policy_cache_base.h"

namespace enterprise_management {
class CachedCloudPolicyResponse;
// <Old-style policy support> (see comment below)
class GenericValue;
// </Old-style policy support>
}  // namespace enterprise_management

namespace policy {

// CloudPolicyCacheBase implementation that persists policy information
// into the file specified by the c'tor parameter |backing_file_path|.
class UserPolicyCache : public CloudPolicyCacheBase {
 public:
  explicit UserPolicyCache(const FilePath& backing_file_path);
  virtual ~UserPolicyCache();

  // CloudPolicyCacheBase implementation:
  virtual void Load() OVERRIDE;
  virtual void SetPolicy(const em::PolicyFetchResponse& policy) OVERRIDE;
  virtual void SetUnmanaged() OVERRIDE;

 private:
  class DiskCache;

  // Invoked by DiskCache after the file cache has been read successfully.
  void OnDiskCacheLoaded(const em::CachedCloudPolicyResponse& cached_response);

  // CloudPolicyCacheBase implementation:
  virtual bool DecodePolicyData(const em::PolicyData& policy_data,
                                PolicyMap* mandatory,
                                PolicyMap* recommended) OVERRIDE;

  // <Old-style policy support>
  // The following member functions are needed to support old-style policy and
  // can be removed once all server-side components (CPanel, D3) have been
  // migrated to providing the new policy format.

  // If |mandatory| and |recommended| are both empty, and |policy_data|
  // contains a field named "repeated GenericNamedValue named_value = 2;",
  // this field is decoded into |mandatory|.
  void MaybeDecodeOldstylePolicy(const std::string& policy_data,
                                 PolicyMap* mandatory,
                                 PolicyMap* recommended);

  Value* DecodeIntegerValue(google::protobuf::int64 value) const;
  Value* DecodeValue(const em::GenericValue& value) const;

  // </Old-style policy support>

  // Manages the cache file.
  scoped_refptr<DiskCache> disk_cache_;

  // Used for constructing the weak ptr passed to |disk_cache_|.
  base::WeakPtrFactory<UserPolicyCache> weak_ptr_factory_;

  DISALLOW_COPY_AND_ASSIGN(UserPolicyCache);
};

}  // namespace policy

#endif  // CHROME_BROWSER_POLICY_USER_POLICY_CACHE_H_