Chromium Code Reviews| 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 "components/nacl/renderer/plugin/pnacl_coordinator.h" | 5 #include "components/nacl/renderer/plugin/pnacl_coordinator.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 } | 140 } |
| 141 | 141 |
| 142 void PnaclCoordinator::ReportNonPpapiError(PP_NaClError err_code, | 142 void PnaclCoordinator::ReportNonPpapiError(PP_NaClError err_code, |
| 143 const std::string& message) { | 143 const std::string& message) { |
| 144 ErrorInfo error_info; | 144 ErrorInfo error_info; |
| 145 error_info.SetReport(err_code, message); | 145 error_info.SetReport(err_code, message); |
| 146 plugin_->ReportLoadError(error_info); | 146 plugin_->ReportLoadError(error_info); |
| 147 ExitWithError(); | 147 ExitWithError(); |
| 148 } | 148 } |
| 149 | 149 |
| 150 void PnaclCoordinator::ReportPpapiError(PP_NaClError err_code, | |
| 151 int32_t pp_error, | |
| 152 const std::string& message) { | |
| 153 std::stringstream ss; | |
| 154 ss << "PnaclCoordinator: " << message << " (pp_error=" << pp_error << ")."; | |
| 155 ErrorInfo error_info; | |
| 156 error_info.SetReport(err_code, ss.str()); | |
| 157 plugin_->ReportLoadError(error_info); | |
| 158 ExitWithError(); | |
| 159 } | |
| 160 | |
| 161 void PnaclCoordinator::ExitWithError() { | 150 void PnaclCoordinator::ExitWithError() { |
| 162 PLUGIN_PRINTF(("PnaclCoordinator::ExitWithError\n")); | 151 PLUGIN_PRINTF(("PnaclCoordinator::ExitWithError\n")); |
| 163 // Free all the intermediate callbacks we ever created. | 152 // Free all the intermediate callbacks we ever created. |
| 164 // Note: this doesn't *cancel* the callbacks from the factories attached | 153 // Note: this doesn't *cancel* the callbacks from the factories attached |
| 165 // to the various helper classes (e.g., pnacl_resources). Thus, those | 154 // to the various helper classes (e.g., pnacl_resources). Thus, those |
| 166 // callbacks may still run asynchronously. We let those run but ignore | 155 // callbacks may still run asynchronously. We let those run but ignore |
| 167 // any other errors they may generate so that they do not end up running | 156 // any other errors they may generate so that they do not end up running |
| 168 // translate_notify_callback_, which has already been freed. | 157 // translate_notify_callback_, which has already been freed. |
| 169 callback_factory_.CancelAll(); | 158 callback_factory_.CancelAll(); |
| 170 if (!error_already_reported_) { | 159 if (!error_already_reported_) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 temp_nexe_file_->Reset(); | 195 temp_nexe_file_->Reset(); |
| 207 | 196 |
| 208 // Report to the browser that translation finished. The browser will take | 197 // Report to the browser that translation finished. The browser will take |
| 209 // care of storing the nexe in the cache. | 198 // care of storing the nexe in the cache. |
| 210 translation_finished_reported_ = true; | 199 translation_finished_reported_ = true; |
| 211 plugin_->nacl_interface()->ReportTranslationFinished( | 200 plugin_->nacl_interface()->ReportTranslationFinished( |
| 212 plugin_->pp_instance(), PP_TRUE, pnacl_options_.opt_level, | 201 plugin_->pp_instance(), PP_TRUE, pnacl_options_.opt_level, |
| 213 pnacl_options_.use_subzero, nexe_size, pexe_size_, | 202 pnacl_options_.use_subzero, nexe_size, pexe_size_, |
| 214 translate_thread_->GetCompileTime()); | 203 translate_thread_->GetCompileTime()); |
| 215 | 204 |
| 216 NexeReadDidOpen(PP_OK); | 205 NexeReadDidOpen(true); |
| 217 } | 206 } |
| 218 | 207 |
| 219 void PnaclCoordinator::NexeReadDidOpen(int32_t pp_error) { | 208 void PnaclCoordinator::NexeReadDidOpen(bool success) { |
| 220 PLUGIN_PRINTF(("PnaclCoordinator::NexeReadDidOpen (pp_error=%" | 209 if (!success) { |
|
bbudge
2016/01/20 21:25:57
Could you just test temp_nexe_file_->IsValid() her
Mark Seaborn
2016/01/20 21:49:47
Good point! Done.
| |
| 221 NACL_PRId32 ")\n", pp_error)); | 210 ReportNonPpapiError(PP_NACL_ERROR_PNACL_CACHE_FETCH_OTHER, |
| 222 if (pp_error != PP_OK) { | 211 "Failed to open translated nexe."); |
| 223 if (pp_error == PP_ERROR_FILENOTFOUND) { | |
| 224 ReportPpapiError(PP_NACL_ERROR_PNACL_CACHE_FETCH_NOTFOUND, | |
| 225 pp_error, | |
| 226 "Failed to open translated nexe (not found)."); | |
| 227 return; | |
| 228 } | |
| 229 if (pp_error == PP_ERROR_NOACCESS) { | |
| 230 ReportPpapiError(PP_NACL_ERROR_PNACL_CACHE_FETCH_NOACCESS, | |
| 231 pp_error, | |
| 232 "Failed to open translated nexe (no access)."); | |
| 233 return; | |
| 234 } | |
| 235 ReportPpapiError(PP_NACL_ERROR_PNACL_CACHE_FETCH_OTHER, | |
| 236 pp_error, | |
| 237 "Failed to open translated nexe."); | |
| 238 return; | 212 return; |
| 239 } | 213 } |
| 240 | 214 |
| 241 translate_notify_callback_.Run(PP_OK); | 215 translate_notify_callback_.Run(PP_OK); |
| 242 } | 216 } |
| 243 | 217 |
| 244 void PnaclCoordinator::OpenBitcodeStream() { | 218 void PnaclCoordinator::OpenBitcodeStream() { |
| 245 // Even though we haven't started downloading, create the translation | 219 // Even though we haven't started downloading, create the translation |
| 246 // thread object immediately. This ensures that any pieces of the file | 220 // thread object immediately. This ensures that any pieces of the file |
| 247 // that get downloaded before the compilation thread is accepting | 221 // that get downloaded before the compilation thread is accepting |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 263 if (handle == PP_kInvalidFileHandle) { | 237 if (handle == PP_kInvalidFileHandle) { |
| 264 ReportNonPpapiError( | 238 ReportNonPpapiError( |
| 265 PP_NACL_ERROR_PNACL_CREATE_TEMP, | 239 PP_NACL_ERROR_PNACL_CREATE_TEMP, |
| 266 std::string( | 240 std::string( |
| 267 "PnaclCoordinator: Got bad temp file handle from GetNexeFd")); | 241 "PnaclCoordinator: Got bad temp file handle from GetNexeFd")); |
| 268 BitcodeStreamDidFinish(PP_ERROR_FAILED); | 242 BitcodeStreamDidFinish(PP_ERROR_FAILED); |
| 269 return; | 243 return; |
| 270 } | 244 } |
| 271 temp_nexe_file_.reset(new TempFile(plugin_, handle)); | 245 temp_nexe_file_.reset(new TempFile(plugin_, handle)); |
| 272 // Open it for reading as the cached nexe file. | 246 // Open it for reading as the cached nexe file. |
| 273 NexeReadDidOpen(temp_nexe_file_->CheckValidity()); | 247 NexeReadDidOpen(temp_nexe_file_->IsValid()); |
| 274 } | 248 } |
| 275 | 249 |
| 276 void PnaclCoordinator::BitcodeStreamCacheMiss(int64_t expected_pexe_size, | 250 void PnaclCoordinator::BitcodeStreamCacheMiss(int64_t expected_pexe_size, |
| 277 PP_FileHandle nexe_handle) { | 251 PP_FileHandle nexe_handle) { |
| 278 // IMPORTANT: Make sure that PnaclResources::StartLoad() is only | 252 // IMPORTANT: Make sure that PnaclResources::StartLoad() is only |
| 279 // called after you receive a response to a request for a .pexe file. | 253 // called after you receive a response to a request for a .pexe file. |
| 280 // | 254 // |
| 281 // The component updater's resource throttles + OnDemand update/install | 255 // The component updater's resource throttles + OnDemand update/install |
| 282 // should block the URL request until the compiler is present. Now we | 256 // should block the URL request until the compiler is present. Now we |
| 283 // can load the resources (e.g. llc and ld nexes). | 257 // can load the resources (e.g. llc and ld nexes). |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 301 "information.")); | 275 "information.")); |
| 302 return; | 276 return; |
| 303 } | 277 } |
| 304 | 278 |
| 305 expected_pexe_size_ = expected_pexe_size; | 279 expected_pexe_size_ = expected_pexe_size; |
| 306 | 280 |
| 307 for (int i = 0; i < split_module_count_; i++) { | 281 for (int i = 0; i < split_module_count_; i++) { |
| 308 PP_FileHandle obj_handle = | 282 PP_FileHandle obj_handle = |
| 309 plugin_->nacl_interface()->CreateTemporaryFile(plugin_->pp_instance()); | 283 plugin_->nacl_interface()->CreateTemporaryFile(plugin_->pp_instance()); |
| 310 scoped_ptr<TempFile> temp_file(new TempFile(plugin_, obj_handle)); | 284 scoped_ptr<TempFile> temp_file(new TempFile(plugin_, obj_handle)); |
| 311 int32_t pp_error = temp_file->CheckValidity(); | 285 if (!temp_file->IsValid()) { |
| 312 if (pp_error != PP_OK) { | 286 ReportNonPpapiError(PP_NACL_ERROR_PNACL_CREATE_TEMP, |
| 313 ReportPpapiError(PP_NACL_ERROR_PNACL_CREATE_TEMP, | 287 "Failed to open scratch object file."); |
| 314 pp_error, | |
| 315 "Failed to open scratch object file."); | |
| 316 return; | 288 return; |
| 317 } else { | 289 } else { |
| 318 obj_files_.push_back(temp_file.release()); | 290 obj_files_.push_back(temp_file.release()); |
| 319 } | 291 } |
| 320 } | 292 } |
| 321 | 293 |
| 322 temp_nexe_file_.reset(new TempFile(plugin_, nexe_handle)); | 294 temp_nexe_file_.reset(new TempFile(plugin_, nexe_handle)); |
| 323 // Open the nexe file for connecting ld and sel_ldr. | 295 // Open the nexe file for connecting ld and sel_ldr. |
| 324 // Start translation when done with this last step of setup! | 296 // Start translation when done with this last step of setup! |
| 325 int32_t pp_error = temp_nexe_file_->CheckValidity(); | 297 if (!temp_nexe_file_->IsValid()) { |
| 326 if (pp_error != PP_OK) { | |
| 327 ReportNonPpapiError( | 298 ReportNonPpapiError( |
| 328 PP_NACL_ERROR_PNACL_CREATE_TEMP, | 299 PP_NACL_ERROR_PNACL_CREATE_TEMP, |
| 329 std::string( | 300 std::string( |
| 330 "PnaclCoordinator: Got bad temp file handle from writing nexe")); | 301 "PnaclCoordinator: Got bad temp file handle from writing nexe")); |
| 331 return; | 302 return; |
| 332 } | 303 } |
| 333 LoadCompiler(); | 304 LoadCompiler(); |
| 334 } | 305 } |
| 335 | 306 |
| 336 void PnaclCoordinator::BitcodeStreamGotData(const void* data, int32_t length) { | 307 void PnaclCoordinator::BitcodeStreamGotData(const void* data, int32_t length) { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 483 "PnaclCoordinator: Linker process could not be created."); | 454 "PnaclCoordinator: Linker process could not be created."); |
| 484 return; | 455 return; |
| 485 } | 456 } |
| 486 GetNaClInterface()->LogTranslateTime( | 457 GetNaClInterface()->LogTranslateTime( |
| 487 "NaCl.Perf.PNaClLoadTime.LoadLinker", | 458 "NaCl.Perf.PNaClLoadTime.LoadLinker", |
| 488 NaClGetTimeOfDayMicroseconds() - ld_load_start_time); | 459 NaClGetTimeOfDayMicroseconds() - ld_load_start_time); |
| 489 translate_thread_->RunLink(); | 460 translate_thread_->RunLink(); |
| 490 } | 461 } |
| 491 | 462 |
| 492 } // namespace plugin | 463 } // namespace plugin |
| OLD | NEW |