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

Side by Side Diff: ppapi/native_client/src/trusted/plugin/service_runtime.cc

Issue 268793002: Pepper: Move DoPostMessage out of trusted plugin. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix threading behavior Created 6 years, 7 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 /* 1 /*
2 * Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 * Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 #define NACL_LOG_MODULE_NAME "Plugin_ServiceRuntime" 7 #define NACL_LOG_MODULE_NAME "Plugin_ServiceRuntime"
8 8
9 #include "ppapi/native_client/src/trusted/plugin/service_runtime.h" 9 #include "ppapi/native_client/src/trusted/plugin/service_runtime.h"
10 10
(...skipping 15 matching lines...) Expand all
26 #include "native_client/src/shared/platform/nacl_sync.h" 26 #include "native_client/src/shared/platform/nacl_sync.h"
27 #include "native_client/src/shared/platform/nacl_sync_checked.h" 27 #include "native_client/src/shared/platform/nacl_sync_checked.h"
28 #include "native_client/src/shared/platform/nacl_sync_raii.h" 28 #include "native_client/src/shared/platform/nacl_sync_raii.h"
29 #include "native_client/src/shared/platform/scoped_ptr_refcount.h" 29 #include "native_client/src/shared/platform/scoped_ptr_refcount.h"
30 #include "native_client/src/trusted/desc/nacl_desc_imc.h" 30 #include "native_client/src/trusted/desc/nacl_desc_imc.h"
31 // remove when we no longer need to cast the DescWrapper below. 31 // remove when we no longer need to cast the DescWrapper below.
32 #include "native_client/src/trusted/desc/nacl_desc_io.h" 32 #include "native_client/src/trusted/desc/nacl_desc_io.h"
33 #include "native_client/src/trusted/desc/nrd_xfer.h" 33 #include "native_client/src/trusted/desc/nrd_xfer.h"
34 #include "native_client/src/trusted/nonnacl_util/sel_ldr_launcher.h" 34 #include "native_client/src/trusted/nonnacl_util/sel_ldr_launcher.h"
35 35
36 // This is here due to a Windows API collision; plugin.h through
37 // file_downloader.h transitively includes Instance.h which defines a
38 // PostMessage method, so this undef must appear before any of those.
39 #ifdef PostMessage
40 #undef PostMessage
41 #endif
42 #include "native_client/src/public/imc_types.h" 36 #include "native_client/src/public/imc_types.h"
43 #include "native_client/src/trusted/service_runtime/nacl_error_code.h" 37 #include "native_client/src/trusted/service_runtime/nacl_error_code.h"
44 #include "native_client/src/trusted/validator/nacl_file_info.h" 38 #include "native_client/src/trusted/validator/nacl_file_info.h"
45 39
46 #include "ppapi/c/pp_errors.h" 40 #include "ppapi/c/pp_errors.h"
47 #include "ppapi/cpp/core.h" 41 #include "ppapi/cpp/core.h"
48 #include "ppapi/cpp/completion_callback.h" 42 #include "ppapi/cpp/completion_callback.h"
49 43
50 #include "ppapi/native_client/src/trusted/plugin/plugin.h" 44 #include "ppapi/native_client/src/trusted/plugin/plugin.h"
51 #include "ppapi/native_client/src/trusted/plugin/plugin_error.h" 45 #include "ppapi/native_client/src/trusted/plugin/plugin_error.h"
52 #include "ppapi/native_client/src/trusted/plugin/pnacl_resources.h" 46 #include "ppapi/native_client/src/trusted/plugin/pnacl_resources.h"
53 #include "ppapi/native_client/src/trusted/plugin/sel_ldr_launcher_chrome.h" 47 #include "ppapi/native_client/src/trusted/plugin/sel_ldr_launcher_chrome.h"
54 #include "ppapi/native_client/src/trusted/plugin/srpc_client.h" 48 #include "ppapi/native_client/src/trusted/plugin/srpc_client.h"
49 #include "ppapi/native_client/src/trusted/plugin/utility.h"
55 #include "ppapi/native_client/src/trusted/weak_ref/call_on_main_thread.h" 50 #include "ppapi/native_client/src/trusted/weak_ref/call_on_main_thread.h"
56 51
57 namespace plugin { 52 namespace plugin {
58 53
59 class OpenManifestEntryAsyncCallback { 54 class OpenManifestEntryAsyncCallback {
60 public: 55 public:
61 OpenManifestEntryAsyncCallback(PP_OpenResourceCompletionCallback callback, 56 OpenManifestEntryAsyncCallback(PP_OpenResourceCompletionCallback callback,
62 void* callback_user_data) 57 void* callback_user_data)
63 : callback_(callback), callback_user_data_(callback_user_data) { 58 : callback_(callback), callback_user_data_(callback_user_data) {
64 } 59 }
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 214
220 void PluginReverseInterface::ShutDown() { 215 void PluginReverseInterface::ShutDown() {
221 NaClLog(4, "PluginReverseInterface::Shutdown: entered\n"); 216 NaClLog(4, "PluginReverseInterface::Shutdown: entered\n");
222 nacl::MutexLocker take(&mu_); 217 nacl::MutexLocker take(&mu_);
223 shutting_down_ = true; 218 shutting_down_ = true;
224 NaClXCondVarBroadcast(&cv_); 219 NaClXCondVarBroadcast(&cv_);
225 NaClLog(4, "PluginReverseInterface::Shutdown: broadcasted, exiting\n"); 220 NaClLog(4, "PluginReverseInterface::Shutdown: broadcasted, exiting\n");
226 } 221 }
227 222
228 void PluginReverseInterface::DoPostMessage(nacl::string message) { 223 void PluginReverseInterface::DoPostMessage(nacl::string message) {
229 PostMessageResource* continuation = new PostMessageResource(message); 224 std::string full_message = std::string("DEBUG_POSTMESSAGE:") + message;
230 CHECK(continuation != NULL); 225 GetNaClInterface()->PostMessageToJavaScript(plugin_->pp_instance(),
231 NaClLog(4, "PluginReverseInterface::DoPostMessage(%s)\n", message.c_str()); 226 full_message.c_str());
232 plugin::WeakRefCallOnMainThread(
233 anchor_,
234 0, /* delay in ms */
235 this,
236 &plugin::PluginReverseInterface::PostMessage_MainThreadContinuation,
237 continuation);
238 } 227 }
239 228
240 void PluginReverseInterface::StartupInitializationComplete() { 229 void PluginReverseInterface::StartupInitializationComplete() {
241 NaClLog(4, "PluginReverseInterface::StartupInitializationComplete\n"); 230 NaClLog(4, "PluginReverseInterface::StartupInitializationComplete\n");
242 if (init_done_cb_.pp_completion_callback().func != NULL) { 231 if (init_done_cb_.pp_completion_callback().func != NULL) {
243 NaClLog(4, 232 NaClLog(4,
244 "PluginReverseInterface::StartupInitializationComplete:" 233 "PluginReverseInterface::StartupInitializationComplete:"
245 " invoking CB\n"); 234 " invoking CB\n");
246 pp::Module::Get()->core()->CallOnMainThread(0, init_done_cb_, PP_OK); 235 pp::Module::Get()->core()->CallOnMainThread(0, init_done_cb_, PP_OK);
247 } else { 236 } else {
248 NaClLog(1, 237 NaClLog(1,
249 "PluginReverseInterface::StartupInitializationComplete:" 238 "PluginReverseInterface::StartupInitializationComplete:"
250 " init_done_cb_ not valid, skipping.\n"); 239 " init_done_cb_ not valid, skipping.\n");
251 } 240 }
252 } 241 }
253 242
254 void PluginReverseInterface::PostMessage_MainThreadContinuation(
255 PostMessageResource* p,
256 int32_t err) {
257 UNREFERENCED_PARAMETER(err);
258 NaClLog(4,
259 "PluginReverseInterface::PostMessage_MainThreadContinuation(%s)\n",
260 p->message.c_str());
261 plugin_->PostMessage(std::string("DEBUG_POSTMESSAGE:") + p->message);
262 }
263
264 // TODO(bsy): OpenManifestEntry should use the manifest to ResolveKey 243 // TODO(bsy): OpenManifestEntry should use the manifest to ResolveKey
265 // and invoke StreamAsFile with a completion callback that invokes 244 // and invoke StreamAsFile with a completion callback that invokes
266 // GetPOSIXFileDesc. 245 // GetPOSIXFileDesc.
267 bool PluginReverseInterface::OpenManifestEntry(nacl::string url_key, 246 bool PluginReverseInterface::OpenManifestEntry(nacl::string url_key,
268 struct NaClFileInfo* info) { 247 struct NaClFileInfo* info) {
269 bool op_complete = false; // NB: mu_ and cv_ also controls access to this! 248 bool op_complete = false; // NB: mu_ and cv_ also controls access to this!
270 // The to_open object is owned by the weak ref callback. Because this function 249 // The to_open object is owned by the weak ref callback. Because this function
271 // waits for the callback to finish, the to_open object will be deallocated on 250 // waits for the callback to finish, the to_open object will be deallocated on
272 // the main thread before this function can return. The pointers it contains 251 // the main thread before this function can return. The pointers it contains
273 // to stack variables will not leak. 252 // to stack variables will not leak.
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 877
899 nacl::string ServiceRuntime::GetCrashLogOutput() { 878 nacl::string ServiceRuntime::GetCrashLogOutput() {
900 if (NULL != subprocess_.get()) { 879 if (NULL != subprocess_.get()) {
901 return subprocess_->GetCrashLogOutput(); 880 return subprocess_->GetCrashLogOutput();
902 } else { 881 } else {
903 return std::string(); 882 return std::string();
904 } 883 }
905 } 884 }
906 885
907 } // namespace plugin 886 } // namespace plugin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698