Chromium Code Reviews| Index: remoting/host/me2me_host.cc |
| diff --git a/remoting/host/me2me_host.cc b/remoting/host/me2me_host.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..14d97e32b9f1c1d380e6ab25a7559364be66ce37 |
| --- /dev/null |
| +++ b/remoting/host/me2me_host.cc |
| @@ -0,0 +1,201 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
|
Wez
2011/11/11 00:24:09
This file should really be remoting_me2me_host.cc,
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| +// |
| +// This file implements a standalone host process for Me2Me, which is used for |
| +// the Virtual Me2Me implementation. Currently, this is Linux-only. |
|
Sergey Ulanov
2011/11/11 00:00:43
I don't think it is necessary to mention Virtual M
Wez
2011/11/11 00:24:09
nit: This host isn't intrinsically tied to the vir
Wez
2011/11/11 00:33:00
The paths are Posix-friendly, and might cause issu
Lambros
2011/11/15 23:27:36
Fixed comment.
Lambros
2011/11/15 23:27:36
Windows will need a different config-file location
|
| + |
| +#include <stdlib.h> |
| + |
| +#include <iostream> |
|
Sergey Ulanov
2011/11/11 00:00:43
is this used anywhere?
Lambros
2011/11/15 23:27:36
Nope. Removed.
|
| +#include <string> |
| + |
| +#include "base/at_exit.h" |
| +#include "base/bind.h" |
| +#include "base/callback.h" |
| +#include "base/command_line.h" |
| +#include "base/file_path.h" |
| +#include "base/file_util.h" |
| +#include "base/logging.h" |
| +#include "base/message_loop.h" |
| +#include "base/threading/thread.h" |
| +#include "build/build_config.h" |
| +#include "crypto/nss_util.h" |
| +#include "remoting/base/constants.h" |
| +#include "remoting/host/chromoting_host.h" |
| +#include "remoting/host/chromoting_host_context.h" |
| +#include "remoting/host/desktop_environment.h" |
| +#include "remoting/host/event_executor.h" |
| +#include "remoting/host/heartbeat_sender.h" |
| +#include "remoting/host/host_config.h" |
| +#include "remoting/host/json_host_config.h" |
| +#include "remoting/host/self_access_verifier.h" |
| + |
| +#if defined(TOOLKIT_USES_GTK) |
| +#include "ui/gfx/gtk_util.h" |
| +#endif |
| + |
| +using remoting::ChromotingHost; |
|
Sergey Ulanov
2011/11/11 00:00:43
Why not put this code in the remoting namespace? T
Lambros
2011/11/15 23:27:36
Done.
|
| +using remoting::DesktopEnvironment; |
| +using remoting::kChromotingTokenDefaultServiceName; |
| +using remoting::kXmppAuthServiceConfigPath; |
| +using remoting::kXmppAuthTokenConfigPath; |
| +using remoting::kXmppLoginConfigPath; |
|
Wez
2011/11/11 00:24:09
The names of these are confusing; "path" implies t
Lambros
2011/11/15 23:27:36
I didn't choose those names - they were already de
|
| +using remoting::protocol::CandidateSessionConfig; |
| +using remoting::protocol::ChannelConfig; |
| + |
| +const char kAuthConfigSwitchName[] = "auth-config"; |
| +const char kHostConfigSwitchName[] = "host-config"; |
| +const FilePath::CharType kDefaultConfigDir[] = |
| + FILE_PATH_LITERAL(".config/chrome-remote-desktop"); |
| +const FilePath::CharType kDefaultAuthConfigFile[] = |
| + FILE_PATH_LITERAL("auth.json"); |
| +const FilePath::CharType kDefaultHostConfigFile[] = |
| + FILE_PATH_LITERAL("host.json"); |
|
Wez
2011/11/11 00:24:09
nit: Add a comment preceding these definitions to
Lambros
2011/11/15 23:27:36
Done.
|
| + |
| +class Me2MeHost { |
|
Sergey Ulanov
2011/11/11 00:00:43
I suggest that we call it simply HostProcess or so
Wez
2011/11/11 00:33:00
SGTM
Lambros
2011/11/15 23:27:36
Done.
|
| + public: |
| + Me2MeHost() {} |
| + |
| + int Run() { |
| + // |message_loop| is declared early so that any code we call into which |
| + // requires a current message-loop won't complain. |
| + // It needs to be a UI message loop to keep runloops spinning on the Mac. |
|
Wez
2011/11/11 00:24:09
This code isn't built for Mac right now, so do we
Lambros
2011/11/15 23:27:36
Without this, the host starts and immediately shut
Wez
2011/11/16 22:26:14
You mean you're not sure why we need a UI message-
|
| + MessageLoop message_loop(MessageLoop::TYPE_UI); |
| + |
| + remoting::ChromotingHostContext context( |
| + base::MessageLoopProxy::current()); |
| + context.Start(); |
| + |
| + base::Thread file_io_thread("FileIO"); |
| + file_io_thread.Start(); |
| + |
| + scoped_refptr<remoting::JsonHostConfig> host_config = |
| + new remoting::JsonHostConfig( |
| + host_config_path_, file_io_thread.message_loop_proxy()); |
| + scoped_refptr<remoting::JsonHostConfig> auth_config = |
| + new remoting::JsonHostConfig( |
| + auth_config_path_, file_io_thread.message_loop_proxy()); |
| + |
| + std::string failed_path; |
| + if (!host_config->Read()) { |
| + failed_path = host_config_path_.value(); |
| + } else if (!auth_config->Read()) { |
| + failed_path = auth_config_path_.value(); |
| + } |
| + if (!failed_path.empty()) { |
| + LOG(ERROR) << "Failed to read configuration file " << failed_path; |
| + context.Stop(); |
| + return 1; |
| + } |
| + |
| + // Copy the needed keys from |auth_config| into |host_config|. |
| + std::string value; |
| + auth_config->GetString(kXmppAuthTokenConfigPath, &value); |
|
Sergey Ulanov
2011/11/11 00:00:43
This looks like a hack to me. Since auth and host
Lambros
2011/11/15 23:27:36
I'm still working out how we can do this. There a
Wez
2011/11/16 22:26:14
I think it's reasonable for the Host to be configu
|
| + host_config->SetString(kXmppAuthTokenConfigPath, value); |
| + auth_config->GetString(kXmppLoginConfigPath, &value); |
| + host_config->SetString(kXmppLoginConfigPath, value); |
|
Wez
2011/11/11 00:24:09
Past this point |auth_config| isn't used, I don't
Lambros
2011/11/15 23:27:36
Done.
|
| + |
| + // For the Me2Me host, we assume we always use the ClientLogin token for |
| + // chromiumsync because we do not have an HTTP stack with which we can |
| + // easily request an OAuth2 access token even if we had a RefreshToken for |
| + // the account. |
| + host_config->SetString(kXmppAuthServiceConfigPath, |
| + kChromotingTokenDefaultServiceName); |
| + |
| + // Initialize AccessVerifier. |
| + scoped_ptr<remoting::AccessVerifier> access_verifier; |
|
Wez
2011/11/11 00:24:09
Why do we need this separate reference for the acc
Lambros
2011/11/15 23:27:36
We don't, it was an artifact of copying remoting_s
|
| + scoped_ptr<remoting::HeartbeatSender> heartbeat_sender; |
|
Wez
2011/11/11 00:24:09
Define this further down, where it is created. If
Lambros
2011/11/15 23:27:36
Done. Probably was an artifact of the way remotin
|
| + scoped_ptr<remoting::SelfAccessVerifier> self_access_verifier( |
| + new remoting::SelfAccessVerifier()); |
| + if (!self_access_verifier->Init(host_config)) |
| + return 1; |
|
Wez
2011/11/11 00:24:09
Wot no error message? ;)
Lambros
2011/11/15 23:27:36
The Init() method logs if there's an error, so the
Wez
2011/11/16 22:26:14
Yuk. We should move that logging out and let the
|
| + access_verifier.reset(self_access_verifier.release()); |
| + |
| + // Construct a chromoting host. |
|
Wez
2011/11/11 00:24:09
nit: the API is Create(), so perhaps "Create the D
Lambros
2011/11/15 23:27:36
Done.
|
| + scoped_ptr<DesktopEnvironment> desktop_environment( |
| + DesktopEnvironment::Create(&context)); |
| + |
| + host_ = ChromotingHost::Create(&context, host_config, |
| + desktop_environment.get(), |
| + access_verifier.release(), false); |
| + |
| + if (protocol_config_.get()) { |
| + host_->set_protocol_config(protocol_config_.release()); |
|
Wez
2011/11/11 00:24:09
Don't think we ever use this.
Lambros
2011/11/15 23:27:36
Done (removed all protocol_config stuff).
|
| + } |
| + |
| + // Initialize HeartbeatSender. |
| + heartbeat_sender.reset( |
| + new remoting::HeartbeatSender(context.network_message_loop(), |
| + host_config)); |
| + if (!heartbeat_sender->Init()) |
| + return 1; |
| + host_->AddStatusObserver(heartbeat_sender.get()); |
| + |
| + // Let the chromoting host run until the shutdown task is executed. |
|
Wez
2011/11/11 00:24:09
nit: "Run the ChromotingHost until the shutdown ta
Lambros
2011/11/15 23:27:36
Done.
|
| + host_->Start(); |
| + message_loop.MessageLoop::Run(); |
| + |
| + // And then stop the chromoting context. |
| + context.Stop(); |
| + file_io_thread.Stop(); |
| + |
| + host_ = NULL; |
| + |
| + return 0; |
| + } |
| + |
| + void set_auth_config_path(const FilePath& config_path) { |
| + auth_config_path_ = config_path; |
| + } |
| + |
| + void set_host_config_path(const FilePath& config_path) { |
| + host_config_path_ = config_path; |
| + } |
| + |
| + void set_protocol_config(CandidateSessionConfig* protocol_config) { |
|
Wez
2011/11/11 00:24:09
Don't think we ever use this?
Lambros
2011/11/15 23:27:36
Done.
|
| + protocol_config_.reset(protocol_config); |
| + } |
| + |
| + private: |
| + FilePath auth_config_path_; |
| + FilePath host_config_path_; |
| + |
| + scoped_ptr<CandidateSessionConfig> protocol_config_; |
|
Wez
2011/11/11 00:24:09
I don't think we ever use this?
Lambros
2011/11/15 23:27:36
Done.
|
| + |
| + scoped_refptr<ChromotingHost> host_; |
| +}; |
| + |
| +int main(int argc, char** argv) { |
| + CommandLine::Init(argc, argv); |
| + const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| + |
| + base::AtExitManager exit_manager; |
| + crypto::EnsureNSPRInit(); |
| + |
| +#if defined(TOOLKIT_USES_GTK) |
| + gfx::GtkInitFromCommandLine(*cmd_line); |
|
Wez
2011/11/11 00:24:09
nit: Add a comment to explain why we need this, an
Lambros
2011/11/15 23:27:36
I've explained GtkInit and AtExitManager, but I do
Wez
2011/11/16 22:26:14
EnsureNSPRInit() starts the Netscape Portable Runt
Lambros
2011/11/17 01:47:07
The (LazyInstance-created) NSSInitSingleton ctor d
Wez
2011/11/17 02:19:28
The main browser process doesn't run a sandbox, so
|
| +#endif // TOOLKIT_USES_GTK |
| + |
| + Me2MeHost me2me_host; |
| + |
| + FilePath default_config_dir = |
| + file_util::GetHomeDir().Append(kDefaultConfigDir); |
| + |
| + if (cmd_line->HasSwitch(kAuthConfigSwitchName)) { |
| + me2me_host.set_auth_config_path( |
| + cmd_line->GetSwitchValuePath(kAuthConfigSwitchName)); |
| + } else { |
| + me2me_host.set_auth_config_path( |
| + default_config_dir.Append(kDefaultAuthConfigFile)); |
|
Wez
2011/11/11 00:24:09
nit: Default the config dir in Me2MeHost's ctor?
Lambros
2011/11/15 23:27:36
Nah, there's no need for a member here. The defau
|
| + } |
| + if (cmd_line->HasSwitch(kHostConfigSwitchName)) { |
| + me2me_host.set_host_config_path( |
| + cmd_line->GetSwitchValuePath(kHostConfigSwitchName)); |
| + } else { |
| + me2me_host.set_host_config_path( |
| + default_config_dir.Append(kDefaultHostConfigFile)); |
|
Wez
2011/11/11 00:24:09
nit: as above?
|
| + } |
|
Wez
2011/11/11 00:24:09
nit: Consider adding a comment before default_conf
Lambros
2011/11/15 23:27:36
Added ProcessCommandLine() method. Hopefully that
|
| + |
| + return me2me_host.Run(); |
| +} |