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

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

Issue 10918255: The Windows portion of Native Messagaing (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Windows is Ready Created 8 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: chrome/browser/extensions/api/messaging/native_message_process_host.h
diff --git a/chrome/browser/extensions/api/messaging/native_message_process_host.h b/chrome/browser/extensions/api/messaging/native_message_process_host.h
index d629b089220de77641eca3596ad40710e73c5564..570d001fcace8ddebbab68ec6c31d76a29a0283f 100644
--- a/chrome/browser/extensions/api/messaging/native_message_process_host.h
+++ b/chrome/browser/extensions/api/messaging/native_message_process_host.h
@@ -18,7 +18,7 @@ class NativeProcessLauncher;
// Manages the native side of a connection between an extension and a native
// process.
//
-// This class must only be created, called, and deleted on the FILE thread.
+// This class must only be created, called, and deleted on the IO thread.
// Public methods typically accept callbacks which will be invoked on the UI
// thread.
class NativeMessageProcessHost
@@ -69,16 +69,15 @@ class NativeMessageProcessHost
};
// Desctruction functor that ensures a NativeMessageProcessHost is destroyed
- // on the FILE thread.
+ // on the IO thread.
class ScopedNativeProcessClose {
public:
inline void operator()(extensions::NativeMessageProcessHost* x) const {
- content::BrowserThread::DeleteSoon(content::BrowserThread::FILE,
- FROM_HERE, x);
+ content::BrowserThread::DeleteSoon(content::BrowserThread::IO,
+ FROM_HERE, x);
}
};
-
virtual ~NativeMessageProcessHost();
// |type| must be TYPE_CONNECT or TYPE_SEND_MESSAGE_REQUEST. |callback| will
@@ -98,7 +97,7 @@ class NativeMessageProcessHost
int destination_port,
MessageType type,
CreateCallback callback,
- const NativeProcessLauncher& launcher);
+ scoped_ptr<NativeProcessLauncher> launcher);
// TYPE_SEND_MESSAGE_REQUEST will be sent via the connection message in
// NativeMessageProcessHost::Create, so only TYPE_CONNECT_MESSAGE is expected.
@@ -111,6 +110,30 @@ class NativeMessageProcessHost
void ReadNowForTesting();
private:
+ enum ReadState {
+ READ_STATE_INVALID,
+ READ_STATE_WAITING_FOR_META,
+ READ_STATE_WAITING_FOR_MESSGAE
Matt Perry 2012/10/24 23:40:31 typo
eaugusti 2012/10/30 22:03:12 Done.
+ };
+
+ // Check that the app's path is within the proper directory on the FILE
+ // thread.
+ static void CheckPathOnFileThread(base::WeakPtr<Client> weak_client_ui,
+ const std::string& native_app_name,
+ const std::string& connection_message,
+ int destination_port,
+ MessageType type,
+ CreateCallback callback,
+ scoped_ptr<NativeProcessLauncher> launcher);
+
+ // Finish the launching process. This will be run on the IO thread.
+ static void FinalizeCreate(base::WeakPtr<Client> weak_client_ui,
+ const std::string& connection_message,
+ int destination_port,
+ MessageType type,
+ CreateCallback callback,
+ scoped_ptr<NativeProcessLauncher> launcher,
+ FilePath native_host_program);
NativeMessageProcessHost(base::WeakPtr<Client> weak_client_ui,
int destination_port,
base::ProcessHandle native_process_handle,
@@ -118,9 +141,13 @@ class NativeMessageProcessHost
FileHandle write_fd,
bool is_send_message);
+
// Initialize any IO watching that needs to occur between the native process.
void InitIO();
+ // Stop any IO operations in progress.
+ void StopIO();
+
// Send a message to the native process with the specified type and payload.
void SendImpl(MessageType type, const std::string& json);
@@ -132,6 +159,11 @@ class NativeMessageProcessHost
bool ReadMessage(MessageType* type, std::string* messgae);
bool ReadData(FileHandle file, char* data, size_t bytes_to_write);
+ // Parse and verify the meta data (type and length) for a message.
+ bool VerifyMessageMetaData(const char* message_meta_data,
+ MessageType* type,
+ uint32* message_length);
+
#if defined(OS_POSIX)
// MessageLoopForIO::Watcher
virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
@@ -147,10 +179,13 @@ class NativeMessageProcessHost
DWORD bytes_transfered,
DWORD error) OVERRIDE;
- MessageLoopForIO::IOContext read_context_;
- MessageLoopForIO::IOContext write_context_;
-#endif // defined(OS_WIN)
+ scoped_ptr<MessageLoopForIO::IOContext> read_context_;
+ scoped_ptr<MessageLoopForIO::IOContext> write_context_;
+ ReadState read_state;
+ std::string pending_message_;
+ char pending_message_meta_data_[8];
+#endif // defined(OS_WIN)
// The Client messages will be posted to. Should only be accessed from the
// UI thread.
@@ -160,6 +195,9 @@ class NativeMessageProcessHost
// |weak_client_ui_| when posting messages.
int destination_port_;
+ // This may be base::kNullProcessHandle during tests. On posix, this is not a
+ // problem. However, on windows this may crash certian calls like
+ // base::GetTerminationStatus().
base::ProcessHandle native_process_handle_;
FileHandle read_file_;

Powered by Google App Engine
This is Rietveld 408576698