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

Side by Side Diff: components/nacl/renderer/plugin/srpc_params.cc

Issue 1569283002: NaCl cleanup: Remove SrpcParams and SrpcClient, which are unused now (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « components/nacl/renderer/plugin/srpc_params.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
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
4 * found in the LICENSE file.
5 */
6
7
8 #include "components/nacl/renderer/plugin/srpc_params.h"
9
10 #include <stddef.h>
11 #include <stdint.h>
12 #include <stdlib.h>
13 #include <string.h>
14
15 #include "native_client/src/shared/srpc/nacl_srpc.h"
16
17
18 namespace plugin {
19
20 namespace {
21
22 bool FillVec(NaClSrpcArg* vec[], const char* types) {
23 const size_t kLength = strlen(types);
24 if (kLength > NACL_SRPC_MAX_ARGS) {
25 return false;
26 }
27 // We use malloc/new here rather than new/delete, because the SRPC layer
28 // is written in C and hence will use malloc/free.
29 // This array will get deallocated by FreeArguments().
30 if (kLength > 0) {
31 NaClSrpcArg* args =
32 reinterpret_cast<NaClSrpcArg*>(malloc(kLength * sizeof(*args)));
33 if (NULL == args) {
34 return false;
35 }
36
37 memset(static_cast<void*>(args), 0, kLength * sizeof(*args));
38 for (size_t i = 0; i < kLength; ++i) {
39 vec[i] = &args[i];
40 args[i].tag = static_cast<NaClSrpcArgType>(types[i]);
41 }
42 }
43 vec[kLength] = NULL;
44 return true;
45 }
46
47 void FreeSrpcArg(NaClSrpcArg* arg) {
48 switch (arg->tag) {
49 case NACL_SRPC_ARG_TYPE_CHAR_ARRAY:
50 free(arg->arrays.carr);
51 break;
52 case NACL_SRPC_ARG_TYPE_DOUBLE_ARRAY:
53 free(arg->arrays.darr);
54 break;
55 case NACL_SRPC_ARG_TYPE_HANDLE:
56 break;
57 case NACL_SRPC_ARG_TYPE_INT_ARRAY:
58 free(arg->arrays.iarr);
59 break;
60 case NACL_SRPC_ARG_TYPE_LONG_ARRAY:
61 free(arg->arrays.larr);
62 break;
63 case NACL_SRPC_ARG_TYPE_STRING:
64 // All strings that are passed in SrpcArg must be allocated using
65 // malloc! We cannot use browser's allocation API
66 // since some of SRPC arguments is handled outside of the plugin code.
67 free(arg->arrays.str);
68 break;
69 case NACL_SRPC_ARG_TYPE_VARIANT_ARRAY:
70 if (arg->arrays.varr) {
71 for (uint32_t i = 0; i < arg->u.count; i++) {
72 FreeSrpcArg(&arg->arrays.varr[i]);
73 }
74 }
75 break;
76 case NACL_SRPC_ARG_TYPE_OBJECT:
77 // This is a pointer to a scriptable object and should be released
78 // by the browser
79 break;
80 case NACL_SRPC_ARG_TYPE_BOOL:
81 case NACL_SRPC_ARG_TYPE_DOUBLE:
82 case NACL_SRPC_ARG_TYPE_INT:
83 case NACL_SRPC_ARG_TYPE_LONG:
84 case NACL_SRPC_ARG_TYPE_INVALID:
85 default:
86 break;
87 }
88 }
89
90 void FreeArguments(NaClSrpcArg* vec[]) {
91 if (NULL == vec[0]) {
92 return;
93 }
94 for (NaClSrpcArg** argp = vec; *argp; ++argp) {
95 FreeSrpcArg(*argp);
96 }
97 // Free the vector containing the arguments themselves that was
98 // allocated with FillVec().
99 free(vec[0]);
100 }
101
102 } // namespace
103
104 bool SrpcParams::Init(const char* in_types, const char* out_types) {
105 if (!FillVec(ins_, in_types)) {
106 return false;
107 }
108 if (!FillVec(outs_, out_types)) {
109 FreeArguments(ins_);
110 return false;
111 }
112 return true;
113 }
114
115 void SrpcParams::FreeAll() {
116 FreeArguments(ins_);
117 FreeArguments(outs_);
118 memset(ins_, 0, sizeof(ins_));
119 memset(outs_, 0, sizeof(outs_));
120 }
121
122 } // namespace plugin
OLDNEW
« no previous file with comments | « components/nacl/renderer/plugin/srpc_params.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698