summaryrefslogtreecommitdiffstats
path: root/remoting/host/it2me
diff options
context:
space:
mode:
authorjamiewalch <jamiewalch@chromium.org>2015-08-20 17:11:22 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-21 00:12:28 +0000
commita1826488343b1923906c2b8bbd194eef51cfda26 (patch)
tree9948ec344aeb6aff0c41977177440628df1b5f6d /remoting/host/it2me
parent8857dc5adb00f9d32bc2f390040a94a39550d1ee (diff)
downloadchromium_src-a1826488343b1923906c2b8bbd194eef51cfda26.zip
chromium_src-a1826488343b1923906c2b8bbd194eef51cfda26.tar.gz
chromium_src-a1826488343b1923906c2b8bbd194eef51cfda26.tar.bz2
Pass error messages from native messaging to web-app.
This replaces a single onDone(result) callback with a pair (onDone(), onError(message, location)). The error message and location are communicated via native messaging as additional parameters, which should ensure backwards-compatibility in both directions. BUG=517176 Review URL: https://codereview.chromium.org/1272833002 Cr-Commit-Position: refs/heads/master@{#344622}
Diffstat (limited to 'remoting/host/it2me')
-rw-r--r--remoting/host/it2me/it2me_native_messaging_host.cc8
-rw-r--r--remoting/host/it2me/it2me_native_messaging_host.h12
-rw-r--r--remoting/host/it2me/it2me_native_messaging_host_unittest.cc53
3 files changed, 49 insertions, 24 deletions
diff --git a/remoting/host/it2me/it2me_native_messaging_host.cc b/remoting/host/it2me/it2me_native_messaging_host.cc
index 1bf175e..65c20c5 100644
--- a/remoting/host/it2me/it2me_native_messaging_host.cc
+++ b/remoting/host/it2me/it2me_native_messaging_host.cc
@@ -115,10 +115,16 @@ void It2MeNativeMessagingHost::OnMessage(const std::string& message) {
void It2MeNativeMessagingHost::Start(Client* client) {
DCHECK(task_runner()->BelongsToCurrentThread());
client_ = client;
+#if !defined(OS_CHROMEOS)
+ log_message_handler_.reset(
+ new LogMessageHandler(
+ base::Bind(&It2MeNativeMessagingHost::SendMessageToClient,
+ base::Unretained(this))));
+#endif // !defined(OS_CHROMEOS)
}
void It2MeNativeMessagingHost::SendMessageToClient(
- scoped_ptr<base::DictionaryValue> message) const {
+ scoped_ptr<base::Value> message) const {
DCHECK(task_runner()->BelongsToCurrentThread());
std::string message_json;
base::JSONWriter::Write(*message, &message_json);
diff --git a/remoting/host/it2me/it2me_native_messaging_host.h b/remoting/host/it2me/it2me_native_messaging_host.h
index 02379ba..f104f1d 100644
--- a/remoting/host/it2me/it2me_native_messaging_host.h
+++ b/remoting/host/it2me/it2me_native_messaging_host.h
@@ -13,6 +13,10 @@
#include "remoting/host/chromoting_host_context.h"
#include "remoting/host/it2me/it2me_host.h"
+#if !defined(OS_CHROMEOS)
+#include "remoting/host/native_messaging/log_message_handler.h"
+#endif
+
namespace base {
class DictionaryValue;
class Value;
@@ -58,13 +62,19 @@ class It2MeNativeMessagingHost : public It2MeHost::Observer,
scoped_ptr<base::DictionaryValue> response);
void SendErrorAndExit(scoped_ptr<base::DictionaryValue> response,
const std::string& description) const;
- void SendMessageToClient(scoped_ptr<base::DictionaryValue> message) const;
+ void SendMessageToClient(scoped_ptr<base::Value> message) const;
Client* client_;
scoped_ptr<ChromotingHostContext> host_context_;
scoped_ptr<It2MeHostFactory> factory_;
scoped_refptr<It2MeHost> it2me_host_;
+#if !defined(OS_CHROMEOS)
+ // Don't install a log message handler on ChromeOS because we run in the
+ // browser process and don't want to intercept all its log messages.
+ scoped_ptr<LogMessageHandler> log_message_handler_;
+#endif
+
// Cached, read-only copies of |it2me_host_| session state.
It2MeHostState state_;
std::string access_code_;
diff --git a/remoting/host/it2me/it2me_native_messaging_host_unittest.cc b/remoting/host/it2me/it2me_native_messaging_host_unittest.cc
index fa0b088..94861e4 100644
--- a/remoting/host/it2me/it2me_native_messaging_host_unittest.cc
+++ b/remoting/host/it2me/it2me_native_messaging_host_unittest.cc
@@ -17,6 +17,7 @@
#include "net/base/net_util.h"
#include "remoting/base/auto_thread_task_runner.h"
#include "remoting/host/chromoting_host_context.h"
+#include "remoting/host/native_messaging/log_message_handler.h"
#include "remoting/host/native_messaging/native_messaging_pipe.h"
#include "remoting/host/native_messaging/pipe_messaging_channel.h"
#include "remoting/host/policy_watcher.h"
@@ -261,31 +262,39 @@ void It2MeNativeMessagingHostTest::TearDown() {
scoped_ptr<base::DictionaryValue>
It2MeNativeMessagingHostTest::ReadMessageFromOutputPipe() {
- uint32 length;
- int read_result = output_read_file_.ReadAtCurrentPos(
- reinterpret_cast<char*>(&length), sizeof(length));
- if (read_result != sizeof(length)) {
- // The output pipe has been closed, return an empty message.
- return nullptr;
- }
+ while (true) {
+ uint32 length;
+ int read_result = output_read_file_.ReadAtCurrentPos(
+ reinterpret_cast<char*>(&length), sizeof(length));
+ if (read_result != sizeof(length)) {
+ // The output pipe has been closed, return an empty message.
+ return nullptr;
+ }
- std::string message_json(length, '\0');
- read_result = output_read_file_.ReadAtCurrentPos(
- string_as_array(&message_json), length);
- if (read_result != static_cast<int>(length)) {
- LOG(ERROR) << "Message size (" << read_result
- << ") doesn't match the header (" << length << ").";
- return nullptr;
- }
+ std::string message_json(length, '\0');
+ read_result = output_read_file_.ReadAtCurrentPos(
+ string_as_array(&message_json), length);
+ if (read_result != static_cast<int>(length)) {
+ LOG(ERROR) << "Message size (" << read_result
+ << ") doesn't match the header (" << length << ").";
+ return nullptr;
+ }
- scoped_ptr<base::Value> message = base::JSONReader::Read(message_json);
- if (!message || !message->IsType(base::Value::TYPE_DICTIONARY)) {
- LOG(ERROR) << "Malformed message:" << message_json;
- return nullptr;
- }
+ scoped_ptr<base::Value> message = base::JSONReader::Read(message_json);
+ if (!message || !message->IsType(base::Value::TYPE_DICTIONARY)) {
+ LOG(ERROR) << "Malformed message:" << message_json;
+ return nullptr;
+ }
- return make_scoped_ptr(
- static_cast<base::DictionaryValue*>(message.release()));
+ scoped_ptr<base::DictionaryValue> result = make_scoped_ptr(
+ static_cast<base::DictionaryValue*>(message.release()));
+ std::string type;
+ // If this is a debug message log, ignore it, otherwise return it.
+ if (!result->GetString("type", &type) ||
+ type != LogMessageHandler::kDebugMessageTypeName) {
+ return result;
+ }
+ }
}
void It2MeNativeMessagingHostTest::WriteMessageToInputPipe(