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

Side by Side Diff: chrome/browser/extensions/api/messaging/native_message_process_host.h

Issue 12386018: Revert 185189. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
(...skipping 22 matching lines...) Expand all
33 // 33 //
34 // This class must only be created, called, and deleted on the IO thread. 34 // 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 35 // Public methods typically accept callbacks which will be invoked on the UI
36 // thread. 36 // thread.
37 class NativeMessageProcessHost 37 class NativeMessageProcessHost
38 #if defined(OS_POSIX) 38 #if defined(OS_POSIX)
39 : public MessageLoopForIO::Watcher 39 : public MessageLoopForIO::Watcher
40 #endif // !defined(OS_POSIX) 40 #endif // !defined(OS_POSIX)
41 { 41 {
42 public: 42 public:
43 // Interface for the object that receives messages from the native process. 43 // Interface for classes that which to recieve messages from the native
44 // process.
44 class Client { 45 class Client {
45 public: 46 public:
46 virtual ~Client() {} 47 virtual ~Client() {}
47 // Called on the UI thread. 48 // Called on the UI thread.
48 virtual void PostMessageFromNativeProcess(int port_id, 49 virtual void PostMessageFromNativeProcess(int port_id,
49 const std::string& message) = 0; 50 const std::string& message) = 0;
50 virtual void CloseChannel(int port_id, bool error) = 0; 51 virtual void CloseChannel(int port_id, bool error) = 0;
51 }; 52 };
52 53
53 virtual ~NativeMessageProcessHost(); 54 virtual ~NativeMessageProcessHost();
54 55
55 static scoped_ptr<NativeMessageProcessHost> Create( 56 static scoped_ptr<NativeMessageProcessHost> Create(
56 base::WeakPtr<Client> weak_client_ui, 57 base::WeakPtr<Client> weak_client_ui,
57 const std::string& source_extension_id,
58 const std::string& native_host_name, 58 const std::string& native_host_name,
59 int destination_port); 59 int destination_port);
60 60
61 // Create using specified |launcher|. Used in tests. 61 // Create using specified |launcher|. Used in tests.
62 static scoped_ptr<NativeMessageProcessHost> CreateWithLauncher( 62 static scoped_ptr<NativeMessageProcessHost> CreateWithLauncher(
63 base::WeakPtr<Client> weak_client_ui, 63 base::WeakPtr<Client> weak_client_ui,
64 const std::string& source_extension_id,
65 const std::string& native_host_name, 64 const std::string& native_host_name,
66 int destination_port, 65 int destination_port,
67 scoped_ptr<NativeProcessLauncher> launcher); 66 scoped_ptr<NativeProcessLauncher> launcher);
68 67
69 // Send a message with the specified payload. 68 // Send a message with the specified payload.
70 void Send(const std::string& json); 69 void Send(const std::string& json);
71 70
72 #if defined(OS_POSIX) 71 #if defined(OS_POSIX)
73 // MessageLoopForIO::Watcher interface 72 // MessageLoopForIO::Watcher interface
74 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; 73 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
75 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; 74 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE;
76 #endif // !defined(OS_POSIX) 75 #endif // !defined(OS_POSIX)
77 76
78 // Try and read a single message from |read_file_|. This should only be called 77 // Try and read a single message from |read_file_|. This should only be called
79 // in unittests when you know there is data in the file. 78 // in unittests when you know there is data in the file.
80 void ReadNowForTesting(); 79 void ReadNowForTesting();
81 80
82 private: 81 private:
83 NativeMessageProcessHost(base::WeakPtr<Client> weak_client_ui, 82 NativeMessageProcessHost(base::WeakPtr<Client> weak_client_ui,
84 const std::string& source_extension_id,
85 const std::string& native_host_name, 83 const std::string& native_host_name,
86 int destination_port, 84 int destination_port,
87 scoped_ptr<NativeProcessLauncher> launcher); 85 scoped_ptr<NativeProcessLauncher> launcher);
88 86
89 // Starts the host process. 87 // Starts the host process.
90 void LaunchHostProcess(); 88 void LaunchHostProcess();
91 89
92 // Callback for NativeProcessLauncher::Launch(). 90 // Callback for NativeProcessLauncher::Launch().
93 void OnHostProcessLaunched(bool result, 91 void OnHostProcessLaunched(bool result,
94 base::PlatformFile read_file, 92 base::PlatformFile read_file,
(...skipping 15 matching lines...) Expand all
110 // write to/from it. Closes IO pipes and schedules CloseChannel() call. 108 // write to/from it. Closes IO pipes and schedules CloseChannel() call.
111 void OnError(); 109 void OnError();
112 110
113 // Closes the connection. Called from OnError() and destructor. 111 // Closes the connection. Called from OnError() and destructor.
114 void Close(); 112 void Close();
115 113
116 // The Client messages will be posted to. Should only be accessed from the 114 // The Client messages will be posted to. Should only be accessed from the
117 // UI thread. 115 // UI thread.
118 base::WeakPtr<Client> weak_client_ui_; 116 base::WeakPtr<Client> weak_client_ui_;
119 117
120 // ID of the calling extension.
121 std::string source_extension_id_;
122
123 // Name of the native messaging host. 118 // Name of the native messaging host.
124 std::string native_host_name_; 119 std::string native_host_name_;
125 120
126 // The id of the port on the other side of this connection. This is passed to 121 // The id of the port on the other side of this connection. This is passed to
127 // |weak_client_ui_| when posting messages. 122 // |weak_client_ui_| when posting messages.
128 int destination_port_; 123 int destination_port_;
129 124
130 // Launcher used to launch the native process. 125 // Launcher used to launch the native process.
131 scoped_ptr<NativeProcessLauncher> launcher_; 126 scoped_ptr<NativeProcessLauncher> launcher_;
132 127
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 160
166 // Set to true when a write is pending. 161 // Set to true when a write is pending.
167 bool write_pending_; 162 bool write_pending_;
168 163
169 DISALLOW_COPY_AND_ASSIGN(NativeMessageProcessHost); 164 DISALLOW_COPY_AND_ASSIGN(NativeMessageProcessHost);
170 }; 165 };
171 166
172 } // namespace extensions 167 } // namespace extensions
173 168
174 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGE_PROCESS_HOST_H _ 169 #endif // CHROME_BROWSER_EXTENSIONS_API_MESSAGING_NATIVE_MESSAGE_PROCESS_HOST_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698