• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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 CHROME_BROWSER_POLICY_USER_POLICY_CACHE_H_
6 #define CHROME_BROWSER_POLICY_USER_POLICY_CACHE_H_
7 #pragma once
8 
9 #include <string>
10 
11 #include "base/file_path.h"
12 #include "chrome/browser/policy/cloud_policy_cache_base.h"
13 
14 // <Old-style policy support> (see comment below)
15 namespace enterprise_management {
16 class GenericValue;
17 }  // namespace enterprise_management
18 // </Old-style policy support>
19 
20 namespace policy {
21 
22 // CloudPolicyCacheBase implementation that persists policy information
23 // into the file specified by the c'tor parameter |backing_file_path|.
24 class UserPolicyCache : public CloudPolicyCacheBase {
25  public:
26   explicit UserPolicyCache(const FilePath& backing_file_path);
27   virtual ~UserPolicyCache();
28 
29   // CloudPolicyCacheBase implementation:
30   virtual void Load() OVERRIDE;
31   virtual void SetPolicy(const em::PolicyFetchResponse& policy) OVERRIDE;
32   virtual void SetUnmanaged() OVERRIDE;
33 
34  private:
35   void PersistPolicy(const em::PolicyFetchResponse& policy,
36                      const base::Time& timestamp);
37 
38   // CloudPolicyCacheBase implementation:
39   virtual bool DecodePolicyData(const em::PolicyData& policy_data,
40                                 PolicyMap* mandatory,
41                                 PolicyMap* recommended) OVERRIDE;
42 
43   // <Old-style policy support>
44   // The following member functions are needed to support old-style policy and
45   // can be removed once all server-side components (CPanel, D3) have been
46   // migrated to providing the new policy format.
47 
48   // If |mandatory| and |recommended| are both empty, and |policy_data|
49   // contains a field named "repeated GenericNamedValue named_value = 2;",
50   // this field is decoded into |mandatory|.
51   void MaybeDecodeOldstylePolicy(const std::string& policy_data,
52                                  PolicyMap* mandatory,
53                                  PolicyMap* recommended);
54 
55   Value* DecodeIntegerValue(google::protobuf::int64 value) const;
56   Value* DecodeValue(const em::GenericValue& value) const;
57 
58   // </Old-style policy support>
59 
60   // The file in which we store a cached version of the policy information.
61   const FilePath backing_file_path_;
62 
63   DISALLOW_COPY_AND_ASSIGN(UserPolicyCache);
64 };
65 
66 }  // namespace policy
67 
68 #endif  // CHROME_BROWSER_POLICY_USER_POLICY_CACHE_H_
69