Commit de311232 authored by reveman's avatar reveman Committed by Commit bot

chrome: Add support for custom crosh command.

This adds the "--crosh-command" command line switch that
cab be used to specify an alternative crosh command.

BUG=677267
TEST=chrome --crosh-command=/bin/bash

Review-Url: https://codereview.chromium.org/2579833005
Cr-Commit-Position: refs/heads/master@{#442767}
parent 536b6260
......@@ -7,6 +7,7 @@
#include <utility>
#include "base/bind.h"
#include "base/command_line.h"
#include "base/json/json_writer.h"
#include "base/memory/ptr_util.h"
#include "base/sys_info.h"
......@@ -14,6 +15,7 @@
#include "chrome/browser/extensions/api/terminal/terminal_extension_helper.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/api/terminal_private.h"
#include "chromeos/process_proxy/process_proxy_registry.h"
#include "content/public/browser/browser_context.h"
......@@ -40,18 +42,22 @@ const char kCroshCommand[] = "/usr/bin/crosh";
// We make stubbed crosh just echo back input.
const char kStubbedCroshCommand[] = "cat";
const char* GetCroshPath() {
std::string GetCroshPath() {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kCroshCommand))
return command_line->GetSwitchValueASCII(switches::kCroshCommand);
if (base::SysInfo::IsRunningOnChromeOS())
return kCroshCommand;
else
return kStubbedCroshCommand;
return std::string(kCroshCommand);
return std::string(kStubbedCroshCommand);
}
const char* GetProcessCommandForName(const std::string& name) {
std::string GetProcessCommandForName(const std::string& name) {
if (name == kCroshName)
return GetCroshPath();
else
return NULL;
return std::string();
}
void NotifyProcessOutput(content::BrowserContext* browser_context,
......@@ -101,7 +107,7 @@ int GetTabOrWindowSessionId(content::BrowserContext* browser_context,
namespace extensions {
TerminalPrivateOpenTerminalProcessFunction::
TerminalPrivateOpenTerminalProcessFunction() : command_(NULL) {}
TerminalPrivateOpenTerminalProcessFunction() {}
TerminalPrivateOpenTerminalProcessFunction::
~TerminalPrivateOpenTerminalProcessFunction() {}
......@@ -113,7 +119,7 @@ TerminalPrivateOpenTerminalProcessFunction::Run() {
EXTENSION_FUNCTION_VALIDATE(params.get());
command_ = GetProcessCommandForName(params->process_name);
if (!command_)
if (command_.empty())
return RespondNow(Error("Invalid process name."));
content::WebContents* caller_contents = GetSenderWebContents();
......@@ -150,12 +156,12 @@ TerminalPrivateOpenTerminalProcessFunction::Run() {
void TerminalPrivateOpenTerminalProcessFunction::OpenOnFileThread(
const ProcessOutputCallback& output_callback,
const OpenProcessCallback& callback) {
DCHECK(command_);
DCHECK(!command_.empty());
chromeos::ProcessProxyRegistry* registry =
chromeos::ProcessProxyRegistry::Get();
int terminal_id = registry->OpenProcess(command_, output_callback);
int terminal_id = registry->OpenProcess(command_.c_str(), output_callback);
content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
base::Bind(callback, terminal_id));
......
......@@ -36,7 +36,7 @@ class TerminalPrivateOpenTerminalProcessFunction
const OpenProcessCallback& callback);
void RespondOnUIThread(int terminal_id);
const char* command_;
std::string command_;
};
// Send input to the terminal process specified by the terminal ID, which is set
......
......@@ -977,6 +977,9 @@ const char kWebApkServerUrl[] = "webapk-server-url";
#if defined(OS_CHROMEOS)
// Enables native cups integration
const char kEnableNativeCups[] = "enable-native-cups";
// Custom crosh command.
const char kCroshCommand[] = "crosh-command";
#endif // defined(OS_CHROMEOS)
#if defined(USE_ASH)
......
......@@ -288,6 +288,7 @@ extern const char kWebApkServerUrl[];
#if defined(OS_CHROMEOS)
extern const char kEnableNativeCups[];
extern const char kCroshCommand[];
#endif // defined(OS_CHROMEOS)
#if defined(USE_ASH)
......
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