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

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

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

Powered by Google App Engine
This is Rietveld 408576698