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

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

Issue 637463002: Revert "Remote Assistance on Chrome OS Part III - NativeMessageHost" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 24ddc1b8dc38c72475555f4c0dbc00ea915aa62d..8d0d1313b404761d0feed7f62068256329004ae9 100644
--- a/remoting/host/it2me/it2me_native_messaging_host.cc
+++ b/remoting/host/it2me/it2me_native_messaging_host.cc
@@ -9,8 +9,9 @@
#include "base/basictypes.h"
#include "base/bind.h"
#include "base/callback.h"
-#include "base/json/json_reader.h"
-#include "base/json/json_writer.h"
+#include "base/callback_helpers.h"
+#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringize_macros.h"
#include "base/threading/thread.h"
@@ -41,8 +42,9 @@ const remoting::protocol::NameMapElement<It2MeHostState> kIt2MeHostStates[] = {
It2MeNativeMessagingHost::It2MeNativeMessagingHost(
scoped_refptr<AutoThreadTaskRunner> task_runner,
+ scoped_ptr<extensions::NativeMessagingChannel> channel,
scoped_ptr<It2MeHostFactory> factory)
- : client_(NULL),
+ : channel_(channel.Pass()),
factory_(factory.Pass()),
weak_factory_(this) {
weak_ptr_ = weak_factory_.GetWeakPtr();
@@ -73,19 +75,27 @@ It2MeNativeMessagingHost::~It2MeNativeMessagingHost() {
}
}
-void It2MeNativeMessagingHost::OnMessage(const std::string& message) {
+void It2MeNativeMessagingHost::Start(const base::Closure& quit_closure) {
DCHECK(task_runner()->BelongsToCurrentThread());
+ DCHECK(!quit_closure.is_null());
- scoped_ptr<base::DictionaryValue> response(new base::DictionaryValue());
- scoped_ptr<base::Value> message_value(base::JSONReader::Read(message));
- if (!message_value->IsType(base::Value::TYPE_DICTIONARY)) {
+ quit_closure_ = quit_closure;
+
+ channel_->Start(this);
+}
+
+void It2MeNativeMessagingHost::OnMessage(scoped_ptr<base::Value> message) {
+ DCHECK(task_runner()->BelongsToCurrentThread());
+
+ if (!message->IsType(base::Value::TYPE_DICTIONARY)) {
LOG(ERROR) << "Received a message that's not a dictionary.";
- client_->CloseChannel(std::string());
+ channel_->SendMessage(nullptr);
return;
}
scoped_ptr<base::DictionaryValue> message_dict(
- static_cast<base::DictionaryValue*>(message_value.release()));
+ 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.
@@ -112,17 +122,9 @@ void It2MeNativeMessagingHost::OnMessage(const std::string& message) {
}
}
-void It2MeNativeMessagingHost::Start(Client* client) {
- DCHECK(task_runner()->BelongsToCurrentThread());
- client_ = client;
-}
-
-void It2MeNativeMessagingHost::SendMessageToClient(
- scoped_ptr<base::DictionaryValue> message) const {
- DCHECK(task_runner()->BelongsToCurrentThread());
- std::string message_json;
- base::JSONWriter::Write(message.get(), &message_json);
- client_->PostMessageFromNativeHost(message_json);
+void It2MeNativeMessagingHost::OnDisconnect() {
+ if (!quit_closure_.is_null())
+ base::ResetAndReturn(&quit_closure_).Run();
}
void It2MeNativeMessagingHost::ProcessHello(
@@ -136,7 +138,7 @@ void It2MeNativeMessagingHost::ProcessHello(
scoped_ptr<base::ListValue> supported_features_list(new base::ListValue());
response->Set("supportedFeatures", supported_features_list.release());
- SendMessageToClient(response.Pass());
+ channel_->SendMessage(response.Pass());
}
void It2MeNativeMessagingHost::ProcessConnect(
@@ -210,7 +212,7 @@ void It2MeNativeMessagingHost::ProcessConnect(
directory_bot_jid_);
it2me_host_->Connect();
- SendMessageToClient(response.Pass());
+ channel_->SendMessage(response.Pass());
}
void It2MeNativeMessagingHost::ProcessDisconnect(
@@ -222,7 +224,7 @@ void It2MeNativeMessagingHost::ProcessDisconnect(
it2me_host_->Disconnect();
it2me_host_ = NULL;
}
- SendMessageToClient(response.Pass());
+ channel_->SendMessage(response.Pass());
}
void It2MeNativeMessagingHost::SendErrorAndExit(
@@ -234,10 +236,10 @@ void It2MeNativeMessagingHost::SendErrorAndExit(
response->SetString("type", "error");
response->SetString("description", description);
- SendMessageToClient(response.Pass());
+ channel_->SendMessage(response.Pass());
- // Trigger a host shutdown by sending an empty message.
- client_->CloseChannel(std::string());
+ // Trigger a host shutdown by sending a NULL message.
+ channel_->SendMessage(nullptr);
}
void It2MeNativeMessagingHost::OnStateChanged(It2MeHostState state) {
@@ -270,7 +272,7 @@ void It2MeNativeMessagingHost::OnStateChanged(It2MeHostState state) {
;
}
- SendMessageToClient(message.Pass());
+ channel_->SendMessage(message.Pass());
}
void It2MeNativeMessagingHost::OnNatPolicyChanged(bool nat_traversal_enabled) {
@@ -280,7 +282,7 @@ void It2MeNativeMessagingHost::OnNatPolicyChanged(bool nat_traversal_enabled) {
message->SetString("type", "natPolicyChanged");
message->SetBoolean("natTraversalEnabled", nat_traversal_enabled);
- SendMessageToClient(message.Pass());
+ channel_->SendMessage(message.Pass());
}
// Stores the Access Code for the web-app to query.
@@ -301,7 +303,7 @@ void It2MeNativeMessagingHost::OnClientAuthenticated(
client_username_ = client_username;
}
-scoped_refptr<base::SingleThreadTaskRunner>
+scoped_refptr<AutoThreadTaskRunner>
It2MeNativeMessagingHost::task_runner() const {
return host_context_->ui_task_runner();
}
« 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