Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(557)

Side by Side Diff: chrome/browser/policy/config_dir_policy_loader.cc

Issue 16392011: Move FileEnumerator to its own file, do some refactoring. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix incorrect includes Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
14 #include "base/json/json_file_value_serializer.h" 15 #include "base/json/json_file_value_serializer.h"
15 #include "base/json/json_reader.h" 16 #include "base/json/json_reader.h"
16 #include "base/logging.h" 17 #include "base/logging.h"
17 #include "base/platform_file.h" 18 #include "base/platform_file.h"
18 #include "base/stl_util.h" 19 #include "base/stl_util.h"
19 #include "chrome/browser/policy/policy_bundle.h" 20 #include "chrome/browser/policy/policy_bundle.h"
20 #include "chrome/browser/policy/policy_load_status.h" 21 #include "chrome/browser/policy/policy_load_status.h"
21 22
22 namespace policy { 23 namespace policy {
23 24
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 base::PlatformFileInfo info; 94 base::PlatformFileInfo info;
94 95
95 for (size_t i = 0; i < arraysize(kConfigDirSuffixes); ++i) { 96 for (size_t i = 0; i < arraysize(kConfigDirSuffixes); ++i) {
96 base::FilePath path(config_dir_.Append(kConfigDirSuffixes[i])); 97 base::FilePath path(config_dir_.Append(kConfigDirSuffixes[i]));
97 98
98 // Skip if the file doesn't exist, or it isn't a directory. 99 // Skip if the file doesn't exist, or it isn't a directory.
99 if (!file_util::GetFileInfo(path, &info) || !info.is_directory) 100 if (!file_util::GetFileInfo(path, &info) || !info.is_directory)
100 continue; 101 continue;
101 102
102 // Enumerate the files and find the most recent modification timestamp. 103 // Enumerate the files and find the most recent modification timestamp.
103 file_util::FileEnumerator file_enumerator(path, false, 104 base::FileEnumerator file_enumerator(path, false,
104 file_util::FileEnumerator::FILES); 105 base::FileEnumerator::FILES);
105 for (base::FilePath config_file = file_enumerator.Next(); 106 for (base::FilePath config_file = file_enumerator.Next();
106 !config_file.empty(); 107 !config_file.empty();
107 config_file = file_enumerator.Next()) { 108 config_file = file_enumerator.Next()) {
108 if (file_util::GetFileInfo(config_file, &info) && !info.is_directory) 109 if (file_util::GetFileInfo(config_file, &info) && !info.is_directory)
109 last_modification = std::max(last_modification, info.last_modified); 110 last_modification = std::max(last_modification, info.last_modified);
110 } 111 }
111 } 112 }
112 113
113 return last_modification; 114 return last_modification;
114 } 115 }
115 116
116 void ConfigDirPolicyLoader::LoadFromPath(const base::FilePath& path, 117 void ConfigDirPolicyLoader::LoadFromPath(const base::FilePath& path,
117 PolicyLevel level, 118 PolicyLevel level,
118 PolicyBundle* bundle) { 119 PolicyBundle* bundle) {
119 // Enumerate the files and sort them lexicographically. 120 // Enumerate the files and sort them lexicographically.
120 std::set<base::FilePath> files; 121 std::set<base::FilePath> files;
121 file_util::FileEnumerator file_enumerator(path, false, 122 base::FileEnumerator file_enumerator(path, false,
122 file_util::FileEnumerator::FILES); 123 base::FileEnumerator::FILES);
123 for (base::FilePath config_file_path = file_enumerator.Next(); 124 for (base::FilePath config_file_path = file_enumerator.Next();
124 !config_file_path.empty(); config_file_path = file_enumerator.Next()) 125 !config_file_path.empty(); config_file_path = file_enumerator.Next())
125 files.insert(config_file_path); 126 files.insert(config_file_path);
126 127
127 PolicyLoadStatusSample status; 128 PolicyLoadStatusSample status;
128 if (files.empty()) { 129 if (files.empty()) {
129 status.Add(POLICY_LOAD_STATUS_NO_POLICY); 130 status.Add(POLICY_LOAD_STATUS_NO_POLICY);
130 return; 131 return;
131 } 132 }
132 133
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } 224 }
224 } 225 }
225 226
226 void ConfigDirPolicyLoader::OnFileUpdated(const base::FilePath& path, 227 void ConfigDirPolicyLoader::OnFileUpdated(const base::FilePath& path,
227 bool error) { 228 bool error) {
228 if (!error) 229 if (!error)
229 Reload(false); 230 Reload(false);
230 } 231 }
231 232
232 } // namespace policy 233 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/media_galleries/fileapi/native_media_file_util.cc ('k') | chrome/browser/policy/policy_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698