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

Side by Side Diff: remoting/host/config_file_watcher.cc

Issue 10910206: [Chromoting] Do not post updated host configuration unless the configuration has actually changed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 | « no previous file | no next file » | 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 #include "remoting/host/config_file_watcher.h" 5 #include "remoting/host/config_file_watcher.h"
6 6
7 #include <string>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
9 #include "base/files/file_path_watcher.h" 11 #include "base/files/file_path_watcher.h"
10 #include "base/file_util.h" 12 #include "base/file_util.h"
11 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
13 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
14 #include "base/timer.h" 16 #include "base/timer.h"
15 17
16 namespace remoting { 18 namespace remoting {
(...skipping 26 matching lines...) Expand all
43 virtual ~ConfigFileWatcherImpl(); 45 virtual ~ConfigFileWatcherImpl();
44 46
45 void FinishStopping(); 47 void FinishStopping();
46 48
47 // Called every time the host configuration file is updated. 49 // Called every time the host configuration file is updated.
48 void OnConfigUpdated(const FilePath& path, bool error); 50 void OnConfigUpdated(const FilePath& path, bool error);
49 51
50 // Reads the configuration file and passes it to the delegate. 52 // Reads the configuration file and passes it to the delegate.
51 void ReloadConfig(); 53 void ReloadConfig();
52 54
55 std::string config_;
53 FilePath config_path_; 56 FilePath config_path_;
54 57
55 scoped_ptr<base::DelayTimer<ConfigFileWatcherImpl> > config_updated_timer_; 58 scoped_ptr<base::DelayTimer<ConfigFileWatcherImpl> > config_updated_timer_;
56 59
57 // Monitors the host configuration file. 60 // Monitors the host configuration file.
58 scoped_ptr<base::files::FilePathWatcher> config_watcher_; 61 scoped_ptr<base::files::FilePathWatcher> config_watcher_;
59 62
60 base::WeakPtrFactory<ConfigFileWatcher::Delegate> delegate_weak_factory_; 63 base::WeakPtrFactory<ConfigFileWatcher::Delegate> delegate_weak_factory_;
61 base::WeakPtr<ConfigFileWatcher::Delegate> delegate_; 64 base::WeakPtr<ConfigFileWatcher::Delegate> delegate_;
62 65
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 std::string config; 173 std::string config;
171 if (!file_util::ReadFileToString(config_path_, &config)) { 174 if (!file_util::ReadFileToString(config_path_, &config)) {
172 LOG(ERROR) << "Failed to read '" << config_path_.value() << "'"; 175 LOG(ERROR) << "Failed to read '" << config_path_.value() << "'";
173 main_task_runner_->PostTask( 176 main_task_runner_->PostTask(
174 FROM_HERE, 177 FROM_HERE,
175 base::Bind(&ConfigFileWatcher::Delegate::OnConfigWatcherError, 178 base::Bind(&ConfigFileWatcher::Delegate::OnConfigWatcherError,
176 delegate_)); 179 delegate_));
177 return; 180 return;
178 } 181 }
179 182
180 main_task_runner_->PostTask( 183 // Post an updated configuration only if it has actually changed.
181 FROM_HERE, 184 if (config_ != config) {
182 base::Bind(&ConfigFileWatcher::Delegate::OnConfigUpdated, delegate_, 185 config_ = config;
183 config)); 186 main_task_runner_->PostTask(
187 FROM_HERE,
188 base::Bind(&ConfigFileWatcher::Delegate::OnConfigUpdated, delegate_,
189 config_));
190 }
184 } 191 }
185 192
186 } // namespace remoting 193 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698