| 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 #ifdef _MSC_VER | 5 #ifdef _MSC_VER |
| 6 // Do not warn about use of std::copy with raw pointers. | 6 // Do not warn about use of std::copy with raw pointers. |
| 7 #pragma warning(disable : 4996) | 7 #pragma warning(disable : 4996) |
| 8 #endif | 8 #endif |
| 9 | 9 |
| 10 #include "ppapi/native_client/src/trusted/plugin/plugin.h" | 10 #include "ppapi/native_client/src/trusted/plugin/plugin.h" |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 | 366 |
| 367 | 367 |
| 368 Plugin::~Plugin() { | 368 Plugin::~Plugin() { |
| 369 int64_t shutdown_start = NaClGetTimeOfDayMicroseconds(); | 369 int64_t shutdown_start = NaClGetTimeOfDayMicroseconds(); |
| 370 | 370 |
| 371 PLUGIN_PRINTF(("Plugin::~Plugin (this=%p)\n", | 371 PLUGIN_PRINTF(("Plugin::~Plugin (this=%p)\n", |
| 372 static_cast<void*>(this))); | 372 static_cast<void*>(this))); |
| 373 // Destroy the coordinator while the rest of the data is still there | 373 // Destroy the coordinator while the rest of the data is still there |
| 374 pnacl_coordinator_.reset(NULL); | 374 pnacl_coordinator_.reset(NULL); |
| 375 | 375 |
| 376 for (std::map<nacl::string, NaClFileInfoAutoCloser*>::iterator it = | |
| 377 url_file_info_map_.begin(); | |
| 378 it != url_file_info_map_.end(); | |
| 379 ++it) { | |
| 380 delete it->second; | |
| 381 } | |
| 382 url_downloaders_.erase(url_downloaders_.begin(), url_downloaders_.end()); | 376 url_downloaders_.erase(url_downloaders_.begin(), url_downloaders_.end()); |
| 383 | 377 |
| 384 // Clean up accounting for our instance inside the NaCl interface. | 378 // Clean up accounting for our instance inside the NaCl interface. |
| 385 if (manifest_id_ != -1) | 379 if (manifest_id_ != -1) |
| 386 nacl_interface_->DestroyManifest(pp_instance(), manifest_id_); | 380 nacl_interface_->DestroyManifest(pp_instance(), manifest_id_); |
| 387 nacl_interface_->InstanceDestroyed(pp_instance()); | 381 nacl_interface_->InstanceDestroyed(pp_instance()); |
| 388 | 382 |
| 389 // ShutDownSubprocesses shuts down the main subprocess, which shuts | 383 // ShutDownSubprocesses shuts down the main subprocess, which shuts |
| 390 // down the main ServiceRuntime object, which kills the subprocess. | 384 // down the main ServiceRuntime object, which kills the subprocess. |
| 391 // As a side effect of the subprocess being killed, the reverse | 385 // As a side effect of the subprocess being killed, the reverse |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 callback_factory_.NewCallback(&Plugin::NaClManifestFileDidOpen); | 556 callback_factory_.NewCallback(&Plugin::NaClManifestFileDidOpen); |
| 563 nacl_interface_->RequestNaClManifest(pp_instance(), | 557 nacl_interface_->RequestNaClManifest(pp_instance(), |
| 564 url.c_str(), | 558 url.c_str(), |
| 565 &manifest_id_, | 559 &manifest_id_, |
| 566 open_callback.pp_completion_callback()); | 560 open_callback.pp_completion_callback()); |
| 567 } | 561 } |
| 568 | 562 |
| 569 void Plugin::UrlDidOpenForStreamAsFile( | 563 void Plugin::UrlDidOpenForStreamAsFile( |
| 570 int32_t pp_error, | 564 int32_t pp_error, |
| 571 FileDownloader* url_downloader, | 565 FileDownloader* url_downloader, |
| 566 NaClFileInfo* out_file_info, |
| 572 pp::CompletionCallback callback) { | 567 pp::CompletionCallback callback) { |
| 573 PLUGIN_PRINTF(("Plugin::UrlDidOpen (pp_error=%" NACL_PRId32 | 568 PLUGIN_PRINTF(("Plugin::UrlDidOpen (pp_error=%" NACL_PRId32 |
| 574 ", url_downloader=%p)\n", pp_error, | 569 ", url_downloader=%p)\n", pp_error, |
| 575 static_cast<void*>(url_downloader))); | 570 static_cast<void*>(url_downloader))); |
| 576 url_downloaders_.erase(url_downloader); | 571 url_downloaders_.erase(url_downloader); |
| 577 nacl::scoped_ptr<FileDownloader> scoped_url_downloader(url_downloader); | 572 nacl::scoped_ptr<FileDownloader> scoped_url_downloader(url_downloader); |
| 578 NaClFileInfo tmp_info(scoped_url_downloader->GetFileInfo()); | 573 NaClFileInfo tmp_info(scoped_url_downloader->GetFileInfo()); |
| 579 NaClFileInfoAutoCloser *info = new NaClFileInfoAutoCloser(&tmp_info); | 574 NaClFileInfoAutoCloser *info = new NaClFileInfoAutoCloser(&tmp_info); |
| 580 | 575 |
| 581 if (pp_error != PP_OK) { | 576 if (pp_error != PP_OK) { |
| 582 callback.Run(pp_error); | 577 callback.Run(pp_error); |
| 583 delete info; | 578 delete info; |
| 584 } else if (info->get_desc() > NACL_NO_FILE_DESC) { | 579 } else if (info->get_desc() > NACL_NO_FILE_DESC) { |
| 585 std::map<nacl::string, NaClFileInfoAutoCloser*>::iterator it = | 580 *out_file_info = info->Release(); |
| 586 url_file_info_map_.find(url_downloader->url()); | |
| 587 if (it != url_file_info_map_.end()) | |
| 588 delete it->second; | |
| 589 url_file_info_map_[url_downloader->url()] = info; | |
| 590 callback.Run(PP_OK); | 581 callback.Run(PP_OK); |
| 591 } else { | 582 } else { |
| 592 callback.Run(PP_ERROR_FAILED); | 583 callback.Run(PP_ERROR_FAILED); |
| 593 delete info; | 584 delete info; |
| 594 } | 585 } |
| 595 } | 586 } |
| 596 | 587 |
| 597 struct NaClFileInfo Plugin::GetFileInfo(const nacl::string& url) { | |
| 598 struct NaClFileInfo info; | |
| 599 memset(&info, 0, sizeof(info)); | |
| 600 std::map<nacl::string, NaClFileInfoAutoCloser*>::iterator it = | |
| 601 url_file_info_map_.find(url); | |
| 602 if (it != url_file_info_map_.end()) { | |
| 603 info = it->second->get(); | |
| 604 info.desc = DUP(info.desc); | |
| 605 } else { | |
| 606 info.desc = -1; | |
| 607 } | |
| 608 return info; | |
| 609 } | |
| 610 | |
| 611 bool Plugin::StreamAsFile(const nacl::string& url, | 588 bool Plugin::StreamAsFile(const nacl::string& url, |
| 589 NaClFileInfo* out_file_info, |
| 612 const pp::CompletionCallback& callback) { | 590 const pp::CompletionCallback& callback) { |
| 613 PLUGIN_PRINTF(("Plugin::StreamAsFile (url='%s')\n", url.c_str())); | 591 PLUGIN_PRINTF(("Plugin::StreamAsFile (url='%s')\n", url.c_str())); |
| 614 FileDownloader* downloader = new FileDownloader(); | 592 FileDownloader* downloader = new FileDownloader(); |
| 615 downloader->Initialize(this); | 593 downloader->Initialize(this); |
| 616 url_downloaders_.insert(downloader); | 594 url_downloaders_.insert(downloader); |
| 617 | 595 |
| 618 // Untrusted loads are always relative to the page's origin. | 596 // Untrusted loads are always relative to the page's origin. |
| 619 if (!GetNaClInterface()->ResolvesRelativeToPluginBaseUrl(pp_instance(), | 597 if (!GetNaClInterface()->ResolvesRelativeToPluginBaseUrl(pp_instance(), |
| 620 url.c_str())) | 598 url.c_str())) |
| 621 return false; | 599 return false; |
| 622 | 600 |
| 623 // Try the fast path first. This will only block if the file is installed. | 601 // Try the fast path first. This will only block if the file is installed. |
| 624 if (OpenURLFast(url, downloader)) { | 602 if (OpenURLFast(url, downloader)) { |
| 625 UrlDidOpenForStreamAsFile(PP_OK, downloader, callback); | 603 UrlDidOpenForStreamAsFile(PP_OK, downloader, out_file_info, callback); |
| 626 return true; | 604 return true; |
| 627 } | 605 } |
| 628 | 606 |
| 629 pp::CompletionCallback open_callback = callback_factory_.NewCallback( | 607 pp::CompletionCallback open_callback = callback_factory_.NewCallback( |
| 630 &Plugin::UrlDidOpenForStreamAsFile, downloader, callback); | 608 &Plugin::UrlDidOpenForStreamAsFile, downloader, out_file_info, callback); |
| 631 // If true, will always call the callback on success or failure. | 609 // If true, will always call the callback on success or failure. |
| 632 return downloader->Open(url, | 610 return downloader->Open(url, |
| 633 DOWNLOAD_TO_FILE, | 611 DOWNLOAD_TO_FILE, |
| 634 open_callback, | 612 open_callback, |
| 635 true, | 613 true, |
| 636 &UpdateDownloadProgress); | 614 &UpdateDownloadProgress); |
| 637 } | 615 } |
| 638 | 616 |
| 639 | 617 |
| 640 void Plugin::ReportLoadSuccess(uint64_t loaded_bytes, uint64_t total_bytes) { | 618 void Plugin::ReportLoadSuccess(uint64_t loaded_bytes, uint64_t total_bytes) { |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 | 746 |
| 769 void Plugin::SetExitStatusOnMainThread(int32_t pp_error, | 747 void Plugin::SetExitStatusOnMainThread(int32_t pp_error, |
| 770 int exit_status) { | 748 int exit_status) { |
| 771 DCHECK(pp::Module::Get()->core()->IsMainThread()); | 749 DCHECK(pp::Module::Get()->core()->IsMainThread()); |
| 772 DCHECK(nacl_interface_); | 750 DCHECK(nacl_interface_); |
| 773 nacl_interface_->SetExitStatus(pp_instance(), exit_status); | 751 nacl_interface_->SetExitStatus(pp_instance(), exit_status); |
| 774 } | 752 } |
| 775 | 753 |
| 776 | 754 |
| 777 } // namespace plugin | 755 } // namespace plugin |
| OLD | NEW |