46b8bc77cd9bff60ac05d589ac4f456d37274a2e
[platform/framework/web/crosswalk.git] / src / components / policy / core / common / policy_loader_mac.h
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.
4
5 #ifndef COMPONENTS_POLICY_CORE_COMMON_POLICY_LOADER_MAC_H_
6 #define COMPONENTS_POLICY_CORE_COMMON_POLICY_LOADER_MAC_H_
7
8 #include <string>
9
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"
16
17 class MacPreferences;
18
19 namespace base {
20 class SequencedTaskRunner;
21 }  // namespace base
22
23 namespace policy {
24
25 class PolicyBundle;
26 class PolicyMap;
27 class Schema;
28
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 {
32  public:
33   PolicyLoaderMac(scoped_refptr<base::SequencedTaskRunner> task_runner,
34                   const base::FilePath& managed_policy_path,
35                   MacPreferences* preferences);
36   virtual ~PolicyLoaderMac();
37
38   // AsyncPolicyLoader implementation.
39   virtual void InitOnBackgroundThread() OVERRIDE;
40   virtual scoped_ptr<PolicyBundle> Load() OVERRIDE;
41   virtual base::Time LastModificationTime() OVERRIDE;
42
43  private:
44   // Callback for the FilePathWatcher.
45   void OnFileUpdated(const base::FilePath& path, bool error);
46
47   // 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|.
49   void LoadPolicyForDomain(
50       PolicyDomain domain,
51       const std::string& domain_name,
52       PolicyBundle* bundle);
53
54   // Loads the policies described in |schema| from the bundle identified by
55   // |bundle_id_string|, and stores them in |policy|.
56   void LoadPolicyForComponent(const std::string& bundle_id_string,
57                               const Schema& schema,
58                               PolicyMap* policy);
59
60   scoped_ptr<MacPreferences> preferences_;
61
62   // Path to the managed preferences file for the current user, if it could
63   // be found. Updates of this file trigger a policy reload.
64   base::FilePath managed_policy_path_;
65
66   // Watches for events on the |managed_policy_path_|.
67   base::FilePathWatcher watcher_;
68
69   DISALLOW_COPY_AND_ASSIGN(PolicyLoaderMac);
70 };
71
72 }  // namespace policy
73
74 #endif  // COMPONENTS_POLICY_CORE_COMMON_POLICY_LOADER_MAC_H_