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