OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_NATIVE_MESSAGE_NATIVE_THREAD_DELEGATE_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_NATIVE_MESSAGE_NATIVE_THREAD_DELEGATE_H_ |
| 7 |
| 8 #include "base/callback.h" |
| 9 #include "base/file_path.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/process.h" |
| 12 #include "base/threading/simple_thread.h" |
| 13 #include "base/threading/thread_restrictions.h" |
| 14 |
| 15 namespace base { |
| 16 class DictionaryValue; |
| 17 } // namespace base |
| 18 |
| 19 class NativeThreadDelegate : public base::DelegateSimpleThread::Delegate { |
| 20 public: |
| 21 typedef base::Callback<void( |
| 22 bool, scoped_ptr<std::string>, scoped_ptr<base::DictionaryValue>)> |
| 23 ExecutionFinishedCallback; |
| 24 |
| 25 NativeThreadDelegate(const base::DictionaryValue* data, |
| 26 scoped_ptr<FilePath> path, |
| 27 ExecutionFinishedCallback callback); |
| 28 ~NativeThreadDelegate(); |
| 29 |
| 30 virtual void Run(); |
| 31 |
| 32 private: |
| 33 // Append any new types to the end. Changing the ordering will break native |
| 34 // apps. |
| 35 enum MessageType { |
| 36 TYPE_SEND_MESSAGE_REQUEST, // Used when an extension is sending a one-off |
| 37 // message to a native app. |
| 38 TYPE_SEND_MESSAGE_RESPONSE, // Used by a native app to respond to a one-off |
| 39 // message. |
| 40 TYPE_CONNECT, // Used when an extension wants to establish a persistent |
| 41 // connection with a native app. |
| 42 TYPE_CONNECT_MESSAGE, // Used for messages after a connection has already |
| 43 // been established. |
| 44 NUM_MESSAGE_TYPES // The number of types of messages. |
| 45 }; |
| 46 |
| 47 bool WriteMessage(MessageType type, int fd); |
| 48 // If returns true, callers owns |*data|. |
| 49 // |type| is only valid if true is returned. |
| 50 bool ReadMessage(MessageType* type, base::DictionaryValue** data, int fd); |
| 51 |
| 52 // Post the response back to the UI thread. |
| 53 void Finish(bool success, |
| 54 const std::string& error, |
| 55 scoped_ptr<base::DictionaryValue> result); |
| 56 void CallbackOnUIThread(bool success, |
| 57 scoped_ptr<std::string> error, |
| 58 scoped_ptr<base::DictionaryValue> result); |
| 59 |
| 60 void exit(); |
| 61 |
| 62 const base::DictionaryValue* message_data_; |
| 63 scoped_ptr<FilePath> path_; |
| 64 base::ProcessHandle handle_; |
| 65 ExecutionFinishedCallback callback_; |
| 66 }; |
| 67 |
| 68 #endif // CHROME_BROWSER_EXTENSIONS_API_NATIVE_MESSAGE_NATIVE_THREAD_DELEGATE_H
_ |
OLD | NEW |