OLD | NEW |
1 /* -*- c++ -*- */ | 1 /* -*- c++ -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2012 The Chromium Authors. All rights reserved. | 3 * Copyright (c) 2012 The Chromium Authors. All rights reserved. |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 // A class containing information regarding a socket connection to a | 8 // A class containing information regarding a socket connection to a |
9 // service runtime instance. | 9 // service runtime instance. |
10 | 10 |
11 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SERVICE_RUNTIME_H_ | 11 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SERVICE_RUNTIME_H_ |
12 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SERVICE_RUNTIME_H_ | 12 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SERVICE_RUNTIME_H_ |
13 | 13 |
14 #include "native_client/src/include/nacl_macros.h" | 14 #include "native_client/src/include/nacl_macros.h" |
15 #include "native_client/src/include/nacl_scoped_ptr.h" | 15 #include "native_client/src/include/nacl_scoped_ptr.h" |
| 16 #include "native_client/src/public/imc_types.h" |
16 #include "native_client/src/shared/platform/nacl_sync.h" | 17 #include "native_client/src/shared/platform/nacl_sync.h" |
17 #include "native_client/src/shared/srpc/nacl_srpc.h" | 18 #include "native_client/src/shared/srpc/nacl_srpc.h" |
18 #include "native_client/src/trusted/reverse_service/reverse_service.h" | |
19 #include "native_client/src/trusted/weak_ref/weak_ref.h" | |
20 | 19 |
21 #include "ppapi/cpp/completion_callback.h" | 20 #include "ppapi/cpp/completion_callback.h" |
22 #include "ppapi/native_client/src/trusted/plugin/utility.h" | 21 #include "ppapi/native_client/src/trusted/plugin/utility.h" |
23 | 22 |
24 struct NaClFileInfo; | 23 struct NaClFileInfo; |
25 | 24 |
26 namespace plugin { | 25 namespace plugin { |
27 | 26 |
28 class ErrorInfo; | 27 class ErrorInfo; |
29 class Plugin; | 28 class Plugin; |
30 class SelLdrLauncherChrome; | 29 class SelLdrLauncherChrome; |
31 class SrpcClient; | 30 class SrpcClient; |
32 class ServiceRuntime; | 31 class ServiceRuntime; |
33 | 32 |
34 // Struct of params used by StartSelLdr. Use a struct so that callback | 33 // Struct of params used by StartSelLdr. Use a struct so that callback |
35 // creation templates aren't overwhelmed with too many parameters. | 34 // creation templates aren't overwhelmed with too many parameters. |
36 struct SelLdrStartParams { | 35 struct SelLdrStartParams { |
37 SelLdrStartParams(const std::string& url, | 36 SelLdrStartParams(const std::string& url, |
38 const PP_NaClFileInfo& file_info, | 37 const PP_NaClFileInfo& file_info, |
39 PP_NaClAppProcessType process_type) | 38 PP_NaClAppProcessType process_type) |
40 : url(url), | 39 : url(url), |
41 file_info(file_info), | 40 file_info(file_info), |
42 process_type(process_type) { | 41 process_type(process_type) { |
43 } | 42 } |
44 std::string url; | 43 std::string url; |
45 PP_NaClFileInfo file_info; | 44 PP_NaClFileInfo file_info; |
46 PP_NaClAppProcessType process_type; | 45 PP_NaClAppProcessType process_type; |
47 }; | 46 }; |
48 | 47 |
49 // Callback resources are essentially our continuation state. | |
50 struct OpenManifestEntryResource { | |
51 public: | |
52 OpenManifestEntryResource(const std::string& target_url, | |
53 struct NaClFileInfo* finfo, | |
54 bool* op_complete) | |
55 : url(target_url), | |
56 file_info(finfo), | |
57 op_complete_ptr(op_complete) {} | |
58 ~OpenManifestEntryResource(); | |
59 | |
60 std::string url; | |
61 struct NaClFileInfo* file_info; | |
62 PP_NaClFileInfo pp_file_info; | |
63 bool* op_complete_ptr; | |
64 }; | |
65 | |
66 // Do not invoke from the main thread, since the main methods will | |
67 // invoke CallOnMainThread and then wait on a condvar for the task to | |
68 // complete: if invoked from the main thread, the main method not | |
69 // returning (and thus unblocking the main thread) means that the | |
70 // main-thread continuation methods will never get called, and thus | |
71 // we'd get a deadlock. | |
72 class PluginReverseInterface: public nacl::ReverseInterface { | |
73 public: | |
74 PluginReverseInterface(nacl::WeakRefAnchor* anchor, | |
75 PP_Instance pp_instance, | |
76 ServiceRuntime* service_runtime); | |
77 | |
78 virtual ~PluginReverseInterface(); | |
79 | |
80 void ShutDown(); | |
81 | |
82 virtual void DoPostMessage(std::string message); | |
83 | |
84 virtual void StartupInitializationComplete(); | |
85 | |
86 virtual bool OpenManifestEntry(std::string url_key, | |
87 struct NaClFileInfo *info); | |
88 | |
89 virtual void ReportCrash(); | |
90 | |
91 virtual void ReportExitStatus(int exit_status); | |
92 | |
93 // TODO(teravest): Remove this method once it's gone from | |
94 // nacl::ReverseInterface. | |
95 virtual int64_t RequestQuotaForWrite(std::string file_id, | |
96 int64_t offset, | |
97 int64_t bytes_to_write); | |
98 | |
99 protected: | |
100 virtual void OpenManifestEntry_MainThreadContinuation( | |
101 OpenManifestEntryResource* p, | |
102 int32_t err); | |
103 | |
104 virtual void StreamAsFile_MainThreadContinuation( | |
105 OpenManifestEntryResource* p, | |
106 int32_t result); | |
107 | |
108 private: | |
109 nacl::WeakRefAnchor* anchor_; // holds a ref | |
110 // Should be used only in main thread in WeakRef-protected callbacks. | |
111 PP_Instance pp_instance_; | |
112 ServiceRuntime* service_runtime_; | |
113 NaClMutex mu_; | |
114 NaClCondVar cv_; | |
115 bool shutting_down_; | |
116 }; | |
117 | |
118 // ServiceRuntime abstracts a NativeClient sel_ldr instance. | 48 // ServiceRuntime abstracts a NativeClient sel_ldr instance. |
119 class ServiceRuntime { | 49 class ServiceRuntime { |
120 public: | 50 public: |
121 ServiceRuntime(Plugin* plugin, | 51 ServiceRuntime(Plugin* plugin, |
122 PP_Instance pp_instance, | 52 PP_Instance pp_instance, |
123 bool main_service_runtime, | 53 bool main_service_runtime, |
124 bool uses_nonsfi_mode); | 54 bool uses_nonsfi_mode); |
125 // The destructor terminates the sel_ldr process. | 55 // The destructor terminates the sel_ldr process. |
126 ~ServiceRuntime(); | 56 ~ServiceRuntime(); |
127 | 57 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 Plugin* plugin() const { return plugin_; } | 92 Plugin* plugin() const { return plugin_; } |
163 void Shutdown(); | 93 void Shutdown(); |
164 | 94 |
165 bool main_service_runtime() const { return main_service_runtime_; } | 95 bool main_service_runtime() const { return main_service_runtime_; } |
166 | 96 |
167 private: | 97 private: |
168 NACL_DISALLOW_COPY_AND_ASSIGN(ServiceRuntime); | 98 NACL_DISALLOW_COPY_AND_ASSIGN(ServiceRuntime); |
169 bool StartNexeInternal(); | 99 bool StartNexeInternal(); |
170 | 100 |
171 bool SetupCommandChannel(); | 101 bool SetupCommandChannel(); |
172 bool InitReverseService(); | |
173 bool StartModule(); | 102 bool StartModule(); |
174 void ReapLogs(); | 103 void ReapLogs(); |
175 | 104 |
176 void ReportLoadError(const ErrorInfo& error_info); | 105 void ReportLoadError(const ErrorInfo& error_info); |
177 | 106 |
178 NaClSrpcChannel command_channel_; | 107 NaClSrpcChannel command_channel_; |
179 Plugin* plugin_; | 108 Plugin* plugin_; |
180 PP_Instance pp_instance_; | 109 PP_Instance pp_instance_; |
181 bool main_service_runtime_; | 110 bool main_service_runtime_; |
182 bool uses_nonsfi_mode_; | 111 bool uses_nonsfi_mode_; |
183 nacl::ReverseService* reverse_service_; | |
184 nacl::scoped_ptr<SelLdrLauncherChrome> subprocess_; | 112 nacl::scoped_ptr<SelLdrLauncherChrome> subprocess_; |
185 | 113 |
186 nacl::WeakRefAnchor* anchor_; | |
187 | |
188 PluginReverseInterface* rev_interface_; | |
189 | |
190 // Mutex and CondVar to protect start_sel_ldr_done_ and nexe_started_. | 114 // Mutex and CondVar to protect start_sel_ldr_done_ and nexe_started_. |
191 NaClMutex mu_; | 115 NaClMutex mu_; |
192 NaClCondVar cond_; | 116 NaClCondVar cond_; |
193 bool start_sel_ldr_done_; | 117 bool start_sel_ldr_done_; |
194 bool sel_ldr_wait_timed_out_; | 118 bool sel_ldr_wait_timed_out_; |
195 bool start_nexe_done_; | 119 bool start_nexe_done_; |
196 bool nexe_started_ok_; | 120 bool nexe_started_ok_; |
197 | 121 |
198 NaClHandle bootstrap_channel_; | 122 NaClHandle bootstrap_channel_; |
199 }; | 123 }; |
200 | 124 |
201 } // namespace plugin | 125 } // namespace plugin |
202 | 126 |
203 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SERVICE_RUNTIME_H_ | 127 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SERVICE_RUNTIME_H_ |
OLD | NEW |