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_POLICY_POLICY_LOADER_MAC_H_
6 #define CHROME_BROWSER_POLICY_POLICY_LOADER_MAC_H_
10 #include <CoreFoundation/CoreFoundation.h>
12 #include "base/files/file_path.h"
13 #include "base/files/file_path_watcher.h"
14 #include "base/memory/ref_counted.h"
15 #include "chrome/browser/policy/async_policy_loader.h"
20 class SequencedTaskRunner;
26 class PolicyDomainDescriptor;
29 struct PolicyDefinitionList;
31 // A policy loader that loads policies from the Mac preferences system, and
32 // watches the managed preferences files for updates.
33 class PolicyLoaderMac : public AsyncPolicyLoader {
35 PolicyLoaderMac(scoped_refptr<base::SequencedTaskRunner> task_runner,
36 const PolicyDefinitionList* policy_list,
37 const base::FilePath& managed_policy_path,
38 MacPreferences* preferences);
39 virtual ~PolicyLoaderMac();
41 // AsyncPolicyLoader implementation.
42 virtual void InitOnBackgroundThread() OVERRIDE;
43 virtual scoped_ptr<PolicyBundle> Load() OVERRIDE;
44 virtual base::Time LastModificationTime() OVERRIDE;
46 // Converts a CFPropertyListRef to the equivalent base::Value. CFDictionary
47 // entries whose key is not a CFStringRef are ignored.
48 // The returned value is owned by the caller.
49 // Returns NULL if an invalid CFType was found, such as CFDate or CFData.
50 static base::Value* CreateValueFromProperty(CFPropertyListRef property);
53 // Callback for the FilePathWatcher.
54 void OnFileUpdated(const base::FilePath& path, bool error);
56 // Loads policies for the components described in |descriptor|, which belong
57 // to the domain |domain_name|, and stores them in the |bundle|.
58 void LoadPolicyForDomain(
59 scoped_refptr<const PolicyDomainDescriptor> descriptor,
60 const std::string& domain_name,
61 PolicyBundle* bundle);
63 // Loads the policies described in |schema| from the bundle identified by
64 // |bundle_id_string|, and stores them in |policy|.
65 void LoadPolicyForComponent(const std::string& bundle_id_string,
69 // List of recognized policies.
70 const PolicyDefinitionList* policy_list_;
72 scoped_ptr<MacPreferences> preferences_;
74 // Path to the managed preferences file for the current user, if it could
75 // be found. Updates of this file trigger a policy reload.
76 base::FilePath managed_policy_path_;
78 // Watches for events on the |managed_policy_path_|.
79 base::FilePathWatcher watcher_;
81 DISALLOW_COPY_AND_ASSIGN(PolicyLoaderMac);
86 #endif // CHROME_BROWSER_POLICY_POLICY_LOADER_MAC_H_