summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--remoting/host/setup/daemon_controller.h2
-rw-r--r--remoting/host/setup/native_messaging_host.cc46
-rw-r--r--remoting/host/setup/native_messaging_host_unittest.cc20
-rw-r--r--remoting/webapp/host_native_messaging.js24
4 files changed, 59 insertions, 33 deletions
diff --git a/remoting/host/setup/daemon_controller.h b/remoting/host/setup/daemon_controller.h
index 4fda7c9..0faf7a5 100644
--- a/remoting/host/setup/daemon_controller.h
+++ b/remoting/host/setup/daemon_controller.h
@@ -18,7 +18,7 @@ namespace remoting {
class DaemonController {
public:
- // Note that these enumeration values are duplicated in daemon_plugin.js and
+ // Note that these enumeration values are duplicated in host_controller.js and
// must be kept in sync.
enum State {
// Placeholder state for platforms on which the daemon process is not
diff --git a/remoting/host/setup/native_messaging_host.cc b/remoting/host/setup/native_messaging_host.cc
index 2d2bd9ed..6e34269 100644
--- a/remoting/host/setup/native_messaging_host.cc
+++ b/remoting/host/setup/native_messaging_host.cc
@@ -241,10 +241,33 @@ bool NativeMessagingHost::ProcessStopDaemon(
bool NativeMessagingHost::ProcessGetDaemonState(
const base::DictionaryValue& message,
scoped_ptr<base::DictionaryValue> response) {
- // TODO(lambroslambrou): Send the state as a string instead of an integer,
- // and update the web-app accordingly.
DaemonController::State state = daemon_controller_->GetState();
- response->SetInteger("state", state);
+ switch (state) {
+ case DaemonController::STATE_NOT_IMPLEMENTED:
+ response->SetString("state", "NOT_IMPLEMENTED");
+ break;
+ case DaemonController::STATE_NOT_INSTALLED:
+ response->SetString("state", "NOT_INSTALLED");
+ break;
+ case DaemonController::STATE_INSTALLING:
+ response->SetString("state", "INSTALLING");
+ break;
+ case DaemonController::STATE_STOPPED:
+ response->SetString("state", "STOPPED");
+ break;
+ case DaemonController::STATE_STARTING:
+ response->SetString("state", "STARTING");
+ break;
+ case DaemonController::STATE_STARTED:
+ response->SetString("state", "STARTED");
+ break;
+ case DaemonController::STATE_STOPPING:
+ response->SetString("state", "STOPPING");
+ break;
+ case DaemonController::STATE_UNKNOWN:
+ response->SetString("state", "UNKNOWN");
+ break;
+ }
SendResponse(response.Pass());
return true;
}
@@ -283,9 +306,20 @@ void NativeMessagingHost::SendUsageStatsConsentResponse(
void NativeMessagingHost::SendAsyncResult(
scoped_ptr<base::DictionaryValue> response,
DaemonController::AsyncResult result) {
- // TODO(lambroslambrou): Send the result as a string instead of an integer,
- // and update the web-app accordingly. See http://crbug.com/232135.
- response->SetInteger("result", result);
+ switch (result) {
+ case DaemonController::RESULT_OK:
+ response->SetString("result", "OK");
+ break;
+ case DaemonController::RESULT_FAILED:
+ response->SetString("result", "FAILED");
+ break;
+ case DaemonController::RESULT_CANCELLED:
+ response->SetString("result", "CANCELLED");
+ break;
+ case DaemonController::RESULT_FAILED_DIRECTORY:
+ response->SetString("result", "FAILED_DIRECTORY");
+ break;
+ }
SendResponse(response.Pass());
}
diff --git a/remoting/host/setup/native_messaging_host_unittest.cc b/remoting/host/setup/native_messaging_host_unittest.cc
index f71fa3c..ab68d3b 100644
--- a/remoting/host/setup/native_messaging_host_unittest.cc
+++ b/remoting/host/setup/native_messaging_host_unittest.cc
@@ -85,9 +85,8 @@ void VerifyStopDaemonResponse(const base::DictionaryValue* response) {
std::string value;
EXPECT_TRUE(response->GetString("type", &value));
EXPECT_EQ("stopDaemonResponse", value);
- int result;
- EXPECT_TRUE(response->GetInteger("result", &result));
- EXPECT_EQ(0, result);
+ EXPECT_TRUE(response->GetString("result", &value));
+ EXPECT_EQ("OK", value);
}
void VerifyGetDaemonStateResponse(const base::DictionaryValue* response) {
@@ -95,9 +94,8 @@ void VerifyGetDaemonStateResponse(const base::DictionaryValue* response) {
std::string value;
EXPECT_TRUE(response->GetString("type", &value));
EXPECT_EQ("getDaemonStateResponse", value);
- int result;
- EXPECT_TRUE(response->GetInteger("state", &result));
- EXPECT_EQ(4, result);
+ EXPECT_TRUE(response->GetString("state", &value));
+ EXPECT_EQ("STARTED", value);
}
void VerifyUpdateDaemonConfigResponse(const base::DictionaryValue* response) {
@@ -105,9 +103,8 @@ void VerifyUpdateDaemonConfigResponse(const base::DictionaryValue* response) {
std::string value;
EXPECT_TRUE(response->GetString("type", &value));
EXPECT_EQ("updateDaemonConfigResponse", value);
- int result;
- EXPECT_TRUE(response->GetInteger("result", &result));
- EXPECT_EQ(0, result);
+ EXPECT_TRUE(response->GetString("result", &value));
+ EXPECT_EQ("OK", value);
}
void VerifyStartDaemonResponse(const base::DictionaryValue* response) {
@@ -115,9 +112,8 @@ void VerifyStartDaemonResponse(const base::DictionaryValue* response) {
std::string value;
EXPECT_TRUE(response->GetString("type", &value));
EXPECT_EQ("startDaemonResponse", value);
- int result;
- EXPECT_TRUE(response->GetInteger("result", &result));
- EXPECT_EQ(0, result);
+ EXPECT_TRUE(response->GetString("result", &value));
+ EXPECT_EQ("OK", value);
}
} // namespace
diff --git a/remoting/webapp/host_native_messaging.js b/remoting/webapp/host_native_messaging.js
index 51180b1..5a35617 100644
--- a/remoting/webapp/host_native_messaging.js
+++ b/remoting/webapp/host_native_messaging.js
@@ -109,16 +109,14 @@ function checkType_(name, object, type) {
* @return {remoting.HostController.AsyncResult?} Converted result.
*/
function asAsyncResult_(result) {
- if (!checkType_('result', result, 'number')) {
+ if (!checkType_('result', result, 'string')) {
return null;
}
- for (var i in remoting.HostController.AsyncResult) {
- if (remoting.HostController.AsyncResult[i] == result) {
- return remoting.HostController.AsyncResult[i];
- }
+ if (!remoting.HostController.AsyncResult.hasOwnProperty(result)) {
+ console.error('NativeMessaging: unexpected result code: ', result);
+ return null;
}
- console.error('NativeMessaging: unexpected result code: ', result);
- return null;
+ return remoting.HostController.AsyncResult[result];
}
/**
@@ -129,16 +127,14 @@ function asAsyncResult_(result) {
* @return {remoting.HostController.State?} Converted result.
*/
function asHostState_(result) {
- if (!checkType_('result', result, 'number')) {
+ if (!checkType_('result', result, 'string')) {
return null;
}
- for (var i in remoting.HostController.State) {
- if (remoting.HostController.State[i] == result) {
- return remoting.HostController.State[i];
- }
+ if (!remoting.HostController.State.hasOwnProperty(result)) {
+ console.error('NativeMessaging: unexpected result code: ', result);
+ return null;
}
- console.error('NativeMessaging: unexpected result code: ', result);
- return null;
+ return remoting.HostController.State[result];
}
/**