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

Side by Side Diff: trunk/src/remoting/host/policy_hack/policy_watcher_linux.cc

Issue 14824006: Revert 198820 "Move FileEnumerator to its own file, do some refa..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 7 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 // 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"
21 #include "base/files/file_path.h" 20 #include "base/files/file_path.h"
22 #include "base/files/file_path_watcher.h" 21 #include "base/files/file_path_watcher.h"
23 #include "base/json/json_file_value_serializer.h" 22 #include "base/json/json_file_value_serializer.h"
24 #include "base/memory/scoped_ptr.h" 23 #include "base/memory/scoped_ptr.h"
25 #include "base/memory/weak_ptr.h" 24 #include "base/memory/weak_ptr.h"
26 #include "base/single_thread_task_runner.h" 25 #include "base/single_thread_task_runner.h"
27 #include "base/synchronization/waitable_event.h" 26 #include "base/synchronization/waitable_event.h"
28 #include "base/time.h" 27 #include "base/time.h"
29 #include "base/values.h" 28 #include "base/values.h"
30 29
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 base::Time last_modification = base::Time(); 103 base::Time last_modification = base::Time();
105 base::PlatformFileInfo file_info; 104 base::PlatformFileInfo file_info;
106 105
107 // If the path does not exist or points to a directory, it's safe to load. 106 // If the path does not exist or points to a directory, it's safe to load.
108 if (!file_util::GetFileInfo(config_dir_, &file_info) || 107 if (!file_util::GetFileInfo(config_dir_, &file_info) ||
109 !file_info.is_directory) { 108 !file_info.is_directory) {
110 return last_modification; 109 return last_modification;
111 } 110 }
112 111
113 // Enumerate the files and find the most recent modification timestamp. 112 // Enumerate the files and find the most recent modification timestamp.
114 base::FileEnumerator file_enumerator(config_dir_, 113 file_util::FileEnumerator file_enumerator(config_dir_,
115 false, 114 false,
116 base::FileEnumerator::FILES); 115 file_util::FileEnumerator::FILES);
117 for (base::FilePath config_file = file_enumerator.Next(); 116 for (base::FilePath config_file = file_enumerator.Next();
118 !config_file.empty(); 117 !config_file.empty();
119 config_file = file_enumerator.Next()) { 118 config_file = file_enumerator.Next()) {
120 if (file_util::GetFileInfo(config_file, &file_info) && 119 if (file_util::GetFileInfo(config_file, &file_info) &&
121 !file_info.is_directory) { 120 !file_info.is_directory) {
122 last_modification = std::max(last_modification, 121 last_modification = std::max(last_modification,
123 file_info.last_modified); 122 file_info.last_modified);
124 } 123 }
125 } 124 }
126 125
127 return last_modification; 126 return last_modification;
128 } 127 }
129 128
130 // Returns NULL if the policy dictionary couldn't be read. 129 // Returns NULL if the policy dictionary couldn't be read.
131 scoped_ptr<DictionaryValue> Load() { 130 scoped_ptr<DictionaryValue> Load() {
132 DCHECK(OnPolicyWatcherThread()); 131 DCHECK(OnPolicyWatcherThread());
133 // Enumerate the files and sort them lexicographically. 132 // Enumerate the files and sort them lexicographically.
134 std::set<base::FilePath> files; 133 std::set<base::FilePath> files;
135 base::FileEnumerator file_enumerator(config_dir_, false, 134 file_util::FileEnumerator file_enumerator(config_dir_, false,
136 base::FileEnumerator::FILES); 135 file_util::FileEnumerator::FILES);
137 for (base::FilePath config_file_path = file_enumerator.Next(); 136 for (base::FilePath config_file_path = file_enumerator.Next();
138 !config_file_path.empty(); config_file_path = file_enumerator.Next()) 137 !config_file_path.empty(); config_file_path = file_enumerator.Next())
139 files.insert(config_file_path); 138 files.insert(config_file_path);
140 139
141 // Start with an empty dictionary and merge the files' contents. 140 // Start with an empty dictionary and merge the files' contents.
142 scoped_ptr<DictionaryValue> policy(new DictionaryValue()); 141 scoped_ptr<DictionaryValue> policy(new DictionaryValue());
143 for (std::set<base::FilePath>::iterator config_file_iter = files.begin(); 142 for (std::set<base::FilePath>::iterator config_file_iter = files.begin();
144 config_file_iter != files.end(); ++config_file_iter) { 143 config_file_iter != files.end(); ++config_file_iter) {
145 JSONFileValueSerializer deserializer(*config_file_iter); 144 JSONFileValueSerializer deserializer(*config_file_iter);
146 deserializer.set_allow_trailing_comma(true); 145 deserializer.set_allow_trailing_comma(true);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 }; 246 };
248 247
249 PolicyWatcher* PolicyWatcher::Create( 248 PolicyWatcher* PolicyWatcher::Create(
250 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { 249 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
251 base::FilePath policy_dir(kPolicyDir); 250 base::FilePath policy_dir(kPolicyDir);
252 return new PolicyWatcherLinux(task_runner, policy_dir); 251 return new PolicyWatcherLinux(task_runner, policy_dir);
253 } 252 }
254 253
255 } // namespace policy_hack 254 } // namespace policy_hack
256 } // namespace remoting 255 } // namespace remoting
OLDNEW
« no previous file with comments | « trunk/src/net/url_request/url_request_file_dir_job.cc ('k') | trunk/src/third_party/leveldatabase/env_chromium.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698