Use the same set of switches for service process autorun and for launching process from browser.

BUG=386897
TBR=rogerta
NOTRY=true

Review URL: https://codereview.chromium.org/347953002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278755 0039d316-1c4b-4281-b951-d872f2087c98
parent 24d47c05
......@@ -18,18 +18,12 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/upgrade_detector.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/service_messages.h"
#include "chrome/common/service_process_util.h"
#include "components/cloud_devices/common/cloud_devices_switches.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
#include "content/public/common/child_process_host.h"
#include "google_apis/gaia/gaia_switches.h"
#include "ui/base/ui_base_switches.h"
using content::BrowserThread;
using content::ChildProcessHost;
// ServiceProcessControl implementation.
ServiceProcessControl::ServiceProcessControl() {
......@@ -118,47 +112,9 @@ void ServiceProcessControl::Launch(const base::Closure& success_task,
UMA_HISTOGRAM_ENUMERATION("CloudPrint.ServiceEvents", SERVICE_EVENT_LAUNCH,
SERVICE_EVENT_MAX);
// A service process should have a different mechanism for starting, but now
// we start it as if it is a child process.
#if defined(OS_LINUX)
int flags = ChildProcessHost::CHILD_ALLOW_SELF;
#else
int flags = ChildProcessHost::CHILD_NORMAL;
#endif
base::FilePath exe_path = ChildProcessHost::GetChildPath(flags);
if (exe_path.empty())
NOTREACHED() << "Unable to get service process binary name.";
CommandLine* cmd_line = new CommandLine(exe_path);
cmd_line->AppendSwitchASCII(switches::kProcessType,
switches::kServiceProcess);
static const char* const kSwitchesToCopy[] = {
switches::kCloudPrintSetupProxy,
switches::kCloudPrintURL,
switches::kCloudPrintXmppEndpoint,
#if defined(OS_WIN)
switches::kEnableCloudPrintXps,
#endif
switches::kEnableLogging,
switches::kIgnoreUrlFetcherCertRequests,
switches::kLang,
switches::kLoggingLevel,
switches::kLsoUrl,
switches::kNoServiceAutorun,
switches::kUserDataDir,
switches::kV,
switches::kVModule,
switches::kWaitForDebugger,
};
cmd_line->CopySwitchesFrom(*CommandLine::ForCurrentProcess(),
kSwitchesToCopy,
arraysize(kSwitchesToCopy));
scoped_ptr<base::CommandLine> cmd_line(CreateServiceProcessCommandLine());
// And then start the process asynchronously.
launcher_ = new Launcher(this, cmd_line);
launcher_ = new Launcher(this, cmd_line.Pass());
launcher_->Run(base::Bind(&ServiceProcessControl::OnProcessLaunched,
base::Unretained(this)));
}
......@@ -356,10 +312,11 @@ ServiceProcessControl* ServiceProcessControl::GetInstance() {
return Singleton<ServiceProcessControl>::get();
}
ServiceProcessControl::Launcher::Launcher(ServiceProcessControl* process,
CommandLine* cmd_line)
ServiceProcessControl::Launcher::Launcher(
ServiceProcessControl* process,
scoped_ptr<base::CommandLine> cmd_line)
: process_(process),
cmd_line_(cmd_line),
cmd_line_(cmd_line.Pass()),
launched_(false),
retry_count_(0),
process_handle_(base::kNullProcessHandle) {
......
......@@ -145,7 +145,8 @@ class ServiceProcessControl : public IPC::Sender,
class Launcher
: public base::RefCountedThreadSafe<ServiceProcessControl::Launcher> {
public:
Launcher(ServiceProcessControl* process, base::CommandLine* cmd_line);
Launcher(ServiceProcessControl* process,
scoped_ptr<base::CommandLine> cmd_line);
// Execute the command line to start the process asynchronously. After the
// command is executed |task| is called with the process handle on the UI
// thread.
......
......@@ -13,6 +13,7 @@ include_rules = [
"+components/signin/core/common",
"+components/translate/core/common",
"+extensions/common",
"+google_apis/gaia", # For gaia_switches.h
"+grit", # For generated headers
"+media",
"+ppapi/shared_impl",
......
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/common/service_process_util.h"
#include <algorithm>
#include "base/command_line.h"
......@@ -18,8 +20,10 @@
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/service_process_util.h"
#include "components/cloud_devices/common/cloud_devices_switches.h"
#include "content/public/common/content_paths.h"
#include "google_apis/gaia/gaia_switches.h"
#include "ui/base/ui_base_switches.h"
#if !defined(OS_MACOSX)
......@@ -151,8 +155,40 @@ bool GetServiceProcessData(std::string* version, base::ProcessId* pid) {
#endif // !OS_MACOSX
scoped_ptr<base::CommandLine> CreateServiceProcessCommandLine() {
base::FilePath exe_path;
PathService::Get(content::CHILD_PROCESS_EXE, &exe_path);
DCHECK(!exe_path.empty()) << "Unable to get service process binary name.";
scoped_ptr<base::CommandLine> command_line(new base::CommandLine(exe_path));
command_line->AppendSwitchASCII(switches::kProcessType,
switches::kServiceProcess);
static const char* const kSwitchesToCopy[] = {
switches::kCloudPrintSetupProxy,
switches::kCloudPrintURL,
switches::kCloudPrintXmppEndpoint,
#if defined(OS_WIN)
switches::kEnableCloudPrintXps,
#endif
switches::kEnableLogging,
switches::kIgnoreUrlFetcherCertRequests,
switches::kLang,
switches::kLoggingLevel,
switches::kLsoUrl,
switches::kNoServiceAutorun,
switches::kUserDataDir,
switches::kV,
switches::kVModule,
switches::kWaitForDebugger,
};
command_line->CopySwitchesFrom(*base::CommandLine::ForCurrentProcess(),
kSwitchesToCopy,
arraysize(kSwitchesToCopy));
return command_line.Pass();
}
ServiceProcessState::ServiceProcessState() : state_(NULL) {
CreateAutoRunCommandLine();
autorun_command_line_ = CreateServiceProcessCommandLine();
CreateState();
}
......@@ -247,21 +283,3 @@ IPC::ChannelHandle ServiceProcessState::GetServiceProcessChannel() {
}
#endif // !OS_MACOSX
void ServiceProcessState::CreateAutoRunCommandLine() {
base::FilePath exe_path;
PathService::Get(content::CHILD_PROCESS_EXE, &exe_path);
DCHECK(!exe_path.empty()) << "Unable to get service process binary name.";
autorun_command_line_.reset(new CommandLine(exe_path));
autorun_command_line_->AppendSwitchASCII(switches::kProcessType,
switches::kServiceProcess);
// The user data directory is the only other flag we currently want to
// possibly store.
const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess();
base::FilePath user_data_dir =
browser_command_line.GetSwitchValuePath(switches::kUserDataDir);
if (!user_data_dir.empty())
autorun_command_line_->AppendSwitchPath(switches::kUserDataDir,
user_data_dir);
}
......@@ -74,6 +74,9 @@ bool GetServiceProcessData(std::string* version, base::ProcessId* pid);
bool ForceServiceProcessShutdown(const std::string& version,
base::ProcessId process_id);
// Creates command-line to run the service process.
scoped_ptr<base::CommandLine> CreateServiceProcessCommandLine();
// This is a class that is used by the service process to signal events and
// share data with external clients. This class lives in this file because the
// internal data structures and mechanisms used by the utility methods above
......@@ -129,10 +132,6 @@ class ServiceProcessState {
// Tear down the platform specific state.
void TearDownState();
// Initializes the command-line that can be used to autorun the service
// process.
void CreateAutoRunCommandLine();
// An opaque object that maintains state. The actual definition of this is
// platform dependent.
struct StateData;
......
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