OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "native_client/src/trusted/plugin/pnacl_coordinator.h" | 5 #include "native_client/src/trusted/plugin/pnacl_coordinator.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "native_client/src/include/portability_io.h" | 10 #include "native_client/src/include/portability_io.h" |
11 #include "native_client/src/shared/platform/nacl_check.h" | 11 #include "native_client/src/shared/platform/nacl_check.h" |
12 #include "native_client/src/trusted/plugin/local_temp_file.h" | 12 #include "native_client/src/trusted/plugin/local_temp_file.h" |
13 #include "native_client/src/trusted/plugin/manifest.h" | 13 #include "native_client/src/trusted/plugin/manifest.h" |
14 #include "native_client/src/trusted/plugin/plugin.h" | 14 #include "native_client/src/trusted/plugin/plugin.h" |
15 #include "native_client/src/trusted/plugin/plugin_error.h" | 15 #include "native_client/src/trusted/plugin/plugin_error.h" |
16 #include "native_client/src/trusted/plugin/pnacl_translate_thread.h" | 16 #include "native_client/src/trusted/plugin/pnacl_translate_thread.h" |
17 #include "native_client/src/trusted/plugin/service_runtime.h" | 17 #include "native_client/src/trusted/plugin/service_runtime.h" |
18 #include "native_client/src/trusted/plugin/temporary_file.h" | 18 #include "native_client/src/trusted/plugin/temporary_file.h" |
| 19 #include "native_client/src/trusted/service_runtime/include/sys/stat.h" |
19 | 20 |
20 #include "ppapi/c/pp_bool.h" | |
21 #include "ppapi/c/pp_errors.h" | 21 #include "ppapi/c/pp_errors.h" |
22 #include "ppapi/c/ppb_file_io.h" | 22 #include "ppapi/c/ppb_file_io.h" |
23 #include "ppapi/cpp/file_io.h" | 23 #include "ppapi/cpp/file_io.h" |
24 | 24 |
25 namespace { | 25 namespace { |
26 const char kPnaclTempDir[] = "/.pnacl"; | 26 const char kPnaclTempDir[] = "/.pnacl"; |
27 const uint32_t kCopyBufSize = 512 << 10; | |
28 } | 27 } |
29 | 28 |
30 namespace plugin { | 29 namespace plugin { |
31 | 30 |
32 ////////////////////////////////////////////////////////////////////// | 31 ////////////////////////////////////////////////////////////////////// |
33 // Pnacl-specific manifest support. | 32 // Pnacl-specific manifest support. |
34 ////////////////////////////////////////////////////////////////////// | 33 ////////////////////////////////////////////////////////////////////// |
35 class ExtensionManifest : public Manifest { | 34 class ExtensionManifest : public Manifest { |
36 public: | 35 public: |
37 explicit ExtensionManifest(const pp::URLUtil_Dev* url_util) | 36 explicit ExtensionManifest(const pp::URLUtil_Dev* url_util) |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 PnaclCoordinator* PnaclCoordinator::BitcodeToNative( | 175 PnaclCoordinator* PnaclCoordinator::BitcodeToNative( |
177 Plugin* plugin, | 176 Plugin* plugin, |
178 const nacl::string& pexe_url, | 177 const nacl::string& pexe_url, |
179 const nacl::string& cache_identity, | 178 const nacl::string& cache_identity, |
180 const pp::CompletionCallback& translate_notify_callback) { | 179 const pp::CompletionCallback& translate_notify_callback) { |
181 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (plugin=%p, pexe=%s)\n", | 180 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (plugin=%p, pexe=%s)\n", |
182 static_cast<void*>(plugin), pexe_url.c_str())); | 181 static_cast<void*>(plugin), pexe_url.c_str())); |
183 PnaclCoordinator* coordinator = | 182 PnaclCoordinator* coordinator = |
184 new PnaclCoordinator(plugin, pexe_url, | 183 new PnaclCoordinator(plugin, pexe_url, |
185 cache_identity, translate_notify_callback); | 184 cache_identity, translate_notify_callback); |
186 coordinator->off_the_record_ = | 185 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (manifest=%p)\n", |
187 plugin->nacl_interface()->IsOffTheRecord(); | 186 reinterpret_cast<const void*>(coordinator->manifest_.get()))); |
188 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeToNative (manifest=%p, " | |
189 "off_the_record=%b)\n", | |
190 reinterpret_cast<const void*>(coordinator->manifest_.get()), | |
191 coordinator->off_the_record_)); | |
192 | |
193 // Load llc and ld. | 187 // Load llc and ld. |
194 std::vector<nacl::string> resource_urls; | 188 std::vector<nacl::string> resource_urls; |
195 resource_urls.push_back(PnaclUrls::GetLlcUrl()); | 189 resource_urls.push_back(PnaclUrls::GetLlcUrl()); |
196 resource_urls.push_back(PnaclUrls::GetLdUrl()); | 190 resource_urls.push_back(PnaclUrls::GetLdUrl()); |
197 pp::CompletionCallback resources_cb = | 191 pp::CompletionCallback resources_cb = |
198 coordinator->callback_factory_.NewCallback( | 192 coordinator->callback_factory_.NewCallback( |
199 &PnaclCoordinator::ResourcesDidLoad); | 193 &PnaclCoordinator::ResourcesDidLoad); |
200 coordinator->resources_.reset( | 194 coordinator->resources_.reset( |
201 new PnaclResources(plugin, | 195 new PnaclResources(plugin, |
202 coordinator, | 196 coordinator, |
(...skipping 30 matching lines...) Expand all Loading... |
233 const nacl::string& pexe_url, | 227 const nacl::string& pexe_url, |
234 const nacl::string& cache_identity, | 228 const nacl::string& cache_identity, |
235 const pp::CompletionCallback& translate_notify_callback) | 229 const pp::CompletionCallback& translate_notify_callback) |
236 : translate_finish_error_(PP_OK), | 230 : translate_finish_error_(PP_OK), |
237 plugin_(plugin), | 231 plugin_(plugin), |
238 translate_notify_callback_(translate_notify_callback), | 232 translate_notify_callback_(translate_notify_callback), |
239 file_system_(new pp::FileSystem(plugin, PP_FILESYSTEMTYPE_LOCALTEMPORARY)), | 233 file_system_(new pp::FileSystem(plugin, PP_FILESYSTEMTYPE_LOCALTEMPORARY)), |
240 manifest_(new ExtensionManifest(plugin->url_util())), | 234 manifest_(new ExtensionManifest(plugin->url_util())), |
241 pexe_url_(pexe_url), | 235 pexe_url_(pexe_url), |
242 cache_identity_(cache_identity), | 236 cache_identity_(cache_identity), |
243 error_already_reported_(false), | 237 error_already_reported_(false) { |
244 off_the_record_(false) { | |
245 PLUGIN_PRINTF(("PnaclCoordinator::PnaclCoordinator (this=%p, plugin=%p)\n", | 238 PLUGIN_PRINTF(("PnaclCoordinator::PnaclCoordinator (this=%p, plugin=%p)\n", |
246 static_cast<void*>(this), static_cast<void*>(plugin))); | 239 static_cast<void*>(this), static_cast<void*>(plugin))); |
247 callback_factory_.Initialize(this); | 240 callback_factory_.Initialize(this); |
248 ld_manifest_.reset(new PnaclLDManifest(plugin_->manifest(), manifest_.get())); | 241 ld_manifest_.reset(new PnaclLDManifest(plugin_->manifest(), manifest_.get())); |
249 } | 242 } |
250 | 243 |
251 PnaclCoordinator::~PnaclCoordinator() { | 244 PnaclCoordinator::~PnaclCoordinator() { |
252 PLUGIN_PRINTF(("PnaclCoordinator::~PnaclCoordinator (this=%p, " | 245 PLUGIN_PRINTF(("PnaclCoordinator::~PnaclCoordinator (this=%p, " |
253 "translate_thread=%p\n", | 246 "translate_thread=%p\n", |
254 static_cast<void*>(this), translate_thread_.get())); | 247 static_cast<void*>(this), translate_thread_.get())); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 } else { | 287 } else { |
295 PLUGIN_PRINTF(("PnaclCoordinator::ReportPpapiError an earlier error was " | 288 PLUGIN_PRINTF(("PnaclCoordinator::ReportPpapiError an earlier error was " |
296 "already reported -- Skipping.\n")); | 289 "already reported -- Skipping.\n")); |
297 } | 290 } |
298 } | 291 } |
299 | 292 |
300 // Signal that Pnacl translation completed normally. | 293 // Signal that Pnacl translation completed normally. |
301 void PnaclCoordinator::TranslateFinished(int32_t pp_error) { | 294 void PnaclCoordinator::TranslateFinished(int32_t pp_error) { |
302 PLUGIN_PRINTF(("PnaclCoordinator::TranslateFinished (pp_error=%" | 295 PLUGIN_PRINTF(("PnaclCoordinator::TranslateFinished (pp_error=%" |
303 NACL_PRId32")\n", pp_error)); | 296 NACL_PRId32")\n", pp_error)); |
304 // Bail out if there was an earlier error (e.g., pexe load failure). | 297 // Save the translate error code, and inspect after cleaning up junk files. |
305 if (translate_finish_error_ != PP_OK) { | 298 // Note: If there was a surfaway and the file objects were actually |
306 ReportPpapiError(translate_finish_error_); | 299 // destroyed, then we are in trouble since the obj_file_, nexe_file_, |
307 return; | 300 // etc. may have been destroyed. |
| 301 // TODO(jvoung,sehr): Fix. |
| 302 // If there was an error already set (e.g. pexe load failure) then we want |
| 303 // to use the first one, (which might be something useful) rather than |
| 304 // the one from the compiler, (which is always just PP_ERROR_FAILED) |
| 305 if (translate_finish_error_ == PP_OK) translate_finish_error_ = pp_error; |
| 306 |
| 307 // Close the nexe temporary file. |
| 308 if (nexe_file_ != NULL) { |
| 309 pp::CompletionCallback cb = |
| 310 callback_factory_.NewCallback(&PnaclCoordinator::NexeFileWasClosed); |
| 311 nexe_file_->Close(cb); |
308 } | 312 } |
309 // Bail out if there is an error from the translation thread. | 313 } |
| 314 |
| 315 void PnaclCoordinator::NexeFileWasClosed(int32_t pp_error) { |
| 316 PLUGIN_PRINTF(("PnaclCoordinator::NexeFileWasClosed (pp_error=%" |
| 317 NACL_PRId32")\n", pp_error)); |
310 if (pp_error != PP_OK) { | 318 if (pp_error != PP_OK) { |
311 ReportPpapiError(pp_error); | 319 ReportPpapiError(pp_error); |
312 return; | 320 return; |
313 } | 321 } |
| 322 // Now that cleanup of the obj file is done, check the old TranslateFinished |
| 323 // error code to see if we should proceed normally or not. |
| 324 if (translate_finish_error_ != PP_OK) { |
| 325 pp::CompletionCallback cb = |
| 326 callback_factory_.NewCallback(&PnaclCoordinator::NexeFileWasDeleted); |
| 327 nexe_file_->Delete(cb); |
| 328 return; |
| 329 } |
314 | 330 |
315 // The nexe is written to the temp_nexe_file_. We must Reset() the file | 331 // Rename the nexe file to the cache id. |
316 // pointer to be able to read it again from the beginning. | 332 if (cache_identity_ != "") { |
317 temp_nexe_file_->Reset(); | 333 pp::CompletionCallback cb = |
318 | 334 callback_factory_.NewCallback(&PnaclCoordinator::NexeFileWasRenamed); |
319 if (cache_identity_ != "" && cached_nexe_file_ != NULL) { | 335 nexe_file_->Rename(cache_identity_, cb); |
320 // We are using a cache, but had a cache miss, which is why we did the | |
321 // translation. Reset cached_nexe_file_ to have a random name, | |
322 // for scratch purposes, before renaming to the final cache_identity_. | |
323 cached_nexe_file_.reset(new LocalTempFile(plugin_, file_system_.get(), | |
324 nacl::string(kPnaclTempDir))); | |
325 pp::CompletionCallback cb = callback_factory_.NewCallback( | |
326 &PnaclCoordinator::CachedNexeOpenedForWrite); | |
327 cached_nexe_file_->OpenWrite(cb); | |
328 } else { | 336 } else { |
329 // For now, tolerate bitcode that is missing a cache identity, and | 337 // For now tolerate bitcode that is missing a cache identity. |
330 // tolerate the lack of caching in incognito mode. | 338 PLUGIN_PRINTF(("PnaclCoordinator -- WARNING: missing cache identity," |
331 PLUGIN_PRINTF(("PnaclCoordinator -- not caching.\n")); | 339 " not caching.\n")); |
332 NexeReadDidOpen(PP_OK); | 340 NexeFileWasRenamed(PP_OK); |
333 } | 341 } |
334 } | 342 } |
335 | 343 |
336 void PnaclCoordinator::CachedNexeOpenedForWrite(int32_t pp_error) { | |
337 if (pp_error != PP_OK) { | |
338 ReportPpapiError(pp_error, "Failed to open cache file for write."); | |
339 return; | |
340 } | |
341 | |
342 // Copy the contents from temp_nexe_file_ -> cached_nexe_file_, | |
343 // then rename the cached_nexe_file_ file to the cache id. | |
344 int64_t cur_offset = 0; | |
345 nacl::DescWrapper* read_wrapper = temp_nexe_file_->read_wrapper(); | |
346 char buf[kCopyBufSize]; | |
347 ssize_t num_read = read_wrapper->Read(buf, sizeof buf); | |
348 // Hit EOF or something. | |
349 if (num_read == 0) { | |
350 NexeWasCopiedToCache(PP_OK); | |
351 return; | |
352 } | |
353 if (num_read < 0) { | |
354 PLUGIN_PRINTF(("PnaclCoordinator::CachedNexeOpenedForWrite read failed " | |
355 "(error=%"NACL_PRId32")\n", num_read)); | |
356 NexeWasCopiedToCache(PP_ERROR_FAILED); | |
357 return; | |
358 } | |
359 pp::CompletionCallback cb = callback_factory_.NewCallback( | |
360 &PnaclCoordinator::DidCopyNexeToCachePartial, num_read, cur_offset); | |
361 cached_nexe_file_->write_file_io()->Write(cur_offset, buf, num_read, cb); | |
362 } | |
363 | |
364 void PnaclCoordinator::DidCopyNexeToCachePartial(int32_t pp_error, | |
365 int32_t num_read_prev, | |
366 int64_t cur_offset) { | |
367 PLUGIN_PRINTF(("PnaclCoordinator::DidCopyNexeToCachePartial " | |
368 "(pp_error=%"NACL_PRId32", num_read_prev=%"NACL_PRId32"" | |
369 ", cur_offset=%"NACL_PRId64").\n", | |
370 pp_error, num_read_prev, cur_offset)); | |
371 // Assume we are done. | |
372 if (pp_error == PP_OK) { | |
373 NexeWasCopiedToCache(PP_OK); | |
374 return; | |
375 } | |
376 if (pp_error < PP_OK) { | |
377 PLUGIN_PRINTF(("PnaclCoordinator::DidCopyNexeToCachePartial failed (err=%" | |
378 NACL_PRId32")\n", pp_error)); | |
379 NexeWasCopiedToCache(pp_error); | |
380 return; | |
381 } | |
382 | |
383 // Check if we wrote as much as we read. | |
384 nacl::DescWrapper* read_wrapper = temp_nexe_file_->read_wrapper(); | |
385 if (pp_error != num_read_prev) { | |
386 PLUGIN_PRINTF(("PnaclCoordinator::DidCopyNexeToCachePartial partial " | |
387 "write (bytes_written=%"NACL_PRId32" vs " | |
388 "read=%"NACL_PRId32")\n", pp_error, num_read_prev)); | |
389 CHECK(pp_error < num_read_prev); | |
390 // Seek back to re-read the bytes that were not written. | |
391 nacl_off64_t seek_result = | |
392 read_wrapper->Seek(pp_error - num_read_prev, SEEK_CUR); | |
393 if (seek_result < 0) { | |
394 PLUGIN_PRINTF(("PnaclCoordinator::DidCopyNexeToCachePartial seek failed " | |
395 "(err=%"NACL_PRId64")\n", seek_result)); | |
396 NexeWasCopiedToCache(PP_ERROR_FAILED); | |
397 return; | |
398 } | |
399 } | |
400 | |
401 int64_t next_offset = cur_offset + pp_error; | |
402 char buf[kCopyBufSize]; | |
403 ssize_t num_read = read_wrapper->Read(buf, sizeof buf); | |
404 PLUGIN_PRINTF(("PnaclCoordinator::DidCopyNexeToCachePartial read (bytes=%" | |
405 NACL_PRId32")\n", num_read)); | |
406 // Hit EOF or something. | |
407 if (num_read == 0) { | |
408 NexeWasCopiedToCache(PP_OK); | |
409 return; | |
410 } | |
411 if (num_read < 0) { | |
412 PLUGIN_PRINTF(("PnaclCoordinator::DidCopyNexeToCachePartial read failed " | |
413 "(error=%"NACL_PRId32")\n", num_read)); | |
414 NexeWasCopiedToCache(PP_ERROR_FAILED); | |
415 return; | |
416 } | |
417 pp::CompletionCallback cb = callback_factory_.NewCallback( | |
418 &PnaclCoordinator::DidCopyNexeToCachePartial, num_read, next_offset); | |
419 PLUGIN_PRINTF(("PnaclCoordinator::CopyNexeToCache Writing (bytes=%d, " | |
420 "buf=%p, file_io=%p)\n", num_read, buf, | |
421 cached_nexe_file_->write_file_io())); | |
422 cached_nexe_file_->write_file_io()->Write(next_offset, buf, num_read, cb); | |
423 } | |
424 | |
425 void PnaclCoordinator::NexeWasCopiedToCache(int32_t pp_error) { | |
426 if (pp_error != PP_OK) { | |
427 // TODO(jvoung): This should probably try to delete the cache file | |
428 // before returning... | |
429 ReportPpapiError(pp_error, "Failed to copy nexe to cache."); | |
430 return; | |
431 } | |
432 // Rename the cached_nexe_file_ file to the cache id, to finalize. | |
433 pp::CompletionCallback cb = | |
434 callback_factory_.NewCallback(&PnaclCoordinator::NexeFileWasRenamed); | |
435 cached_nexe_file_->Rename(cache_identity_, cb); | |
436 } | |
437 | |
438 void PnaclCoordinator::NexeFileWasRenamed(int32_t pp_error) { | 344 void PnaclCoordinator::NexeFileWasRenamed(int32_t pp_error) { |
439 PLUGIN_PRINTF(("PnaclCoordinator::NexeFileWasRenamed (pp_error=%" | 345 PLUGIN_PRINTF(("PnaclCoordinator::NexeFileWasRenamed (pp_error=%" |
440 NACL_PRId32")\n", pp_error)); | 346 NACL_PRId32")\n", pp_error)); |
441 // NOTE: if the file already existed, it looks like the rename will | 347 // NOTE: if the file already existed, it looks like the rename will |
442 // happily succeed. However, we should add a test for this. | 348 // happily succeed. However, we should add a test for this. |
443 if (pp_error != PP_OK) { | 349 if (pp_error != PP_OK) { |
444 ReportPpapiError(pp_error, "Failed to place cached bitcode translation."); | 350 ReportPpapiError(pp_error, "Failed to place cached bitcode translation."); |
445 return; | 351 return; |
446 } | 352 } |
447 | 353 nexe_file_->FinishRename(); |
448 cached_nexe_file_->FinishRename(); | 354 // Open the nexe temporary file for reading. |
449 // Open the cache file for reading. | |
450 pp::CompletionCallback cb = | 355 pp::CompletionCallback cb = |
451 callback_factory_.NewCallback(&PnaclCoordinator::NexeReadDidOpen); | 356 callback_factory_.NewCallback(&PnaclCoordinator::NexeReadDidOpen); |
452 cached_nexe_file_->OpenRead(cb); | 357 nexe_file_->OpenRead(cb); |
453 } | 358 } |
454 | 359 |
455 void PnaclCoordinator::NexeReadDidOpen(int32_t pp_error) { | 360 void PnaclCoordinator::NexeReadDidOpen(int32_t pp_error) { |
456 PLUGIN_PRINTF(("PnaclCoordinator::NexeReadDidOpen (pp_error=%" | 361 PLUGIN_PRINTF(("PnaclCoordinator::NexeReadDidOpen (pp_error=%" |
457 NACL_PRId32")\n", pp_error)); | 362 NACL_PRId32")\n", pp_error)); |
458 if (pp_error != PP_OK) { | 363 if (pp_error != PP_OK) { |
459 ReportPpapiError(pp_error, "Failed to open translated nexe."); | 364 ReportPpapiError(pp_error, "Failed to open translated nexe."); |
460 return; | 365 return; |
461 } | 366 } |
462 | 367 // Transfer ownership of the nexe wrapper to the coordinator. |
463 // Transfer ownership of cache/temp file's wrapper to the coordinator. | 368 translated_fd_.reset(nexe_file_->release_read_wrapper()); |
464 if (cached_nexe_file_ != NULL) { | |
465 translated_fd_.reset(cached_nexe_file_->release_read_wrapper()); | |
466 } else { | |
467 translated_fd_.reset(temp_nexe_file_->release_read_wrapper()); | |
468 } | |
469 plugin_->EnqueueProgressEvent(Plugin::kProgressEventProgress); | 369 plugin_->EnqueueProgressEvent(Plugin::kProgressEventProgress); |
470 translate_notify_callback_.Run(pp_error); | 370 translate_notify_callback_.Run(pp_error); |
471 } | 371 } |
472 | 372 |
| 373 void PnaclCoordinator::NexeFileWasDeleted(int32_t pp_error) { |
| 374 PLUGIN_PRINTF(("PnaclCoordinator::NexeFileWasDeleted (pp_error=%" |
| 375 NACL_PRId32")\n", pp_error)); |
| 376 ReportPpapiError(translate_finish_error_); |
| 377 } |
| 378 |
473 void PnaclCoordinator::ResourcesDidLoad(int32_t pp_error) { | 379 void PnaclCoordinator::ResourcesDidLoad(int32_t pp_error) { |
474 PLUGIN_PRINTF(("PnaclCoordinator::ResourcesDidLoad (pp_error=%" | 380 PLUGIN_PRINTF(("PnaclCoordinator::ResourcesDidLoad (pp_error=%" |
475 NACL_PRId32")\n", pp_error)); | 381 NACL_PRId32")\n", pp_error)); |
476 if (pp_error != PP_OK) { | 382 if (pp_error != PP_OK) { |
477 ReportPpapiError(pp_error, "resources failed to load."); | 383 ReportPpapiError(pp_error, "resources failed to load."); |
478 return; | 384 return; |
479 } | 385 } |
480 | 386 // Open the local temporary file system to create the temporary files |
481 if (!off_the_record_) { | 387 // for the object and nexe. |
482 // Open the local temporary FS to see if we get a hit in the cache. | 388 pp::CompletionCallback cb = |
483 pp::CompletionCallback cb = | 389 callback_factory_.NewCallback(&PnaclCoordinator::FileSystemDidOpen); |
484 callback_factory_.NewCallback(&PnaclCoordinator::FileSystemDidOpen); | 390 if (!file_system_->Open(0, cb)) { |
485 if (!file_system_->Open(0, cb)) { | 391 ReportNonPpapiError("failed to open file system."); |
486 ReportNonPpapiError("failed to open file system."); | |
487 } | |
488 } else { | |
489 // We don't have a cache, so do the non-cached codepath. | |
490 CachedFileDidOpen(PP_ERROR_FAILED); | |
491 } | 392 } |
492 } | 393 } |
493 | 394 |
494 void PnaclCoordinator::FileSystemDidOpen(int32_t pp_error) { | 395 void PnaclCoordinator::FileSystemDidOpen(int32_t pp_error) { |
495 PLUGIN_PRINTF(("PnaclCoordinator::FileSystemDidOpen (pp_error=%" | 396 PLUGIN_PRINTF(("PnaclCoordinator::FileSystemDidOpen (pp_error=%" |
496 NACL_PRId32")\n", pp_error)); | 397 NACL_PRId32")\n", pp_error)); |
497 if (pp_error != PP_OK) { | 398 if (pp_error != PP_OK) { |
498 ReportPpapiError(pp_error, "file system didn't open."); | 399 ReportPpapiError(pp_error, "file system didn't open."); |
499 return; | 400 return; |
500 } | 401 } |
501 dir_ref_.reset(new pp::FileRef(*file_system_, kPnaclTempDir)); | 402 dir_ref_.reset(new pp::FileRef(*file_system_, |
| 403 kPnaclTempDir)); |
502 // Attempt to create the directory. | 404 // Attempt to create the directory. |
503 pp::CompletionCallback cb = | 405 pp::CompletionCallback cb = |
504 callback_factory_.NewCallback(&PnaclCoordinator::DirectoryWasCreated); | 406 callback_factory_.NewCallback(&PnaclCoordinator::DirectoryWasCreated); |
505 dir_ref_->MakeDirectory(cb); | 407 dir_ref_->MakeDirectory(cb); |
506 } | 408 } |
507 | 409 |
508 void PnaclCoordinator::DirectoryWasCreated(int32_t pp_error) { | 410 void PnaclCoordinator::DirectoryWasCreated(int32_t pp_error) { |
509 PLUGIN_PRINTF(("PnaclCoordinator::DirectoryWasCreated (pp_error=%" | 411 PLUGIN_PRINTF(("PnaclCoordinator::DirectoryWasCreated (pp_error=%" |
510 NACL_PRId32")\n", pp_error)); | 412 NACL_PRId32")\n", pp_error)); |
511 if (pp_error != PP_ERROR_FILEEXISTS && pp_error != PP_OK) { | 413 if (pp_error != PP_ERROR_FILEEXISTS && pp_error != PP_OK) { |
512 // Directory did not exist and could not be created. | 414 // Directory did not exist and could not be created. |
513 ReportPpapiError(pp_error, "directory creation/check failed."); | 415 ReportPpapiError(pp_error, "directory creation/check failed."); |
514 return; | 416 return; |
515 } | 417 } |
516 if (cache_identity_ != "") { | 418 if (cache_identity_ != "") { |
517 cached_nexe_file_.reset(new LocalTempFile(plugin_, file_system_.get(), | 419 nexe_file_.reset(new LocalTempFile(plugin_, file_system_.get(), |
518 nacl::string(kPnaclTempDir), | 420 nacl::string(kPnaclTempDir), |
519 cache_identity_)); | 421 cache_identity_)); |
520 pp::CompletionCallback cb = | 422 pp::CompletionCallback cb = |
521 callback_factory_.NewCallback(&PnaclCoordinator::CachedFileDidOpen); | 423 callback_factory_.NewCallback(&PnaclCoordinator::CachedFileDidOpen); |
522 cached_nexe_file_->OpenRead(cb); | 424 nexe_file_->OpenRead(cb); |
523 } else { | 425 } else { |
524 // For now, tolerate lack of cache identity... | 426 // For now, tolerate lack of cache identity... |
525 CachedFileDidOpen(PP_ERROR_FAILED); | 427 CachedFileDidOpen(PP_ERROR_FAILED); |
526 } | 428 } |
527 } | 429 } |
528 | 430 |
529 void PnaclCoordinator::CachedFileDidOpen(int32_t pp_error) { | 431 void PnaclCoordinator::CachedFileDidOpen(int32_t pp_error) { |
530 PLUGIN_PRINTF(("PnaclCoordinator::CachedFileDidOpen (pp_error=%" | 432 PLUGIN_PRINTF(("PnaclCoordinator::CachedFileDidOpen (pp_error=%" |
531 NACL_PRId32")\n", pp_error)); | 433 NACL_PRId32")\n", pp_error)); |
532 if (pp_error == PP_OK) { | 434 if (pp_error == PP_OK) { |
(...skipping 27 matching lines...) Expand all Loading... |
560 // TODO(dschuff): need to use url_util_->ResolveRelativeToURL? | 462 // TODO(dschuff): need to use url_util_->ResolveRelativeToURL? |
561 if (!streaming_downloader_->OpenStream(pexe_url_, cb, this)) { | 463 if (!streaming_downloader_->OpenStream(pexe_url_, cb, this)) { |
562 ReportNonPpapiError(nacl::string("failed to open stream ") + pexe_url_); | 464 ReportNonPpapiError(nacl::string("failed to open stream ") + pexe_url_); |
563 } | 465 } |
564 } | 466 } |
565 | 467 |
566 void PnaclCoordinator::BitcodeStreamDidFinish(int32_t pp_error) { | 468 void PnaclCoordinator::BitcodeStreamDidFinish(int32_t pp_error) { |
567 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeStreamDidFinish (pp_error=%" | 469 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeStreamDidFinish (pp_error=%" |
568 NACL_PRId32")\n", pp_error)); | 470 NACL_PRId32")\n", pp_error)); |
569 if (pp_error != PP_OK) { | 471 if (pp_error != PP_OK) { |
570 // Defer reporting the error and cleanup until after the translation | 472 // Defer reporting the error and obj_file/nexe_file cleanup until after |
571 // thread returns, because it may be accessing the coordinator's | 473 // the translation thread returns, because it may be accessing the |
572 // objects or writing to the files. | 474 // coordinator's objects or writing to the files. |
573 translate_finish_error_ = pp_error; | 475 translate_finish_error_ = pp_error; |
574 error_info_.SetReport(ERROR_UNKNOWN, | 476 error_info_.SetReport(ERROR_UNKNOWN, |
575 nacl::string("PnaclCoordinator: pexe load failed.")); | 477 nacl::string("PnaclCoordinator: pexe load failed.")); |
576 translate_thread_->SetSubprocessesShouldDie(); | 478 translate_thread_->SetSubprocessesShouldDie(); |
577 } | 479 } |
578 } | 480 } |
579 | 481 |
580 void PnaclCoordinator::BitcodeStreamGotData(int32_t pp_error, | 482 void PnaclCoordinator::BitcodeStreamGotData(int32_t pp_error, |
581 FileStreamData data) { | 483 FileStreamData data) { |
582 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeStreamGotData (pp_error=%" | 484 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeStreamGotData (pp_error=%" |
583 NACL_PRId32", data=%p)\n", pp_error, data ? &(*data)[0] : 0)); | 485 NACL_PRId32", data=%p)\n", pp_error, data ? &(*data)[0] : 0)); |
584 DCHECK(translate_thread_.get()); | 486 DCHECK(translate_thread_.get()); |
585 translate_thread_->PutBytes(data, pp_error); | 487 translate_thread_->PutBytes(data, pp_error); |
586 } | 488 } |
587 | 489 |
588 StreamCallback PnaclCoordinator::GetCallback() { | 490 StreamCallback PnaclCoordinator::GetCallback() { |
589 return callback_factory_.NewCallbackWithOutput( | 491 return callback_factory_.NewCallbackWithOutput( |
590 &PnaclCoordinator::BitcodeStreamGotData); | 492 &PnaclCoordinator::BitcodeStreamGotData); |
591 } | 493 } |
592 | 494 |
593 void PnaclCoordinator::ObjectFileDidOpen(int32_t pp_error) { | 495 void PnaclCoordinator::ObjectFileDidOpen(int32_t pp_error) { |
594 PLUGIN_PRINTF(("PnaclCoordinator::ObjectFileDidOpen (pp_error=%" | 496 PLUGIN_PRINTF(("PnaclCoordinator::ObjectFileDidOpen (pp_error=%" |
595 NACL_PRId32")\n", pp_error)); | 497 NACL_PRId32")\n", pp_error)); |
596 if (pp_error != PP_OK) { | 498 if (pp_error != PP_OK) { |
597 ReportPpapiError(pp_error); | 499 ReportPpapiError(pp_error); |
598 return; | 500 return; |
599 } | 501 } |
600 // Create the nexe file for connecting ld and sel_ldr. | 502 // Create the nexe file for connecting ld and sel_ldr. |
601 // Start translation when done with this last step of setup! | 503 // Start translation when done with this last step of setup! |
602 temp_nexe_file_.reset(new TempFile(plugin_)); | 504 nexe_file_.reset(new LocalTempFile(plugin_, file_system_.get(), |
| 505 nacl::string(kPnaclTempDir))); |
603 pp::CompletionCallback cb = | 506 pp::CompletionCallback cb = |
604 callback_factory_.NewCallback(&PnaclCoordinator::RunTranslate); | 507 callback_factory_.NewCallback(&PnaclCoordinator::RunTranslate); |
605 temp_nexe_file_->Open(cb); | 508 nexe_file_->OpenWrite(cb); |
606 } | 509 } |
607 | 510 |
608 void PnaclCoordinator::RunTranslate(int32_t pp_error) { | 511 void PnaclCoordinator::RunTranslate(int32_t pp_error) { |
609 PLUGIN_PRINTF(("PnaclCoordinator::RunTranslate (pp_error=%" | 512 PLUGIN_PRINTF(("PnaclCoordinator::RunTranslate (pp_error=%" |
610 NACL_PRId32")\n", pp_error)); | 513 NACL_PRId32")\n", pp_error)); |
611 // Invoke llc followed by ld off the main thread. This allows use of | 514 // Invoke llc followed by ld off the main thread. This allows use of |
612 // blocking RPCs that would otherwise block the JavaScript main thread. | 515 // blocking RPCs that would otherwise block the JavaScript main thread. |
613 pp::CompletionCallback report_translate_finished = | 516 pp::CompletionCallback report_translate_finished = |
614 callback_factory_.NewCallback(&PnaclCoordinator::TranslateFinished); | 517 callback_factory_.NewCallback(&PnaclCoordinator::TranslateFinished); |
615 | 518 |
616 CHECK(translate_thread_ != NULL); | 519 CHECK(translate_thread_ != NULL); |
617 translate_thread_->RunTranslate(report_translate_finished, | 520 translate_thread_->RunTranslate(report_translate_finished, |
618 manifest_.get(), | 521 manifest_.get(), |
619 ld_manifest_.get(), | 522 ld_manifest_.get(), |
620 obj_file_.get(), | 523 obj_file_.get(), |
621 temp_nexe_file_.get(), | 524 nexe_file_.get(), |
622 &error_info_, | 525 &error_info_, |
623 resources_.get(), | 526 resources_.get(), |
624 plugin_); | 527 plugin_); |
625 } | 528 } |
626 | 529 |
627 } // namespace plugin | 530 } // namespace plugin |
OLD | NEW |