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

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

Issue 103693006: Me2me Native Messaging host on Windows: restructure NativeMessagingHost and NativeMessagingChannel.… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years 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 a025e3f3ab58dd53b5dfa3830134eb9d8150c6dd..5701ce37f3e84483a6f35055e45968ec87b04f41 100644
--- a/remoting/host/it2me/it2me_native_messaging_host.cc
+++ b/remoting/host/it2me/it2me_native_messaging_host.cc
@@ -9,6 +9,7 @@
#include "base/basictypes.h"
#include "base/bind.h"
#include "base/callback.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"
@@ -61,15 +62,31 @@ It2MeNativeMessagingHost::It2MeNativeMessagingHost(
directory_bot_jid_ = service_urls->directory_bot_jid();
}
-It2MeNativeMessagingHost::~It2MeNativeMessagingHost() {}
+It2MeNativeMessagingHost::~It2MeNativeMessagingHost() {
+ DCHECK(task_runner()->BelongsToCurrentThread());
+}
+
+void It2MeNativeMessagingHost::Start(
+ base::PlatformFile input,
+ base::PlatformFile output,
+ const base::Closure& quit_closure) {
+ DCHECK(task_runner()->BelongsToCurrentThread());
+
+ // Set up the native messaging channel.
+ channel_.reset(
+ new NativeMessagingChannel(
+ base::Bind(&It2MeNativeMessagingHost::ProcessMessage, weak_ptr_),
+ input,
+ output));
-void It2MeNativeMessagingHost::SetSendMessageCallback(
- const SendMessageCallback& send_message) {
- send_message_ = send_message;
+ quit_closure_ = quit_closure;
+ channel_->Start(base::Bind(&It2MeNativeMessagingHost::ShutDown, weak_ptr_));
}
void It2MeNativeMessagingHost::ProcessMessage(
scoped_ptr<base::DictionaryValue> message) {
+ DCHECK(task_runner()->BelongsToCurrentThread());
+
scoped_ptr<base::DictionaryValue> response(new base::DictionaryValue());
// If the client supplies an ID, it will expect it in the response. This
@@ -100,18 +117,22 @@ void It2MeNativeMessagingHost::ProcessMessage(
void It2MeNativeMessagingHost::ProcessHello(
const base::DictionaryValue& message,
scoped_ptr<base::DictionaryValue> response) {
+ DCHECK(task_runner()->BelongsToCurrentThread());
+
response->SetString("version", STRINGIZE(VERSION));
// This list will be populated when new features are added.
scoped_ptr<base::ListValue> supported_features_list(new base::ListValue());
response->Set("supportedFeatures", supported_features_list.release());
- send_message_.Run(response.Pass());
+ channel_->SendMessage(response.Pass());
}
void It2MeNativeMessagingHost::ProcessConnect(
const base::DictionaryValue& message,
scoped_ptr<base::DictionaryValue> response) {
+ DCHECK(task_runner()->BelongsToCurrentThread());
+
if (it2me_host_.get()) {
SendErrorAndExit(response.Pass(),
"Connect can be called only when disconnected.");
@@ -178,30 +199,34 @@ void It2MeNativeMessagingHost::ProcessConnect(
directory_bot_jid_);
it2me_host_->Connect();
- send_message_.Run(response.Pass());
+ channel_->SendMessage(response.Pass());
}
void It2MeNativeMessagingHost::ProcessDisconnect(
const base::DictionaryValue& message,
scoped_ptr<base::DictionaryValue> response) {
+ DCHECK(task_runner()->BelongsToCurrentThread());
+
if (it2me_host_.get()) {
it2me_host_->Disconnect();
it2me_host_ = NULL;
}
- send_message_.Run(response.Pass());
+ channel_->SendMessage(response.Pass());
}
void It2MeNativeMessagingHost::SendErrorAndExit(
scoped_ptr<base::DictionaryValue> response,
const std::string& description) {
+ DCHECK(task_runner()->BelongsToCurrentThread());
+
LOG(ERROR) << description;
response->SetString("type", "error");
response->SetString("description", description);
- send_message_.Run(response.Pass());
+ channel_->SendMessage(response.Pass());
// Trigger a host shutdown by sending a NULL message.
- send_message_.Run(scoped_ptr<base::DictionaryValue>());
+ channel_->SendMessage(scoped_ptr<base::DictionaryValue>());
}
void It2MeNativeMessagingHost::OnStateChanged(It2MeHostState state) {
@@ -234,7 +259,7 @@ void It2MeNativeMessagingHost::OnStateChanged(It2MeHostState state) {
;
}
- send_message_.Run(message.Pass());
+ channel_->SendMessage(message.Pass());
}
void It2MeNativeMessagingHost::OnNatPolicyChanged(bool nat_traversal_enabled) {
@@ -244,7 +269,7 @@ void It2MeNativeMessagingHost::OnNatPolicyChanged(bool nat_traversal_enabled) {
message->SetString("type", "natPolicyChanged");
message->SetBoolean("natTraversalEnabled", nat_traversal_enabled);
- send_message_.Run(message.Pass());
+ channel_->SendMessage(message.Pass());
}
// Stores the Access Code for the web-app to query.
@@ -266,11 +291,15 @@ void It2MeNativeMessagingHost::OnClientAuthenticated(
}
void It2MeNativeMessagingHost::ShutDown() {
Sergey Ulanov 2013/12/12 19:10:28 Do you really need this method? I think you can ju
weitao 2013/12/12 23:33:48 Done.
+ DCHECK(task_runner()->BelongsToCurrentThread());
+
if (it2me_host_.get()) {
it2me_host_->Disconnect();
it2me_host_ = NULL;
}
- host_context_.reset();
+
+ if (!quit_closure_.is_null())
+ base::ResetAndReturn(&quit_closure_).Run();
}
scoped_refptr<AutoThreadTaskRunner> It2MeNativeMessagingHost::task_runner() {

Powered by Google App Engine
This is Rietveld 408576698