Commit 2dfac17b authored by lhchavez's avatar lhchavez Committed by Commit bot

arc: Remove components/arc/standalone

ARC standalone project was cancelled. Let's remove that code.

BUG=None
TEST=trybots

Review-Url: https://codereview.chromium.org/2384173004
Cr-Commit-Position: refs/heads/master@{#422701}
parent 738aeed4
......@@ -218,54 +218,3 @@ source_set("unit_tests") {
"//url:url",
]
}
static_library("arc_standalone_service") {
sources = [
"standalone/service_helper.cc",
"standalone/service_helper.h",
]
deps = [
"//base",
]
}
static_library("arc_standalone") {
sources = [
"standalone/arc_standalone_bridge_runner.cc",
"standalone/arc_standalone_bridge_runner.h",
]
deps = [
":arc",
":arc_standalone_service",
"//base",
"//ipc:ipc",
]
}
test("arc_standalone_service_unittests") {
sources = [
"standalone/service_helper_unittest.cc",
]
deps = [
":arc_standalone_service",
"//base/test:test_support",
"//testing/gtest",
]
}
executable("arc_standalone_bridge") {
sources = [
"standalone/arc_standalone_bridge_main.cc",
]
deps = [
":arc_standalone",
":arc_standalone_service",
"//base",
"//ipc:ipc",
"//mojo/edk/system",
]
}
// Copyright 2016 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/bind.h"
#include "base/command_line.h"
#include "components/arc/standalone/arc_standalone_bridge_runner.h"
#include "components/arc/standalone/service_helper.h"
#include "mojo/edk/embedder/embedder.h"
// This is experimental only. Do not use in production.
// All threads in the standalone runner must be I/O threads.
int main(int argc, char** argv) {
base::CommandLine::Init(argc, argv);
base::AtExitManager at_exit_manager;
mojo::edk::Init();
// Instantiate runner, which instantiates message loop.
arc::ArcStandaloneBridgeRunner runner;
arc::ServiceHelper helper;
helper.Init(base::Bind(&arc::ArcStandaloneBridgeRunner::Stop,
base::Unretained(&runner),
1));
// Spin the message loop.
int exit_code = runner.Run();
return exit_code;
}
// Copyright 2016 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 "components/arc/standalone/arc_standalone_bridge_runner.h"
#include "base/bind.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
namespace arc {
ArcStandaloneBridgeRunner::ArcStandaloneBridgeRunner() : exit_code_(0) {
}
ArcStandaloneBridgeRunner::~ArcStandaloneBridgeRunner() {
}
int ArcStandaloneBridgeRunner::Run() {
DCHECK(thread_checker_.CalledOnValidThread());
run_loop_.reset(new base::RunLoop());
run_loop_->Run();
run_loop_.reset(nullptr);
return exit_code_;
}
void ArcStandaloneBridgeRunner::Stop(int exit_code) {
DCHECK(thread_checker_.CalledOnValidThread());
exit_code_ = exit_code;
CHECK(run_loop_);
message_loop_.task_runner()->PostTask(FROM_HERE, run_loop_->QuitClosure());
}
} // namespace arc
// Copyright 2016 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 COMPONENTS_ARC_STANDALONE_ARC_STANDALONE_BRIDGE_RUNNER_H_
#define COMPONENTS_ARC_STANDALONE_ARC_STANDALONE_BRIDGE_RUNNER_H_
#include <memory>
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/threading/thread_checker.h"
namespace arc {
// Runner of the standalone ARC++ bridge, which hosts an IO message loop.
class ArcStandaloneBridgeRunner {
public:
ArcStandaloneBridgeRunner();
~ArcStandaloneBridgeRunner();
// Starts the message loop. Needs to be run on the thread where this
// instance is created.
int Run();
// Stops the message loop. Needs to be called in a message loop.
void Stop(int exit_code);
private:
base::MessageLoopForIO message_loop_;
std::unique_ptr<base::RunLoop> run_loop_;
base::ThreadChecker thread_checker_;
int exit_code_;
DISALLOW_COPY_AND_ASSIGN(ArcStandaloneBridgeRunner);
};
} // namespace arc
#endif // COMPONENTS_ARC_STANDALONE_ARC_STANDALONE_BRIDGE_RUNNER_H_
// Copyright 2016 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 "components/arc/standalone/service_helper.h"
#include "base/bind.h"
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/posix/eintr_wrapper.h"
namespace arc {
// static
ServiceHelper* ServiceHelper::self_ = nullptr;
ServiceHelper::ServiceHelper() {
}
ServiceHelper::~ServiceHelper() {
// Best efforts clean up, ignore the return values.
sigaction(SIGINT, &old_sigint_, NULL);
sigaction(SIGTERM, &old_sigterm_, NULL);
}
void ServiceHelper::Init(const base::Closure& closure) {
CHECK(!ServiceHelper::self_);
ServiceHelper::self_ = this;
closure_ = closure;
// Initialize pipe
int pipe_fd[2];
CHECK_EQ(0, pipe(pipe_fd));
read_fd_.reset(pipe_fd[0]);
write_fd_.reset(pipe_fd[1]);
CHECK(base::SetNonBlocking(write_fd_.get()));
watch_controller_ = base::FileDescriptorWatcher::WatchReadable(
read_fd_.get(), base::Bind(&ServiceHelper::OnFileCanReadWithoutBlocking,
base::Unretained(this)));
struct sigaction action = {};
CHECK_EQ(0, sigemptyset(&action.sa_mask));
action.sa_handler = ServiceHelper::TerminationHandler;
action.sa_flags = 0;
CHECK_EQ(0, sigaction(SIGINT, &action, &old_sigint_));
CHECK_EQ(0, sigaction(SIGTERM, &action, &old_sigterm_));
}
// static
void ServiceHelper::TerminationHandler(int /* signum */) {
if (HANDLE_EINTR(write(self_->write_fd_.get(), "1", 1)) < 0) {
_exit(2); // We still need to exit the program, but in a brute force way.
}
}
void ServiceHelper::OnFileCanReadWithoutBlocking() {
char c;
// We don't really care about the return value, since it indicates closing.
HANDLE_EINTR(read(read_fd_.get(), &c, 1));
closure_.Run();
}
} // namespace arc
// Copyright 2016 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 COMPONENTS_ARC_STANDALONE_SERVICE_HELPER_H_
#define COMPONENTS_ARC_STANDALONE_SERVICE_HELPER_H_
#include <signal.h>
#include <memory>
#include "base/files/file_descriptor_watcher_posix.h"
#include "base/files/scoped_file.h"
namespace arc {
// Helper class to set up service-like processes.
class ServiceHelper {
public:
ServiceHelper();
~ServiceHelper();
// Must be called after message loop instantiation.
void Init(const base::Closure& closure);
private:
void OnFileCanReadWithoutBlocking();
static void TerminationHandler(int /* signum */);
// Static variable to guarantee instantiated only once per process.
static ServiceHelper* self_;
base::Closure closure_;
base::ScopedFD read_fd_;
base::ScopedFD write_fd_;
std::unique_ptr<base::FileDescriptorWatcher::Controller> watch_controller_;
struct sigaction old_sigint_;
struct sigaction old_sigterm_;
DISALLOW_COPY_AND_ASSIGN(ServiceHelper);
};
} // namespace arc
#endif // COMPONENTS_ARC_STANDALONE_SERVICE_HELPER_H_
// Copyright 2016 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 "components/arc/standalone/service_helper.h"
#include <signal.h>
#include <unistd.h>
#include <memory>
#include "base/bind.h"
#include "base/files/file_descriptor_watcher_posix.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/test/launcher/unit_test_launcher.h"
#include "base/test/test_suite.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace arc {
class ServiceHelperTest : public ::testing::Test {
public:
ServiceHelperTest() {}
~ServiceHelperTest() override {}
void Quit() {
CHECK(base_loop_);
CHECK(run_loop_);
base_loop_->task_runner()->PostTask(FROM_HERE, run_loop_->QuitClosure());
}
void Init() {
// Dynamically create the message loop to avoid thread check failure of task
// runner in Debug mode.
base_loop_.reset(new base::MessageLoopForIO());
run_loop_.reset(new base::RunLoop());
// Required to watch a file descriptor from ServiceHelper.
file_descriptor_watcher_ =
base::MakeUnique<FileDescriptorWatcher>(base_loop_.get());
// This cannot be put inside SetUp() because we need to run it after fork().
helper_.reset(new ServiceHelper());
helper_->Init(base::Bind(&ServiceHelperTest::Quit,
base::Unretained(this)));
}
protected:
std::unique_ptr<base::MessageLoopForIO> base_loop_;
std::unique_ptr<base::MessageLoopForIO> file_descriptor_watcher_;
std::unique_ptr<base::RunLoop> run_loop_;
std::unique_ptr<ServiceHelper> helper_;
private:
DISALLOW_COPY_AND_ASSIGN(ServiceHelperTest);
};
TEST_F(ServiceHelperTest, CheckExternalTerm) {
// Fork ourselves and run it.
pid_t child_pid = fork();
if (child_pid == 0) { // Child process
Init();
run_loop_->Run();
helper_.reset(); // Make sure ServiceHelper dtor does not crash.
_Exit(EXIT_SUCCESS);
} else if (child_pid == -1) { // Failed to fork
FAIL();
} else { // Parent process
// Deliberate race. If ServiceHelper had bugs and stalled, the short
// timeout would kill forked process and stop the test. In that case
// there will be a crash from improperly terminated message loop
// and we shall capture the error.
base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1));
kill(child_pid, SIGTERM);
int status;
ASSERT_EQ(child_pid, waitpid(child_pid, &status, 0));
ASSERT_TRUE(WIFEXITED(status));
}
}
} // namespace arc
int main(int argc, char** argv) {
base::TestSuite test_suite(argc, argv);
return base::LaunchUnitTestsSerially(
argc, argv,
base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite)));
}
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