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

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

Issue 183793007: Pepper: Cleanup in PepperReverseInterface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | « no previous file | 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
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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 int32_t err) { 130 int32_t err) {
131 UNREFERENCED_PARAMETER(err); 131 UNREFERENCED_PARAMETER(err);
132 NaClLog(4, 132 NaClLog(4,
133 "PluginReverseInterface::PostMessage_MainThreadContinuation(%s)\n", 133 "PluginReverseInterface::PostMessage_MainThreadContinuation(%s)\n",
134 p->message.c_str()); 134 p->message.c_str());
135 plugin_->PostMessage(std::string("DEBUG_POSTMESSAGE:") + p->message); 135 plugin_->PostMessage(std::string("DEBUG_POSTMESSAGE:") + p->message);
136 } 136 }
137 137
138 bool PluginReverseInterface::EnumerateManifestKeys( 138 bool PluginReverseInterface::EnumerateManifestKeys(
139 std::set<nacl::string>* out_keys) { 139 std::set<nacl::string>* out_keys) {
140 Manifest const* mp = manifest_; 140 return manifest_->GetFileKeys(out_keys);
141
142 if (!mp->GetFileKeys(out_keys)) {
143 return false;
144 }
145
146 return true;
147 } 141 }
148 142
149 // TODO(bsy): OpenManifestEntry should use the manifest to ResolveKey 143 // TODO(bsy): OpenManifestEntry should use the manifest to ResolveKey
150 // and invoke StreamAsFile with a completion callback that invokes 144 // and invoke StreamAsFile with a completion callback that invokes
151 // GetPOSIXFileDesc. 145 // GetPOSIXFileDesc.
152 bool PluginReverseInterface::OpenManifestEntry(nacl::string url_key, 146 bool PluginReverseInterface::OpenManifestEntry(nacl::string url_key,
153 struct NaClFileInfo* info) { 147 struct NaClFileInfo* info) {
154 ErrorInfo error_info; 148 ErrorInfo error_info;
155 bool op_complete = false; // NB: mu_ and cv_ also controls access to this! 149 bool op_complete = false; // NB: mu_ and cv_ also controls access to this!
156 // The to_open object is owned by the weak ref callback. Because this function 150 // The to_open object is owned by the weak ref callback. Because this function
157 // waits for the callback to finish, the to_open object will be deallocated on 151 // waits for the callback to finish, the to_open object will be deallocated on
158 // the main thread before this function can return. The pointers it contains 152 // the main thread before this function can return. The pointers it contains
159 // to stack variables will not leak. 153 // to stack variables will not leak.
160 OpenManifestEntryResource* to_open = 154 OpenManifestEntryResource* to_open =
161 new OpenManifestEntryResource(url_key, info, 155 new OpenManifestEntryResource(url_key, info,
162 &error_info, &op_complete); 156 &error_info, &op_complete);
163 CHECK(to_open != NULL); 157 CHECK(to_open != NULL);
164 NaClLog(4, "PluginReverseInterface::OpenManifestEntry: %s\n", 158 NaClLog(4, "PluginReverseInterface::OpenManifestEntry: %s\n",
165 url_key.c_str()); 159 url_key.c_str());
166 // This assumes we are not on the main thread. If false, we deadlock. 160 // This assumes we are not on the main thread. If false, we deadlock.
167 plugin::WeakRefCallOnMainThread( 161 plugin::WeakRefCallOnMainThread(
168 anchor_, 162 anchor_,
169 0, 163 0,
170 this, 164 this,
171 &plugin::PluginReverseInterface::OpenManifestEntry_MainThreadContinuation, 165 &plugin::PluginReverseInterface::OpenManifestEntry_MainThreadContinuation,
172 to_open); 166 to_open);
173 NaClLog(4, 167 NaClLog(4,
174 "PluginReverseInterface::OpenManifestEntry:" 168 "PluginReverseInterface::OpenManifestEntry:"
175 " waiting on main thread\n"); 169 " waiting on main thread\n");
176 bool shutting_down; 170
177 do { 171 {
178 nacl::MutexLocker take(&mu_); 172 nacl::MutexLocker take(&mu_);
179 for (;;) { 173 while (!shutting_down_ && !op_complete)
174 NaClXCondVarWait(&cv_, &mu_);
175 NaClLog(4, "PluginReverseInterface::OpenManifestEntry: done!\n");
176 if (shutting_down_) {
180 NaClLog(4, 177 NaClLog(4,
181 "PluginReverseInterface::OpenManifestEntry:" 178 "PluginReverseInterface::OpenManifestEntry:"
182 " got lock, checking shutdown and completion: (%s, %s)\n", 179 " plugin is shutting down\n");
183 shutting_down_ ? "yes" : "no", 180 return false;
184 op_complete ? "yes" : "no");
185 shutting_down = shutting_down_;
186 if (op_complete || shutting_down) {
187 NaClLog(4,
188 "PluginReverseInterface::OpenManifestEntry:"
189 " done!\n");
190 break;
191 }
192 NaClXCondVarWait(&cv_, &mu_);
193 } 181 }
194 } while (0);
195 if (shutting_down) {
196 NaClLog(4,
197 "PluginReverseInterface::OpenManifestEntry:"
198 " plugin is shutting down\n");
199 return false;
200 } 182 }
201 // out_desc has the returned descriptor if successful, else -1.
202 183
203 // The caller is responsible for not closing *out_desc. If it is 184 // info->desc has the returned descriptor if successful, else -1.
185
186 // The caller is responsible for not closing info->desc. If it is
204 // closed prematurely, then another open could re-use the OS 187 // closed prematurely, then another open could re-use the OS
205 // descriptor, confusing the opened_ map. If the caller is going to 188 // descriptor, confusing the opened_ map. If the caller is going to
206 // want to make a NaClDesc object and transfer it etc., then the 189 // want to make a NaClDesc object and transfer it etc., then the
207 // caller should DUP the descriptor (but remember the original 190 // caller should DUP the descriptor (but remember the original
208 // value) for use by the NaClDesc object, which closes when the 191 // value) for use by the NaClDesc object, which closes when the
209 // object is destroyed. 192 // object is destroyed.
210 NaClLog(4, 193 NaClLog(4,
211 "PluginReverseInterface::OpenManifestEntry:" 194 "PluginReverseInterface::OpenManifestEntry: info->desc = %d\n",
212 " *out_desc = %d\n",
213 info->desc); 195 info->desc);
214 if (info->desc == -1) { 196 if (info->desc == -1) {
215 // TODO(bsy,ncbray): what else should we do with the error? This 197 // TODO(bsy,ncbray): what else should we do with the error? This
216 // is a runtime error that may simply be a programming error in 198 // is a runtime error that may simply be a programming error in
217 // the untrusted code, or it may be something else wrong w/ the 199 // the untrusted code, or it may be something else wrong w/ the
218 // manifest. 200 // manifest.
219 NaClLog(4, 201 NaClLog(4,
220 "OpenManifestEntry: failed for key %s, code %d (%s)\n", 202 "OpenManifestEntry: failed for key %s, code %d (%s)\n",
221 url_key.c_str(), 203 url_key.c_str(),
222 error_info.error_code(), 204 error_info.error_code(),
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 *p->op_complete_ptr = true; 334 *p->op_complete_ptr = true;
353 NaClXCondVarBroadcast(&cv_); 335 NaClXCondVarBroadcast(&cv_);
354 } 336 }
355 337
356 bool PluginReverseInterface::CloseManifestEntry(int32_t desc) { 338 bool PluginReverseInterface::CloseManifestEntry(int32_t desc) {
357 bool op_complete = false; 339 bool op_complete = false;
358 bool op_result; 340 bool op_result;
359 CloseManifestEntryResource* to_close = 341 CloseManifestEntryResource* to_close =
360 new CloseManifestEntryResource(desc, &op_complete, &op_result); 342 new CloseManifestEntryResource(desc, &op_complete, &op_result);
361 343
362 bool shutting_down;
363 plugin::WeakRefCallOnMainThread( 344 plugin::WeakRefCallOnMainThread(
364 anchor_, 345 anchor_,
365 0, 346 0,
366 this, 347 this,
367 &plugin::PluginReverseInterface:: 348 &plugin::PluginReverseInterface::
368 CloseManifestEntry_MainThreadContinuation, 349 CloseManifestEntry_MainThreadContinuation,
369 to_close); 350 to_close);
351
370 // wait for completion or surf-away. 352 // wait for completion or surf-away.
371 do { 353 {
372 nacl::MutexLocker take(&mu_); 354 nacl::MutexLocker take(&mu_);
373 for (;;) { 355 while (!shutting_down_ && !op_complete)
374 shutting_down = shutting_down_;
375 if (op_complete || shutting_down) {
376 break;
377 }
378 NaClXCondVarWait(&cv_, &mu_); 356 NaClXCondVarWait(&cv_, &mu_);
379 } 357 if (shutting_down_)
380 } while (0); 358 return false;
359 }
381 360
382 if (shutting_down) return false;
383 // op_result true if close was successful; false otherwise (e.g., bad desc). 361 // op_result true if close was successful; false otherwise (e.g., bad desc).
384 return op_result; 362 return op_result;
385 } 363 }
386 364
387 void PluginReverseInterface::CloseManifestEntry_MainThreadContinuation( 365 void PluginReverseInterface::CloseManifestEntry_MainThreadContinuation(
388 CloseManifestEntryResource* cls, 366 CloseManifestEntryResource* cls,
389 int32_t err) { 367 int32_t err) {
390 UNREFERENCED_PARAMETER(err); 368 UNREFERENCED_PARAMETER(err);
391 369
392 nacl::MutexLocker take(&mu_); 370 nacl::MutexLocker take(&mu_);
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 717
740 nacl::string ServiceRuntime::GetCrashLogOutput() { 718 nacl::string ServiceRuntime::GetCrashLogOutput() {
741 if (NULL != subprocess_.get()) { 719 if (NULL != subprocess_.get()) {
742 return subprocess_->GetCrashLogOutput(); 720 return subprocess_->GetCrashLogOutput();
743 } else { 721 } else {
744 return std::string(); 722 return std::string();
745 } 723 }
746 } 724 }
747 725
748 } // namespace plugin 726 } // namespace plugin
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698