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

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

Issue 335343006: Pepper: Small cleanup in PNaClCoordinator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // 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 "ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h" 5 #include "ppapi/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/checked_cast.h" 10 #include "native_client/src/include/checked_cast.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 const PP_PNaClOptions& pnacl_options, 100 const PP_PNaClOptions& pnacl_options,
101 const pp::CompletionCallback& translate_notify_callback) 101 const pp::CompletionCallback& translate_notify_callback)
102 : translate_finish_error_(PP_OK), 102 : translate_finish_error_(PP_OK),
103 plugin_(plugin), 103 plugin_(plugin),
104 translate_notify_callback_(translate_notify_callback), 104 translate_notify_callback_(translate_notify_callback),
105 translation_finished_reported_(false), 105 translation_finished_reported_(false),
106 pexe_url_(pexe_url), 106 pexe_url_(pexe_url),
107 pnacl_options_(pnacl_options), 107 pnacl_options_(pnacl_options),
108 architecture_attributes_(GetArchitectureAttributes(plugin)), 108 architecture_attributes_(GetArchitectureAttributes(plugin)),
109 split_module_count_(1), 109 split_module_count_(1),
110 num_object_files_opened_(0),
111 is_cache_hit_(PP_FALSE), 110 is_cache_hit_(PP_FALSE),
112 error_already_reported_(false), 111 error_already_reported_(false),
113 pnacl_init_time_(0), 112 pnacl_init_time_(0),
114 pexe_size_(0), 113 pexe_size_(0),
115 pexe_bytes_compiled_(0), 114 pexe_bytes_compiled_(0),
116 expected_pexe_size_(-1) { 115 expected_pexe_size_(-1) {
117 PLUGIN_PRINTF(("PnaclCoordinator::PnaclCoordinator (this=%p, plugin=%p)\n", 116 PLUGIN_PRINTF(("PnaclCoordinator::PnaclCoordinator (this=%p, plugin=%p)\n",
118 static_cast<void*>(this), static_cast<void*>(plugin))); 117 static_cast<void*>(this), static_cast<void*>(plugin)));
119 callback_factory_.Initialize(this); 118 callback_factory_.Initialize(this);
120 } 119 }
121 120
122 PnaclCoordinator::~PnaclCoordinator() { 121 PnaclCoordinator::~PnaclCoordinator() {
123 PLUGIN_PRINTF(("PnaclCoordinator::~PnaclCoordinator (this=%p, " 122 PLUGIN_PRINTF(("PnaclCoordinator::~PnaclCoordinator (this=%p, "
124 "translate_thread=%p\n", 123 "translate_thread=%p\n",
125 static_cast<void*>(this), translate_thread_.get())); 124 static_cast<void*>(this), translate_thread_.get()));
126 // Stopping the translate thread will cause the translate thread to try to 125 // Stopping the translate thread will cause the translate thread to try to
127 // run translation_complete_callback_ on the main thread. This destructor is 126 // run translation_complete_callback_ on the main thread. This destructor is
128 // running from the main thread, and by the time it exits, callback_factory_ 127 // running from the main thread, and by the time it exits, callback_factory_
129 // will have been destroyed. This will result in the cancellation of 128 // will have been destroyed. This will result in the cancellation of
130 // translation_complete_callback_, so no notification will be delivered. 129 // translation_complete_callback_, so no notification will be delivered.
131 if (translate_thread_.get() != NULL) { 130 if (translate_thread_.get() != NULL)
132 translate_thread_->AbortSubprocesses(); 131 translate_thread_->AbortSubprocesses();
133 }
134 if (!translation_finished_reported_) { 132 if (!translation_finished_reported_) {
135 plugin_->nacl_interface()->ReportTranslationFinished( 133 plugin_->nacl_interface()->ReportTranslationFinished(
136 plugin_->pp_instance(), 134 plugin_->pp_instance(),
137 PP_FALSE, 0, 0, 0, 0); 135 PP_FALSE, 0, 0, 0, 0);
138 } 136 }
139 // Force deleting the translate_thread now. It must be deleted 137 // Force deleting the translate_thread now. It must be deleted
140 // before any scoped_* fields hanging off of PnaclCoordinator 138 // before any scoped_* fields hanging off of PnaclCoordinator
141 // since the thread may be accessing those fields. 139 // since the thread may be accessing those fields.
142 // It will also be accessing obj_files_. 140 // It will also be accessing obj_files_.
143 translate_thread_.reset(NULL); 141 translate_thread_.reset(NULL);
144 // TODO(jvoung): use base/memory/scoped_vector.h to hold obj_files_. 142 for (size_t i = 0; i < obj_files_.size(); i++)
145 for (int i = 0; i < num_object_files_opened_; i++) {
146 delete obj_files_[i]; 143 delete obj_files_[i];
147 }
148 } 144 }
149 145
150 PP_FileHandle PnaclCoordinator::TakeTranslatedFileHandle() { 146 PP_FileHandle PnaclCoordinator::TakeTranslatedFileHandle() {
151 DCHECK(temp_nexe_file_ != NULL); 147 DCHECK(temp_nexe_file_ != NULL);
152 return temp_nexe_file_->TakeFileHandle(); 148 return temp_nexe_file_->TakeFileHandle();
153 } 149 }
154 150
155 void PnaclCoordinator::ReportNonPpapiError(PP_NaClError err_code, 151 void PnaclCoordinator::ReportNonPpapiError(PP_NaClError err_code,
156 const nacl::string& message) { 152 const nacl::string& message) {
157 ErrorInfo error_info; 153 ErrorInfo error_info;
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 392
397 if (is_cache_hit_ == PP_TRUE) { 393 if (is_cache_hit_ == PP_TRUE) {
398 // Cache hit -- no need to stream the rest of the file. 394 // Cache hit -- no need to stream the rest of the file.
399 streaming_downloader_.reset(NULL); 395 streaming_downloader_.reset(NULL);
400 // Open it for reading as the cached nexe file. 396 // Open it for reading as the cached nexe file.
401 NexeReadDidOpen(temp_nexe_file_->Open(false)); 397 NexeReadDidOpen(temp_nexe_file_->Open(false));
402 } else { 398 } else {
403 // Open an object file first so the translator can start writing to it 399 // Open an object file first so the translator can start writing to it
404 // during streaming translation. 400 // during streaming translation.
405 for (int i = 0; i < split_module_count_; i++) { 401 for (int i = 0; i < split_module_count_; i++) {
406 obj_files_.push_back(new TempFile(plugin_)); 402 nacl::scoped_ptr<TempFile> temp_file(new TempFile(plugin_));
407 int32_t pp_error = obj_files_[i]->Open(true); 403 int32_t pp_error = temp_file->Open(true);
408 if (pp_error != PP_OK) { 404 if (pp_error != PP_OK) {
409 ReportPpapiError(PP_NACL_ERROR_PNACL_CREATE_TEMP, 405 ReportPpapiError(PP_NACL_ERROR_PNACL_CREATE_TEMP,
410 pp_error, 406 pp_error,
411 "Failed to open scratch object file."); 407 "Failed to open scratch object file.");
408 return;
412 } else { 409 } else {
413 num_object_files_opened_++; 410 obj_files_.push_back(temp_file.release());
414 } 411 }
415 } 412 }
416 invalid_desc_wrapper_.reset(plugin_->wrapper_factory()->MakeInvalid()); 413 invalid_desc_wrapper_.reset(plugin_->wrapper_factory()->MakeInvalid());
417 414
418 // Meanwhile, a miss means we know we need to stream the bitcode, so stream 415 // Meanwhile, a miss means we know we need to stream the bitcode, so stream
419 // the rest of it now. (Calling BeginStreaming means that the downloader 416 // the rest of it now. (Calling BeginStreaming means that the downloader
420 // will begin handing data to the coordinator, which is safe any time after 417 // will begin handing data to the coordinator, which is safe any time after
421 // the translate_thread_ object has been initialized). 418 // the translate_thread_ object has been initialized).
422 pp::CompletionCallback finish_cb = callback_factory_.NewCallback( 419 pp::CompletionCallback finish_cb = callback_factory_.NewCallback(
423 &PnaclCoordinator::BitcodeStreamDidFinish); 420 &PnaclCoordinator::BitcodeStreamDidFinish);
424 streaming_downloader_->BeginStreaming(finish_cb); 421 streaming_downloader_->BeginStreaming(finish_cb);
425 422
426 if (num_object_files_opened_ == split_module_count_) { 423 // Open the nexe file for connecting ld and sel_ldr.
427 // Open the nexe file for connecting ld and sel_ldr. 424 // Start translation when done with this last step of setup!
428 // Start translation when done with this last step of setup! 425 RunTranslate(temp_nexe_file_->Open(true));
429 RunTranslate(temp_nexe_file_->Open(true));
430 }
431 } 426 }
432 } 427 }
433 428
434 void PnaclCoordinator::BitcodeStreamDidFinish(int32_t pp_error) { 429 void PnaclCoordinator::BitcodeStreamDidFinish(int32_t pp_error) {
435 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeStreamDidFinish (pp_error=%" 430 PLUGIN_PRINTF(("PnaclCoordinator::BitcodeStreamDidFinish (pp_error=%"
436 NACL_PRId32 ")\n", pp_error)); 431 NACL_PRId32 ")\n", pp_error));
437 if (pp_error != PP_OK) { 432 if (pp_error != PP_OK) {
438 // Defer reporting the error and cleanup until after the translation 433 // Defer reporting the error and cleanup until after the translation
439 // thread returns, because it may be accessing the coordinator's 434 // thread returns, because it may be accessing the coordinator's
440 // objects or writing to the files. 435 // objects or writing to the files.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 invalid_desc_wrapper_.get(), 531 invalid_desc_wrapper_.get(),
537 &error_info_, 532 &error_info_,
538 resources_.get(), 533 resources_.get(),
539 &pnacl_options_, 534 &pnacl_options_,
540 architecture_attributes_, 535 architecture_attributes_,
541 this, 536 this,
542 plugin_); 537 plugin_);
543 } 538 }
544 539
545 } // namespace plugin 540 } // namespace plugin
OLDNEW
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698