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

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

Issue 10831184: Fix Me2Me host to properly reload config when it changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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
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 // This file implements a standalone host process for Me2Me. 5 // This file implements a standalone host process for Me2Me.
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/at_exit.h" 9 #include "base/at_exit.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); 109 network_change_notifier_.reset(net::NetworkChangeNotifier::Create());
110 config_updated_timer_.reset(new base::DelayTimer<HostProcess>( 110 config_updated_timer_.reset(new base::DelayTimer<HostProcess>(
111 FROM_HERE, base::TimeDelta::FromSeconds(2), this, 111 FROM_HERE, base::TimeDelta::FromSeconds(2), this,
112 &HostProcess::ConfigUpdatedDelayed)); 112 &HostProcess::ConfigUpdatedDelayed));
113 } 113 }
114 114
115 bool InitWithCommandLine(const CommandLine* cmd_line) { 115 bool InitWithCommandLine(const CommandLine* cmd_line) {
116 FilePath default_config_dir = remoting::GetConfigDir(); 116 FilePath default_config_dir = remoting::GetConfigDir();
117 if (cmd_line->HasSwitch(kAuthConfigSwitchName)) { 117 if (cmd_line->HasSwitch(kAuthConfigSwitchName)) {
118 FilePath path = cmd_line->GetSwitchValuePath(kAuthConfigSwitchName); 118 FilePath path = cmd_line->GetSwitchValuePath(kAuthConfigSwitchName);
119 if (!config_.AddConfigPath(path)) { 119 config_.AddConfigPath(path);
120 return false;
121 }
122 } 120 }
123 121
124 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile); 122 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile);
125 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { 123 if (cmd_line->HasSwitch(kHostConfigSwitchName)) {
126 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); 124 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName);
127 } 125 }
128 if (!config_.AddConfigPath(host_config_path_)) { 126 config_.AddConfigPath(host_config_path_);
129 return false;
130 }
131 127
132 return true; 128 return true;
simonmorris 2012/08/07 01:03:02 true -> LoadConfig() ?
Sergey Ulanov 2012/08/07 01:22:43 Run() will call LoadConfig() - don't think we need
simonmorris 2012/08/07 15:48:59 OK.
133 } 129 }
134 130
135 void ConfigUpdated() { 131 void ConfigUpdated() {
136 // The timer should be set and cleaned up on the same thread.
137 DCHECK(message_loop_.message_loop_proxy()->BelongsToCurrentThread()); 132 DCHECK(message_loop_.message_loop_proxy()->BelongsToCurrentThread());
138 133
139 // Call ConfigUpdatedDelayed after a short delay, so that this object won't 134 // Call ConfigUpdatedDelayed after a short delay, so that this object won't
140 // try to read the updated configuration file before it has been 135 // try to read the updated configuration file before it has been
141 // completely written. 136 // completely written.
142 // If the writer moves the new configuration file into place atomically, 137 // If the writer moves the new configuration file into place atomically,
143 // this delay may not be necessary. 138 // this delay may not be necessary.
144 config_updated_timer_->Reset(); 139 config_updated_timer_->Reset();
145 } 140 }
146 141
147 void ConfigUpdatedDelayed() { 142 void ConfigUpdatedDelayed() {
143 DCHECK(message_loop_.message_loop_proxy()->BelongsToCurrentThread());
144
148 if (LoadConfig()) { 145 if (LoadConfig()) {
146 // PostTask to create new authenticator factory in case PIN has changed.
149 context_->network_task_runner()->PostTask( 147 context_->network_task_runner()->PostTask(
150 FROM_HERE, 148 FROM_HERE,
151 base::Bind(&HostProcess::CreateAuthenticatorFactory, 149 base::Bind(&HostProcess::CreateAuthenticatorFactory,
152 base::Unretained(this))); 150 base::Unretained(this)));
153 } else { 151 } else {
154 LOG(ERROR) << "Invalid configuration."; 152 LOG(ERROR) << "Invalid configuration.";
155 } 153 }
156 } 154 }
157 155
158 #if defined(OS_WIN) 156 #if defined(OS_WIN)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 message_loop_.message_loop_proxy(), 188 message_loop_.message_loop_proxy(),
191 base::Bind(&HostProcess::ConfigUpdated, base::Unretained(this)))); 189 base::Bind(&HostProcess::ConfigUpdated, base::Unretained(this))));
192 config_watcher_.reset(new base::files::FilePathWatcher()); 190 config_watcher_.reset(new base::files::FilePathWatcher());
193 if (!config_watcher_->Watch(host_config_path_, delegate)) { 191 if (!config_watcher_->Watch(host_config_path_, delegate)) {
194 LOG(ERROR) << "Couldn't watch file " << host_config_path_.value(); 192 LOG(ERROR) << "Couldn't watch file " << host_config_path_.value();
195 } 193 }
196 #endif 194 #endif
197 } 195 }
198 196
199 void CreateAuthenticatorFactory() { 197 void CreateAuthenticatorFactory() {
198 DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
200 scoped_ptr<protocol::AuthenticatorFactory> factory( 199 scoped_ptr<protocol::AuthenticatorFactory> factory(
201 new protocol::Me2MeHostAuthenticatorFactory( 200 new protocol::Me2MeHostAuthenticatorFactory(
202 key_pair_.GenerateCertificate(), 201 key_pair_.GenerateCertificate(),
203 *key_pair_.private_key(), host_secret_hash_)); 202 *key_pair_.private_key(), host_secret_hash_));
204 host_->SetAuthenticatorFactory(factory.Pass()); 203 host_->SetAuthenticatorFactory(factory.Pass());
205 } 204 }
206 205
207 int Run() { 206 int Run() {
208 if (!LoadConfig()) { 207 if (!LoadConfig()) {
209 return kInvalidHostConfigurationExitCode; 208 return kInvalidHostConfigurationExitCode;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 private: 243 private:
245 void StartWatchingPolicy() { 244 void StartWatchingPolicy() {
246 policy_watcher_.reset( 245 policy_watcher_.reset(
247 policy_hack::PolicyWatcher::Create(context_->file_task_runner())); 246 policy_hack::PolicyWatcher::Create(context_->file_task_runner()));
248 policy_watcher_->StartWatching( 247 policy_watcher_->StartWatching(
249 base::Bind(&HostProcess::OnPolicyUpdate, base::Unretained(this))); 248 base::Bind(&HostProcess::OnPolicyUpdate, base::Unretained(this)));
250 } 249 }
251 250
252 // Read host config, returning true if successful. 251 // Read host config, returning true if successful.
253 bool LoadConfig() { 252 bool LoadConfig() {
253 DCHECK(message_loop_.message_loop_proxy()->BelongsToCurrentThread());
254
255 // TODO(sergeyu): There is a potential race condition: this function is
256 // called on the main thread while the class members it mutates are used on
257 // the network thread. Fix it. http://crbug.com/140986 .
258
259 if (!config_.Read()) {
260 LOG(ERROR) << "Failed to read config file.";
261 return false;
262 }
263
254 if (!config_.GetString(kHostIdConfigPath, &host_id_)) { 264 if (!config_.GetString(kHostIdConfigPath, &host_id_)) {
255 LOG(ERROR) << "host_id is not defined in the config."; 265 LOG(ERROR) << "host_id is not defined in the config.";
256 return false; 266 return false;
257 } 267 }
258 268
259 if (!key_pair_.Load(config_)) { 269 if (!key_pair_.Load(config_)) {
260 return false; 270 return false;
261 } 271 }
262 272
263 std::string host_secret_hash_string; 273 std::string host_secret_hash_string;
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 user32.GetFunctionPointer("SetProcessDPIAware")); 647 user32.GetFunctionPointer("SetProcessDPIAware"));
638 set_process_dpi_aware(); 648 set_process_dpi_aware();
639 } 649 }
640 650
641 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting 651 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting
642 // the command line from GetCommandLineW(), so we can safely pass NULL here. 652 // the command line from GetCommandLineW(), so we can safely pass NULL here.
643 return main(0, NULL); 653 return main(0, NULL);
644 } 654 }
645 655
646 #endif // defined(OS_WIN) 656 #endif // defined(OS_WIN)
OLDNEW
« remoting/host/composite_host_config.h ('K') | « remoting/host/composite_host_config.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698