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 COMPONENTS_POLICY_CORE_COMMON_POLICY_LOADER_MAC_H_
6 #define COMPONENTS_POLICY_CORE_COMMON_POLICY_LOADER_MAC_H_
10 #include "base/files/file_path.h"
11 #include "base/files/file_path_watcher.h"
12 #include "base/memory/ref_counted.h"
13 #include "components/policy/core/common/async_policy_loader.h"
14 #include "components/policy/core/common/policy_namespace.h"
15 #include "components/policy/policy_export.h"
20 class SequencedTaskRunner
;
29 // A policy loader that loads policies from the Mac preferences system, and
30 // watches the managed preferences files for updates.
31 class POLICY_EXPORT PolicyLoaderMac
: public AsyncPolicyLoader
{
33 PolicyLoaderMac(scoped_refptr
<base::SequencedTaskRunner
> task_runner
,
34 const base::FilePath
& managed_policy_path
,
35 MacPreferences
* preferences
);
37 // |application_id| will be passed into Mac's Preference Utilities API
38 // instead of the default value of kCFPreferencesCurrentApplication.
39 PolicyLoaderMac(scoped_refptr
<base::SequencedTaskRunner
> task_runner
,
40 const base::FilePath
& managed_policy_path
,
41 MacPreferences
* preferences
,
42 CFStringRef application_id
);
44 ~PolicyLoaderMac() override
;
46 // AsyncPolicyLoader implementation.
47 void InitOnBackgroundThread() override
;
48 scoped_ptr
<PolicyBundle
> Load() override
;
49 base::Time
LastModificationTime() override
;
51 #if defined(OS_MACOSX) && !defined(OS_IOS)
52 // Gets the path to the preferences (.plist) file associated with the given
53 // |bundle_id|. The file at the returned path might not exist (yet).
54 // Returns an empty path upon failure.
55 static base::FilePath
GetManagedPolicyPath(CFStringRef bundle_id
);
59 // Callback for the FilePathWatcher.
60 void OnFileUpdated(const base::FilePath
& path
, bool error
);
62 // Loads policies for the components described in the current schema_map()
63 // which belong to the domain |domain_name|, and stores them in the |bundle|.
64 void LoadPolicyForDomain(
66 const std::string
& domain_name
,
67 PolicyBundle
* bundle
);
69 // Loads the policies described in |schema| from the bundle identified by
70 // |bundle_id_string|, and stores them in |policy|.
71 void LoadPolicyForComponent(const std::string
& bundle_id_string
,
75 scoped_ptr
<MacPreferences
> preferences_
;
77 // Path to the managed preferences file for the current user, if it could
78 // be found. Updates of this file trigger a policy reload.
79 base::FilePath managed_policy_path_
;
81 // Watches for events on the |managed_policy_path_|.
82 base::FilePathWatcher watcher_
;
84 // Application ID to pass into Mac's Preference Utilities API.
85 CFStringRef application_id_
;
87 DISALLOW_COPY_AND_ASSIGN(PolicyLoaderMac
);
92 #endif // COMPONENTS_POLICY_CORE_COMMON_POLICY_LOADER_MAC_H_