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

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

Issue 7216027: typesafe call-on-main-thread interface. no cast to/from void* required. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: '' Created 9 years, 6 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/service_runtime.h ('k') | src/trusted/weak_ref/call_on_main_thread.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. 2 * Copyright (c) 2011 The Native Client 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 #include "native_client/src/trusted/plugin/service_runtime.h" 7 #include "native_client/src/trusted/plugin/service_runtime.h"
8 8
9 #include <utility> 9 #include <utility>
10 #include <map> 10 #include <map>
(...skipping 14 matching lines...) Expand all
25 25
26 #include "native_client/src/trusted/plugin/browser_interface.h" 26 #include "native_client/src/trusted/plugin/browser_interface.h"
27 #include "native_client/src/trusted/plugin/connected_socket.h" 27 #include "native_client/src/trusted/plugin/connected_socket.h"
28 #include "native_client/src/trusted/plugin/plugin.h" 28 #include "native_client/src/trusted/plugin/plugin.h"
29 #include "native_client/src/trusted/plugin/scriptable_handle.h" 29 #include "native_client/src/trusted/plugin/scriptable_handle.h"
30 #include "native_client/src/trusted/plugin/shared_memory.h" 30 #include "native_client/src/trusted/plugin/shared_memory.h"
31 #include "native_client/src/trusted/plugin/socket_address.h" 31 #include "native_client/src/trusted/plugin/socket_address.h"
32 #include "native_client/src/trusted/plugin/srt_socket.h" 32 #include "native_client/src/trusted/plugin/srt_socket.h"
33 #include "native_client/src/trusted/plugin/utility.h" 33 #include "native_client/src/trusted/plugin/utility.h"
34 34
35 #include "native_client/src/trusted/weak_ref/call_on_main_thread.h"
36
35 #include "native_client/src/trusted/service_runtime/nacl_error_code.h" 37 #include "native_client/src/trusted/service_runtime/nacl_error_code.h"
36 #include "native_client/src/trusted/service_runtime/include/sys/nacl_imc_api.h" 38 #include "native_client/src/trusted/service_runtime/include/sys/nacl_imc_api.h"
37 39
38 #include "ppapi/c/pp_errors.h" 40 #include "ppapi/c/pp_errors.h"
39 #include "ppapi/cpp/core.h" 41 #include "ppapi/cpp/core.h"
40 #include "ppapi/cpp/completion_callback.h" 42 #include "ppapi/cpp/completion_callback.h"
41 43
42 using std::vector; 44 using std::vector;
43 45
44 namespace plugin { 46 namespace plugin {
45 47
46 typedef std::pair<Plugin*, nacl::string> LogCallbackData; 48 typedef std::pair<Plugin*, nacl::string> LogCallbackData;
47 49
48 struct LogToJavaScriptConsoleResource { 50 struct LogToJavaScriptConsoleResource {
49 public: 51 public:
50 LogToJavaScriptConsoleResource(std::string msg, Plugin* plugin_ptr) 52 LogToJavaScriptConsoleResource(std::string msg, Plugin* plugin_ptr)
51 : message(msg), 53 : message(msg),
52 plugin(plugin_ptr) {} 54 plugin(plugin_ptr) {}
53 std::string message; 55 std::string message;
54 Plugin* plugin; 56 Plugin* plugin;
55 }; 57 };
56 58
57 // Must be called on the main thread. 59 // Must be called on the main thread.
58 void LogToJavaScriptConsole(nacl::WeakRef<LogToJavaScriptConsoleResource>* wr, 60 void LogToJavaScriptConsole(LogToJavaScriptConsoleResource* p,
59 int32_t err) { 61 int32_t err) {
60 UNREFERENCED_PARAMETER(err); 62 UNREFERENCED_PARAMETER(err);
61 nacl::scoped_ptr<LogToJavaScriptConsoleResource> p;
62 wr->ReleaseAndUnref(&p);
63 if (p == NULL) {
64 NaClLog(1, "LogToJavaScriptConsole: Weak ref died\n");
65 return;
66 }
67 NaClLog(1, "LogToJavaScriptConsole: Weak ref okay: %p\n",
68 reinterpret_cast<void*>(p.get()));
69 p->plugin->browser_interface()->AddToConsole(p->plugin->instance_id(), 63 p->plugin->browser_interface()->AddToConsole(p->plugin->instance_id(),
70 p->message); 64 p->message);
71 } 65 }
72 66
73 void PluginReverseInterface::Log(nacl::string message) { 67 void PluginReverseInterface::Log(nacl::string message) {
74 (void) WeakRefCompletionCallback(anchor_, 0, 68 (void) plugin::WeakRefCallOnMainThread(
75 LogToJavaScriptConsole, 69 anchor_,
76 new LogToJavaScriptConsoleResource( 70 0, /* delay in ms */
77 message, plugin_)); 71 LogToJavaScriptConsole,
72 new LogToJavaScriptConsoleResource(
73 message, plugin_));
78 } 74 }
79 75
80 ServiceRuntime::ServiceRuntime(Plugin* plugin) 76 ServiceRuntime::ServiceRuntime(Plugin* plugin)
81 : default_socket_address_(NULL), 77 : default_socket_address_(NULL),
82 plugin_(plugin), 78 plugin_(plugin),
83 browser_interface_(plugin->browser_interface()), 79 browser_interface_(plugin->browser_interface()),
84 runtime_channel_(NULL), 80 runtime_channel_(NULL),
85 reverse_service_(NULL), 81 reverse_service_(NULL),
86 subprocess_(NULL), 82 subprocess_(NULL),
87 async_receive_desc_(NULL), 83 async_receive_desc_(NULL),
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 SocketAddress::New(plugin, descs[0])); 396 SocketAddress::New(plugin, descs[0]));
401 cleanup: 397 cleanup:
402 // TODO(sehr,mseaborn): use scoped_ptr for management of DescWrappers. 398 // TODO(sehr,mseaborn): use scoped_ptr for management of DescWrappers.
403 delete imc_desc; 399 delete imc_desc;
404 PLUGIN_PRINTF(("ServiceRuntime::GetSocketAddress (return %p)\n", 400 PLUGIN_PRINTF(("ServiceRuntime::GetSocketAddress (return %p)\n",
405 static_cast<void*>(retval))); 401 static_cast<void*>(retval)));
406 return retval; 402 return retval;
407 } 403 }
408 404
409 } // namespace plugin 405 } // namespace plugin
OLDNEW
« no previous file with comments | « src/trusted/plugin/service_runtime.h ('k') | src/trusted/weak_ref/call_on_main_thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698