From af96a772f4986e37bb7efe108760ca6901d22fa5 Mon Sep 17 00:00:00 2001 From: "sanjeevr@chromium.org" Date: Tue, 14 Sep 2010 17:20:44 +0000 Subject: The LSID for Cloud Print can now be supplied on the command line even if Cloud Print was previously enabled. This had broken during a recent change to remember the enabled state of Cloud Print in the service process. BUG=None TEST=With cloud print previously enabled, try launching the service process with a new LSID in the command line. Review URL: http://codereview.chromium.org/3384001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59387 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/service/service_main.cc | 10 +--------- chrome/service/service_process.cc | 26 ++++++++++++++++++-------- chrome/service/service_process.h | 4 +++- chrome/service/service_process_unittest.cc | 10 +++++++--- 4 files changed, 29 insertions(+), 21 deletions(-) (limited to 'chrome/service') diff --git a/chrome/service/service_main.cc b/chrome/service/service_main.cc index 03ccfe3..28eda80 100644 --- a/chrome/service/service_main.cc +++ b/chrome/service/service_main.cc @@ -29,15 +29,7 @@ int ServiceProcessMain(const MainFunctionParams& parameters) { #endif // defined(OS_WIN) ServiceProcess service_process; - service_process.Initialize(&main_message_loop); - - // Enable Cloud Print if needed. - if (parameters.command_line_.HasSwitch(switches::kEnableCloudPrintProxy)) { - std::string lsid = - parameters.command_line_.GetSwitchValueASCII( - switches::kServiceAccountLsid); - service_process.GetCloudPrintProxy()->EnableForUser(lsid); - } + service_process.Initialize(&main_message_loop, parameters.command_line_); MessageLoop::current()->Run(); service_process.Teardown(); diff --git a/chrome/service/service_process.cc b/chrome/service/service_process.cc index 69649b4..f22db02 100644 --- a/chrome/service/service_process.cc +++ b/chrome/service/service_process.cc @@ -58,7 +58,8 @@ ServiceProcess::ServiceProcess() g_service_process = this; } -bool ServiceProcess::Initialize(MessageLoop* message_loop) { +bool ServiceProcess::Initialize(MessageLoop* message_loop, + const CommandLine& command_line) { main_message_loop_ = message_loop; network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); base::Thread::Options options; @@ -71,6 +72,12 @@ bool ServiceProcess::Initialize(MessageLoop* message_loop) { Teardown(); return false; } + + // See if we have been suppiled an LSID in the command line. This LSID will + // override the credentials we use for Cloud Print. + std::string lsid = command_line.GetSwitchValueASCII( + switches::kServiceAccountLsid); + FilePath user_data_dir; PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); FilePath pref_path = user_data_dir.Append(chrome::kServiceStateFileName); @@ -87,14 +94,17 @@ bool ServiceProcess::Initialize(MessageLoop* message_loop) { // If true then we start the host. StartChromotingHost(); } + // Enable Cloud Print if needed. First check the command-line. + bool cloud_print_proxy_enabled = + command_line.HasSwitch(switches::kEnableCloudPrintProxy); + if (!cloud_print_proxy_enabled) { + // Then check if the cloud print proxy was previously enabled. + values->GetBoolean(prefs::kCloudPrintProxyEnabled, + &cloud_print_proxy_enabled); + } - bool cloud_print_proxy_enabled = false; - - // Check if the cloud print proxy is already enabled. - if (values->GetBoolean(prefs::kCloudPrintProxyEnabled, - &cloud_print_proxy_enabled) && - cloud_print_proxy_enabled) { - GetCloudPrintProxy()->EnableForUser(std::string()); + if (cloud_print_proxy_enabled) { + GetCloudPrintProxy()->EnableForUser(lsid); } LOG(INFO) << "Starting Service Process IPC Server"; diff --git a/chrome/service/service_process.h b/chrome/service/service_process.h index 96e112d..55c6d62 100644 --- a/chrome/service/service_process.h +++ b/chrome/service/service_process.h @@ -28,6 +28,8 @@ class HostKeyPair; class JsonHostConfig; } +class CommandLine; + // The ServiceProcess does not inherit from ChildProcess because this // process can live independently of the browser process. class ServiceProcess : public RemotingDirectoryService::Client, @@ -37,7 +39,7 @@ class ServiceProcess : public RemotingDirectoryService::Client, ~ServiceProcess(); // Initialize the ServiceProcess with the message loop that it should run on. - bool Initialize(MessageLoop* message_loop); + bool Initialize(MessageLoop* message_loop, const CommandLine& command_line); bool Teardown(); // TODO(sanjeevr): Change various parts of the code such as // net::ProxyService::CreateSystemProxyConfigService to take in diff --git a/chrome/service/service_process_unittest.cc b/chrome/service/service_process_unittest.cc index b63efb6..884da04 100644 --- a/chrome/service/service_process_unittest.cc +++ b/chrome/service/service_process_unittest.cc @@ -5,6 +5,7 @@ #include #include "base/base64.h" +#include "base/command_line.h" #include "base/crypto/rsa_private_key.h" #include "base/message_loop.h" #include "base/waitable_event.h" @@ -16,7 +17,8 @@ TEST(ServiceProcessTest, DISABLED_Run) { MessageLoopForUI main_message_loop; ServiceProcess process; - EXPECT_TRUE(process.Initialize(&main_message_loop)); + CommandLine command_line(CommandLine::ARGUMENTS_ONLY); + EXPECT_TRUE(process.Initialize(&main_message_loop, command_line)); EXPECT_TRUE(process.Teardown()); } @@ -25,7 +27,8 @@ TEST(ServiceProcessTest, DISABLED_Run) { TEST(ServiceProcessTest, DISABLED_RunChromoting) { MessageLoopForUI main_message_loop; ServiceProcess process; - EXPECT_TRUE(process.Initialize(&main_message_loop)); + CommandLine command_line(CommandLine::ARGUMENTS_ONLY); + EXPECT_TRUE(process.Initialize(&main_message_loop, command_line)); // Then config the chromoting host and start it. remoting::HostKeyPair key; @@ -49,7 +52,8 @@ ACTION_P(QuitMessageLoop, message_loop) { TEST(ServiceProcessTest, DISABLED_RunChromotingUntilShutdown) { MessageLoopForUI main_message_loop; MockServiceProcess process; - EXPECT_TRUE(process.Initialize(&main_message_loop)); + CommandLine command_line(CommandLine::ARGUMENTS_ONLY); + EXPECT_TRUE(process.Initialize(&main_message_loop, command_line)); // Expect chromoting shutdown be called because the login token is invalid. EXPECT_CALL(process, OnChromotingHostShutdown()) -- cgit v1.1