Commit 95b433f3 authored by Yuwei Huang's avatar Yuwei Huang Committed by Commit Bot

[remoting] Implement It2MeCliHost

This CL implements a binary that allows starting an IT2ME host from
command line. This will help debugging the FTL migration process for
ChromeOS enterprise.

The code is mostly copied and modified from CRDHostDelegate.

Bug: 962765
Change-Id: I74d5b6c49b7c55703f6d52a81aa0327456f8174e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1610891
Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarSergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarJoe Downing <joedow@chromium.org>
Auto-Submit: Yuwei Huang <yuweih@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659992}
parent 5c4d56c1
......@@ -67,7 +67,7 @@ It2MeHost::~It2MeHost() {
}
void It2MeHost::set_enable_dialogs(bool enable) {
#if defined(OS_CHROMEOS)
#if defined(OS_CHROMEOS) || !defined(NDEBUG)
enable_dialogs_ = enable;
#else
NOTREACHED() << "It2MeHost::set_enable_dialogs is only supported on ChromeOS";
......
......@@ -284,7 +284,7 @@ void It2MeNativeMessagingHost::ProcessConnect(
// Create the It2Me host and start connecting. Note that disabling dialogs is
// only supported on ChromeOS.
it2me_host_ = factory_->CreateIt2MeHost();
#if defined(OS_CHROMEOS)
#if defined(OS_CHROMEOS) || !defined(NDEBUG)
it2me_host_->set_enable_dialogs(!no_dialogs);
#endif
it2me_host_->Connect(host_context_->Copy(), std::move(policies),
......
......@@ -129,6 +129,24 @@ if (enable_remoting_host && !is_android && !is_chromeos) {
]
}
# A binary for starting an IT2ME host from command line.
executable("it2me_cli_host") {
testonly = true
sources = [
"it2me_cli_host.cc",
"it2me_cli_host.h",
"it2me_cli_host_main.cc",
]
deps = [
":test_support",
"//mojo/core/embedder",
"//remoting/base",
"//remoting/host",
"//remoting/host/it2me:common",
"//remoting/host/native_messaging",
]
}
static_library("it2me_standalone_host") {
testonly = true
......
include_rules = [
"+extensions/browser/api/messaging",
"+google_apis",
"+jingle/glue",
"+mojo/core/embedder",
......
This diff is collapsed.
// Copyright 2019 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.
#ifndef REMOTING_TEST_IT2ME_CLI_HOST_H_
#define REMOTING_TEST_IT2ME_CLI_HOST_H_
#include <memory>
#include <string>
#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/values.h"
#include "extensions/browser/api/messaging/native_message_host.h"
#include "remoting/base/oauth_token_getter.h"
namespace remoting {
namespace test {
class TestOAuthTokenGetter;
class TestTokenStorage;
} // namespace test
class AutoThreadTaskRunner;
class It2MeCliHost final : public extensions::NativeMessageHost::Client {
public:
static bool ShouldPrintHelp();
static void PrintHelp();
It2MeCliHost();
~It2MeCliHost() override;
void Start();
private:
// extensions::NativeMessageHost::Client:
// Invoked when native host sends a message
void PostMessageFromNativeHost(const std::string& message) override;
void CloseChannel(const std::string& error_message) override;
// Sends message to host in separate task.
void SendMessageToHost(const std::string& type, const base::Value& params);
// Actually sends message to host.
void DoSendMessage(const std::string& json);
void OnProtocolBroken(const std::string& message);
void StartCRDHostAndGetCode(OAuthTokenGetter::Status status,
const std::string& user_email,
const std::string& access_token);
// Shuts down host in a separate task.
void ShutdownHost();
// Actually shuts down a host.
void DoShutdownHost();
// Handlers for messages from host
void OnHelloResponse();
void OnDisconnectResponse();
void OnStateError(const std::string& error_state, const base::Value& message);
void OnStateRemoteConnected(const base::Value& message);
void OnStateRemoteDisconnected();
void OnStateReceivedAccessCode(const base::Value& message);
std::unique_ptr<test::TestTokenStorage> storage_;
std::unique_ptr<test::TestOAuthTokenGetter> token_getter_;
scoped_refptr<AutoThreadTaskRunner> ui_task_runner_;
std::unique_ptr<extensions::NativeMessageHost> host_;
// Filled structure with parameters for "connect" message.
base::Value connect_params_;
// Determines actions when receiving messages from CRD host,
// if command is still running (no error / access code), then
// callbacks have to be called.
bool command_awaiting_crd_access_code_;
// True if remote session was established.
bool remote_connected_;
base::WeakPtrFactory<It2MeCliHost> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(It2MeCliHost);
};
} // namespace remoting
#endif // REMOTING_TEST_IT2ME_CLI_HOST_H_
// Copyright 2019 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.
#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/message_loop/message_loop.h"
#include "base/task/thread_pool/thread_pool.h"
#include "build/build_config.h"
#include "mojo/core/embedder/embedder.h"
#include "remoting/host/resources.h"
#include "remoting/test/it2me_cli_host.h"
#if defined(OS_LINUX)
#include "base/linux_util.h"
#endif // defined(OS_LINUX)
int main(int argc, char const* argv[]) {
base::AtExitManager exitManager;
base::CommandLine::Init(argc, argv);
if (remoting::It2MeCliHost::ShouldPrintHelp()) {
remoting::It2MeCliHost::PrintHelp();
return 0;
}
#if defined(OS_LINUX)
// Need to prime the host OS version value for linux to prevent IO on the
// network thread. base::GetLinuxDistro() caches the result.
base::GetLinuxDistro();
#endif // OS_LINUX
base::MessageLoopForIO message_loop;
remoting::It2MeCliHost cli_host;
base::ThreadPool::CreateAndStartWithDefaultParams("It2MeCliHost");
mojo::core::Init();
remoting::LoadResources("");
cli_host.Start();
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment