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 #include "chrome/browser/policy/config_dir_policy_loader.h" | 5 #include "chrome/browser/policy/config_dir_policy_loader.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
14 #include "base/files/file_enumerator.h" | |
15 #include "base/json/json_file_value_serializer.h" | 14 #include "base/json/json_file_value_serializer.h" |
16 #include "base/json/json_reader.h" | 15 #include "base/json/json_reader.h" |
17 #include "base/logging.h" | 16 #include "base/logging.h" |
18 #include "base/platform_file.h" | 17 #include "base/platform_file.h" |
19 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
20 #include "chrome/browser/policy/policy_bundle.h" | 19 #include "chrome/browser/policy/policy_bundle.h" |
21 #include "chrome/browser/policy/policy_load_status.h" | 20 #include "chrome/browser/policy/policy_load_status.h" |
22 | 21 |
23 namespace policy { | 22 namespace policy { |
24 | 23 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 base::PlatformFileInfo info; | 93 base::PlatformFileInfo info; |
95 | 94 |
96 for (size_t i = 0; i < arraysize(kConfigDirSuffixes); ++i) { | 95 for (size_t i = 0; i < arraysize(kConfigDirSuffixes); ++i) { |
97 base::FilePath path(config_dir_.Append(kConfigDirSuffixes[i])); | 96 base::FilePath path(config_dir_.Append(kConfigDirSuffixes[i])); |
98 | 97 |
99 // Skip if the file doesn't exist, or it isn't a directory. | 98 // Skip if the file doesn't exist, or it isn't a directory. |
100 if (!file_util::GetFileInfo(path, &info) || !info.is_directory) | 99 if (!file_util::GetFileInfo(path, &info) || !info.is_directory) |
101 continue; | 100 continue; |
102 | 101 |
103 // Enumerate the files and find the most recent modification timestamp. | 102 // Enumerate the files and find the most recent modification timestamp. |
104 base::FileEnumerator file_enumerator(path, false, | 103 file_util::FileEnumerator file_enumerator(path, false, |
105 base::FileEnumerator::FILES); | 104 file_util::FileEnumerator::FILES); |
106 for (base::FilePath config_file = file_enumerator.Next(); | 105 for (base::FilePath config_file = file_enumerator.Next(); |
107 !config_file.empty(); | 106 !config_file.empty(); |
108 config_file = file_enumerator.Next()) { | 107 config_file = file_enumerator.Next()) { |
109 if (file_util::GetFileInfo(config_file, &info) && !info.is_directory) | 108 if (file_util::GetFileInfo(config_file, &info) && !info.is_directory) |
110 last_modification = std::max(last_modification, info.last_modified); | 109 last_modification = std::max(last_modification, info.last_modified); |
111 } | 110 } |
112 } | 111 } |
113 | 112 |
114 return last_modification; | 113 return last_modification; |
115 } | 114 } |
116 | 115 |
117 void ConfigDirPolicyLoader::LoadFromPath(const base::FilePath& path, | 116 void ConfigDirPolicyLoader::LoadFromPath(const base::FilePath& path, |
118 PolicyLevel level, | 117 PolicyLevel level, |
119 PolicyBundle* bundle) { | 118 PolicyBundle* bundle) { |
120 // Enumerate the files and sort them lexicographically. | 119 // Enumerate the files and sort them lexicographically. |
121 std::set<base::FilePath> files; | 120 std::set<base::FilePath> files; |
122 base::FileEnumerator file_enumerator(path, false, | 121 file_util::FileEnumerator file_enumerator(path, false, |
123 base::FileEnumerator::FILES); | 122 file_util::FileEnumerator::FILES); |
124 for (base::FilePath config_file_path = file_enumerator.Next(); | 123 for (base::FilePath config_file_path = file_enumerator.Next(); |
125 !config_file_path.empty(); config_file_path = file_enumerator.Next()) | 124 !config_file_path.empty(); config_file_path = file_enumerator.Next()) |
126 files.insert(config_file_path); | 125 files.insert(config_file_path); |
127 | 126 |
128 PolicyLoadStatusSample status; | 127 PolicyLoadStatusSample status; |
129 if (files.empty()) { | 128 if (files.empty()) { |
130 status.Add(POLICY_LOAD_STATUS_NO_POLICY); | 129 status.Add(POLICY_LOAD_STATUS_NO_POLICY); |
131 return; | 130 return; |
132 } | 131 } |
133 | 132 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 } | 223 } |
225 } | 224 } |
226 | 225 |
227 void ConfigDirPolicyLoader::OnFileUpdated(const base::FilePath& path, | 226 void ConfigDirPolicyLoader::OnFileUpdated(const base::FilePath& path, |
228 bool error) { | 227 bool error) { |
229 if (!error) | 228 if (!error) |
230 Reload(false); | 229 Reload(false); |
231 } | 230 } |
232 | 231 |
233 } // namespace policy | 232 } // namespace policy |
OLD | NEW |