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

Side by Side Diff: src/trusted/plugin/service_runtime.h

Issue 7799028: Remove src/trusted/plugin (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: fix gyp file for necessary -I Created 9 years, 3 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
« no previous file with comments | « src/trusted/plugin/scriptable_handle.cc ('k') | src/trusted/plugin/service_runtime.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /* -*- c++ -*- */
2 /*
3 * Copyright (c) 2011 The Native Client Authors. All rights reserved.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 // A class containing information regarding a socket connection to a
9 // service runtime instance.
10
11 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SERVICE_RUNTIME_H_
12 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SERVICE_RUNTIME_H_
13
14 #include "native_client/src/include/nacl_macros.h"
15 #include "native_client/src/include/nacl_scoped_ptr.h"
16 #include "native_client/src/include/nacl_string.h"
17 #include "native_client/src/shared/imc/nacl_imc.h"
18 #include "native_client/src/shared/platform/nacl_sync.h"
19 #include "native_client/src/shared/srpc/nacl_srpc.h"
20 #include "native_client/src/trusted/reverse_service/reverse_service.h"
21 #include "native_client/src/trusted/plugin/utility.h"
22 #include "native_client/src/trusted/plugin/file_downloader.h"
23 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h"
24 #include "native_client/src/trusted/weak_ref/weak_ref.h"
25
26 #include "ppapi/cpp/completion_callback.h"
27
28 namespace nacl {
29 class DescWrapper;
30 struct SelLdrLauncher;
31 } // namespace
32
33 namespace plugin {
34
35 class BrowserInterface;
36 class ErrorInfo;
37 class Plugin;
38 class SrpcClient;
39 class SrtSocket;
40 class ScriptableHandle;
41 class ServiceRuntime;
42
43 // Callback resources are essentially our continuation state.
44
45 struct LogToJavaScriptConsoleResource {
46 public:
47 explicit LogToJavaScriptConsoleResource(std::string msg)
48 : message(msg) {}
49 std::string message;
50 };
51
52 struct OpenManifestEntryResource {
53 public:
54 OpenManifestEntryResource(std::string target_url,
55 int32_t* descp,
56 ErrorInfo* infop,
57 bool* portablep,
58 bool* op_complete)
59 : url(target_url),
60 out_desc(descp),
61 error_info(infop),
62 is_portable(portablep),
63 op_complete_ptr(op_complete) {}
64 std::string url;
65 int32_t* out_desc;
66 ErrorInfo* error_info;
67 bool* is_portable;
68 bool* op_complete_ptr;
69 };
70
71 struct CloseManifestEntryResource {
72 public:
73 CloseManifestEntryResource(int32_t desc_to_close,
74 bool* op_complete,
75 bool* op_result)
76 : desc(desc_to_close),
77 op_complete_ptr(op_complete),
78 op_result_ptr(op_result) {}
79
80 int32_t desc;
81 bool* op_complete_ptr;
82 bool* op_result_ptr;
83 };
84
85 // Do not invoke from the main thread, since the main methods will
86 // invoke CallOnMainThread and then wait on a condvar for the task to
87 // complete: if invoked from the main thread, the main method not
88 // returning (and thus unblocking the main thread) means that the
89 // main-thread continuation methods will never get called, and thus
90 // we'd get a deadlock.
91 class PluginReverseInterface: public nacl::ReverseInterface {
92 public:
93 PluginReverseInterface(nacl::WeakRefAnchor* anchor,
94 Plugin* plugin,
95 pp::CompletionCallback init_done_cb);
96
97 virtual ~PluginReverseInterface();
98
99 void ShutDown();
100
101 virtual void Log(nacl::string message);
102
103 virtual void StartupInitializationComplete();
104
105 virtual bool EnumerateManifestKeys(std::set<nacl::string>* out_keys);
106
107 virtual bool OpenManifestEntry(nacl::string url_key, int32_t* out_desc);
108
109 virtual bool CloseManifestEntry(int32_t desc);
110
111 protected:
112 virtual void Log_MainThreadContinuation(LogToJavaScriptConsoleResource* p,
113 int32_t err);
114
115 virtual void OpenManifestEntry_MainThreadContinuation(
116 OpenManifestEntryResource* p,
117 int32_t err);
118
119 virtual void StreamAsFile_MainThreadContinuation(
120 OpenManifestEntryResource* p,
121 int32_t result);
122
123 virtual void CloseManifestEntry_MainThreadContinuation(
124 CloseManifestEntryResource* cls,
125 int32_t err);
126
127 private:
128 nacl::WeakRefAnchor* anchor_; // holds a ref
129 Plugin* plugin_; // value may be copied, but should be used only in
130 // main thread in WeakRef-protected callbacks.
131 NaClMutex mu_;
132 NaClCondVar cv_;
133 bool shutting_down_;
134
135 pp::CompletionCallback init_done_cb_;
136 };
137
138 // ServiceRuntime abstracts a NativeClient sel_ldr instance.
139 class ServiceRuntime {
140 public:
141 // TODO(sehr): This class should also implement factory methods, using the
142 // Start method below.
143 ServiceRuntime(Plugin* plugin,
144 pp::CompletionCallback init_done_cb);
145 // The destructor terminates the sel_ldr process.
146 ~ServiceRuntime();
147
148 // Spawn a sel_ldr instance and establish an SrpcClient to it. The nexe
149 // to be started is passed through |nacl_file_desc|. On success, returns
150 // true. On failure, returns false and |error_string| is set to something
151 // describing the error.
152 bool Start(nacl::DescWrapper* nacl_file_desc, ErrorInfo* error_info);
153
154 // Starts the application channel to the nexe.
155 SrpcClient* SetupAppChannel();
156
157 bool Kill();
158 bool Log(int severity, nacl::string msg);
159 Plugin* plugin() const { return plugin_; }
160 void Shutdown();
161
162 nacl::DescWrapper* async_receive_desc() { return async_receive_desc_.get(); }
163 nacl::DescWrapper* async_send_desc() { return async_send_desc_.get(); }
164
165 private:
166 NACL_DISALLOW_COPY_AND_ASSIGN(ServiceRuntime);
167 bool InitCommunication(nacl::DescWrapper* shm, ErrorInfo* error_info);
168
169 NaClSrpcChannel command_channel_;
170 Plugin* plugin_;
171 BrowserInterface* browser_interface_;
172 nacl::ReverseService* reverse_service_;
173 nacl::scoped_ptr<nacl::SelLdrLauncher> subprocess_;
174
175 // We need two IMC sockets rather than one because IMC sockets are
176 // not full-duplex on Windows.
177 // See http://code.google.com/p/nativeclient/issues/detail?id=690.
178 // TODO(mseaborn): We should not have to work around this.
179 nacl::scoped_ptr<nacl::DescWrapper> async_receive_desc_;
180 nacl::scoped_ptr<nacl::DescWrapper> async_send_desc_;
181
182 nacl::WeakRefAnchor* anchor_;
183
184 PluginReverseInterface* rev_interface_;
185 };
186
187 } // namespace plugin
188
189 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SERVICE_RUNTIME_H_
OLDNEW
« no previous file with comments | « src/trusted/plugin/scriptable_handle.cc ('k') | src/trusted/plugin/service_runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698