| 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 COMPONENTS_POLICY_CORE_COMMON_POLICY_LOADER_MAC_H_ | 5 #ifndef COMPONENTS_POLICY_CORE_COMMON_POLICY_LOADER_MAC_H_ |
| 6 #define COMPONENTS_POLICY_CORE_COMMON_POLICY_LOADER_MAC_H_ | 6 #define COMPONENTS_POLICY_CORE_COMMON_POLICY_LOADER_MAC_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 class PolicyMap; | 26 class PolicyMap; |
| 27 class Schema; | 27 class Schema; |
| 28 | 28 |
| 29 // A policy loader that loads policies from the Mac preferences system, and | 29 // A policy loader that loads policies from the Mac preferences system, and |
| 30 // watches the managed preferences files for updates. | 30 // watches the managed preferences files for updates. |
| 31 class POLICY_EXPORT PolicyLoaderMac : public AsyncPolicyLoader { | 31 class POLICY_EXPORT PolicyLoaderMac : public AsyncPolicyLoader { |
| 32 public: | 32 public: |
| 33 PolicyLoaderMac(scoped_refptr<base::SequencedTaskRunner> task_runner, | 33 PolicyLoaderMac(scoped_refptr<base::SequencedTaskRunner> task_runner, |
| 34 const base::FilePath& managed_policy_path, | 34 const base::FilePath& managed_policy_path, |
| 35 MacPreferences* preferences); | 35 MacPreferences* preferences); |
| 36 |
| 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); |
| 43 |
| 36 ~PolicyLoaderMac() override; | 44 ~PolicyLoaderMac() override; |
| 37 | 45 |
| 38 // AsyncPolicyLoader implementation. | 46 // AsyncPolicyLoader implementation. |
| 39 void InitOnBackgroundThread() override; | 47 void InitOnBackgroundThread() override; |
| 40 scoped_ptr<PolicyBundle> Load() override; | 48 scoped_ptr<PolicyBundle> Load() override; |
| 41 base::Time LastModificationTime() override; | 49 base::Time LastModificationTime() override; |
| 42 | 50 |
| 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); |
| 56 #endif |
| 57 |
| 43 private: | 58 private: |
| 44 // Callback for the FilePathWatcher. | 59 // Callback for the FilePathWatcher. |
| 45 void OnFileUpdated(const base::FilePath& path, bool error); | 60 void OnFileUpdated(const base::FilePath& path, bool error); |
| 46 | 61 |
| 47 // Loads policies for the components described in the current schema_map() | 62 // Loads policies for the components described in the current schema_map() |
| 48 // which belong to the domain |domain_name|, and stores them in the |bundle|. | 63 // which belong to the domain |domain_name|, and stores them in the |bundle|. |
| 49 void LoadPolicyForDomain( | 64 void LoadPolicyForDomain( |
| 50 PolicyDomain domain, | 65 PolicyDomain domain, |
| 51 const std::string& domain_name, | 66 const std::string& domain_name, |
| 52 PolicyBundle* bundle); | 67 PolicyBundle* bundle); |
| 53 | 68 |
| 54 // Loads the policies described in |schema| from the bundle identified by | 69 // Loads the policies described in |schema| from the bundle identified by |
| 55 // |bundle_id_string|, and stores them in |policy|. | 70 // |bundle_id_string|, and stores them in |policy|. |
| 56 void LoadPolicyForComponent(const std::string& bundle_id_string, | 71 void LoadPolicyForComponent(const std::string& bundle_id_string, |
| 57 const Schema& schema, | 72 const Schema& schema, |
| 58 PolicyMap* policy); | 73 PolicyMap* policy); |
| 59 | 74 |
| 60 scoped_ptr<MacPreferences> preferences_; | 75 scoped_ptr<MacPreferences> preferences_; |
| 61 | 76 |
| 62 // Path to the managed preferences file for the current user, if it could | 77 // Path to the managed preferences file for the current user, if it could |
| 63 // be found. Updates of this file trigger a policy reload. | 78 // be found. Updates of this file trigger a policy reload. |
| 64 base::FilePath managed_policy_path_; | 79 base::FilePath managed_policy_path_; |
| 65 | 80 |
| 66 // Watches for events on the |managed_policy_path_|. | 81 // Watches for events on the |managed_policy_path_|. |
| 67 base::FilePathWatcher watcher_; | 82 base::FilePathWatcher watcher_; |
| 68 | 83 |
| 84 // Application ID to pass into Mac's Preference Utilities API. |
| 85 CFStringRef application_id_; |
| 86 |
| 69 DISALLOW_COPY_AND_ASSIGN(PolicyLoaderMac); | 87 DISALLOW_COPY_AND_ASSIGN(PolicyLoaderMac); |
| 70 }; | 88 }; |
| 71 | 89 |
| 72 } // namespace policy | 90 } // namespace policy |
| 73 | 91 |
| 74 #endif // COMPONENTS_POLICY_CORE_COMMON_POLICY_LOADER_MAC_H_ | 92 #endif // COMPONENTS_POLICY_CORE_COMMON_POLICY_LOADER_MAC_H_ |
| OLD | NEW |