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 // 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/nat_policy.h" | 15 #include "remoting/host/policy_hack/nat_policy.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_path.h" | 19 #include "base/file_path.h" |
20 #include "base/file_util.h" | 20 #include "base/file_util.h" |
21 #include "base/files/file_path_watcher.h" | 21 #include "base/files/file_path_watcher.h" |
22 #include "base/json/json_file_value_serializer.h" | 22 #include "base/json/json_file_value_serializer.h" |
23 #include "base/memory/scoped_ptr.h" | 23 #include "base/memory/scoped_ptr.h" |
24 #include "base/memory/weak_ptr.h" | 24 #include "base/memory/weak_ptr.h" |
25 #include "base/message_loop_proxy.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 FilePath::CharType kPolicyDir[] = |
36 FILE_PATH_LITERAL("/etc/opt/chrome/policies/managed"); | 36 FILE_PATH_LITERAL("/etc/opt/chrome/policies/managed"); |
37 | 37 |
38 // Amount of time we wait for the files on disk to settle before trying to load | 38 // Amount of time we wait for the files on disk to settle before trying to load |
39 // them. This alleviates the problem of reading partially written files and | 39 // them. This alleviates the problem of reading partially written files and |
40 // makes it possible to batch quasi-simultaneous changes. | 40 // makes it possible to batch quasi-simultaneous changes. |
41 const int kSettleIntervalSeconds = 5; | 41 const int kSettleIntervalSeconds = 5; |
42 | 42 |
43 } // namespace | 43 } // namespace |
44 | 44 |
45 class NatPolicyLinux : public NatPolicy { | 45 class NatPolicyLinux : public NatPolicy { |
46 public: | 46 public: |
47 NatPolicyLinux(base::MessageLoopProxy* message_loop_proxy, | 47 NatPolicyLinux(scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
48 const FilePath& config_dir) | 48 const FilePath& config_dir) |
49 : NatPolicy(message_loop_proxy), | 49 : NatPolicy(task_runner), |
50 config_dir_(config_dir), | 50 config_dir_(config_dir), |
51 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 51 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
52 // Detach the factory because we ensure that only the policy thread ever | 52 // Detach the factory because we ensure that only the policy thread ever |
53 // calls methods on this. Also, the API contract of having to call | 53 // calls methods on this. Also, the API contract of having to call |
54 // StopWatching() (which signals completion) after StartWatching() | 54 // StopWatching() (which signals completion) after StartWatching() |
55 // before this object can be destructed ensures there are no users of | 55 // before this object can be destructed ensures there are no users of |
56 // this object before it is destructed. | 56 // this object before it is destructed. |
57 weak_factory_.DetachFromThread(); | 57 weak_factory_.DetachFromThread(); |
58 } | 58 } |
59 | 59 |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 // wall clock times come from the same source, just in case there is some | 261 // wall clock times come from the same source, just in case there is some |
262 // non-local filesystem involved. | 262 // non-local filesystem involved. |
263 base::Time last_modification_clock_; | 263 base::Time last_modification_clock_; |
264 | 264 |
265 const FilePath config_dir_; | 265 const FilePath config_dir_; |
266 | 266 |
267 // Allows us to cancel any inflight FileWatcher events or scheduled reloads. | 267 // Allows us to cancel any inflight FileWatcher events or scheduled reloads. |
268 base::WeakPtrFactory<NatPolicyLinux> weak_factory_; | 268 base::WeakPtrFactory<NatPolicyLinux> weak_factory_; |
269 }; | 269 }; |
270 | 270 |
271 NatPolicy* NatPolicy::Create(base::MessageLoopProxy* message_loop_proxy) { | 271 NatPolicy* NatPolicy::Create( |
| 272 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
272 FilePath policy_dir(kPolicyDir); | 273 FilePath policy_dir(kPolicyDir); |
273 return new NatPolicyLinux(message_loop_proxy, policy_dir); | 274 return new NatPolicyLinux(task_runner, policy_dir); |
274 } | 275 } |
275 | 276 |
276 } // namespace policy_hack | 277 } // namespace policy_hack |
277 } // namespace remoting | 278 } // namespace remoting |
OLD | NEW |