OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGE_PROCESS_HOST_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGE_PROCESS_HOST_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGE_PROCESS_HOST_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGE_PROCESS_HOST_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "base/process.h" | 14 #include "base/process.h" |
15 #include "chrome/browser/extensions/api/messaging/native_process_launcher.h" | 15 #include "chrome/browser/extensions/api/messaging/native_process_launcher.h" |
16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
17 | 17 |
18 namespace base { | 18 namespace net { |
19 class ListValue; | |
20 } | |
21 | 19 |
22 namespace net { | |
23 class DrainableIOBuffer; | 20 class DrainableIOBuffer; |
24 class FileStream; | 21 class FileStream; |
25 class IOBuffer; | 22 class IOBuffer; |
26 class IOBufferWithSize; | 23 class IOBufferWithSize; |
| 24 |
27 } // namespace net | 25 } // namespace net |
28 | 26 |
29 namespace extensions { | 27 namespace extensions { |
30 | 28 |
31 // Manages the native side of a connection between an extension and a native | 29 // Manages the native side of a connection between an extension and a native |
32 // process. | 30 // process. |
33 // | 31 // |
34 // This class must only be created, called, and deleted on the IO thread. | 32 // This class must only be created, called, and deleted on the IO thread. |
35 // Public methods typically accept callbacks which will be invoked on the UI | 33 // Public methods typically accept callbacks which will be invoked on the UI |
36 // thread. | 34 // thread. |
37 class NativeMessageProcessHost | 35 class NativeMessageProcessHost |
38 #if defined(OS_POSIX) | 36 #if defined(OS_POSIX) |
39 : public base::MessageLoopForIO::Watcher | 37 : public base::MessageLoopForIO::Watcher |
40 #endif // !defined(OS_POSIX) | 38 #endif // !defined(OS_POSIX) |
41 { | 39 { |
42 public: | 40 public: |
43 // Interface for the object that receives messages from the native process. | 41 // Interface for the object that receives messages from the native process. |
44 class Client { | 42 class Client { |
45 public: | 43 public: |
46 virtual ~Client() {} | 44 virtual ~Client() {} |
47 // Called on the UI thread. | 45 // Called on the UI thread. |
48 virtual void PostMessageFromNativeProcess( | 46 virtual void PostMessageFromNativeProcess(int port_id, |
49 int port_id, | 47 const std::string& message) = 0; |
50 scoped_ptr<base::ListValue> message) = 0; | |
51 virtual void CloseChannel(int port_id, | 48 virtual void CloseChannel(int port_id, |
52 const std::string& error_message) = 0; | 49 const std::string& error_message) = 0; |
53 }; | 50 }; |
54 | 51 |
55 virtual ~NativeMessageProcessHost(); | 52 virtual ~NativeMessageProcessHost(); |
56 | 53 |
57 static scoped_ptr<NativeMessageProcessHost> Create( | 54 static scoped_ptr<NativeMessageProcessHost> Create( |
58 base::WeakPtr<Client> weak_client_ui, | 55 base::WeakPtr<Client> weak_client_ui, |
59 const std::string& source_extension_id, | 56 const std::string& source_extension_id, |
60 const std::string& native_host_name, | 57 const std::string& native_host_name, |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 160 |
164 // Set to true when a write is pending. | 161 // Set to true when a write is pending. |
165 bool write_pending_; | 162 bool write_pending_; |
166 | 163 |
167 DISALLOW_COPY_AND_ASSIGN(NativeMessageProcessHost); | 164 DISALLOW_COPY_AND_ASSIGN(NativeMessageProcessHost); |
168 }; | 165 }; |
169 | 166 |
170 } // namespace extensions | 167 } // namespace extensions |
171 | 168 |
172 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGE_PROCESS_HOST_H
_ | 169 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGE_PROCESS_HOST_H
_ |
OLD | NEW |