Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef REMOTING_HOST_DAEMON_CONFIG_WATCHER_H_ | |
| 6 #define REMOTING_HOST_DAEMON_CONFIG_WATCHER_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/compiler_specific.h" | |
| 10 #include "base/file_path.h" | |
| 11 #include "base/memory/ref_counted.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "base/timer.h" | |
| 15 | |
| 16 namespace base { | |
| 17 class SingleThreadTaskRunner; | |
| 18 class Thread; | |
| 19 | |
| 20 namespace files { | |
| 21 class FilePathWatcher; | |
| 22 } // namespace files | |
| 23 } // namespace base | |
| 24 | |
| 25 namespace remoting { | |
| 26 | |
| 27 extern const char kHostConfigSwitchName[]; | |
| 28 extern const FilePath::CharType kDefaultHostConfigFile[]; | |
| 29 | |
| 30 class ConfigFileWatcher { | |
| 31 public: | |
| 32 class Delegate { | |
| 33 public: | |
| 34 virtual ~Delegate(); | |
|
Wez
2012/08/30 20:36:04
nit: Should this be protected, so that only implem
alexeypa (please no reviews)
2012/08/30 23:15:13
None of delegate declarations use protected destru
Wez
2012/08/31 00:23:04
It doesn't seem right, does it? Either way, not a
| |
| 35 | |
| 36 // Called once after starting watching the configuration file and every time | |
| 37 // the file changes. | |
| 38 virtual void OnConfigUpdated(const std::string& config) = 0; | |
| 39 | |
| 40 // Called when the configuration file watcher encountered an error. | |
| 41 virtual void OnConfigWatcherError() = 0; | |
| 42 }; | |
| 43 | |
| 44 // Creates a configuration file watcher that lives at the |io_task_runner| | |
| 45 // thread but posts config file updates on on |main_task_runner|. | |
| 46 ConfigFileWatcher( | |
| 47 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | |
| 48 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | |
| 49 const base::WeakPtr<Delegate>& delegate); | |
|
Wez
2012/08/30 20:36:04
nit: You're forcing the caller to arrange to provi
alexeypa (please no reviews)
2012/08/30 23:15:13
Done.
| |
| 50 | |
| 51 virtual ~ConfigFileWatcher(); | |
| 52 | |
| 53 // Starts watching |config_path|. | |
| 54 void Watch(const FilePath& config_path); | |
| 55 | |
| 56 // Stops watching the configuration file and delete itself. | |
| 57 void StopAndDelete(); | |
|
Wez
2012/08/30 20:36:04
Should the destructor be public if it's intended t
alexeypa (please no reviews)
2012/08/30 23:15:13
scoped_ptr<ConfigFileWatcher> will not compile if
Wez
2012/08/31 00:23:04
If the calling code isn't at liberty to delete the
alexeypa (please no reviews)
2012/08/31 21:26:55
No, the only real need is to detect that StopAndDe
| |
| 58 | |
| 59 private: | |
| 60 // Called every time the host configuration file is updated. | |
| 61 void OnConfigUpdated(const FilePath& path, bool error); | |
| 62 | |
| 63 // Reads the configuration file and passes it to the delegate. | |
| 64 void ReloadConfig(); | |
| 65 | |
| 66 FilePath config_path_; | |
| 67 | |
| 68 scoped_ptr<base::DelayTimer<ConfigFileWatcher> > config_updated_timer_; | |
| 69 | |
| 70 // Monitors the host configuration file changes. | |
|
Wez
2012/08/30 20:36:04
nit: Remove "changes", or add "for" before it.
alexeypa (please no reviews)
2012/08/30 23:15:13
Done.
| |
| 71 scoped_ptr<base::files::FilePathWatcher> config_watcher_; | |
| 72 | |
| 73 base::WeakPtr<Delegate> delegate_; | |
| 74 | |
| 75 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | |
| 76 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | |
| 77 | |
| 78 DISALLOW_COPY_AND_ASSIGN(ConfigFileWatcher); | |
| 79 }; | |
| 80 | |
| 81 } // namespace remoting | |
| 82 | |
| 83 #endif // REMOTING_HOST_DAEMON_CONFIG_WATCHER_H_ | |
| OLD | NEW |