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

Unified Diff: remoting/host/me2me_host.cc

Issue 8469013: Add remoting_me2me_host. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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
« no previous file with comments | « no previous file | remoting/remoting.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
+// 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.
+
+#include <stdlib.h>
+
+#include <iostream>
+#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;
+using remoting::DesktopEnvironment;
+using remoting::kChromotingTokenDefaultServiceName;
+using remoting::kXmppAuthServiceConfigPath;
+using remoting::kXmppAuthTokenConfigPath;
+using remoting::kXmppLoginConfigPath;
+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");
+
+class Me2MeHost {
+ 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.
+ 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);
+ host_config->SetString(kXmppAuthTokenConfigPath, value);
+ auth_config->GetString(kXmppLoginConfigPath, &value);
+ host_config->SetString(kXmppLoginConfigPath, value);
+
+ // 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;
+ scoped_ptr<remoting::HeartbeatSender> heartbeat_sender;
+ scoped_ptr<remoting::SelfAccessVerifier> self_access_verifier(
+ new remoting::SelfAccessVerifier());
+ if (!self_access_verifier->Init(host_config))
+ return 1;
+ access_verifier.reset(self_access_verifier.release());
+
+ // Construct a chromoting host.
+ 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());
+ }
+
+ // 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.
+ 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) {
+ protocol_config_.reset(protocol_config);
+ }
+
+ private:
+ FilePath auth_config_path_;
+ FilePath host_config_path_;
+
+ scoped_ptr<CandidateSessionConfig> protocol_config_;
+
+ 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);
+#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));
+ }
+ 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));
+ }
+
+ return me2me_host.Run();
+}
« no previous file with comments | « no previous file | remoting/remoting.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698