summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-23 23:20:57 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-23 23:20:57 +0000
commite96bf0c56566457022d20682ee278cd135d7c681 (patch)
tree16aae1f02aa4ca3948343ffb75f6010f9d1da125
parent4232100ca0d42e558e75a728b69abca4b28499bf (diff)
downloadchromium_src-e96bf0c56566457022d20682ee278cd135d7c681.zip
chromium_src-e96bf0c56566457022d20682ee278cd135d7c681.tar.gz
chromium_src-e96bf0c56566457022d20682ee278cd135d7c681.tar.bz2
Resubmit r56600 - Start/stop service process when browser starts and stop
Save the information that the setup of remoting has completed. After setup has been completed we start and stop service process when --enable-remoting presents when browser starts. Also save the information in the service process that host is registered and ready to be used. Again start chromoting host automatically once the host registration is done. BUG=50244, 50242, 50243, 50249 Review URL: http://codereview.chromium.org/3153029 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57120 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/browser.cc1
-rw-r--r--chrome/browser/browser_main.cc16
-rw-r--r--chrome/browser/remoting/remoting_resources_source.cc4
-rw-r--r--chrome/browser/remoting/remoting_setup_flow.cc25
-rw-r--r--chrome/browser/service/service_process_control.cc19
-rw-r--r--chrome/browser/service/service_process_control_manager.cc6
-rw-r--r--chrome/browser/sync/resources/setup_done.html3
-rw-r--r--chrome/common/pref_names.cc5
-rw-r--r--chrome/common/pref_names.h3
-rw-r--r--chrome/service/remoting/remoting_directory_service.cc4
-rw-r--r--chrome/service/service_main.cc5
-rw-r--r--chrome/service/service_process.cc21
-rw-r--r--remoting/host/chromoting_host.cc5
13 files changed, 94 insertions, 23 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index f8c91744..d012fff4 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -1989,6 +1989,7 @@ void Browser::RegisterUserPrefs(PrefService* prefs) {
prefs->RegisterBooleanPref(prefs::kWebAppCreateInQuickLaunchBar, true);
prefs->RegisterBooleanPref(prefs::kUseVerticalTabs, false);
prefs->RegisterBooleanPref(prefs::kEnableTranslate, true);
+ prefs->RegisterBooleanPref(prefs::kRemotingHasSetupCompleted, false);
}
// static
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index bf299bd..7fb3dcc 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -59,6 +59,8 @@
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
#include "chrome/browser/search_engines/template_url_model.h"
#include "chrome/browser/search_engines/template_url_prepopulate_data.h"
+#include "chrome/browser/service/service_process_control.h"
+#include "chrome/browser/service/service_process_control_manager.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/translate/translate_manager.h"
#include "chrome/common/child_process.h"
@@ -73,6 +75,7 @@
#include "chrome/common/net/net_resource_provider.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/result_codes.h"
+#include "chrome/common/service_process_type.h"
#include "chrome/installer/util/google_update_settings.h"
#include "chrome/installer/util/master_preferences.h"
#include "grit/app_locale_settings.h"
@@ -1363,6 +1366,19 @@ int BrowserMain(const MainFunctionParams& parameters) {
ChildProcess::WaitForDebugger(L"Browser");
}
+ // If remoting or cloud print proxy is enabled and setup has been completed
+ // we start the service process here.
+ // The prerequisite for running the service process is that we have IO, UI
+ // and PROCESS_LAUNCHER threads up and running.
+ // TODO(hclam): Need to check for cloud print proxy too.
+ if (parsed_command_line.HasSwitch(switches::kEnableRemoting)) {
+ if (user_prefs->GetBoolean(prefs::kRemotingHasSetupCompleted)) {
+ ServiceProcessControl* control = ServiceProcessControlManager::instance()
+ ->GetProcessControl(profile, kServiceProcessRemoting);
+ control->Launch(NULL);
+ }
+ }
+
int result_code = ResultCodes::NORMAL_EXIT;
if (parameters.ui_task) {
// We are in test mode. Run one task and enter the main message loop.
diff --git a/chrome/browser/remoting/remoting_resources_source.cc b/chrome/browser/remoting/remoting_resources_source.cc
index 4c18089..a57596a 100644
--- a/chrome/browser/remoting/remoting_resources_source.cc
+++ b/chrome/browser/remoting/remoting_resources_source.cc
@@ -52,9 +52,7 @@ void RemotingResourcesSource::StartDataRequest(const std::string& path_raw,
localized_strings.SetString("settingupsync",
l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_SETTING_UP_SYNC));
- localized_strings.SetString("introduction",
- ASCIIToUTF16("Remoting ") +
- l10n_util::GetStringUTF16(IDS_PRODUCT_NAME));
+ localized_strings.SetString("introduction", "");
localized_strings.SetString("signinprefix",
l10n_util::GetStringUTF16(IDS_SYNC_LOGIN_SIGNIN_PREFIX));
localized_strings.SetString("signinsuffix",
diff --git a/chrome/browser/remoting/remoting_setup_flow.cc b/chrome/browser/remoting/remoting_setup_flow.cc
index 5bf1a23..85e94ed 100644
--- a/chrome/browser/remoting/remoting_setup_flow.cc
+++ b/chrome/browser/remoting/remoting_setup_flow.cc
@@ -68,14 +68,6 @@ void RemotingSetupFlow::OnDialogClosed(const std::string& json_retval) {
delete this;
}
-// static
-void RemotingSetupFlow::GetArgsForGaiaLogin(DictionaryValue* args) {
- args->SetString("iframeToShow", "login");
- args->SetString("user", "");
- args->SetInteger("error", 0);
- args->SetBoolean("editable_user", true);
-}
-
void RemotingSetupFlow::GetDOMMessageHandlers(
std::vector<DOMMessageHandler*>* handlers) const {
// Create the message handler only after we are asked.
@@ -168,13 +160,24 @@ void RemotingSetupFlow::OnProcessLaunched() {
process_control_->EnableRemotingWithTokens(login_, remoting_token_,
sync_token_);
message_handler_->ShowSetupDone();
+
+ // Save the preference that we have completed the setup of remoting.
+ profile_->GetPrefs()->SetBoolean(prefs::kRemotingHasSetupCompleted, true);
}
// static
RemotingSetupFlow* RemotingSetupFlow::Run(Profile* profile) {
// Set the arguments for showing the gaia login page.
DictionaryValue args;
- GetArgsForGaiaLogin(&args);
+ args.SetString("iframeToShow", "login");
+ args.SetString("user", "");
+ args.SetInteger("error", 0);
+ args.SetBoolean("editable_user", true);
+
+ if (profile->GetPrefs()->GetBoolean(prefs::kRemotingHasSetupCompleted)) {
+ args.SetString("iframeToShow", "done");
+ }
+
std::string json_args;
base::JSONWriter::Write(&args, false, &json_args);
@@ -194,7 +197,7 @@ void OpenRemotingSetupDialog(Profile* profile) {
RemotingSetupFlow::Run(profile->GetOriginalProfile());
}
-// TODO(hclam): Need to refcount RemotingSetupFlow. I need to lifetime of
-// objects are all correct.
+// TODO(hclam): Need to refcount RemotingSetupFlow. I need to fix
+// lifetime of objects.
DISABLE_RUNNABLE_METHOD_REFCOUNT(RemotingSetupFlow);
DISABLE_RUNNABLE_METHOD_REFCOUNT(RemotingSetupMessageHandler);
diff --git a/chrome/browser/service/service_process_control.cc b/chrome/browser/service/service_process_control.cc
index 57dd7b7..97e277b 100644
--- a/chrome/browser/service/service_process_control.cc
+++ b/chrome/browser/service/service_process_control.cc
@@ -110,6 +110,7 @@ void ServiceProcessControl::ConnectInternal() {
base::Thread* io_thread = g_browser_process->io_thread();
// TODO(hclam): Determine the the channel id from profile and type.
+ // TODO(hclam): Handle error connecting to channel.
const std::string channel_id = GetServiceProcessChannelName(type_);
channel_.reset(
new IPC::SyncChannel(channel_id, IPC::Channel::MODE_CLIENT, this, NULL,
@@ -121,8 +122,10 @@ void ServiceProcessControl::ConnectInternal() {
void ServiceProcessControl::Launch(Task* task) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
if (channel_.get()) {
- task->Run();
- delete task;
+ if (task) {
+ task->Run();
+ delete task;
+ }
return;
}
@@ -148,6 +151,10 @@ void ServiceProcessControl::Launch(Task* task) {
if (!logging_level.empty())
cmd_line->AppendSwitchASCII(switches::kLoggingLevel, logging_level);
+ if (browser_command_line.HasSwitch(switches::kWaitForDebuggerChildren)) {
+ cmd_line->AppendSwitch(switches::kWaitForDebugger);
+ }
+
// And then start the process asynchronously.
launcher_ = new Launcher(this, cmd_line);
launcher_->Run(
@@ -163,7 +170,7 @@ void ServiceProcessControl::OnProcessLaunched(Task* task) {
// After we have successfully created the service process we try to connect
// to it. The launch task is transfered to a connect task.
ConnectInternal();
- } else {
+ } else if (task) {
// If we don't have process handle that means launching the service process
// has failed.
task->Run();
@@ -184,6 +191,8 @@ void ServiceProcessControl::OnMessageReceived(const IPC::Message& message) {
void ServiceProcessControl::OnChannelConnected(int32 peer_pid) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
+ if (!connect_done_task_.get())
+ return;
connect_done_task_->Run();
connect_done_task_.reset();
}
@@ -191,12 +200,16 @@ void ServiceProcessControl::OnChannelConnected(int32 peer_pid) {
void ServiceProcessControl::OnChannelError() {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
channel_.reset();
+ if (!connect_done_task_.get())
+ return;
connect_done_task_->Run();
connect_done_task_.reset();
}
bool ServiceProcessControl::Send(IPC::Message* message) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
+ if (!channel_.get())
+ return false;
return channel_->Send(message);
}
diff --git a/chrome/browser/service/service_process_control_manager.cc b/chrome/browser/service/service_process_control_manager.cc
index 821de9a..6c946b4 100644
--- a/chrome/browser/service/service_process_control_manager.cc
+++ b/chrome/browser/service/service_process_control_manager.cc
@@ -36,6 +36,12 @@ ServiceProcessControl* ServiceProcessControlManager::GetProcessControl(
}
void ServiceProcessControlManager::Shutdown() {
+ // TODO(hclam): Normally we should just delete the list but for simplicity
+ // we also shutdown the service processes.
+ for (ServiceProcessControlList::iterator i = process_control_list_.begin();
+ i != process_control_list_.end(); ++i) {
+ (*i)->Shutdown();
+ }
STLDeleteElements(&process_control_list_);
}
diff --git a/chrome/browser/sync/resources/setup_done.html b/chrome/browser/sync/resources/setup_done.html
index 42ea800..973164b 100644
--- a/chrome/browser/sync/resources/setup_done.html
+++ b/chrome/browser/sync/resources/setup_done.html
@@ -44,8 +44,7 @@ html[os='mac'] input[type='submit'] {
</style>
<script>
function setShowFirstTimeSetupSummary() {
- document.getElementById("summary").innerHTML =
- templateData['firsttimesetupsummary'];
+ // TODO(hclam): Show the information for the first time setup.
}
function setSyncedToUser(synced_to) {
document.getElementById('user').innerHTML = synced_to;
diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc
index 1becd70..cf74af4 100644
--- a/chrome/common/pref_names.cc
+++ b/chrome/common/pref_names.cc
@@ -922,6 +922,8 @@ const char kLoginDatabaseMigrated[] = "login_database.migrated";
// The root URL of the cloud print service.
const char kCloudPrintServiceURL[] = "cloud_print.service_url";
+const char kRemotingHasSetupCompleted[] = "remoting.has_setup_completed";
+
// The list of BackgroundContents that should be loaded when the browser
// launches.
const char kRegisteredBackgroundContents[] = "background_contents.registered";
@@ -943,6 +945,9 @@ extern const char kCloudPrintEmail[] = "cloud_print.email";
extern const char kCloudPrintPrintSystemSettings[] =
"cloud_print.print_system_settings";
+// Used by the service process to determine if the remoting host is enabled.
+const char kRemotingHostEnabled[] = "remoting.host_enabled";
+
// Boolean to disable proxy altogether. If true, other proxy
// preferences are ignored.
const char kNoProxyServer[] = "proxy.disabled";
diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h
index 1697d53..232d0fd 100644
--- a/chrome/common/pref_names.h
+++ b/chrome/common/pref_names.h
@@ -356,6 +356,9 @@ extern const char kCloudPrintXMPPAuthToken[];
extern const char kCloudPrintEmail[];
extern const char kCloudPrintPrintSystemSettings[];
+extern const char kRemotingHasSetupCompleted[];
+extern const char kRemotingHostEnabled[];
+
extern const char kNoProxyServer[];
extern const char kProxyAutoDetect[];
extern const char kProxyServer[];
diff --git a/chrome/service/remoting/remoting_directory_service.cc b/chrome/service/remoting/remoting_directory_service.cc
index 697a576..8bc6b0a0 100644
--- a/chrome/service/remoting/remoting_directory_service.cc
+++ b/chrome/service/remoting/remoting_directory_service.cc
@@ -75,9 +75,7 @@ void RemotingDirectoryService::OnURLFetchComplete(
// Destroy the fetcher after the response has been received.
fetcher_.reset();
- LOG(INFO) << "Remoting directory response: \n" << data.c_str();
-
- // TODO(hclam): Simply checking 200 status is not ennough.
+ // TODO(hclam): Simply checking 200 status is not enough.
if (response_code == 200) {
client_->OnRemotingHostAdded();
} else {
diff --git a/chrome/service/service_main.cc b/chrome/service/service_main.cc
index 2670c5c..03ccfe3 100644
--- a/chrome/service/service_main.cc
+++ b/chrome/service/service_main.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/debug_util.h"
#include "base/message_loop.h"
#include "base/path_service.h"
#include "chrome/common/chrome_paths.h"
@@ -14,6 +15,10 @@
// Mainline routine for running as the service process.
int ServiceProcessMain(const MainFunctionParams& parameters) {
MessageLoopForUI main_message_loop;
+ if (parameters.command_line_.HasSwitch(switches::kWaitForDebugger)) {
+ DebugUtil::WaitForDebugger(60, true);
+ }
+
PlatformThread::SetName("CrServiceMain");
#if defined(OS_WIN)
diff --git a/chrome/service/service_process.cc b/chrome/service/service_process.cc
index f6d38e6..3dc4601 100644
--- a/chrome/service/service_process.cc
+++ b/chrome/service/service_process.cc
@@ -8,9 +8,11 @@
#include "base/path_service.h"
#include "base/utf_string_conversions.h"
+#include "base/values.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/json_pref_store.h"
+#include "chrome/common/pref_names.h"
#include "chrome/common/service_process_type.h"
#include "chrome/common/service_process_util.h"
#include "chrome/service/cloud_print/cloud_print_proxy.h"
@@ -65,6 +67,16 @@ bool ServiceProcess::Initialize(MessageLoop* message_loop) {
file_thread_->message_loop_proxy()));
service_prefs_->ReadPrefs();
+ DictionaryValue* values = service_prefs_->prefs();
+ bool remoting_host_enabled = false;
+
+ // Check if remoting host is already enabled.
+ if (values->GetBoolean(prefs::kRemotingHostEnabled, &remoting_host_enabled) &&
+ remoting_host_enabled) {
+ // If true then we start the host.
+ StartChromotingHost();
+ }
+
// TODO(hclam): Each type of service process should has it own instance of
// process and thus channel, but now we have only one process for all types
// so the type parameter doesn't matter now.
@@ -81,7 +93,6 @@ bool ServiceProcess::Initialize(MessageLoop* message_loop) {
}
bool ServiceProcess::Teardown() {
- // TODO(hclam): Remove this as this looks like dead code.
if (service_prefs_.get()) {
service_prefs_->WritePrefs();
service_prefs_.reset();
@@ -132,6 +143,8 @@ bool ServiceProcess::EnableChromotingHostWithTokens(
talk_token_ = talk_token;
// Use the remoting directory to register the host.
+ if (remoting_directory_.get())
+ remoting_directory_->CancelRequest();
remoting_directory_.reset(new RemotingDirectoryService(this));
remoting_directory_->AddHost(remoting_token);
return true;
@@ -207,6 +220,12 @@ void ServiceProcess::OnRemotingHostAdded() {
remoting_token_ = "";
talk_token_ = "";
+ // Save the preference that we have enabled the remoting host.
+ service_prefs_->prefs()->SetBoolean(prefs::kRemotingHostEnabled, true);
+
+ // Force writing prefs to the disk.
+ service_prefs_->WritePrefs();
+
// TODO(hclam): If we have a problem we need to send an IPC message back
// to the client that started this.
bool ret = StartChromotingHost();
diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc
index 3e47f54..1bc7b98 100644
--- a/remoting/host/chromoting_host.cc
+++ b/remoting/host/chromoting_host.cc
@@ -255,6 +255,11 @@ void ChromotingHost::DoShutdown() {
jingle_client_->Close();
}
+ // Stop the heartbeat sender.
+ if (heartbeat_sender_) {
+ heartbeat_sender_->Stop();
+ }
+
// Lastly call the shutdown task.
if (shutdown_task_.get()) {
shutdown_task_->Run();