summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-06 01:10:14 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-06 01:10:14 +0000
commit8ddbaac46292230ca3d8b5647e94d1a5bd4859ae (patch)
tree63d2a0d8e0be89a72b1dd46d83d74090fe29e71c /chrome
parent176c18328ad6e115b7a191e09e09266671f9cac1 (diff)
downloadchromium_src-8ddbaac46292230ca3d8b5647e94d1a5bd4859ae.zip
chromium_src-8ddbaac46292230ca3d8b5647e94d1a5bd4859ae.tar.gz
chromium_src-8ddbaac46292230ca3d8b5647e94d1a5bd4859ae.tar.bz2
Fixes for the Remoting setup flow.
1. Add gaia_login.html and setup_flow_error.html resources. 2. Add SetupFlowErrorStepBase for errors. 3. More flexible message handling. 4. Support for multiple message handlers in ServiceProcessControl. BUG=67218 TEST=Unittests. Review URL: http://codereview.chromium.org/6064006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70573 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/app/generated_resources.grd13
-rw-r--r--chrome/browser/browser_resources.grd1
-rw-r--r--chrome/browser/remoting/remoting_resources_source.cc16
-rw-r--r--chrome/browser/remoting/resources/remoting_setup_done.html42
-rw-r--r--chrome/browser/remoting/resources/remoting_setup_error.html23
-rw-r--r--chrome/browser/remoting/resources/remoting_setup_flow.css38
-rw-r--r--chrome/browser/remoting/resources/remoting_setup_flow.html27
-rw-r--r--chrome/browser/remoting/setup_flow.cc92
-rw-r--r--chrome/browser/remoting/setup_flow.h74
-rw-r--r--chrome/browser/remoting/setup_flow_login_step.cc26
-rw-r--r--chrome/browser/remoting/setup_flow_login_step.h8
-rw-r--r--chrome/browser/service/service_process_control.cc33
-rw-r--r--chrome/browser/service/service_process_control.h36
-rw-r--r--chrome/browser/service/service_process_control_browsertest.cc6
-rw-r--r--chrome/browser/ui/browser.cc4
15 files changed, 328 insertions, 111 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index 9cf707b..4cfd1e6 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -8298,7 +8298,18 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_REMOTING_SETUP_DIALOG_TITLE" desc="Title of the remoting setup dialog.">
Set up remoting
</message>
-
+ <message name="IDS_REMOTING_SUCCESS_TITLE" desc="Header of the page that is shown when remoting configuration is finished.">
+ Success!
+ </message>
+ <message name="IDS_REMOTING_SUCCESS_MESSAGE" desc="Message shown during remoting host setup after the host is successfully initialized.">
+ Remoting was started successfully. Now you should be able to connect to this computer remotely.
+ </message>
+ <message name="IDS_REMOTING_SERVICE_PROCESS_FAILED_MESSAGE" desc="Message shown during remoting host setup if there was an error starting service process.">
+ Unable to start service process.
+ </message>
+ <message name="IDS_REMOTING_RETRY_BUTTON_TEXT" desc="Text for retry button">
+ Retry
+ </message>
<!-- Sync strings -->
diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd
index af317b1..dade7cd 100644
--- a/chrome/browser/browser_resources.grd
+++ b/chrome/browser/browser_resources.grd
@@ -67,6 +67,7 @@ without changes to the corresponding grd file. etaa -->
<include name="IDR_SYNC_SETUP_FLOW_HTML" file="sync\resources\setup_flow.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_REMOTING_SETUP_FLOW_HTML" file="remoting\resources\remoting_setup_flow.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_REMOTING_SETUP_DONE_HTML" file="remoting\resources\remoting_setup_done.html" flattenhtml="true" type="BINDATA" />
+ <include name="IDR_REMOTING_SETUP_ERROR_HTML" file="remoting\resources\remoting_setup_error.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_CLOUD_PRINT_SETUP_FLOW_HTML" file="printing\cloud_print\resources\cloud_print_setup_flow.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_CLOUD_PRINT_SETUP_LOGIN_HTML" file="printing\cloud_print\resources\cloud_print_setup_login.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_CLOUD_PRINT_SETUP_DONE_HTML" file="printing\cloud_print\resources\cloud_print_setup_done.html" flattenhtml="true" type="BINDATA" />
diff --git a/chrome/browser/remoting/remoting_resources_source.cc b/chrome/browser/remoting/remoting_resources_source.cc
index 9057e1d..656763c 100644
--- a/chrome/browser/remoting/remoting_resources_source.cc
+++ b/chrome/browser/remoting/remoting_resources_source.cc
@@ -39,6 +39,7 @@ void RemotingResourcesSource::StartDataRequest(const std::string& path_raw,
const char kRemotingGaiaLoginPath[] = "gaialogin";
const char kRemotingSetupFlowPath[] = "setup";
const char kRemotingSetupDonePath[] = "setupdone";
+ const char kRemotingSetupErrorPath[] = "setuperror";
std::string response;
if (path_raw == kRemotingGaiaLoginPath) {
@@ -93,14 +94,25 @@ void RemotingResourcesSource::StartDataRequest(const std::string& path_raw,
} else if (path_raw == kRemotingSetupDonePath) {
DictionaryValue localized_strings;
localized_strings.SetString("success",
- l10n_util::GetStringUTF16(IDS_SYNC_SUCCESS));
+ l10n_util::GetStringUTF16(IDS_REMOTING_SUCCESS_TITLE));
localized_strings.SetString("okay",
- l10n_util::GetStringUTF16(IDS_SYNC_SETUP_OK_BUTTON_LABEL));
+ l10n_util::GetStringUTF16(IDS_OK));
static const base::StringPiece html(ResourceBundle::GetSharedInstance()
.GetRawDataResource(IDR_REMOTING_SETUP_DONE_HTML));
SetFontAndTextDirection(&localized_strings);
response = jstemplate_builder::GetI18nTemplateHtml(
html, &localized_strings);
+ } else if (path_raw == kRemotingSetupErrorPath) {
+ DictionaryValue localized_strings;
+ localized_strings.SetString("close",
+ l10n_util::GetStringUTF16(IDS_CLOSE));
+ localized_strings.SetString("retry",
+ l10n_util::GetStringUTF16(IDS_REMOTING_RETRY_BUTTON_TEXT));
+ static const base::StringPiece html(ResourceBundle::GetSharedInstance()
+ .GetRawDataResource(IDR_REMOTING_SETUP_ERROR_HTML));
+ SetFontAndTextDirection(&localized_strings);
+ response = jstemplate_builder::GetI18nTemplateHtml(
+ html, &localized_strings);
} else if (path_raw == kRemotingSetupFlowPath) {
static const base::StringPiece html(ResourceBundle::GetSharedInstance()
.GetRawDataResource(IDR_REMOTING_SETUP_FLOW_HTML));
diff --git a/chrome/browser/remoting/resources/remoting_setup_done.html b/chrome/browser/remoting/resources/remoting_setup_done.html
index 673f40b..6d54e62 100644
--- a/chrome/browser/remoting/resources/remoting_setup_done.html
+++ b/chrome/browser/remoting/resources/remoting_setup_done.html
@@ -1,47 +1,7 @@
<html i18n-values="dir:textdirection;">
<head>
<title></title>
-<style type="text/css">
-body {
- background: #FFFFFF;
- font-size: 11pt;
- line-height: 1.5em;
- margin: 10px 15px;
- -webkit-user-select: none;
-}
-.remoting-header {
- font-size: 1.2em;
- font-weight: bold;
-}
-.remoting-success-image {
- text-align: center;
- margin: 20px;
-}
-#message {
- font-weight: bold;
-}
-.remoting-footer {
- position: fixed;
- right: 0px;
- bottom: 0px;
- margin-right: 10px;
- margin-bottom: 10px;
-}
-html[dir='rtl'] .remoting-footer {
- text-align: left;
- left: 0px;
- bottom: 0px;
- margin-left: 20px;
-}
-input[type='submit'] {
- min-width: 87px;
- min-height: 26px;
-}
-html[os='mac'] input[type='submit'] {
- font-size: 12pt;
-}
-
-</style>
+<link rel="stylesheet" type="text/css" href="remoting_setup_flow.css" />
<script>
function setShowFirstTimeSetupSummary() {
document.getElementById("summary").innerHTML =
diff --git a/chrome/browser/remoting/resources/remoting_setup_error.html b/chrome/browser/remoting/resources/remoting_setup_error.html
new file mode 100644
index 0000000..807b264
--- /dev/null
+++ b/chrome/browser/remoting/resources/remoting_setup_error.html
@@ -0,0 +1,23 @@
+<html i18n-values="dir:textdirection;">
+<head>
+<title></title>
+<link rel="stylesheet" type="text/css" href="remoting_setup_flow.css" />
+<script>
+ function setMessage(msg) {
+ document.getElementById('msgContent').innerHTML = msg;
+ }
+ function onPageShown() {
+ document.getElementById("close").focus();
+ }
+</script>
+</head>
+<body i18n-values=".style.fontFamily:fontfamily">
+ <div id="msgContent"></div>
+ <div class="remoting-footer">
+ <input id="retry" type="submit" i18n-values="value:retry"
+ onclick='chrome.send("RemotingSetup", ["Retry"])' />
+ <input id="close" type="submit" i18n-values="value:close"
+ onclick='chrome.send("DialogClose", [""])' />
+ </div>
+</body>
+</html>
diff --git a/chrome/browser/remoting/resources/remoting_setup_flow.css b/chrome/browser/remoting/resources/remoting_setup_flow.css
new file mode 100644
index 0000000..37094f0
--- /dev/null
+++ b/chrome/browser/remoting/resources/remoting_setup_flow.css
@@ -0,0 +1,38 @@
+body {
+ background: #FFFFFF;
+ font-size: 11pt;
+ line-height: 1.5em;
+ margin: 10px 15px;
+ -webkit-user-select: none;
+}
+.remoting-header {
+ font-size: 1.2em;
+ font-weight: bold;
+}
+.remoting-success-image {
+ text-align: center;
+ margin: 20px;
+}
+#message {
+ font-weight: bold;
+}
+.remoting-footer {
+ position: fixed;
+ right: 0px;
+ bottom: 0px;
+ margin-right: 10px;
+ margin-bottom: 10px;
+}
+html[dir='rtl'] .remoting-footer {
+ text-align: left;
+ left: 0px;
+ bottom: 0px;
+ margin-left: 20px;
+}
+input[type='submit'] {
+ min-width: 87px;
+ min-height: 26px;
+}
+html[os='mac'] input[type='submit'] {
+ font-size: 12pt;
+}
diff --git a/chrome/browser/remoting/resources/remoting_setup_flow.html b/chrome/browser/remoting/resources/remoting_setup_flow.html
index aafe008..13affed 100644
--- a/chrome/browser/remoting/resources/remoting_setup_flow.html
+++ b/chrome/browser/remoting/resources/remoting_setup_flow.html
@@ -13,14 +13,28 @@
function hideAllPages() {
document.getElementById('login').style.display = 'none';
document.getElementById('login').tabIndex = -1;
- document.getElementById('done').style.display = 'none';
+ document.getElementById('done').style.display = 'none';
document.getElementById('done').tabIndex = -1;
- }
+ document.getElementById('error').style.display = 'none';
+ document.getElementById('error').tabIndex = -1;
+ }
- function showSetupDone() {
+ function showPage(page) {
hideAllPages();
- document.getElementById('done').style.display = 'block';
- document.getElementById('done').tabIndex = 0;
+ document.getElementById(page).style.display = 'block';
+ document.getElementById(page).tabIndex = 0;
+ }
+
+ function showLogin() {
+ showPage('login')
+ }
+
+ function showSetupDone() {
+ showPage('done')
+ }
+
+ function showError() {
+ showPage('error')
}
</script>
</head>
@@ -31,5 +45,8 @@
<iframe id="done" frameborder="0" width="100%" scrolling="no" height="100%"
src="chrome://remotingresources/setupdone" style="display:none"
tabindex="-1"></iframe>
+ <iframe id="error" frameborder="0" width="100%" scrolling="no" height="100%"
+ src="chrome://remotingresources/setuperror" style="display:none"
+ tabindex="-1"></iframe>
</body>
</html>
diff --git a/chrome/browser/remoting/setup_flow.cc b/chrome/browser/remoting/setup_flow.cc
index c6756bb..f2b23c8 100644
--- a/chrome/browser/remoting/setup_flow.cc
+++ b/chrome/browser/remoting/setup_flow.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -27,6 +27,7 @@
namespace remoting {
static const wchar_t kDoneIframeXPath[] = L"//iframe[@id='done']";
+static const wchar_t kErrorIframeXPath[] = L"//iframe[@id='error']";
SetupFlowStep::SetupFlowStep() { }
SetupFlowStep::~SetupFlowStep() { }
@@ -63,17 +64,47 @@ void SetupFlowStepBase::FinishStep(SetupFlowStep* next_step) {
done_callback_->Run();
}
-SetupFlowDoneStep::SetupFlowDoneStep() { }
+SetupFlowErrorStepBase::SetupFlowErrorStepBase() { }
+SetupFlowErrorStepBase::~SetupFlowErrorStepBase() { }
+
+void SetupFlowErrorStepBase::HandleMessage(const std::string& message,
+ const Value* arg) {
+ if (message == "Retry") {
+ Retry();
+ }
+}
+
+void SetupFlowErrorStepBase::Cancel() { }
+
+void SetupFlowErrorStepBase::DoStart() {
+ std::wstring javascript =
+ L"setMessage('" + UTF16ToWide(GetErrorMessage()) + L"');";
+ ExecuteJavascriptInIFrame(kErrorIframeXPath, javascript);
+
+ flow()->dom_ui()->CallJavascriptFunction(L"showError");
+
+ ExecuteJavascriptInIFrame(kErrorIframeXPath, L"onPageShown();");
+}
+
+SetupFlowDoneStep::SetupFlowDoneStep() {
+ message_ = l10n_util::GetStringUTF16(IDS_REMOTING_SUCCESS_MESSAGE);
+}
+
+SetupFlowDoneStep::SetupFlowDoneStep(const string16& message)
+ : message_(message) {
+}
+
SetupFlowDoneStep::~SetupFlowDoneStep() { }
void SetupFlowDoneStep::HandleMessage(const std::string& message,
- const ListValue* args) {
+ const Value* arg) {
}
void SetupFlowDoneStep::Cancel() { }
void SetupFlowDoneStep::DoStart() {
- std::wstring javascript = L"setMessage('You are all set!');";
+ std::wstring javascript =
+ L"setMessage('" + UTF16ToWide(message_) + L"');";
ExecuteJavascriptInIFrame(kDoneIframeXPath, javascript);
flow()->dom_ui()->CallJavascriptFunction(L"showSetupDone");
@@ -81,6 +112,12 @@ void SetupFlowDoneStep::DoStart() {
ExecuteJavascriptInIFrame(kDoneIframeXPath, L"onPageShown();");
}
+SetupFlowContext::SetupFlowContext() {
+}
+
+SetupFlowContext::~SetupFlowContext() {
+}
+
SetupFlow::SetupFlow(const std::string& args, Profile* profile,
SetupFlowStep* first_step)
: dom_ui_(NULL),
@@ -175,12 +212,42 @@ DOMMessageHandler* SetupFlow::Attach(DOMUI* dom_ui) {
}
void SetupFlow::RegisterMessages() {
- dom_ui_->RegisterMessageCallback("SubmitAuth",
- NewCallback(this, &SetupFlow::HandleSubmitAuth));
+ dom_ui_->RegisterMessageCallback(
+ "SubmitAuth", NewCallback(this, &SetupFlow::HandleSubmitAuth));
+ dom_ui_->RegisterMessageCallback(
+ "RemotingSetup", NewCallback(this, &SetupFlow::HandleUIMessage));
}
void SetupFlow::HandleSubmitAuth(const ListValue* args) {
- current_step_->HandleMessage("SubmitAuth", args);
+ Value* first_arg = NULL;
+ if (!args->Get(0, &first_arg)) {
+ NOTREACHED();
+ return;
+ }
+
+ current_step_->HandleMessage("SubmitAuth", first_arg);
+}
+
+void SetupFlow::HandleUIMessage(const ListValue* args) {
+ std::string message;
+ Value* message_value;
+ if (!args->Get(0, &message_value) ||
+ !message_value->GetAsString(&message)) {
+ NOTREACHED();
+ return;
+ }
+
+ // Message argument is optional and set to NULL if it is not
+ // provided by the sending page.
+ Value* arg_value = NULL;
+ if (args->GetSize() >= 2) {
+ if (!args->Get(1, &arg_value)) {
+ NOTREACHED();
+ return;
+ }
+ }
+
+ current_step_->HandleMessage(message, arg_value);
}
void SetupFlow::StartCurrentStep() {
@@ -188,7 +255,16 @@ void SetupFlow::StartCurrentStep() {
}
void SetupFlow::OnStepDone() {
- current_step_.reset(current_step_->GetNextStep());
+ SetupFlowStep* next_step = current_step_->GetNextStep();
+
+ if (current_step_.get()) {
+ // Can't destroy current step here. Schedule it to be destroyed later.
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ new DeleteTask<SetupFlowStep>(current_step_.release()));
+ }
+
+ current_step_.reset(next_step);
StartCurrentStep();
}
diff --git a/chrome/browser/remoting/setup_flow.h b/chrome/browser/remoting/setup_flow.h
index f5dee29..d5d16dc 100644
--- a/chrome/browser/remoting/setup_flow.h
+++ b/chrome/browser/remoting/setup_flow.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,8 +8,10 @@
#include "base/callback.h"
#include "base/scoped_ptr.h"
#include "chrome/browser/dom_ui/html_dialog_ui.h"
+#include "chrome/common/remoting/chromoting_host_info.h"
class ListValue;
+class ServiceProcessControl;
namespace remoting {
@@ -30,9 +32,9 @@ class SetupFlowStep {
// The callback must be called on the same thread as Start().
virtual void Start(SetupFlow* flow, DoneCallback* done_callback) = 0;
- // Called to handle |message| received from UI.
- virtual void HandleMessage(const std::string& message,
- const ListValue* args) = 0;
+ // Called to handle |message| received from UI. |args| may be set to
+ // NULL.
+ virtual void HandleMessage(const std::string& message, const Value* arg) = 0;
// Called if user closes the dialog.
virtual void Cancel() = 0;
@@ -81,27 +83,84 @@ class SetupFlowStepBase : public SetupFlowStep {
DISALLOW_COPY_AND_ASSIGN(SetupFlowStepBase);
};
+// Base class for error steps. It shows the error message returned by
+// GetErrorMessage() and Retry button.
+class SetupFlowErrorStepBase : public SetupFlowStepBase {
+ public:
+ SetupFlowErrorStepBase();
+ virtual ~SetupFlowErrorStepBase();
+
+ // SetupFlowStep implementation.
+ virtual void HandleMessage(const std::string& message, const Value* arg);
+ virtual void Cancel();
+
+ protected:
+ virtual void DoStart();
+
+ // Returns error message that is shown to the user.
+ virtual string16 GetErrorMessage() = 0;
+
+ // Called when user clicks Retry button. Normally this methoud just
+ // calls FinishStep() with an appropriate next step.
+ virtual void Retry() = 0;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SetupFlowErrorStepBase);
+};
+
// The last step in the setup flow. This step never finishes, user is
// expected to close dialog after that.
class SetupFlowDoneStep : public SetupFlowStepBase {
public:
SetupFlowDoneStep();
+ explicit SetupFlowDoneStep(const string16& message);
virtual ~SetupFlowDoneStep();
// SetupFlowStep implementation.
- virtual void HandleMessage(const std::string& message, const ListValue* args);
+ virtual void HandleMessage(const std::string& message, const Value* arg);
virtual void Cancel();
protected:
void DoStart();
private:
+ string16 message_;
+
DISALLOW_COPY_AND_ASSIGN(SetupFlowDoneStep);
};
+// SetupFlowContext stores data that needs to be passed between
+// different setup flow steps.
+struct SetupFlowContext {
+ SetupFlowContext();
+ ~SetupFlowContext();
+
+ std::string login;
+ std::string remoting_token;
+ std::string talk_token;
+
+ ChromotingHostInfo host_info;
+};
+
// This class is responsible for showing a remoting setup dialog and
// perform operations to fill the content of the dialog and handle
// user actions in the dialog.
+//
+// Each page in the setup flow may send message to the current
+// step. In order to do that it must use send a RemotingSetup message
+// and specify message name as the first value in the argument
+// list. For example the following code sends Retry message to the
+// current step:
+//
+// chrome.send("RemotingSetup", ["Retry"])
+//
+// Assitional message parameters may be provided via send value in the
+// arguments list, e.g.:
+//
+// chrome.send("RemotingSetup", ["SubmitAuth", auth_data])
+//
+// In this case auth_data would be passed in
+// SetupFlowStep::HandleMessage().
class SetupFlow : public DOMMessageHandler,
public HtmlDialogUIDelegate {
public:
@@ -111,6 +170,7 @@ class SetupFlow : public DOMMessageHandler,
DOMUI* dom_ui() { return dom_ui_; }
Profile* profile() { return profile_; }
+ SetupFlowContext* context() { return &context_; }
private:
explicit SetupFlow(const std::string& args, Profile* profile,
@@ -132,7 +192,9 @@ class SetupFlow : public DOMMessageHandler,
virtual DOMMessageHandler* Attach(DOMUI* dom_ui);
virtual void RegisterMessages();
+ // Message handlers for the messages we receive from UI.
void HandleSubmitAuth(const ListValue* args);
+ void HandleUIMessage(const ListValue* args);
void StartCurrentStep();
void OnStepDone();
@@ -145,6 +207,8 @@ class SetupFlow : public DOMMessageHandler,
std::string dialog_start_args_;
Profile* profile_;
+ SetupFlowContext context_;
+
scoped_ptr<SetupFlowStep> current_step_;
DISALLOW_COPY_AND_ASSIGN(SetupFlow);
diff --git a/chrome/browser/remoting/setup_flow_login_step.cc b/chrome/browser/remoting/setup_flow_login_step.cc
index a485a07..9b7cf7b 100644
--- a/chrome/browser/remoting/setup_flow_login_step.cc
+++ b/chrome/browser/remoting/setup_flow_login_step.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -22,11 +22,15 @@ SetupFlowLoginStep::SetupFlowLoginStep() { }
SetupFlowLoginStep::~SetupFlowLoginStep() { }
void SetupFlowLoginStep::HandleMessage(const std::string& message,
- const ListValue* args) {
+ const Value* arg) {
if (message == "SubmitAuth") {
- std::string json(dom_ui_util::GetJsonResponseFromFirstArgumentInList(args));
- if (json.empty())
+ DCHECK(arg);
+
+ std::string json;
+ if (!arg->GetAsString(&json) || json.empty()) {
+ NOTREACHED();
return;
+ }
scoped_ptr<Value> parsed_value(base::JSONReader::Read(json, false));
if (!parsed_value.get() || !parsed_value->IsType(Value::TYPE_DICTIONARY)) {
@@ -37,7 +41,8 @@ void SetupFlowLoginStep::HandleMessage(const std::string& message,
CHECK(parsed_value->IsType(Value::TYPE_DICTIONARY));
std::string username, password, captcha;
- DictionaryValue* result = static_cast<DictionaryValue*>(parsed_value.get());
+ const DictionaryValue* result =
+ static_cast<const DictionaryValue*>(parsed_value.get());
if (!result->GetString("user", &username) ||
!result->GetString("pass", &password) ||
!result->GetString("captcha", &captcha)) {
@@ -57,8 +62,7 @@ void SetupFlowLoginStep::Cancel() {
void SetupFlowLoginStep::OnUserSubmittedAuth(const std::string& user,
const std::string& password,
const std::string& captcha) {
- // Save the login name only.
- login_ = user;
+ flow()->context()->login = user;
// Start the authenticator.
authenticator_.reset(
@@ -73,7 +77,7 @@ void SetupFlowLoginStep::OnUserSubmittedAuth(const std::string& user,
void SetupFlowLoginStep::OnClientLoginSuccess(
const GaiaAuthConsumer::ClientLoginResult& credentials) {
// Save the token for remoting.
- remoting_token_ = credentials.token;
+ flow()->context()->remoting_token = credentials.token;
// After login has succeeded try to fetch the token for sync.
// We need the token for sync to connect to the talk network.
@@ -90,7 +94,7 @@ void SetupFlowLoginStep::OnClientLoginFailure(
void SetupFlowLoginStep::OnIssueAuthTokenSuccess(
const std::string& service, const std::string& auth_token) {
// Save the sync token.
- talk_token_ = auth_token;
+ flow()->context()->talk_token = auth_token;
authenticator_.reset();
FinishStep(new SetupFlowDoneStep());
@@ -104,7 +108,6 @@ void SetupFlowLoginStep::OnIssueAuthTokenFailure(const std::string& service,
void SetupFlowLoginStep::DoStart() {
DictionaryValue args;
- args.SetString("iframeToShow", "login");
// TODO(sergeyu): Supply current login name if the service was started before.
args.SetString("user", "");
args.SetBoolean("editable_user", true);
@@ -115,7 +118,7 @@ void SetupFlowLoginStep::ShowGaiaLogin(const DictionaryValue& args) {
DOMUI* dom_ui = flow()->dom_ui();
DCHECK(dom_ui);
- dom_ui->CallJavascriptFunction(L"showGaiaLoginIframe");
+ dom_ui->CallJavascriptFunction(L"showLogin");
std::string json;
base::JSONWriter::Write(&args, false, &json);
@@ -126,7 +129,6 @@ void SetupFlowLoginStep::ShowGaiaLogin(const DictionaryValue& args) {
void SetupFlowLoginStep::ShowGaiaFailed(const GoogleServiceAuthError& error) {
DictionaryValue args;
- args.SetString("iframeToShow", "login");
args.SetString("user", "");
args.SetInteger("error", error.state());
args.SetBoolean("editable_user", true);
diff --git a/chrome/browser/remoting/setup_flow_login_step.h b/chrome/browser/remoting/setup_flow_login_step.h
index 7c48df7..9aee6b5 100644
--- a/chrome/browser/remoting/setup_flow_login_step.h
+++ b/chrome/browser/remoting/setup_flow_login_step.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -18,8 +18,7 @@ class SetupFlowLoginStep : public SetupFlowStepBase, public GaiaAuthConsumer {
virtual ~SetupFlowLoginStep();
// SetupFlowStep implementation.
- virtual void HandleMessage(const std::string& message,
- const ListValue* args);
+ virtual void HandleMessage(const std::string& message, const Value* arg);
virtual void Cancel();
// GaiaAuthConsumer implementation.
@@ -46,9 +45,6 @@ class SetupFlowLoginStep : public SetupFlowStepBase, public GaiaAuthConsumer {
// Fetcher to obtain the Chromoting Directory token.
scoped_ptr<GaiaAuthFetcher> authenticator_;
- std::string login_;
- std::string remoting_token_;
- std::string talk_token_;
DISALLOW_COPY_AND_ASSIGN(SetupFlowLoginStep);
};
diff --git a/chrome/browser/service/service_process_control.cc b/chrome/browser/service/service_process_control.cc
index ccce948..2873ddc 100644
--- a/chrome/browser/service/service_process_control.cc
+++ b/chrome/browser/service/service_process_control.cc
@@ -96,8 +96,7 @@ class ServiceProcessControl::Launcher
// ServiceProcessControl implementation.
ServiceProcessControl::ServiceProcessControl(Profile* profile)
- : profile_(profile),
- message_handler_(NULL) {
+ : profile_(profile) {
}
ServiceProcessControl::~ServiceProcessControl() {
@@ -279,10 +278,11 @@ void ServiceProcessControl::Observe(NotificationType type,
}
void ServiceProcessControl::OnGoodDay() {
- if (!message_handler_)
- return;
-
- message_handler_->OnGoodDay();
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ for (std::set<MessageHandler*>::iterator it = message_handlers_.begin();
+ it != message_handlers_.end(); ++it) {
+ (*it)->OnGoodDay();
+ }
}
void ServiceProcessControl::OnCloudPrintProxyIsEnabled(bool enabled,
@@ -297,9 +297,9 @@ void ServiceProcessControl::OnCloudPrintProxyIsEnabled(bool enabled,
void ServiceProcessControl::OnRemotingHostInfo(
remoting::ChromotingHostInfo host_info) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- if (remoting_host_status_callback_ != NULL) {
- remoting_host_status_callback_->Run(host_info);
- remoting_host_status_callback_.reset();
+ for (std::set<MessageHandler*>::iterator it = message_handlers_.begin();
+ it != message_handlers_.end(); ++it) {
+ (*it)->OnRemotingHostInfo(host_info);
}
}
@@ -335,11 +335,18 @@ bool ServiceProcessControl::DisableRemotingHost() {
return Send(new ServiceMsg_DisableRemotingHost());
}
-bool ServiceProcessControl::GetRemotingHostStatus(
- GetRemotingHostStatusCallback* status_callback) {
- DCHECK(status_callback);
- remoting_host_status_callback_.reset(status_callback);
+bool ServiceProcessControl::RequestRemotingHostStatus() {
return Send(new ServiceMsg_GetRemotingHostInfo);
}
+void ServiceProcessControl::AddMessageHandler(
+ MessageHandler* message_handler) {
+ message_handlers_.insert(message_handler);
+}
+
+void ServiceProcessControl::RemoveMessageHandler(
+ MessageHandler* message_handler) {
+ message_handlers_.erase(message_handler);
+}
+
DISABLE_RUNNABLE_METHOD_REFCOUNT(ServiceProcessControl);
diff --git a/chrome/browser/service/service_process_control.h b/chrome/browser/service/service_process_control.h
index 9162736..78c3141 100644
--- a/chrome/browser/service/service_process_control.h
+++ b/chrome/browser/service/service_process_control.h
@@ -6,6 +6,7 @@
#define CHROME_BROWSER_SERVICE_SERVICE_PROCESS_CONTROL_H_
#include <queue>
+#include <set>
#include <string>
#include <vector>
@@ -41,15 +42,20 @@ class ServiceProcessControl : public IPC::Channel::Sender,
typedef IDMap<ServiceProcessControl>::iterator iterator;
typedef std::queue<IPC::Message> MessageQueue;
typedef Callback1<const remoting::ChromotingHostInfo&>::Type
- GetRemotingHostStatusCallback;
+ RemotingHostStatusHandler;
// An interface for handling messages received from the service process.
class MessageHandler {
public:
virtual ~MessageHandler() {}
+
// This is a test signal sent from the service process. This can be used
// the healthiness of the service.
virtual void OnGoodDay() = 0;
+
+ // Called when we receive reply to remoting host status request.
+ virtual void OnRemotingHostInfo(
+ const remoting::ChromotingHostInfo& host_info) = 0;
};
// Construct a ServiceProcessControl with |profile|..
@@ -103,29 +109,30 @@ class ServiceProcessControl : public IPC::Channel::Sender,
// Return true if the message was sent.
bool Shutdown();
- // Send a message to the service process to request a response
- // containing the enablement status of the cloud print proxy and the
- // registered email address. The callback gets the information when
- // received.
+ // Send request for cloud print proxy status and the registered
+ // email address. The callback gets the information when received.
bool GetCloudPrintProxyStatus(
Callback2<bool, std::string>::Type* cloud_print_status_callback);
// Send a message to enable the remoting service in the service process.
// Return true if the message was sent.
bool SetRemotingHostCredentials(const std::string& user,
- const std::string& auth_token);
+ const std::string& auth_token);
bool EnableRemotingHost();
bool DisableRemotingHost();
- bool GetRemotingHostStatus(
- GetRemotingHostStatusCallback* status_callback);
+ // Send request for current status of the remoting service.
+ bool RequestRemotingHostStatus();
+
+ // Add a message handler for receiving messages from the service
+ // process.
+ void AddMessageHandler(MessageHandler* message_handler);
- // Set the message handler for receiving messages from the service process.
- // TODO(hclam): Allow more than 1 handler.
- void SetMessageHandler(MessageHandler* message_handler) {
- message_handler_ = message_handler;
- }
+ // Remove a message handler from the list of message handlers. Must
+ // not be called from a message handler (i.e. while a message is
+ // being processed).
+ void RemoveMessageHandler(MessageHandler* message_handler);
private:
class Launcher;
@@ -161,10 +168,9 @@ class ServiceProcessControl : public IPC::Channel::Sender,
// Callback that gets invoked when a status message is received from
// the cloud print proxy.
scoped_ptr<Callback2<bool, std::string>::Type> cloud_print_status_callback_;
- scoped_ptr<GetRemotingHostStatusCallback> remoting_host_status_callback_;
// Handler for messages from service process.
- MessageHandler* message_handler_;
+ std::set<MessageHandler*> message_handlers_;
NotificationRegistrar registrar_;
};
diff --git a/chrome/browser/service/service_process_control_browsertest.cc b/chrome/browser/service/service_process_control_browsertest.cc
index 8cf596c..519c005 100644
--- a/chrome/browser/service/service_process_control_browsertest.cc
+++ b/chrome/browser/service/service_process_control_browsertest.cc
@@ -72,7 +72,7 @@ class ServiceProcessControlBrowserTest
service_pid,
base::kProcessAccessWaitForTermination,
&service_process_handle_));
- process()->SetMessageHandler(this);
+ process()->AddMessageHandler(this);
// Quit the current message. Post a QuitTask instead of just calling Quit()
// because this can get invoked in the context of a Launch() call and we
// may not be in Run() yet.
@@ -90,6 +90,10 @@ class ServiceProcessControlBrowserTest
MessageLoop::current()->Quit();
}
+ virtual void OnRemotingHostInfo(
+ const remoting::ChromotingHostInfo& host_info) {
+ }
+
ServiceProcessControl* process() { return process_; }
private:
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc
index aa3b271..af397de 100644
--- a/chrome/browser/ui/browser.cc
+++ b/chrome/browser/ui/browser.cc
@@ -112,7 +112,7 @@
#include "webkit/glue/window_open_disposition.h"
#if defined(ENABLE_REMOTING)
-#include "chrome/browser/remoting/remoting_setup_flow.h"
+#include "chrome/browser/remoting/setup_flow.h"
#endif
#if defined(OS_WIN)
@@ -1853,7 +1853,7 @@ void Browser::OpenSyncMyBookmarksDialog() {
#if defined(ENABLE_REMOTING)
void Browser::OpenRemotingSetupDialog() {
- RemotingSetupFlow::OpenDialog(profile_);
+ remoting::SetupFlow::OpenSetupDialog(profile_);
}
#endif