diff options
author | alexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-11 18:24:24 +0000 |
---|---|---|
committer | alexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-11 18:24:24 +0000 |
commit | 3a2a692110b92c26b2747e02d4a20ad30aa35680 (patch) | |
tree | eb4ef3cd927f02a7c178167ab3c53e29c4d1d7a1 /remoting | |
parent | d897845a70bcd85644dafec57282d58370082996 (diff) | |
download | chromium_src-3a2a692110b92c26b2747e02d4a20ad30aa35680.zip chromium_src-3a2a692110b92c26b2747e02d4a20ad30aa35680.tar.gz chromium_src-3a2a692110b92c26b2747e02d4a20ad30aa35680.tar.bz2 |
Making sure that |config_updated_timer_| is scheduled and destroyed on the same thread.
BUG=127321
Review URL: https://chromiumcodereview.appspot.com/10389086
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@136616 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/host/remoting_me2me_host.cc | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/remoting/host/remoting_me2me_host.cc b/remoting/host/remoting_me2me_host.cc index 8f4ddf7..cf732e3 100644 --- a/remoting/host/remoting_me2me_host.cc +++ b/remoting/host/remoting_me2me_host.cc @@ -100,7 +100,7 @@ class HostProcess network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); config_updated_timer_.reset(new base::DelayTimer<HostProcess>( FROM_HERE, base::TimeDelta::FromSeconds(2), this, - &HostProcess::ConfigUpdated)); + &HostProcess::ConfigUpdatedDelayed)); } void InitWithCommandLine(const CommandLine* cmd_line) { @@ -123,6 +123,18 @@ class HostProcess } void ConfigUpdated() { + // The timer should be set and cleaned up on the same thread. + DCHECK(message_loop_.message_loop_proxy()->BelongsToCurrentThread()); + + // Call ConfigUpdatedDelayed after a short delay, so that this object won't + // try to read the updated configuration file before it has been + // completely written. + // If the writer moves the new configuration file into place atomically, + // this delay may not be necessary. + config_updated_timer_->Reset(); + } + + void ConfigUpdatedDelayed() { if (LoadConfig()) { context_->network_message_loop()->PostTask( FROM_HERE, @@ -136,21 +148,22 @@ class HostProcess #if defined(OS_WIN) class ConfigChangedDelegate : public base::files::FilePathWatcher::Delegate { public: - ConfigChangedDelegate(HostProcess* host_process) : - host_process_(host_process) { + ConfigChangedDelegate(base::MessageLoopProxy* message_loop, + const base::Closure& callback) + : message_loop_(message_loop), + callback_(callback) { } + void OnFilePathChanged(const FilePath& path) OVERRIDE { - // Call ConfigUpdated after a short delay, so that this object won't - // try to read the updated configuration file before it has been - // completely written. - // If the writer moves the new configuration file into place atomically, - // this delay may not be necessary. - host_process_->config_updated_timer_->Reset(); + message_loop_->PostTask(FROM_HERE, callback_); } + void OnFilePathError(const FilePath& path) OVERRIDE { } + private: - HostProcess* host_process_; + scoped_refptr<base::MessageLoopProxy> message_loop_; + base::Closure callback_; DISALLOW_COPY_AND_ASSIGN(ConfigChangedDelegate); }; @@ -159,10 +172,12 @@ class HostProcess void ListenForConfigChanges() { #if defined(OS_MACOSX) remoting::RegisterHupSignalHandler( - base::Bind(&HostProcess::ConfigUpdated, base::Unretained(this))); + base::Bind(&HostProcess::ConfigUpdatedDelayed, base::Unretained(this))); #elif defined(OS_WIN) scoped_refptr<base::files::FilePathWatcher::Delegate> delegate( - new ConfigChangedDelegate(this)); + new ConfigChangedDelegate( + message_loop_.message_loop_proxy(), + base::Bind(&HostProcess::ConfigUpdated, base::Unretained(this)))); config_watcher_.reset(new base::files::FilePathWatcher()); if (!config_watcher_->Watch(host_config_path_, delegate)) { LOG(ERROR) << "Couldn't watch file " << host_config_path_.value(); |