| 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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 | 266 |
| 267 scoped_ptr<ChromotingHostContext> context_; | 267 scoped_ptr<ChromotingHostContext> context_; |
| 268 | 268 |
| 269 // Created on the UI thread but used from the network thread. | 269 // Created on the UI thread but used from the network thread. |
| 270 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 270 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
| 271 | 271 |
| 272 // Accessed on the UI thread. | 272 // Accessed on the UI thread. |
| 273 scoped_ptr<IPC::ChannelProxy> daemon_channel_; | 273 scoped_ptr<IPC::ChannelProxy> daemon_channel_; |
| 274 | 274 |
| 275 // Created on the UI thread but used from the network thread. | 275 // Created on the UI thread but used from the network thread. |
| 276 FilePath host_config_path_; | 276 base::FilePath host_config_path_; |
| 277 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_; | 277 scoped_ptr<DesktopEnvironmentFactory> desktop_environment_factory_; |
| 278 | 278 |
| 279 // Accessed on the network thread. | 279 // Accessed on the network thread. |
| 280 HostState state_; | 280 HostState state_; |
| 281 | 281 |
| 282 scoped_ptr<ConfigFileWatcher> config_watcher_; | 282 scoped_ptr<ConfigFileWatcher> config_watcher_; |
| 283 | 283 |
| 284 std::string host_id_; | 284 std::string host_id_; |
| 285 protocol::SharedSecretHash host_secret_hash_; | 285 protocol::SharedSecretHash host_secret_hash_; |
| 286 HostKeyPair key_pair_; | 286 HostKeyPair key_pair_; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 #else // !defined(REMOTING_MULTI_PROCESS) | 395 #else // !defined(REMOTING_MULTI_PROCESS) |
| 396 // Connect to the daemon process. | 396 // Connect to the daemon process. |
| 397 std::string channel_name = | 397 std::string channel_name = |
| 398 cmd_line->GetSwitchValueASCII(kDaemonPipeSwitchName); | 398 cmd_line->GetSwitchValueASCII(kDaemonPipeSwitchName); |
| 399 if (!channel_name.empty()) { | 399 if (!channel_name.empty()) { |
| 400 daemon_channel_.reset(new IPC::ChannelProxy( | 400 daemon_channel_.reset(new IPC::ChannelProxy( |
| 401 channel_name, IPC::Channel::MODE_CLIENT, this, | 401 channel_name, IPC::Channel::MODE_CLIENT, this, |
| 402 context_->network_task_runner())); | 402 context_->network_task_runner())); |
| 403 } | 403 } |
| 404 | 404 |
| 405 FilePath default_config_dir = remoting::GetConfigDir(); | 405 base::FilePath default_config_dir = remoting::GetConfigDir(); |
| 406 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile); | 406 host_config_path_ = default_config_dir.Append(kDefaultHostConfigFile); |
| 407 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { | 407 if (cmd_line->HasSwitch(kHostConfigSwitchName)) { |
| 408 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); | 408 host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName); |
| 409 } | 409 } |
| 410 #endif // !defined(REMOTING_MULTI_PROCESS) | 410 #endif // !defined(REMOTING_MULTI_PROCESS) |
| 411 | 411 |
| 412 return true; | 412 return true; |
| 413 } | 413 } |
| 414 | 414 |
| 415 void HostProcess::OnConfigUpdated( | 415 void HostProcess::OnConfigUpdated( |
| 416 const std::string& serialized_config) { | 416 const std::string& serialized_config) { |
| 417 if (!context_->network_task_runner()->BelongsToCurrentThread()) { | 417 if (!context_->network_task_runner()->BelongsToCurrentThread()) { |
| 418 context_->network_task_runner()->PostTask(FROM_HERE, | 418 context_->network_task_runner()->PostTask(FROM_HERE, |
| 419 base::Bind(&HostProcess::OnConfigUpdated, this, serialized_config)); | 419 base::Bind(&HostProcess::OnConfigUpdated, this, serialized_config)); |
| 420 return; | 420 return; |
| 421 } | 421 } |
| 422 | 422 |
| 423 // Filter out duplicates. | 423 // Filter out duplicates. |
| 424 if (serialized_config_ == serialized_config) | 424 if (serialized_config_ == serialized_config) |
| 425 return; | 425 return; |
| 426 | 426 |
| 427 LOG(INFO) << "Processing new host configuration."; | 427 LOG(INFO) << "Processing new host configuration."; |
| 428 | 428 |
| 429 serialized_config_ = serialized_config; | 429 serialized_config_ = serialized_config; |
| 430 scoped_ptr<JsonHostConfig> config(new JsonHostConfig(FilePath())); | 430 scoped_ptr<JsonHostConfig> config(new JsonHostConfig(base::FilePath())); |
| 431 if (!config->SetSerializedData(serialized_config)) { | 431 if (!config->SetSerializedData(serialized_config)) { |
| 432 LOG(ERROR) << "Invalid configuration."; | 432 LOG(ERROR) << "Invalid configuration."; |
| 433 ShutdownHost(kInvalidHostConfigurationExitCode); | 433 ShutdownHost(kInvalidHostConfigurationExitCode); |
| 434 return; | 434 return; |
| 435 } | 435 } |
| 436 | 436 |
| 437 if (!ApplyConfig(config.Pass())) { | 437 if (!ApplyConfig(config.Pass())) { |
| 438 LOG(ERROR) << "Failed to apply the configuration."; | 438 LOG(ERROR) << "Failed to apply the configuration."; |
| 439 ShutdownHost(kInvalidHostConfigurationExitCode); | 439 ShutdownHost(kInvalidHostConfigurationExitCode); |
| 440 return; | 440 return; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); | 551 DCHECK(context_->ui_task_runner()->BelongsToCurrentThread()); |
| 552 | 552 |
| 553 if (!InitWithCommandLine(CommandLine::ForCurrentProcess())) { | 553 if (!InitWithCommandLine(CommandLine::ForCurrentProcess())) { |
| 554 OnConfigWatcherError(); | 554 OnConfigWatcherError(); |
| 555 return; | 555 return; |
| 556 } | 556 } |
| 557 | 557 |
| 558 #if defined(OS_LINUX) | 558 #if defined(OS_LINUX) |
| 559 // If an audio pipe is specific on the command-line then initialize | 559 // If an audio pipe is specific on the command-line then initialize |
| 560 // AudioCapturerLinux to capture from it. | 560 // AudioCapturerLinux to capture from it. |
| 561 FilePath audio_pipe_name = CommandLine::ForCurrentProcess()-> | 561 base::FilePath audio_pipe_name = CommandLine::ForCurrentProcess()-> |
| 562 GetSwitchValuePath(kAudioPipeSwitchName); | 562 GetSwitchValuePath(kAudioPipeSwitchName); |
| 563 if (!audio_pipe_name.empty()) { | 563 if (!audio_pipe_name.empty()) { |
| 564 remoting::AudioCapturerLinux::InitializePipeReader( | 564 remoting::AudioCapturerLinux::InitializePipeReader( |
| 565 context_->audio_task_runner(), audio_pipe_name); | 565 context_->audio_task_runner(), audio_pipe_name); |
| 566 } | 566 } |
| 567 #endif // defined(OS_LINUX) | 567 #endif // defined(OS_LINUX) |
| 568 | 568 |
| 569 // Create a desktop environment factory appropriate to the build type & | 569 // Create a desktop environment factory appropriate to the build type & |
| 570 // platform. | 570 // platform. |
| 571 #if defined(OS_WIN) | 571 #if defined(OS_WIN) |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 host_user_interface_.reset(); | 634 host_user_interface_.reset(); |
| 635 | 635 |
| 636 // It is now safe for the HostProcess to be deleted. | 636 // It is now safe for the HostProcess to be deleted. |
| 637 self_ = NULL; | 637 self_ = NULL; |
| 638 | 638 |
| 639 #if defined(OS_LINUX) | 639 #if defined(OS_LINUX) |
| 640 // Cause the global AudioPipeReader to be freed, otherwise the audio | 640 // Cause the global AudioPipeReader to be freed, otherwise the audio |
| 641 // thread will remain in-use and prevent the process from exiting. | 641 // thread will remain in-use and prevent the process from exiting. |
| 642 // TODO(wez): DesktopEnvironmentFactory should own the pipe reader. | 642 // TODO(wez): DesktopEnvironmentFactory should own the pipe reader. |
| 643 // See crbug.com/161373 and crbug.com/104544. | 643 // See crbug.com/161373 and crbug.com/104544. |
| 644 AudioCapturerLinux::InitializePipeReader(NULL, FilePath()); | 644 AudioCapturerLinux::InitializePipeReader(NULL, base::FilePath()); |
| 645 #endif | 645 #endif |
| 646 } | 646 } |
| 647 | 647 |
| 648 // Overridden from HeartbeatSender::Listener | 648 // Overridden from HeartbeatSender::Listener |
| 649 void HostProcess::OnUnknownHostIdError() { | 649 void HostProcess::OnUnknownHostIdError() { |
| 650 LOG(ERROR) << "Host ID not found."; | 650 LOG(ERROR) << "Host ID not found."; |
| 651 ShutdownHost(kInvalidHostIdExitCode); | 651 ShutdownHost(kInvalidHostIdExitCode); |
| 652 } | 652 } |
| 653 | 653 |
| 654 void HostProcess::OnHostDeleted() { | 654 void HostProcess::OnHostDeleted() { |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1128 | 1128 |
| 1129 // Register and initialize common controls. | 1129 // Register and initialize common controls. |
| 1130 INITCOMMONCONTROLSEX info; | 1130 INITCOMMONCONTROLSEX info; |
| 1131 info.dwSize = sizeof(info); | 1131 info.dwSize = sizeof(info); |
| 1132 info.dwICC = ICC_STANDARD_CLASSES; | 1132 info.dwICC = ICC_STANDARD_CLASSES; |
| 1133 InitCommonControlsEx(&info); | 1133 InitCommonControlsEx(&info); |
| 1134 | 1134 |
| 1135 // Mark the process as DPI-aware, so Windows won't scale coordinates in APIs. | 1135 // Mark the process as DPI-aware, so Windows won't scale coordinates in APIs. |
| 1136 // N.B. This API exists on Vista and above. | 1136 // N.B. This API exists on Vista and above. |
| 1137 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { | 1137 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
| 1138 FilePath path(base::GetNativeLibraryName(UTF8ToUTF16("user32"))); | 1138 base::FilePath path(base::GetNativeLibraryName(UTF8ToUTF16("user32"))); |
| 1139 base::ScopedNativeLibrary user32(path); | 1139 base::ScopedNativeLibrary user32(path); |
| 1140 CHECK(user32.is_valid()); | 1140 CHECK(user32.is_valid()); |
| 1141 | 1141 |
| 1142 typedef BOOL (WINAPI * SetProcessDPIAwareFn)(); | 1142 typedef BOOL (WINAPI * SetProcessDPIAwareFn)(); |
| 1143 SetProcessDPIAwareFn set_process_dpi_aware = | 1143 SetProcessDPIAwareFn set_process_dpi_aware = |
| 1144 static_cast<SetProcessDPIAwareFn>( | 1144 static_cast<SetProcessDPIAwareFn>( |
| 1145 user32.GetFunctionPointer("SetProcessDPIAware")); | 1145 user32.GetFunctionPointer("SetProcessDPIAware")); |
| 1146 set_process_dpi_aware(); | 1146 set_process_dpi_aware(); |
| 1147 } | 1147 } |
| 1148 | 1148 |
| 1149 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting | 1149 // CommandLine::Init() ignores the passed |argc| and |argv| on Windows getting |
| 1150 // the command line from GetCommandLineW(), so we can safely pass NULL here. | 1150 // the command line from GetCommandLineW(), so we can safely pass NULL here. |
| 1151 return main(0, NULL); | 1151 return main(0, NULL); |
| 1152 } | 1152 } |
| 1153 | 1153 |
| 1154 #endif // defined(OS_WIN) | 1154 #endif // defined(OS_WIN) |
| OLD | NEW |