OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_POLICY_POLICY_LOADER_MAC_H_ | 5 #ifndef CHROME_BROWSER_POLICY_POLICY_LOADER_MAC_H_ |
6 #define CHROME_BROWSER_POLICY_POLICY_LOADER_MAC_H_ | 6 #define CHROME_BROWSER_POLICY_POLICY_LOADER_MAC_H_ |
7 | 7 |
| 8 #include <string> |
| 9 |
8 #include <CoreFoundation/CoreFoundation.h> | 10 #include <CoreFoundation/CoreFoundation.h> |
9 | 11 |
10 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
11 #include "base/files/file_path_watcher.h" | 13 #include "base/files/file_path_watcher.h" |
| 14 #include "base/memory/ref_counted.h" |
12 #include "chrome/browser/policy/async_policy_loader.h" | 15 #include "chrome/browser/policy/async_policy_loader.h" |
13 | 16 |
14 class MacPreferences; | 17 class MacPreferences; |
15 | 18 |
16 namespace base { | 19 namespace base { |
17 class Value; | 20 class Value; |
18 } // namespace base | 21 } // namespace base |
19 | 22 |
20 namespace policy { | 23 namespace policy { |
21 | 24 |
| 25 class PolicyDomainDescriptor; |
| 26 class PolicyMap; |
| 27 class PolicySchema; |
22 struct PolicyDefinitionList; | 28 struct PolicyDefinitionList; |
23 | 29 |
24 // A policy loader that loads policies from the Mac preferences system, and | 30 // A policy loader that loads policies from the Mac preferences system, and |
25 // watches the managed preferences files for updates. | 31 // watches the managed preferences files for updates. |
26 class PolicyLoaderMac : public AsyncPolicyLoader { | 32 class PolicyLoaderMac : public AsyncPolicyLoader { |
27 public: | 33 public: |
28 PolicyLoaderMac(const PolicyDefinitionList* policy_list, | 34 PolicyLoaderMac(const PolicyDefinitionList* policy_list, |
29 MacPreferences* preferences); | 35 MacPreferences* preferences); |
30 virtual ~PolicyLoaderMac(); | 36 virtual ~PolicyLoaderMac(); |
31 | 37 |
32 // AsyncPolicyLoader implementation. | 38 // AsyncPolicyLoader implementation. |
33 virtual void InitOnFile() OVERRIDE; | 39 virtual void InitOnFile() OVERRIDE; |
34 virtual scoped_ptr<PolicyBundle> Load() OVERRIDE; | 40 virtual scoped_ptr<PolicyBundle> Load() OVERRIDE; |
35 virtual base::Time LastModificationTime() OVERRIDE; | 41 virtual base::Time LastModificationTime() OVERRIDE; |
36 | 42 |
37 // Converts a CFPropertyListRef to the equivalent base::Value. CFDictionary | 43 // Converts a CFPropertyListRef to the equivalent base::Value. CFDictionary |
38 // entries whose key is not a CFStringRef are ignored. | 44 // entries whose key is not a CFStringRef are ignored. |
39 // The returned value is owned by the caller. | 45 // The returned value is owned by the caller. |
40 // Returns NULL if an invalid CFType was found, such as CFDate or CFData. | 46 // Returns NULL if an invalid CFType was found, such as CFDate or CFData. |
41 static base::Value* CreateValueFromProperty(CFPropertyListRef property); | 47 static base::Value* CreateValueFromProperty(CFPropertyListRef property); |
42 | 48 |
43 private: | 49 private: |
44 // Callback for the FilePathWatcher. | 50 // Callback for the FilePathWatcher. |
45 void OnFileUpdated(const base::FilePath& path, bool error); | 51 void OnFileUpdated(const base::FilePath& path, bool error); |
46 | 52 |
| 53 // Loads policies for the components described in |descriptor|, which belong |
| 54 // to the domain |domain_name|, and stores them in the |bundle|. |
| 55 void LoadPolicyForDomain( |
| 56 scoped_refptr<const PolicyDomainDescriptor> descriptor, |
| 57 const std::string& domain_name, |
| 58 PolicyBundle* bundle); |
| 59 |
| 60 // Loads the policies described in |schema| from the bundle identified by |
| 61 // |bundle_id_string|, and stores them in |policy|. |
| 62 void LoadPolicyForComponent(const std::string& bundle_id_string, |
| 63 const PolicySchema* schema, |
| 64 PolicyMap* policy); |
| 65 |
47 // List of recognized policies. | 66 // List of recognized policies. |
48 const PolicyDefinitionList* policy_list_; | 67 const PolicyDefinitionList* policy_list_; |
49 | 68 |
50 scoped_ptr<MacPreferences> preferences_; | 69 scoped_ptr<MacPreferences> preferences_; |
51 | 70 |
52 // Path to the managed preferences file for the current user, if it could | 71 // Path to the managed preferences file for the current user, if it could |
53 // be found. Updates of this file trigger a policy reload. | 72 // be found. Updates of this file trigger a policy reload. |
54 base::FilePath managed_policy_path_; | 73 base::FilePath managed_policy_path_; |
55 | 74 |
56 // Watches for events on the |managed_policy_path_|. | 75 // Watches for events on the |managed_policy_path_|. |
57 base::FilePathWatcher watcher_; | 76 base::FilePathWatcher watcher_; |
58 | 77 |
59 DISALLOW_COPY_AND_ASSIGN(PolicyLoaderMac); | 78 DISALLOW_COPY_AND_ASSIGN(PolicyLoaderMac); |
60 }; | 79 }; |
61 | 80 |
62 } // namespace policy | 81 } // namespace policy |
63 | 82 |
64 #endif // CHROME_BROWSER_POLICY_POLICY_LOADER_MAC_H_ | 83 #endif // CHROME_BROWSER_POLICY_POLICY_LOADER_MAC_H_ |
OLD | NEW |