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

Unified Diff: remoting/host/remoting_me2me_host.cc

Issue 10855249: [Chromoting] The daemon process now starts the networking process and passes the host configuration… (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 side-by-side diff with in-line comments
Download patch
Index: remoting/host/remoting_me2me_host.cc
diff --git a/remoting/host/remoting_me2me_host.cc b/remoting/host/remoting_me2me_host.cc
index be25fa363bd9e0e28aa3ef1fa00777313f1a5ae9..1884c088fa6ae6c6e22c989edb6884834551b8b5 100644
--- a/remoting/host/remoting_me2me_host.cc
+++ b/remoting/host/remoting_me2me_host.cc
@@ -12,7 +12,6 @@
#include "base/command_line.h"
#include "base/file_path.h"
#include "base/file_util.h"
-#include "base/files/file_path_watcher.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
@@ -33,7 +32,7 @@
#include "remoting/host/branding.h"
#include "remoting/host/chromoting_host.h"
#include "remoting/host/chromoting_host_context.h"
-#include "remoting/host/composite_host_config.h"
+#include "remoting/host/chromoting_messages.h"
#include "remoting/host/constants.h"
#include "remoting/host/desktop_environment.h"
#include "remoting/host/event_executor.h"
@@ -70,13 +69,22 @@
#include "ui/gfx/gtk_util.h"
#endif // defined(TOOLKIT_GTK)
+#if defined(REMOTING_MULTI_PROCESS)
+#include "remoting/host/json_host_config.h"
+#else // !defined(REMOTING_MULTI_PROCESS)
+#include "base/files/file_path_watcher.h"
+#include "remoting/host/composite_host_config.h"
+#endif // !defined(REMOTING_MULTI_PROCESS)
+
namespace {
// This is used for tagging system event logs.
const char kApplicationName[] = "chromoting";
-// The command line switch specifying the name of the Chromoting IPC channel.
-const char kDaemonIpcSwitchName[] = "chromoting-ipc";
+// The command line switch specifying the name of the daemon IPC endpoint.
+const char kDaemonIpcSwitchName[] = "daemon-pipe";
+
+#if !defined(REMOTING_MULTI_PROCESS)
// These are used for parsing the config-file locations from the command line,
// and for defining the default locations if the switches are not present.
@@ -86,6 +94,8 @@ const char kHostConfigSwitchName[] = "host-config";
const FilePath::CharType kDefaultHostConfigFile[] =
FILE_PATH_LITERAL("host.json");
+#endif // !defined(REMOTING_MULTI_PROCESS)
+
const int kMinPortNumber = 12400;
const int kMaxPortNumber = 12409;
@@ -107,6 +117,9 @@ class HostProcess
public:
HostProcess()
: message_loop_(MessageLoop::TYPE_UI),
+#if defined(REMOTING_MULTI_PROCESS)
+ config_(FilePath()),
+#endif // defined(REMOTING_MULTI_PROCESS)
#ifdef OFFICIAL_BUILD
oauth_use_official_client_id_(true),
#else
@@ -127,9 +140,12 @@ class HostProcess
new ChromotingHostContext(message_loop_.message_loop_proxy()));
context_->Start();
network_change_notifier_.reset(net::NetworkChangeNotifier::Create());
+
+#if !defined(REMOTING_MULTI_PROCESS)
config_updated_timer_.reset(new base::DelayTimer<HostProcess>(
FROM_HERE, base::TimeDelta::FromSeconds(2), this,
&HostProcess::ConfigUpdatedDelayed));
+#endif // !defined(REMOTING_MULTI_PROCESS)
}
bool InitWithCommandLine(const CommandLine* cmd_line) {
@@ -148,6 +164,7 @@ class HostProcess
context_->network_task_runner()));
}
+#if !defined(REMOTING_MULTI_PROCESS)
FilePath default_config_dir = remoting::GetConfigDir();
if (cmd_line->HasSwitch(kAuthConfigSwitchName)) {
FilePath path = cmd_line->GetSwitchValuePath(kAuthConfigSwitchName);
@@ -159,10 +176,50 @@ class HostProcess
host_config_path_ = cmd_line->GetSwitchValuePath(kHostConfigSwitchName);
}
config_.AddConfigPath(host_config_path_);
+#endif // !defined(REMOTING_MULTI_PROCESS)
return true;
}
+#if defined(REMOTING_MULTI_PROCESS)
+
+ void OnConfigUpdated(const std::string& config) {
+ DCHECK(message_loop_.message_loop_proxy()->BelongsToCurrentThread());
+
+ LOG(INFO) << "Processing new host configuration.";
+
+ if (!config_.SetSerializedData(config)) {
+ LOG(ERROR) << "Invalid configuration.";
+ return;
+ }
+
+ if (!ApplyConfig()) {
+ // TODO(alexeypa): make the process exit with
+ // |kInvalidHostConfigurationExitCode|
+ LOG(ERROR) << "Failed to apply the configuration.";
+ return;
+ }
+
+ // Start watching the policy (and eventually start the host) if this is
+ // the first configuration update. Otherwise, post a task to create new
+ // authenticator factory in case PIN has changed.
+ if (policy_watcher_.get() == NULL) {
+#if defined(OS_MACOSX) || defined(OS_WIN)
+ host_user_interface_.reset(new HostUserInterface(context_.get()));
+#endif
+
+ StartWatchingPolicy();
+ } else {
+ // PostTask to create new authenticator factory in case PIN has changed.
+ context_->network_task_runner()->PostTask(
+ FROM_HERE,
+ base::Bind(&HostProcess::CreateAuthenticatorFactory,
+ base::Unretained(this)));
+ }
+ }
+
+#else // !defined(REMOTING_MULTI_PROCESS)
+
void ConfigUpdated() {
DCHECK(message_loop_.message_loop_proxy()->BelongsToCurrentThread());
@@ -229,6 +286,8 @@ class HostProcess
#endif // defined (OS_WIN)
}
+#endif // !defined(REMOTING_MULTI_PROCESS)
+
void CreateAuthenticatorFactory() {
DCHECK(context_->network_task_runner()->BelongsToCurrentThread());
scoped_ptr<protocol::AuthenticatorFactory> factory(
@@ -240,10 +299,23 @@ class HostProcess
// IPC::Listener implementation.
virtual bool OnMessageReceived(const IPC::Message& message) {
+ DCHECK(message_loop_.message_loop_proxy()->BelongsToCurrentThread());
+
+#if defined(REMOTING_MULTI_PROCESS)
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP(HostProcess, message)
+ IPC_MESSAGE_HANDLER(ChromotingDaemonNetworkMsg_Configuration,
+ OnConfigUpdated)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+#else // !defined(REMOTING_MULTI_PROCESS)
return false;
+#endif // !defined(REMOTING_MULTI_PROCESS)
}
int Run() {
+#if !defined(REMOTING_MULTI_PROCESS)
if (!LoadConfig()) {
return kInvalidHostConfigurationExitCode;
}
@@ -260,6 +332,8 @@ class HostProcess
base::Bind(&HostProcess::ListenForConfigChanges,
base::Unretained(this)));
#endif
+#endif // !defined(REMOTING_MULTI_PROCESS)
+
message_loop_.Run();
#if defined(OS_MACOSX) || defined(OS_WIN)
@@ -289,19 +363,10 @@ class HostProcess
base::Bind(&HostProcess::OnPolicyUpdate, base::Unretained(this)));
}
- // Read host config, returning true if successful.
- bool LoadConfig() {
+ // Applies the host config, returning true if successful.
+ bool ApplyConfig() {
DCHECK(message_loop_.message_loop_proxy()->BelongsToCurrentThread());
- // TODO(sergeyu): There is a potential race condition: this function is
- // called on the main thread while the class members it mutates are used on
- // the network thread. Fix it. http://crbug.com/140986 .
-
- if (!config_.Read()) {
- LOG(ERROR) << "Failed to read config file.";
- return false;
- }
-
if (!config_.GetString(kHostIdConfigPath, &host_id_)) {
LOG(ERROR) << "host_id is not defined in the config.";
return false;
@@ -351,6 +416,23 @@ class HostProcess
return true;
}
+#if !defined(REMOTING_MULTI_PROCESS)
+ // Read host config, returning true if successful.
+ bool LoadConfig() {
+ DCHECK(message_loop_.message_loop_proxy()->BelongsToCurrentThread());
+
+ // TODO(sergeyu): There is a potential race condition: this function is
+ // called on the main thread while the class members it mutates are used on
+ // the network thread. Fix it. http://crbug.com/140986.
+ if (!config_.Read()) {
+ LOG(ERROR) << "Failed to read config file.";
+ return false;
+ }
+
+ return ApplyConfig();
+ }
+#endif // !defined(REMOTING_MULTI_PROCESS)
+
void OnPolicyUpdate(scoped_ptr<base::DictionaryValue> policies) {
if (!context_->network_task_runner()->BelongsToCurrentThread()) {
context_->network_task_runner()->PostTask(FROM_HERE, base::Bind(
@@ -603,8 +685,14 @@ class HostProcess
scoped_ptr<IPC::ChannelProxy> daemon_channel_;
scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
- FilePath host_config_path_;
+#if defined(REMOTING_MULTI_PROCESS)
+ JsonHostConfig config_;
+#else // !defined(REMOTING_MULTI_PROCESS)
CompositeHostConfig config_;
+ FilePath host_config_path_;
+ scoped_ptr<base::DelayTimer<HostProcess> > config_updated_timer_;
+ scoped_ptr<base::files::FilePathWatcher> config_watcher_;
+#endif // !defined(REMOTING_MULTI_PROCESS)
std::string host_id_;
HostKeyPair key_pair_;
@@ -618,8 +706,6 @@ class HostProcess
scoped_ptr<policy_hack::PolicyWatcher> policy_watcher_;
bool allow_nat_traversal_;
- scoped_ptr<base::files::FilePathWatcher> config_watcher_;
- scoped_ptr<base::DelayTimer<HostProcess> > config_updated_timer_;
bool restarting_;
bool shutting_down_;

Powered by Google App Engine
This is Rietveld 408576698