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

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

Issue 10826107: Add an IPC for PNaCl to check if the session is incognito, before deciding (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: bump buffer size Created 8 years, 4 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
OLDNEW
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 = 131072;
sehr (please use chromium) 2012/08/02 22:37:49 I usually prefer something like 128 << 10 for thes
jvoung - send to chromium... 2012/08/02 22:44:29 Done.
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
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
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
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 // TODO(jvoung): This should probably try to delete the cache file
422 // before returning...
423 ReportPpapiError(pp_error, "Failed to copy nexe to cache.");
424 return;
425 }
426 // Rename the cached_nexe_file_ file to the cache id, to finalize.
427 pp::CompletionCallback cb =
428 callback_factory_.NewCallback(&PnaclCoordinator::NexeFileWasRenamed);
429 cached_nexe_file_->Rename(cache_identity_, cb);
342 } 430 }
343 431
344 void PnaclCoordinator::NexeFileWasRenamed(int32_t pp_error) { 432 void PnaclCoordinator::NexeFileWasRenamed(int32_t pp_error) {
345 PLUGIN_PRINTF(("PnaclCoordinator::NexeFileWasRenamed (pp_error=%" 433 PLUGIN_PRINTF(("PnaclCoordinator::NexeFileWasRenamed (pp_error=%"
346 NACL_PRId32")\n", pp_error)); 434 NACL_PRId32")\n", pp_error));
347 // NOTE: if the file already existed, it looks like the rename will 435 // NOTE: if the file already existed, it looks like the rename will
348 // happily succeed. However, we should add a test for this. 436 // happily succeed. However, we should add a test for this.
349 if (pp_error != PP_OK) { 437 if (pp_error != PP_OK) {
350 ReportPpapiError(pp_error, "Failed to place cached bitcode translation."); 438 ReportPpapiError(pp_error, "Failed to place cached bitcode translation.");
351 return; 439 return;
352 } 440 }
353 nexe_file_->FinishRename(); 441
354 // Open the nexe temporary file for reading. 442 cached_nexe_file_->FinishRename();
443 // Open the cache file for reading.
355 pp::CompletionCallback cb = 444 pp::CompletionCallback cb =
356 callback_factory_.NewCallback(&PnaclCoordinator::NexeReadDidOpen); 445 callback_factory_.NewCallback(&PnaclCoordinator::NexeReadDidOpen);
357 nexe_file_->OpenRead(cb); 446 cached_nexe_file_->OpenRead(cb);
358 } 447 }
359 448
360 void PnaclCoordinator::NexeReadDidOpen(int32_t pp_error) { 449 void PnaclCoordinator::NexeReadDidOpen(int32_t pp_error) {
361 PLUGIN_PRINTF(("PnaclCoordinator::NexeReadDidOpen (pp_error=%" 450 PLUGIN_PRINTF(("PnaclCoordinator::NexeReadDidOpen (pp_error=%"
362 NACL_PRId32")\n", pp_error)); 451 NACL_PRId32")\n", pp_error));
363 if (pp_error != PP_OK) { 452 if (pp_error != PP_OK) {
364 ReportPpapiError(pp_error, "Failed to open translated nexe."); 453 ReportPpapiError(pp_error, "Failed to open translated nexe.");
365 return; 454 return;
366 } 455 }
367 // Transfer ownership of the nexe wrapper to the coordinator. 456
368 translated_fd_.reset(nexe_file_->release_read_wrapper()); 457 // Transfer ownership of cache/temp file's wrapper to the coordinator.
458 if (cached_nexe_file_ != NULL) {
459 translated_fd_.reset(cached_nexe_file_->release_read_wrapper());
460 } else {
461 translated_fd_.reset(temp_nexe_file_->release_read_wrapper());
462 }
369 plugin_->EnqueueProgressEvent(Plugin::kProgressEventProgress); 463 plugin_->EnqueueProgressEvent(Plugin::kProgressEventProgress);
370 translate_notify_callback_.Run(pp_error); 464 translate_notify_callback_.Run(pp_error);
371 } 465 }
372 466
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) { 467 void PnaclCoordinator::ResourcesDidLoad(int32_t pp_error) {
380 PLUGIN_PRINTF(("PnaclCoordinator::ResourcesDidLoad (pp_error=%" 468 PLUGIN_PRINTF(("PnaclCoordinator::ResourcesDidLoad (pp_error=%"
381 NACL_PRId32")\n", pp_error)); 469 NACL_PRId32")\n", pp_error));
382 if (pp_error != PP_OK) { 470 if (pp_error != PP_OK) {
383 ReportPpapiError(pp_error, "resources failed to load."); 471 ReportPpapiError(pp_error, "resources failed to load.");
384 return; 472 return;
385 } 473 }
386 // Open the local temporary file system to create the temporary files 474
387 // for the object and nexe. 475 if (!off_the_record_) {
388 pp::CompletionCallback cb = 476 // Open the local temporary FS to see if we get a hit in the cache.
389 callback_factory_.NewCallback(&PnaclCoordinator::FileSystemDidOpen); 477 pp::CompletionCallback cb =
390 if (!file_system_->Open(0, cb)) { 478 callback_factory_.NewCallback(&PnaclCoordinator::FileSystemDidOpen);
391 ReportNonPpapiError("failed to open file system."); 479 if (!file_system_->Open(0, cb)) {
480 ReportNonPpapiError("failed to open file system.");
481 }
482 } else {
483 // We don't have a cache, so do the non-cached codepath.
484 CachedFileDidOpen(PP_ERROR_FAILED);
392 } 485 }
393 } 486 }
394 487
395 void PnaclCoordinator::FileSystemDidOpen(int32_t pp_error) { 488 void PnaclCoordinator::FileSystemDidOpen(int32_t pp_error) {
396 PLUGIN_PRINTF(("PnaclCoordinator::FileSystemDidOpen (pp_error=%" 489 PLUGIN_PRINTF(("PnaclCoordinator::FileSystemDidOpen (pp_error=%"
397 NACL_PRId32")\n", pp_error)); 490 NACL_PRId32")\n", pp_error));
398 if (pp_error != PP_OK) { 491 if (pp_error != PP_OK) {
399 ReportPpapiError(pp_error, "file system didn't open."); 492 ReportPpapiError(pp_error, "file system didn't open.");
400 return; 493 return;
401 } 494 }
402 dir_ref_.reset(new pp::FileRef(*file_system_, 495 dir_ref_.reset(new pp::FileRef(*file_system_, kPnaclTempDir));
403 kPnaclTempDir));
404 // Attempt to create the directory. 496 // Attempt to create the directory.
405 pp::CompletionCallback cb = 497 pp::CompletionCallback cb =
406 callback_factory_.NewCallback(&PnaclCoordinator::DirectoryWasCreated); 498 callback_factory_.NewCallback(&PnaclCoordinator::DirectoryWasCreated);
407 dir_ref_->MakeDirectory(cb); 499 dir_ref_->MakeDirectory(cb);
408 } 500 }
409 501
410 void PnaclCoordinator::DirectoryWasCreated(int32_t pp_error) { 502 void PnaclCoordinator::DirectoryWasCreated(int32_t pp_error) {
411 PLUGIN_PRINTF(("PnaclCoordinator::DirectoryWasCreated (pp_error=%" 503 PLUGIN_PRINTF(("PnaclCoordinator::DirectoryWasCreated (pp_error=%"
412 NACL_PRId32")\n", pp_error)); 504 NACL_PRId32")\n", pp_error));
413 if (pp_error != PP_ERROR_FILEEXISTS && pp_error != PP_OK) { 505 if (pp_error != PP_ERROR_FILEEXISTS && pp_error != PP_OK) {
414 // Directory did not exist and could not be created. 506 // Directory did not exist and could not be created.
415 ReportPpapiError(pp_error, "directory creation/check failed."); 507 ReportPpapiError(pp_error, "directory creation/check failed.");
416 return; 508 return;
417 } 509 }
418 if (cache_identity_ != "") { 510 if (cache_identity_ != "") {
419 nexe_file_.reset(new LocalTempFile(plugin_, file_system_.get(), 511 cached_nexe_file_.reset(new LocalTempFile(plugin_, file_system_.get(),
420 nacl::string(kPnaclTempDir), 512 nacl::string(kPnaclTempDir),
421 cache_identity_)); 513 cache_identity_));
422 pp::CompletionCallback cb = 514 pp::CompletionCallback cb =
423 callback_factory_.NewCallback(&PnaclCoordinator::CachedFileDidOpen); 515 callback_factory_.NewCallback(&PnaclCoordinator::CachedFileDidOpen);
424 nexe_file_->OpenRead(cb); 516 cached_nexe_file_->OpenRead(cb);
425 } else { 517 } else {
426 // For now, tolerate lack of cache identity... 518 // For now, tolerate lack of cache identity...
427 CachedFileDidOpen(PP_ERROR_FAILED); 519 CachedFileDidOpen(PP_ERROR_FAILED);
428 } 520 }
429 } 521 }
430 522
431 void PnaclCoordinator::CachedFileDidOpen(int32_t pp_error) { 523 void PnaclCoordinator::CachedFileDidOpen(int32_t pp_error) {
432 PLUGIN_PRINTF(("PnaclCoordinator::CachedFileDidOpen (pp_error=%" 524 PLUGIN_PRINTF(("PnaclCoordinator::CachedFileDidOpen (pp_error=%"
433 NACL_PRId32")\n", pp_error)); 525 NACL_PRId32")\n", pp_error));
434 if (pp_error == PP_OK) { 526 if (pp_error == PP_OK) {
(...skipping 27 matching lines...) Expand all
462 // TODO(dschuff): need to use url_util_->ResolveRelativeToURL? 554 // TODO(dschuff): need to use url_util_->ResolveRelativeToURL?
463 if (!streaming_downloader_->OpenStream(pexe_url_, cb, this)) { 555 if (!streaming_downloader_->OpenStream(pexe_url_, cb, this)) {
464 ReportNonPpapiError(nacl::string("failed to open stream ") + pexe_url_); 556 ReportNonPpapiError(nacl::string("failed to open stream ") + pexe_url_);
465 } 557 }
466 } 558 }
467 559
468 void PnaclCoordinator::BitcodeStreamDidFinish(int32_t pp_error) { 560 void PnaclCoordinator::BitcodeStreamDidFinish(int32_t pp_error) {
469 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeStreamDidFinish (pp_error=%" 561 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeStreamDidFinish (pp_error=%"
470 NACL_PRId32")\n", pp_error)); 562 NACL_PRId32")\n", pp_error));
471 if (pp_error != PP_OK) { 563 if (pp_error != PP_OK) {
472 // Defer reporting the error and obj_file/nexe_file cleanup until after 564 // Defer reporting the error and cleanup until after the translation
473 // the translation thread returns, because it may be accessing the 565 // thread returns, because it may be accessing the coordinator's
474 // coordinator's objects or writing to the files. 566 // objects or writing to the files.
475 translate_finish_error_ = pp_error; 567 translate_finish_error_ = pp_error;
476 error_info_.SetReport(ERROR_UNKNOWN, 568 error_info_.SetReport(ERROR_UNKNOWN,
477 nacl::string("PnaclCoordinator: pexe load failed.")); 569 nacl::string("PnaclCoordinator: pexe load failed."));
478 translate_thread_->SetSubprocessesShouldDie(); 570 translate_thread_->SetSubprocessesShouldDie();
479 } 571 }
480 } 572 }
481 573
482 void PnaclCoordinator::BitcodeStreamGotData(int32_t pp_error, 574 void PnaclCoordinator::BitcodeStreamGotData(int32_t pp_error,
483 FileStreamData data) { 575 FileStreamData data) {
484 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeStreamGotData (pp_error=%" 576 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeStreamGotData (pp_error=%"
485 NACL_PRId32", data=%p)\n", pp_error, data ? &(*data)[0] : 0)); 577 NACL_PRId32", data=%p)\n", pp_error, data ? &(*data)[0] : 0));
486 DCHECK(translate_thread_.get()); 578 DCHECK(translate_thread_.get());
487 translate_thread_->PutBytes(data, pp_error); 579 translate_thread_->PutBytes(data, pp_error);
488 } 580 }
489 581
490 StreamCallback PnaclCoordinator::GetCallback() { 582 StreamCallback PnaclCoordinator::GetCallback() {
491 return callback_factory_.NewCallbackWithOutput( 583 return callback_factory_.NewCallbackWithOutput(
492 &PnaclCoordinator::BitcodeStreamGotData); 584 &PnaclCoordinator::BitcodeStreamGotData);
493 } 585 }
494 586
495 void PnaclCoordinator::ObjectFileDidOpen(int32_t pp_error) { 587 void PnaclCoordinator::ObjectFileDidOpen(int32_t pp_error) {
496 PLUGIN_PRINTF(("PnaclCoordinator::ObjectFileDidOpen (pp_error=%" 588 PLUGIN_PRINTF(("PnaclCoordinator::ObjectFileDidOpen (pp_error=%"
497 NACL_PRId32")\n", pp_error)); 589 NACL_PRId32")\n", pp_error));
498 if (pp_error != PP_OK) { 590 if (pp_error != PP_OK) {
499 ReportPpapiError(pp_error); 591 ReportPpapiError(pp_error);
500 return; 592 return;
501 } 593 }
502 // Create the nexe file for connecting ld and sel_ldr. 594 // Create the nexe file for connecting ld and sel_ldr.
503 // Start translation when done with this last step of setup! 595 // Start translation when done with this last step of setup!
504 nexe_file_.reset(new LocalTempFile(plugin_, file_system_.get(), 596 temp_nexe_file_.reset(new TempFile(plugin_));
505 nacl::string(kPnaclTempDir)));
506 pp::CompletionCallback cb = 597 pp::CompletionCallback cb =
507 callback_factory_.NewCallback(&PnaclCoordinator::RunTranslate); 598 callback_factory_.NewCallback(&PnaclCoordinator::RunTranslate);
508 nexe_file_->OpenWrite(cb); 599 temp_nexe_file_->Open(cb);
509 } 600 }
510 601
511 void PnaclCoordinator::RunTranslate(int32_t pp_error) { 602 void PnaclCoordinator::RunTranslate(int32_t pp_error) {
512 PLUGIN_PRINTF(("PnaclCoordinator::RunTranslate (pp_error=%" 603 PLUGIN_PRINTF(("PnaclCoordinator::RunTranslate (pp_error=%"
513 NACL_PRId32")\n", pp_error)); 604 NACL_PRId32")\n", pp_error));
514 // Invoke llc followed by ld off the main thread. This allows use of 605 // Invoke llc followed by ld off the main thread. This allows use of
515 // blocking RPCs that would otherwise block the JavaScript main thread. 606 // blocking RPCs that would otherwise block the JavaScript main thread.
516 pp::CompletionCallback report_translate_finished = 607 pp::CompletionCallback report_translate_finished =
517 callback_factory_.NewCallback(&PnaclCoordinator::TranslateFinished); 608 callback_factory_.NewCallback(&PnaclCoordinator::TranslateFinished);
518 609
519 CHECK(translate_thread_ != NULL); 610 CHECK(translate_thread_ != NULL);
520 translate_thread_->RunTranslate(report_translate_finished, 611 translate_thread_->RunTranslate(report_translate_finished,
521 manifest_.get(), 612 manifest_.get(),
522 ld_manifest_.get(), 613 ld_manifest_.get(),
523 obj_file_.get(), 614 obj_file_.get(),
524 nexe_file_.get(), 615 temp_nexe_file_.get(),
525 &error_info_, 616 &error_info_,
526 resources_.get(), 617 resources_.get(),
527 plugin_); 618 plugin_);
528 } 619 }
529 620
530 } // namespace plugin 621 } // namespace plugin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698