Chromium Code Reviews| 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 6fb65df5ec7548a40489fdd78c90cec94bd21009..fba1dacef9c86a1019bb25f67632b49c7fe32114 100644 |
| --- a/remoting/host/it2me/it2me_native_messaging_host.cc |
| +++ b/remoting/host/it2me/it2me_native_messaging_host.cc |
| @@ -9,9 +9,8 @@ |
| #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/json/json_reader.h" |
| +#include "base/json/json_writer.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "base/strings/stringize_macros.h" |
| #include "base/threading/thread.h" |
| @@ -42,10 +41,8 @@ const remoting::protocol::NameMapElement<It2MeHostState> kIt2MeHostStates[] = { |
| It2MeNativeMessagingHost::It2MeNativeMessagingHost( |
| scoped_refptr<AutoThreadTaskRunner> task_runner, |
| - scoped_ptr<extensions::NativeMessagingChannel> channel, |
| scoped_ptr<It2MeHostFactory> factory) |
| - : channel_(channel.Pass()), |
| - factory_(factory.Pass()), |
| + : factory_(factory.Pass()), |
| weak_factory_(this) { |
| weak_ptr_ = weak_factory_.GetWeakPtr(); |
| @@ -75,16 +72,8 @@ It2MeNativeMessagingHost::~It2MeNativeMessagingHost() { |
| } |
| } |
| -void It2MeNativeMessagingHost::Start(const base::Closure& quit_closure) { |
| - DCHECK(task_runner()->BelongsToCurrentThread()); |
| - DCHECK(!quit_closure.is_null()); |
| - |
| - quit_closure_ = quit_closure; |
| - |
| - channel_->Start(this); |
| -} |
| - |
| -void It2MeNativeMessagingHost::OnMessage(scoped_ptr<base::Value> message) { |
| +void It2MeNativeMessagingHost::OnMessage(const std::string& json) { |
| + scoped_ptr<base::Value> message(base::JSONReader::Read(json)); |
| DCHECK(task_runner()->BelongsToCurrentThread()); |
| scoped_ptr<base::DictionaryValue> message_dict( |
| @@ -116,9 +105,15 @@ void It2MeNativeMessagingHost::OnMessage(scoped_ptr<base::Value> message) { |
| } |
| } |
| -void It2MeNativeMessagingHost::OnDisconnect() { |
| - if (!quit_closure_.is_null()) |
| - base::ResetAndReturn(&quit_closure_).Run(); |
| +void It2MeNativeMessagingHost::set_client(Client* client) { |
| + client_ = client; |
|
Sergey Ulanov
2014/10/01 23:23:59
DCHECK that we are on the right thread.
kelvinp
2014/10/02 03:12:17
Done.
|
| +} |
| + |
| +void It2MeNativeMessagingHost::SendMessageToClient( |
| + scoped_ptr<base::DictionaryValue> message) const { |
| + std::string message_json; |
|
Sergey Ulanov
2014/10/01 23:23:59
same here
kelvinp
2014/10/02 03:12:17
Done.
|
| + base::JSONWriter::Write(message.get(), &message_json); |
| + client_->PostMessageFromNativeHost(message_json); |
| } |
| void It2MeNativeMessagingHost::ProcessHello( |
| @@ -132,7 +127,7 @@ void It2MeNativeMessagingHost::ProcessHello( |
| scoped_ptr<base::ListValue> supported_features_list(new base::ListValue()); |
| response->Set("supportedFeatures", supported_features_list.release()); |
| - channel_->SendMessage(response.PassAs<base::Value>()); |
| + SendMessageToClient(response.Pass()); |
| } |
| void It2MeNativeMessagingHost::ProcessConnect( |
| @@ -206,7 +201,7 @@ void It2MeNativeMessagingHost::ProcessConnect( |
| directory_bot_jid_); |
| it2me_host_->Connect(); |
| - channel_->SendMessage(response.PassAs<base::Value>()); |
| + SendMessageToClient(response.Pass()); |
| } |
| void It2MeNativeMessagingHost::ProcessDisconnect( |
| @@ -218,7 +213,7 @@ void It2MeNativeMessagingHost::ProcessDisconnect( |
| it2me_host_->Disconnect(); |
| it2me_host_ = NULL; |
| } |
| - channel_->SendMessage(response.PassAs<base::Value>()); |
| + SendMessageToClient(response.Pass()); |
| } |
| void It2MeNativeMessagingHost::SendErrorAndExit( |
| @@ -230,10 +225,10 @@ void It2MeNativeMessagingHost::SendErrorAndExit( |
| response->SetString("type", "error"); |
| response->SetString("description", description); |
| - channel_->SendMessage(response.PassAs<base::Value>()); |
| + SendMessageToClient(response.Pass()); |
| // Trigger a host shutdown by sending a NULL message. |
|
Sergey Ulanov
2014/10/01 23:23:59
update the comment
kelvinp
2014/10/02 03:12:17
Done.
|
| - channel_->SendMessage(scoped_ptr<base::Value>()); |
| + client_->CloseChannel(""); |
|
Sergey Ulanov
2014/10/01 23:23:59
Use std::string() instead of "" for empty string.
kelvinp
2014/10/02 03:12:17
Done.
|
| } |
| void It2MeNativeMessagingHost::OnStateChanged(It2MeHostState state) { |
| @@ -266,7 +261,7 @@ void It2MeNativeMessagingHost::OnStateChanged(It2MeHostState state) { |
| ; |
| } |
| - channel_->SendMessage(message.PassAs<base::Value>()); |
| + SendMessageToClient(message.Pass()); |
| } |
| void It2MeNativeMessagingHost::OnNatPolicyChanged(bool nat_traversal_enabled) { |
| @@ -276,7 +271,7 @@ void It2MeNativeMessagingHost::OnNatPolicyChanged(bool nat_traversal_enabled) { |
| message->SetString("type", "natPolicyChanged"); |
| message->SetBoolean("natTraversalEnabled", nat_traversal_enabled); |
| - channel_->SendMessage(message.PassAs<base::Value>()); |
| + SendMessageToClient(message.Pass()); |
| } |
| // Stores the Access Code for the web-app to query. |
| @@ -297,7 +292,7 @@ void It2MeNativeMessagingHost::OnClientAuthenticated( |
| client_username_ = client_username; |
| } |
| -scoped_refptr<AutoThreadTaskRunner> |
| +scoped_refptr<base::SingleThreadTaskRunner> |
| It2MeNativeMessagingHost::task_runner() const { |
| return host_context_->ui_task_runner(); |
| } |