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

Unified Diff: chrome/browser/extensions/api/native_message/native_thread_delegate.h

Issue 10818013: Native Messaging! (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 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/native_message/native_thread_delegate.h
diff --git a/chrome/browser/extensions/api/native_message/native_thread_delegate.h b/chrome/browser/extensions/api/native_message/native_thread_delegate.h
new file mode 100644
index 0000000000000000000000000000000000000000..fef0df729fb30119fe270f8bf57265fbf71f7bac
--- /dev/null
+++ b/chrome/browser/extensions/api/native_message/native_thread_delegate.h
@@ -0,0 +1,68 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_API_NATIVE_MESSAGE_NATIVE_THREAD_DELEGATE_H_
+#define CHROME_BROWSER_EXTENSIONS_API_NATIVE_MESSAGE_NATIVE_THREAD_DELEGATE_H_
+
+#include "base/callback.h"
+#include "base/file_path.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/process.h"
+#include "base/threading/simple_thread.h"
+#include "base/threading/thread_restrictions.h"
+
+namespace base {
+class DictionaryValue;
+} // namespace base
+
+class NativeThreadDelegate : public base::DelegateSimpleThread::Delegate {
+ public:
+ typedef base::Callback<void(
+ bool, scoped_ptr<std::string>, scoped_ptr<base::DictionaryValue>)>
+ ExecutionFinishedCallback;
+
+ NativeThreadDelegate(const base::DictionaryValue* data,
+ scoped_ptr<FilePath> path,
+ ExecutionFinishedCallback callback);
+ ~NativeThreadDelegate();
+
+ virtual void Run();
+
+ private:
+ // Append any new types to the end. Changing the ordering will break native
+ // apps.
+ enum MessageType {
+ TYPE_SEND_MESSAGE_REQUEST, // Used when an extension is sending a one-off
+ // message to a native app.
+ TYPE_SEND_MESSAGE_RESPONSE, // Used by a native app to respond to a one-off
+ // message.
+ TYPE_CONNECT, // Used when an extension wants to establish a persistent
+ // connection with a native app.
+ TYPE_CONNECT_MESSAGE, // Used for messages after a connection has already
+ // been established.
+ NUM_MESSAGE_TYPES // The number of types of messages.
+ };
+
+ bool WriteMessage(MessageType type, int fd);
+ // If returns true, callers owns |*data|.
+ // |type| is only valid if true is returned.
+ bool ReadMessage(MessageType* type, base::DictionaryValue** data, int fd);
+
+ // Post the response back to the UI thread.
+ void Finish(bool success,
+ const std::string& error,
+ scoped_ptr<base::DictionaryValue> result);
+ void CallbackOnUIThread(bool success,
+ scoped_ptr<std::string> error,
+ scoped_ptr<base::DictionaryValue> result);
+
+ void exit();
+
+ const base::DictionaryValue* message_data_;
+ scoped_ptr<FilePath> path_;
+ base::ProcessHandle handle_;
+ ExecutionFinishedCallback callback_;
+};
+
+#endif // CHROME_BROWSER_EXTENSIONS_API_NATIVE_MESSAGE_NATIVE_THREAD_DELEGATE_H_

Powered by Google App Engine
This is Rietveld 408576698