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 // Most of this code is copied from various classes in | 5 // Most of this code is copied from various classes in |
6 // src/chrome/browser/policy. In particular, look at | 6 // src/chrome/browser/policy. In particular, look at |
7 // | 7 // |
8 // file_based_policy_loader.{h,cc} | 8 // file_based_policy_loader.{h,cc} |
9 // config_dir_policy_provider.{h,cc} | 9 // config_dir_policy_provider.{h,cc} |
10 // | 10 // |
11 // This is a reduction of the functionality in those classes. | 11 // This is a reduction of the functionality in those classes. |
12 | 12 |
13 #include <set> | 13 #include <set> |
14 | 14 |
15 #include "remoting/host/policy_hack/policy_watcher.h" | 15 #include "remoting/host/policy_hack/policy_watcher.h" |
16 | 16 |
17 #include "base/bind.h" | 17 #include "base/bind.h" |
18 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
19 #include "base/file_util.h" | 19 #include "base/file_util.h" |
| 20 #include "base/files/file_enumerator.h" |
20 #include "base/files/file_path.h" | 21 #include "base/files/file_path.h" |
21 #include "base/files/file_path_watcher.h" | 22 #include "base/files/file_path_watcher.h" |
22 #include "base/json/json_file_value_serializer.h" | 23 #include "base/json/json_file_value_serializer.h" |
23 #include "base/memory/scoped_ptr.h" | 24 #include "base/memory/scoped_ptr.h" |
24 #include "base/memory/weak_ptr.h" | 25 #include "base/memory/weak_ptr.h" |
25 #include "base/single_thread_task_runner.h" | 26 #include "base/single_thread_task_runner.h" |
26 #include "base/synchronization/waitable_event.h" | 27 #include "base/synchronization/waitable_event.h" |
27 #include "base/time.h" | 28 #include "base/time.h" |
28 #include "base/values.h" | 29 #include "base/values.h" |
29 | 30 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 base::Time last_modification = base::Time(); | 102 base::Time last_modification = base::Time(); |
102 base::PlatformFileInfo file_info; | 103 base::PlatformFileInfo file_info; |
103 | 104 |
104 // If the path does not exist or points to a directory, it's safe to load. | 105 // If the path does not exist or points to a directory, it's safe to load. |
105 if (!file_util::GetFileInfo(config_dir_, &file_info) || | 106 if (!file_util::GetFileInfo(config_dir_, &file_info) || |
106 !file_info.is_directory) { | 107 !file_info.is_directory) { |
107 return last_modification; | 108 return last_modification; |
108 } | 109 } |
109 | 110 |
110 // Enumerate the files and find the most recent modification timestamp. | 111 // Enumerate the files and find the most recent modification timestamp. |
111 file_util::FileEnumerator file_enumerator(config_dir_, | 112 base::FileEnumerator file_enumerator(config_dir_, |
112 false, | 113 false, |
113 file_util::FileEnumerator::FILES); | 114 base::FileEnumerator::FILES); |
114 for (base::FilePath config_file = file_enumerator.Next(); | 115 for (base::FilePath config_file = file_enumerator.Next(); |
115 !config_file.empty(); | 116 !config_file.empty(); |
116 config_file = file_enumerator.Next()) { | 117 config_file = file_enumerator.Next()) { |
117 if (file_util::GetFileInfo(config_file, &file_info) && | 118 if (file_util::GetFileInfo(config_file, &file_info) && |
118 !file_info.is_directory) { | 119 !file_info.is_directory) { |
119 last_modification = std::max(last_modification, | 120 last_modification = std::max(last_modification, |
120 file_info.last_modified); | 121 file_info.last_modified); |
121 } | 122 } |
122 } | 123 } |
123 | 124 |
124 return last_modification; | 125 return last_modification; |
125 } | 126 } |
126 | 127 |
127 // Returns NULL if the policy dictionary couldn't be read. | 128 // Returns NULL if the policy dictionary couldn't be read. |
128 scoped_ptr<DictionaryValue> Load() { | 129 scoped_ptr<DictionaryValue> Load() { |
129 DCHECK(OnPolicyWatcherThread()); | 130 DCHECK(OnPolicyWatcherThread()); |
130 // Enumerate the files and sort them lexicographically. | 131 // Enumerate the files and sort them lexicographically. |
131 std::set<base::FilePath> files; | 132 std::set<base::FilePath> files; |
132 file_util::FileEnumerator file_enumerator(config_dir_, false, | 133 base::FileEnumerator file_enumerator(config_dir_, false, |
133 file_util::FileEnumerator::FILES); | 134 base::FileEnumerator::FILES); |
134 for (base::FilePath config_file_path = file_enumerator.Next(); | 135 for (base::FilePath config_file_path = file_enumerator.Next(); |
135 !config_file_path.empty(); config_file_path = file_enumerator.Next()) | 136 !config_file_path.empty(); config_file_path = file_enumerator.Next()) |
136 files.insert(config_file_path); | 137 files.insert(config_file_path); |
137 | 138 |
138 // Start with an empty dictionary and merge the files' contents. | 139 // Start with an empty dictionary and merge the files' contents. |
139 scoped_ptr<DictionaryValue> policy(new DictionaryValue()); | 140 scoped_ptr<DictionaryValue> policy(new DictionaryValue()); |
140 for (std::set<base::FilePath>::iterator config_file_iter = files.begin(); | 141 for (std::set<base::FilePath>::iterator config_file_iter = files.begin(); |
141 config_file_iter != files.end(); ++config_file_iter) { | 142 config_file_iter != files.end(); ++config_file_iter) { |
142 JSONFileValueSerializer deserializer(*config_file_iter); | 143 JSONFileValueSerializer deserializer(*config_file_iter); |
143 deserializer.set_allow_trailing_comma(true); | 144 deserializer.set_allow_trailing_comma(true); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 }; | 245 }; |
245 | 246 |
246 PolicyWatcher* PolicyWatcher::Create( | 247 PolicyWatcher* PolicyWatcher::Create( |
247 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | 248 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
248 base::FilePath policy_dir(kPolicyDir); | 249 base::FilePath policy_dir(kPolicyDir); |
249 return new PolicyWatcherLinux(task_runner, policy_dir); | 250 return new PolicyWatcherLinux(task_runner, policy_dir); |
250 } | 251 } |
251 | 252 |
252 } // namespace policy_hack | 253 } // namespace policy_hack |
253 } // namespace remoting | 254 } // namespace remoting |
OLD | NEW |