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

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

Issue 12163003: Add FilePath to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 | « remoting/host/linux/audio_pipe_reader.cc ('k') | remoting/host/remoting_me2me_host.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 //
(...skipping 14 matching lines...) Expand all
25 #include "base/single_thread_task_runner.h" 25 #include "base/single_thread_task_runner.h"
26 #include "base/synchronization/waitable_event.h" 26 #include "base/synchronization/waitable_event.h"
27 #include "base/time.h" 27 #include "base/time.h"
28 #include "base/values.h" 28 #include "base/values.h"
29 29
30 namespace remoting { 30 namespace remoting {
31 namespace policy_hack { 31 namespace policy_hack {
32 32
33 namespace { 33 namespace {
34 34
35 const FilePath::CharType kPolicyDir[] = 35 const base::FilePath::CharType kPolicyDir[] =
36 // Always read the Chrome policies (even on Chromium) so that policy 36 // Always read the Chrome policies (even on Chromium) so that policy
37 // enforcement can't be bypassed by running Chromium. 37 // enforcement can't be bypassed by running Chromium.
38 FILE_PATH_LITERAL("/etc/opt/chrome/policies/managed"); 38 FILE_PATH_LITERAL("/etc/opt/chrome/policies/managed");
39 39
40 // Amount of time we wait for the files on disk to settle before trying to load 40 // Amount of time we wait for the files on disk to settle before trying to load
41 // them. This alleviates the problem of reading partially written files and 41 // them. This alleviates the problem of reading partially written files and
42 // makes it possible to batch quasi-simultaneous changes. 42 // makes it possible to batch quasi-simultaneous changes.
43 const int kSettleIntervalSeconds = 5; 43 const int kSettleIntervalSeconds = 5;
44 44
45 } // namespace 45 } // namespace
46 46
47 class PolicyWatcherLinux : public PolicyWatcher { 47 class PolicyWatcherLinux : public PolicyWatcher {
48 public: 48 public:
49 PolicyWatcherLinux(scoped_refptr<base::SingleThreadTaskRunner> task_runner, 49 PolicyWatcherLinux(scoped_refptr<base::SingleThreadTaskRunner> task_runner,
50 const FilePath& config_dir) 50 const base::FilePath& config_dir)
51 : PolicyWatcher(task_runner), 51 : PolicyWatcher(task_runner),
52 config_dir_(config_dir), 52 config_dir_(config_dir),
53 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 53 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
54 // Detach the factory because we ensure that only the policy thread ever 54 // Detach the factory because we ensure that only the policy thread ever
55 // calls methods on this. Also, the API contract of having to call 55 // calls methods on this. Also, the API contract of having to call
56 // StopWatching() (which signals completion) after StartWatching() 56 // StopWatching() (which signals completion) after StartWatching()
57 // before this object can be destructed ensures there are no users of 57 // before this object can be destructed ensures there are no users of
58 // this object before it is destructed. 58 // this object before it is destructed.
59 weak_factory_.DetachFromThread(); 59 weak_factory_.DetachFromThread();
60 } 60 }
(...skipping 21 matching lines...) Expand all
82 ScheduleFallbackReloadTask(); 82 ScheduleFallbackReloadTask();
83 } 83 }
84 84
85 virtual void StopWatchingInternal() OVERRIDE { 85 virtual void StopWatchingInternal() OVERRIDE {
86 DCHECK(OnPolicyWatcherThread()); 86 DCHECK(OnPolicyWatcherThread());
87 // Cancel any inflight requests. 87 // Cancel any inflight requests.
88 watcher_.reset(); 88 watcher_.reset();
89 } 89 }
90 90
91 private: 91 private:
92 void OnFilePathChanged(const FilePath& path, bool error) { 92 void OnFilePathChanged(const base::FilePath& path, bool error) {
93 DCHECK(OnPolicyWatcherThread()); 93 DCHECK(OnPolicyWatcherThread());
94 94
95 if (!error) 95 if (!error)
96 Reload(); 96 Reload();
97 else 97 else
98 LOG(ERROR) << "PolicyWatcherLinux on " << path.value() << " failed."; 98 LOG(ERROR) << "PolicyWatcherLinux on " << path.value() << " failed.";
99 } 99 }
100 100
101 base::Time GetLastModification() { 101 base::Time GetLastModification() {
102 DCHECK(OnPolicyWatcherThread()); 102 DCHECK(OnPolicyWatcherThread());
103 base::Time last_modification = base::Time(); 103 base::Time last_modification = base::Time();
104 base::PlatformFileInfo file_info; 104 base::PlatformFileInfo file_info;
105 105
106 // 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.
107 if (!file_util::GetFileInfo(config_dir_, &file_info) || 107 if (!file_util::GetFileInfo(config_dir_, &file_info) ||
108 !file_info.is_directory) { 108 !file_info.is_directory) {
109 return last_modification; 109 return last_modification;
110 } 110 }
111 111
112 // Enumerate the files and find the most recent modification timestamp. 112 // Enumerate the files and find the most recent modification timestamp.
113 file_util::FileEnumerator file_enumerator(config_dir_, 113 file_util::FileEnumerator file_enumerator(config_dir_,
114 false, 114 false,
115 file_util::FileEnumerator::FILES); 115 file_util::FileEnumerator::FILES);
116 for (FilePath config_file = file_enumerator.Next(); 116 for (base::FilePath config_file = file_enumerator.Next();
117 !config_file.empty(); 117 !config_file.empty();
118 config_file = file_enumerator.Next()) { 118 config_file = file_enumerator.Next()) {
119 if (file_util::GetFileInfo(config_file, &file_info) && 119 if (file_util::GetFileInfo(config_file, &file_info) &&
120 !file_info.is_directory) { 120 !file_info.is_directory) {
121 last_modification = std::max(last_modification, 121 last_modification = std::max(last_modification,
122 file_info.last_modified); 122 file_info.last_modified);
123 } 123 }
124 } 124 }
125 125
126 return last_modification; 126 return last_modification;
127 } 127 }
128 128
129 // Returns NULL if the policy dictionary couldn't be read. 129 // Returns NULL if the policy dictionary couldn't be read.
130 scoped_ptr<DictionaryValue> Load() { 130 scoped_ptr<DictionaryValue> Load() {
131 DCHECK(OnPolicyWatcherThread()); 131 DCHECK(OnPolicyWatcherThread());
132 // Enumerate the files and sort them lexicographically. 132 // Enumerate the files and sort them lexicographically.
133 std::set<FilePath> files; 133 std::set<base::FilePath> files;
134 file_util::FileEnumerator file_enumerator(config_dir_, false, 134 file_util::FileEnumerator file_enumerator(config_dir_, false,
135 file_util::FileEnumerator::FILES); 135 file_util::FileEnumerator::FILES);
136 for (FilePath config_file_path = file_enumerator.Next(); 136 for (base::FilePath config_file_path = file_enumerator.Next();
137 !config_file_path.empty(); config_file_path = file_enumerator.Next()) 137 !config_file_path.empty(); config_file_path = file_enumerator.Next())
138 files.insert(config_file_path); 138 files.insert(config_file_path);
139 139
140 // Start with an empty dictionary and merge the files' contents. 140 // Start with an empty dictionary and merge the files' contents.
141 scoped_ptr<DictionaryValue> policy(new DictionaryValue()); 141 scoped_ptr<DictionaryValue> policy(new DictionaryValue());
142 for (std::set<FilePath>::iterator config_file_iter = files.begin(); 142 for (std::set<base::FilePath>::iterator config_file_iter = files.begin();
143 config_file_iter != files.end(); ++config_file_iter) { 143 config_file_iter != files.end(); ++config_file_iter) {
144 JSONFileValueSerializer deserializer(*config_file_iter); 144 JSONFileValueSerializer deserializer(*config_file_iter);
145 deserializer.set_allow_trailing_comma(true); 145 deserializer.set_allow_trailing_comma(true);
146 int error_code = 0; 146 int error_code = 0;
147 std::string error_msg; 147 std::string error_msg;
148 scoped_ptr<Value> value( 148 scoped_ptr<Value> value(
149 deserializer.Deserialize(&error_code, &error_msg)); 149 deserializer.Deserialize(&error_code, &error_msg));
150 if (!value.get()) { 150 if (!value.get()) {
151 LOG(WARNING) << "Failed to read configuration file " 151 LOG(WARNING) << "Failed to read configuration file "
152 << config_file_iter->value() << ": " << error_msg; 152 << config_file_iter->value() << ": " << error_msg;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 232
233 // Records last known modification timestamp of |config_dir_|. 233 // Records last known modification timestamp of |config_dir_|.
234 base::Time last_modification_file_; 234 base::Time last_modification_file_;
235 235
236 // The wall clock time at which the last modification timestamp was 236 // The wall clock time at which the last modification timestamp was
237 // recorded. It's better to not assume the file notification time and the 237 // recorded. It's better to not assume the file notification time and the
238 // wall clock times come from the same source, just in case there is some 238 // wall clock times come from the same source, just in case there is some
239 // non-local filesystem involved. 239 // non-local filesystem involved.
240 base::Time last_modification_clock_; 240 base::Time last_modification_clock_;
241 241
242 const FilePath config_dir_; 242 const base::FilePath config_dir_;
243 243
244 // Allows us to cancel any inflight FileWatcher events or scheduled reloads. 244 // Allows us to cancel any inflight FileWatcher events or scheduled reloads.
245 base::WeakPtrFactory<PolicyWatcherLinux> weak_factory_; 245 base::WeakPtrFactory<PolicyWatcherLinux> weak_factory_;
246 }; 246 };
247 247
248 PolicyWatcher* PolicyWatcher::Create( 248 PolicyWatcher* PolicyWatcher::Create(
249 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { 249 scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
250 FilePath policy_dir(kPolicyDir); 250 base::FilePath policy_dir(kPolicyDir);
251 return new PolicyWatcherLinux(task_runner, policy_dir); 251 return new PolicyWatcherLinux(task_runner, policy_dir);
252 } 252 }
253 253
254 } // namespace policy_hack 254 } // namespace policy_hack
255 } // namespace remoting 255 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/linux/audio_pipe_reader.cc ('k') | remoting/host/remoting_me2me_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698