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

Unified Diff: chrome/browser/extensions/api/messaging/native_message_process_host.cc

Issue 11968028: Remove connect message from Native Messaging API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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: chrome/browser/extensions/api/messaging/native_message_process_host.cc
diff --git a/chrome/browser/extensions/api/messaging/native_message_process_host.cc b/chrome/browser/extensions/api/messaging/native_message_process_host.cc
index c431811ab6297a1c376b12cebc198203c6a65631..3634e8f4aab38d9a392b1c7eb3969be7beb14a2f 100644
--- a/chrome/browser/extensions/api/messaging/native_message_process_host.cc
+++ b/chrome/browser/extensions/api/messaging/native_message_process_host.cc
@@ -33,16 +33,14 @@ NativeMessageProcessHost::NativeMessageProcessHost(
int destination_port,
base::ProcessHandle native_process_handle,
FileHandle read_file,
- FileHandle write_file,
- bool is_send_message)
+ FileHandle write_file)
: weak_client_ui_(weak_client_ui),
destination_port_(destination_port),
native_process_handle_(native_process_handle),
read_file_(read_file),
write_file_(write_file),
scoped_read_file_(&read_file_),
- scoped_write_file_(&write_file_),
- is_send_message_(is_send_message) {
+ scoped_write_file_(&write_file_) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
InitIO();
}
@@ -63,26 +61,21 @@ NativeMessageProcessHost::~NativeMessageProcessHost() {
// static
void NativeMessageProcessHost::Create(base::WeakPtr<Client> weak_client_ui,
const std::string& native_app_name,
- const std::string& connection_message,
int destination_port,
- MessageType type,
CreateCallback callback) {
NativeProcessLauncher launcher;
- CreateWithLauncher(weak_client_ui, native_app_name, connection_message,
- destination_port, type, callback, launcher);
+ CreateWithLauncher(weak_client_ui, native_app_name, destination_port,
+ callback, launcher);
}
// static
void NativeMessageProcessHost::CreateWithLauncher(
base::WeakPtr<Client> weak_client_ui,
const std::string& native_app_name,
- const std::string& connection_message,
int destination_port,
- MessageType type,
CreateCallback callback,
const NativeProcessLauncher& launcher) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
- DCHECK(type == TYPE_SEND_MESSAGE_REQUEST || type == TYPE_CONNECT);
ScopedHost process;
if (Feature::GetCurrentChannel() > chrome::VersionInfo::CHANNEL_DEV ||
@@ -127,17 +120,14 @@ void NativeMessageProcessHost::CreateWithLauncher(
process.reset(new NativeMessageProcessHost(
weak_client_ui, destination_port, native_process_handle, read_handle,
- write_handle, type == TYPE_SEND_MESSAGE_REQUEST));
-
- process->SendImpl(type, connection_message);
+ write_handle));
content::BrowserThread::PostTask(
content::BrowserThread::UI, FROM_HERE,
base::Bind(callback, base::Passed(&process)));
}
-void NativeMessageProcessHost::SendImpl(MessageType type,
- const std::string& json) {
+void NativeMessageProcessHost::Send(const std::string& json) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
// Make sure that the process has not died.
@@ -149,21 +139,17 @@ void NativeMessageProcessHost::SendImpl(MessageType type,
destination_port_, true));
}
- WriteMessage(type, json);
+ WriteMessage(json);
}
-bool NativeMessageProcessHost::WriteMessage(MessageType type,
- const std::string& message) {
+bool NativeMessageProcessHost::WriteMessage(const std::string& message) {
Pickle pickle;
- // Pickles will always pad bytes to 32-bit alignment, so just use a unit32.
- pickle.WriteUInt32(type);
-
// Pickles write the length of a string before it as a uint32.
pickle.WriteString(message);
// Make sure that the pickle doesn't do any unexpected padding.
- CHECK(8 + message.length() == pickle.payload_size());
+ CHECK_EQ(4 + message.length(), pickle.payload_size());
if (!WriteData(write_file_, const_cast<const Pickle*>(&pickle)->payload(),
pickle.payload_size())) {
@@ -174,40 +160,22 @@ bool NativeMessageProcessHost::WriteMessage(MessageType type,
return true;
}
-bool NativeMessageProcessHost::ReadMessage(MessageType* type,
- std::string* message) {
- // Read the type (uint32) and length (uint32).
- char message_meta_data[8];
- if (!ReadData(read_file_, message_meta_data, 8)) {
- LOG(ERROR) << "Error reading the message type and length.";
+bool NativeMessageProcessHost::ReadMessage(std::string* message) {
+ // Read the length (uint32).
+ char message_meta_data[4];
+ if (!ReadData(read_file_, message_meta_data, sizeof(message_meta_data))) {
+ LOG(ERROR) << "Error reading the message length.";
return false;
}
Pickle pickle;
pickle.WriteBytes(message_meta_data, 8);
PickleIterator pickle_it(pickle);
- uint32 uint_type;
uint32 data_length;
- if (!pickle_it.ReadUInt32(&uint_type) ||
- !pickle_it.ReadUInt32(&data_length)) {
- LOG(ERROR) << "Error getting the message type and length from the pickle.";
- return false;
- }
-
- if (uint_type >= NUM_MESSAGE_TYPES) {
- LOG(ERROR) << type << " is not a valid message type.";
- return false;
- }
-
- if ((is_send_message_ && (uint_type != TYPE_SEND_MESSAGE_RESPONSE)) ||
- (!is_send_message_ && (uint_type != TYPE_CONNECT_MESSAGE))) {
- LOG(ERROR) << "Recieved a message of type " << uint_type << ". "
- << "Expecting a message of type "
- << (is_send_message_ ? TYPE_SEND_MESSAGE_RESPONSE :
- TYPE_CONNECT_MESSAGE);
+ if (!pickle_it.ReadUInt32(&data_length)) {
+ LOG(ERROR) << "Error getting the message length from the pickle.";
return false;
}
- *type = static_cast<MessageType>(uint_type);
if (data_length > kMaxMessageDataLength) {
LOG(ERROR) << data_length << " is too large for the length of a message. "

Powered by Google App Engine
This is Rietveld 408576698