summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-18 21:04:49 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-18 21:04:49 +0000
commite57d57b67290c8dfd701ac5021264a9ae1588b81 (patch)
treed419061b3690fd591a87aff809096f120f201d46 /chrome
parent8e303b21eb3e190b420e82a15d5d151bc8df0dd4 (diff)
downloadchromium_src-e57d57b67290c8dfd701ac5021264a9ae1588b81.zip
chromium_src-e57d57b67290c8dfd701ac5021264a9ae1588b81.tar.gz
chromium_src-e57d57b67290c8dfd701ac5021264a9ae1588b81.tar.bz2
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. Review URL: http://codereview.chromium.org/3185015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56600 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-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/remoting/resources/setup_done.html6
-rw-r--r--chrome/browser/service/service_process_control.cc13
-rw-r--r--chrome/browser/service/service_process_control_manager.cc6
-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_process.cc19
11 files changed, 78 insertions, 24 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index ac91d86..3f10c59 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -1965,6 +1965,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 b5fa926..108f6f1 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"
@@ -1366,6 +1369,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 f49e335..984bc53 100644
--- a/chrome/browser/remoting/remoting_resources_source.cc
+++ b/chrome/browser/remoting/remoting_resources_source.cc
@@ -51,9 +51,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 27deaff..1f4411b 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/remoting/resources/setup_done.html b/chrome/browser/remoting/resources/setup_done.html
index 88a365c..70311f8 100644
--- a/chrome/browser/remoting/resources/setup_done.html
+++ b/chrome/browser/remoting/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 setMessage(msg) {
document.getElementById('msgContent').innerHTML = msg;
@@ -57,8 +56,7 @@ html[os='mac'] input[type='submit'] {
</head>
<body i18n-values=".style.fontFamily:fontfamily">
<div class="remoting-header" i18n-content="success"></div>
- <div id="msgContent"></div>
- <div id="summary" i18n-content="setupsummary"></div>
+ <div id="msgContent">Setup completed.</div>
<div class="remoting-footer">
<input id="close" type="submit" i18n-values="value:okay"
onclick='chrome.send("DialogClose", [""])' />
diff --git a/chrome/browser/service/service_process_control.cc b/chrome/browser/service/service_process_control.cc
index 9b76dc7..5979084 100644
--- a/chrome/browser/service/service_process_control.cc
+++ b/chrome/browser/service/service_process_control.cc
@@ -109,6 +109,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,
@@ -120,8 +121,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;
}
@@ -162,7 +165,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();
@@ -183,6 +186,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();
}
@@ -190,6 +195,8 @@ 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();
}
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/common/pref_names.cc b/chrome/common/pref_names.cc
index 02f92424..16aa70e 100644
--- a/chrome/common/pref_names.cc
+++ b/chrome/common/pref_names.cc
@@ -914,6 +914,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";
@@ -935,6 +937,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 18503a0..58d5741 100644
--- a/chrome/common/pref_names.h
+++ b/chrome/common/pref_names.h
@@ -353,6 +353,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_process.cc b/chrome/service/service_process.cc
index f6d38e6..13979e7 100644
--- a/chrome/service/service_process.cc
+++ b/chrome/service/service_process.cc
@@ -11,6 +11,7 @@
#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 +66,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.
@@ -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();