Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(627)

Unified Diff: remoting/host/it2me/it2me_native_messaging_host.cc

Issue 558403002: Remote Assistance on Chrome OS Part II - Native Messaging renaming (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase on ToT Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/host/it2me/it2me_native_messaging_host.cc
diff --git a/remoting/host/it2me/it2me_native_messaging_host.cc b/remoting/host/it2me/it2me_native_messaging_host.cc
index 11d447cc884c89654285459c2aa2cf1b81d883ed..6fb65df5ec7548a40489fdd78c90cec94bd21009 100644
--- a/remoting/host/it2me/it2me_native_messaging_host.cc
+++ b/remoting/host/it2me/it2me_native_messaging_host.cc
@@ -42,7 +42,7 @@ const remoting::protocol::NameMapElement<It2MeHostState> kIt2MeHostStates[] = {
It2MeNativeMessagingHost::It2MeNativeMessagingHost(
scoped_refptr<AutoThreadTaskRunner> task_runner,
- scoped_ptr<NativeMessagingChannel> channel,
+ scoped_ptr<extensions::NativeMessagingChannel> channel,
scoped_ptr<It2MeHostFactory> factory)
: channel_(channel.Pass()),
factory_(factory.Pass()),
@@ -75,28 +75,30 @@ It2MeNativeMessagingHost::~It2MeNativeMessagingHost() {
}
}
-void It2MeNativeMessagingHost::Start(const base::Closure& quit_closure) const {
+void It2MeNativeMessagingHost::Start(const base::Closure& quit_closure) {
DCHECK(task_runner()->BelongsToCurrentThread());
+ DCHECK(!quit_closure.is_null());
- channel_->Start(
- base::Bind(&It2MeNativeMessagingHost::ProcessMessage, weak_ptr_),
- quit_closure);
+ quit_closure_ = quit_closure;
+
+ channel_->Start(this);
}
-void It2MeNativeMessagingHost::ProcessMessage(
- scoped_ptr<base::DictionaryValue> message) {
+void It2MeNativeMessagingHost::OnMessage(scoped_ptr<base::Value> message) {
DCHECK(task_runner()->BelongsToCurrentThread());
+ scoped_ptr<base::DictionaryValue> message_dict(
+ static_cast<base::DictionaryValue*>(message.release()));
scoped_ptr<base::DictionaryValue> response(new base::DictionaryValue());
// If the client supplies an ID, it will expect it in the response. This
// might be a string or a number, so cope with both.
const base::Value* id;
- if (message->Get("id", &id))
+ if (message_dict->Get("id", &id))
response->Set("id", id->DeepCopy());
std::string type;
- if (!message->GetString("type", &type)) {
+ if (!message_dict->GetString("type", &type)) {
SendErrorAndExit(response.Pass(), "'type' not found in request.");
return;
}
@@ -104,16 +106,21 @@ void It2MeNativeMessagingHost::ProcessMessage(
response->SetString("type", type + "Response");
if (type == "hello") {
- ProcessHello(*message, response.Pass());
+ ProcessHello(*message_dict, response.Pass());
} else if (type == "connect") {
- ProcessConnect(*message, response.Pass());
+ ProcessConnect(*message_dict, response.Pass());
} else if (type == "disconnect") {
- ProcessDisconnect(*message, response.Pass());
+ ProcessDisconnect(*message_dict, response.Pass());
} else {
SendErrorAndExit(response.Pass(), "Unsupported request type: " + type);
}
}
+void It2MeNativeMessagingHost::OnDisconnect() {
+ if (!quit_closure_.is_null())
+ base::ResetAndReturn(&quit_closure_).Run();
+}
+
void It2MeNativeMessagingHost::ProcessHello(
const base::DictionaryValue& message,
scoped_ptr<base::DictionaryValue> response) const {
@@ -125,7 +132,7 @@ void It2MeNativeMessagingHost::ProcessHello(
scoped_ptr<base::ListValue> supported_features_list(new base::ListValue());
response->Set("supportedFeatures", supported_features_list.release());
- channel_->SendMessage(response.Pass());
+ channel_->SendMessage(response.PassAs<base::Value>());
}
void It2MeNativeMessagingHost::ProcessConnect(
@@ -199,7 +206,7 @@ void It2MeNativeMessagingHost::ProcessConnect(
directory_bot_jid_);
it2me_host_->Connect();
- channel_->SendMessage(response.Pass());
+ channel_->SendMessage(response.PassAs<base::Value>());
}
void It2MeNativeMessagingHost::ProcessDisconnect(
@@ -211,7 +218,7 @@ void It2MeNativeMessagingHost::ProcessDisconnect(
it2me_host_->Disconnect();
it2me_host_ = NULL;
}
- channel_->SendMessage(response.Pass());
+ channel_->SendMessage(response.PassAs<base::Value>());
}
void It2MeNativeMessagingHost::SendErrorAndExit(
@@ -223,10 +230,10 @@ void It2MeNativeMessagingHost::SendErrorAndExit(
response->SetString("type", "error");
response->SetString("description", description);
- channel_->SendMessage(response.Pass());
+ channel_->SendMessage(response.PassAs<base::Value>());
// Trigger a host shutdown by sending a NULL message.
- channel_->SendMessage(scoped_ptr<base::DictionaryValue>());
+ channel_->SendMessage(scoped_ptr<base::Value>());
}
void It2MeNativeMessagingHost::OnStateChanged(It2MeHostState state) {
@@ -259,7 +266,7 @@ void It2MeNativeMessagingHost::OnStateChanged(It2MeHostState state) {
;
}
- channel_->SendMessage(message.Pass());
+ channel_->SendMessage(message.PassAs<base::Value>());
}
void It2MeNativeMessagingHost::OnNatPolicyChanged(bool nat_traversal_enabled) {
@@ -269,7 +276,7 @@ void It2MeNativeMessagingHost::OnNatPolicyChanged(bool nat_traversal_enabled) {
message->SetString("type", "natPolicyChanged");
message->SetBoolean("natTraversalEnabled", nat_traversal_enabled);
- channel_->SendMessage(message.Pass());
+ channel_->SendMessage(message.PassAs<base::Value>());
}
// Stores the Access Code for the web-app to query.
« no previous file with comments | « remoting/host/it2me/it2me_native_messaging_host.h ('k') | remoting/host/it2me/it2me_native_messaging_host_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698