Chromium Code Reviews| 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 // 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); | 126 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); |
| 127 } | 127 } |
| 128 if (!config_.AddConfigPath(host_config_path_)) { | 128 if (!config_.AddConfigPath(host_config_path_)) { |
| 129 return false; | 129 return false; |
| 130 } | 130 } |
| 131 | 131 |
| 132 return true; | 132 return true; |
| 133 } | 133 } |
| 134 | 134 |
| 135 void ConfigUpdated() { | 135 void ConfigUpdated() { |
| 136 // The timer should be set and cleaned up on the same thread. | |
| 137 DCHECK(message_loop_.message_loop_proxy()->BelongsToCurrentThread()); | 136 DCHECK(message_loop_.message_loop_proxy()->BelongsToCurrentThread()); |
| 138 | 137 |
| 139 // Call ConfigUpdatedDelayed after a short delay, so that this object won't | 138 // Call ConfigUpdatedDelayed after a short delay, so that this object won't |
| 140 // try to read the updated configuration file before it has been | 139 // try to read the updated configuration file before it has been |
| 141 // completely written. | 140 // completely written. |
| 142 // If the writer moves the new configuration file into place atomically, | 141 // If the writer moves the new configuration file into place atomically, |
| 143 // this delay may not be necessary. | 142 // this delay may not be necessary. |
| 144 config_updated_timer_->Reset(); | 143 config_updated_timer_->Reset(); |
| 145 } | 144 } |
| 146 | 145 |
| 147 void ConfigUpdatedDelayed() { | 146 void ConfigUpdatedDelayed() { |
| 148 if (LoadConfig()) { | 147 DCHECK(message_loop_.message_loop_proxy()->BelongsToCurrentThread()); |
| 148 | |
| 149 if (config_.Reload() && LoadConfig()) { | |
|
simonmorris
2012/08/07 00:43:35
I think it's more natural to include the call to R
Sergey Ulanov
2012/08/07 00:57:03
Done. Also changed CompositeHostConfig::AddConfigP
| |
| 150 // PostTask to create new authenticator factory in case PIN has changed. | |
| 149 context_->network_task_runner()->PostTask( | 151 context_->network_task_runner()->PostTask( |
| 150 FROM_HERE, | 152 FROM_HERE, |
| 151 base::Bind(&HostProcess::CreateAuthenticatorFactory, | 153 base::Bind(&HostProcess::CreateAuthenticatorFactory, |
| 152 base::Unretained(this))); | 154 base::Unretained(this))); |
| 153 } else { | 155 } else { |
| 154 LOG(ERROR) << "Invalid configuration."; | 156 LOG(ERROR) << "Invalid configuration."; |
| 155 } | 157 } |
| 156 } | 158 } |
| 157 | 159 |
| 158 #if defined(OS_WIN) | 160 #if defined(OS_WIN) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 message_loop_.message_loop_proxy(), | 192 message_loop_.message_loop_proxy(), |
| 191 base::Bind(&HostProcess::ConfigUpdated, base::Unretained(this)))); | 193 base::Bind(&HostProcess::ConfigUpdated, base::Unretained(this)))); |
| 192 config_watcher_.reset(new base::files::FilePathWatcher()); | 194 config_watcher_.reset(new base::files::FilePathWatcher()); |
| 193 if (!config_watcher_->Watch(host_config_path_, delegate)) { | 195 if (!config_watcher_->Watch(host_config_path_, delegate)) { |
| 194 LOG(ERROR) << "Couldn't watch file " << host_config_path_.value(); | 196 LOG(ERROR) << "Couldn't watch file " << host_config_path_.value(); |
| 195 } | 197 } |
| 196 #endif | 198 #endif |
| 197 } | 199 } |
| 198 | 200 |
| 199 void CreateAuthenticatorFactory() { | 201 void CreateAuthenticatorFactory() { |
| 202 DCHECK(context_->network_task_runner()->BelongsToCurrentThread()); | |
| 200 scoped_ptr<protocol::AuthenticatorFactory> factory( | 203 scoped_ptr<protocol::AuthenticatorFactory> factory( |
| 201 new protocol::Me2MeHostAuthenticatorFactory( | 204 new protocol::Me2MeHostAuthenticatorFactory( |
| 202 key_pair_.GenerateCertificate(), | 205 key_pair_.GenerateCertificate(), |
| 203 *key_pair_.private_key(), host_secret_hash_)); | 206 *key_pair_.private_key(), host_secret_hash_)); |
| 204 host_->SetAuthenticatorFactory(factory.Pass()); | 207 host_->SetAuthenticatorFactory(factory.Pass()); |
| 205 } | 208 } |
| 206 | 209 |
| 207 int Run() { | 210 int Run() { |
| 208 if (!LoadConfig()) { | 211 if (!LoadConfig()) { |
| 209 return kInvalidHostConfigurationExitCode; | 212 return kInvalidHostConfigurationExitCode; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 private: | 247 private: |
| 245 void StartWatchingPolicy() { | 248 void StartWatchingPolicy() { |
| 246 policy_watcher_.reset( | 249 policy_watcher_.reset( |
| 247 policy_hack::PolicyWatcher::Create(context_->file_task_runner())); | 250 policy_hack::PolicyWatcher::Create(context_->file_task_runner())); |
| 248 policy_watcher_->StartWatching( | 251 policy_watcher_->StartWatching( |
| 249 base::Bind(&HostProcess::OnPolicyUpdate, base::Unretained(this))); | 252 base::Bind(&HostProcess::OnPolicyUpdate, base::Unretained(this))); |
| 250 } | 253 } |
| 251 | 254 |
| 252 // Read host config, returning true if successful. | 255 // Read host config, returning true if successful. |
| 253 bool LoadConfig() { | 256 bool LoadConfig() { |
| 257 DCHECK(message_loop_.message_loop_proxy()->BelongsToCurrentThread()); | |
| 258 | |
| 259 // TODO(sergeyu): There is a potential race condition: this function is | |
| 260 // called on the main thread while the class members it mutates are used on | |
| 261 // the network thread. Fix it. http://crbug.com/140986 . | |
| 262 | |
| 254 if (!config_.GetString(kHostIdConfigPath, &host_id_)) { | 263 if (!config_.GetString(kHostIdConfigPath, &host_id_)) { |
| 255 LOG(ERROR) << "host_id is not defined in the config."; | 264 LOG(ERROR) << "host_id is not defined in the config."; |
| 256 return false; | 265 return false; |
| 257 } | 266 } |
| 258 | 267 |
| 259 if (!key_pair_.Load(config_)) { | 268 if (!key_pair_.Load(config_)) { |
| 260 return false; | 269 return false; |
| 261 } | 270 } |
| 262 | 271 |
| 263 std::string host_secret_hash_string; | 272 std::string host_secret_hash_string; |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 637 user32.GetFunctionPointer("SetProcessDPIAware")); | 646 user32.GetFunctionPointer("SetProcessDPIAware")); |
| 638 set_process_dpi_aware(); | 647 set_process_dpi_aware(); |
| 639 } | 648 } |
| 640 | 649 |
| 641 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting | 650 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting |
| 642 // the command line from GetCommandLineW(), so we can safely pass NULL here. | 651 // the command line from GetCommandLineW(), so we can safely pass NULL here. |
| 643 return main(0, NULL); | 652 return main(0, NULL); |
| 644 } | 653 } |
| 645 | 654 |
| 646 #endif // defined(OS_WIN) | 655 #endif // defined(OS_WIN) |
| OLD | NEW |