diff options
Diffstat (limited to 'ppapi/native_client/src/trusted/plugin/plugin.cc')
-rw-r--r-- | ppapi/native_client/src/trusted/plugin/plugin.cc | 250 |
1 files changed, 115 insertions, 135 deletions
diff --git a/ppapi/native_client/src/trusted/plugin/plugin.cc b/ppapi/native_client/src/trusted/plugin/plugin.cc index 2bf3021..3309d65 100644 --- a/ppapi/native_client/src/trusted/plugin/plugin.cc +++ b/ppapi/native_client/src/trusted/plugin/plugin.cc @@ -34,7 +34,6 @@ #include "ppapi/c/ppb_var.h" #include "ppapi/c/ppp_instance.h" #include "ppapi/c/private/ppb_nacl_private.h" -#include "ppapi/c/private/ppb_uma_private.h" #include "ppapi/cpp/dev/url_util_dev.h" #include "ppapi/cpp/module.h" #include "ppapi/cpp/text_input_controller.h" @@ -104,63 +103,108 @@ const PPB_NaCl_Private* GetNaClInterface() { module->GetBrowserInterface(PPB_NACL_PRIVATE_INTERFACE)); } -const PPB_UMA_Private* GetUMAInterface() { - pp::Module *module = pp::Module::Get(); - CHECK(module); - return static_cast<const PPB_UMA_Private*>( - module->GetBrowserInterface(PPB_UMA_PRIVATE_INTERFACE)); -} +} // namespace -void HistogramTimeSmall(const std::string& name, int64_t ms) { - if (ms < 0) return; +bool Plugin::EarlyInit(int argc, const char* argn[], const char* argv[]) { + PLUGIN_PRINTF(("Plugin::EarlyInit (instance=%p)\n", + static_cast<void*>(this))); + +#ifdef NACL_OSX + // TODO(kochi): For crbug.com/102808, this is a stopgap solution for Lion + // until we expose IME API to .nexe. This disables any IME interference + // against key inputs, so you cannot use off-the-spot IME input for NaCl apps. + // This makes discrepancy among platforms and therefore we should remove + // this hack when IME API is made available. + // The default for non-Mac platforms is still off-the-spot IME mode. + pp::TextInputController(this).SetTextInputType(PP_TEXTINPUT_TYPE_NONE); +#endif + + // Remember the embed/object argn/argv pairs. + argn_ = new char*[argc]; + argv_ = new char*[argc]; + argc_ = 0; + for (int i = 0; i < argc; ++i) { + if (NULL != argn_ && NULL != argv_) { + argn_[argc_] = strdup(argn[i]); + argv_[argc_] = strdup(argv[i]); + if (NULL == argn_[argc_] || NULL == argv_[argc_]) { + // Give up on passing arguments. + free(argn_[argc_]); + free(argv_[argc_]); + continue; + } + ++argc_; + } + } + // TODO(sehr): this leaks strings if there is a subsequent failure. - const PPB_UMA_Private* ptr = GetUMAInterface(); - if (ptr == NULL) return; + // Set up the factory used to produce DescWrappers. + wrapper_factory_ = new nacl::DescWrapperFactory(); + if (NULL == wrapper_factory_) { + return false; + } + PLUGIN_PRINTF(("Plugin::Init (wrapper_factory=%p)\n", + static_cast<void*>(wrapper_factory_))); - ptr->HistogramCustomTimes(pp::Var(name).pp_var(), - ms, - kTimeSmallMin, kTimeSmallMax, - kTimeSmallBuckets); + PLUGIN_PRINTF(("Plugin::Init (return 1)\n")); + // Return success. + return true; } -void HistogramTimeMedium(const std::string& name, int64_t ms) { - if (ms < 0) return; +void Plugin::ShutDownSubprocesses() { + PLUGIN_PRINTF(("Plugin::ShutDownSubprocesses (this=%p)\n", + static_cast<void*>(this))); + PLUGIN_PRINTF(("Plugin::ShutDownSubprocesses (%s)\n", + main_subprocess_.detailed_description().c_str())); - const PPB_UMA_Private* ptr = GetUMAInterface(); - if (ptr == NULL) return; + // Shut down service runtime. This must be done before all other calls so + // they don't block forever when waiting for the upcall thread to exit. + main_subprocess_.Shutdown(); - ptr->HistogramCustomTimes(pp::Var(name).pp_var(), - ms, - kTimeMediumMin, kTimeMediumMax, - kTimeMediumBuckets); + PLUGIN_PRINTF(("Plugin::ShutDownSubprocess (this=%p, return)\n", + static_cast<void*>(this))); } -void HistogramTimeLarge(const std::string& name, int64_t ms) { +void Plugin::HistogramTimeSmall(const std::string& name, + int64_t ms) { if (ms < 0) return; + uma_interface_.HistogramCustomTimes(name, + ms, + kTimeSmallMin, kTimeSmallMax, + kTimeSmallBuckets); +} - const PPB_UMA_Private* ptr = GetUMAInterface(); - if (ptr == NULL) return; +void Plugin::HistogramTimeMedium(const std::string& name, + int64_t ms) { + if (ms < 0) return; + uma_interface_.HistogramCustomTimes(name, + ms, + kTimeMediumMin, kTimeMediumMax, + kTimeMediumBuckets); +} - ptr->HistogramCustomTimes(pp::Var(name).pp_var(), - ms, - kTimeLargeMin, kTimeLargeMax, - kTimeLargeBuckets); +void Plugin::HistogramTimeLarge(const std::string& name, + int64_t ms) { + if (ms < 0) return; + uma_interface_.HistogramCustomTimes(name, + ms, + kTimeLargeMin, kTimeLargeMax, + kTimeLargeBuckets); } -void HistogramSizeKB(const std::string& name, int32_t sample) { +void Plugin::HistogramSizeKB(const std::string& name, + int32_t sample) { if (sample < 0) return; - - const PPB_UMA_Private* ptr = GetUMAInterface(); - if (ptr == NULL) return; - - ptr->HistogramCustomCounts(pp::Var(name).pp_var(), - sample, - kSizeKBMin, kSizeKBMax, - kSizeKBBuckets); + uma_interface_.HistogramCustomCounts(name, + sample, + kSizeKBMin, kSizeKBMax, + kSizeKBBuckets); } -void HistogramEnumerate(const std::string& name, int sample, int maximum, - int out_of_range_replacement) { +void Plugin::HistogramEnumerate(const std::string& name, + int sample, + int maximum, + int out_of_range_replacement) { if (sample < 0 || sample >= maximum) { if (out_of_range_replacement < 0) // No replacement for bad input, abort. @@ -169,12 +213,10 @@ void HistogramEnumerate(const std::string& name, int sample, int maximum, // Use a specific value to signal a bad input. sample = out_of_range_replacement; } - const PPB_UMA_Private* ptr = GetUMAInterface(); - if (ptr == NULL) return; - ptr->HistogramEnumeration(pp::Var(name).pp_var(), sample, maximum); + uma_interface_.HistogramEnumeration(name, sample, maximum); } -void HistogramEnumerateOsArch(const std::string& sandbox_isa) { +void Plugin::HistogramEnumerateOsArch(const std::string& sandbox_isa) { enum NaClOSArch { kNaClLinux32 = 0, kNaClLinux64, @@ -205,22 +247,21 @@ void HistogramEnumerateOsArch(const std::string& sandbox_isa) { HistogramEnumerate("NaCl.Client.OSArch", os_arch, kNaClOSArchMax, -1); } -void HistogramEnumerateLoadStatus(PluginErrorCode error_code, - bool is_installed) { +void Plugin::HistogramEnumerateLoadStatus(PluginErrorCode error_code, + bool is_installed) { HistogramEnumerate("NaCl.LoadStatus.Plugin", error_code, ERROR_MAX, ERROR_UNKNOWN); // Gather data to see if being installed changes load outcomes. const char* name = is_installed ? "NaCl.LoadStatus.Plugin.InstalledApp" : "NaCl.LoadStatus.Plugin.NotInstalledApp"; - HistogramEnumerate(name, error_code, ERROR_MAX, - ERROR_UNKNOWN); + HistogramEnumerate(name, error_code, ERROR_MAX, ERROR_UNKNOWN); } -void HistogramEnumerateSelLdrLoadStatus(NaClErrorCode error_code, - bool is_installed) { - HistogramEnumerate("NaCl.LoadStatus.SelLdr", error_code, NACL_ERROR_CODE_MAX, - LOAD_STATUS_UNKNOWN); +void Plugin::HistogramEnumerateSelLdrLoadStatus(NaClErrorCode error_code, + bool is_installed) { + HistogramEnumerate("NaCl.LoadStatus.SelLdr", error_code, + NACL_ERROR_CODE_MAX, LOAD_STATUS_UNKNOWN); // Gather data to see if being installed changes load outcomes. const char* name = is_installed ? "NaCl.LoadStatus.SelLdr.InstalledApp" : @@ -229,11 +270,12 @@ void HistogramEnumerateSelLdrLoadStatus(NaClErrorCode error_code, LOAD_STATUS_UNKNOWN); } -void HistogramEnumerateManifestIsDataURI(bool is_data_uri) { +void Plugin::HistogramEnumerateManifestIsDataURI(bool is_data_uri) { HistogramEnumerate("NaCl.Manifest.IsDataURI", is_data_uri, 2, -1); } -void HistogramHTTPStatusCode(const std::string& name, int status) { +void Plugin::HistogramHTTPStatusCode(const std::string& name, + int status) { // Log the status codes in rough buckets - 1XX, 2XX, etc. int sample = status / 100; // HTTP status codes only go up to 5XX, using "6" to indicate an internal @@ -244,84 +286,6 @@ void HistogramHTTPStatusCode(const std::string& name, int status) { HistogramEnumerate(name, sample, 7, 6); } -} // namespace - -bool Plugin::EarlyInit(int argc, const char* argn[], const char* argv[]) { - PLUGIN_PRINTF(("Plugin::EarlyInit (instance=%p)\n", - static_cast<void*>(this))); - -#ifdef NACL_OSX - // TODO(kochi): For crbug.com/102808, this is a stopgap solution for Lion - // until we expose IME API to .nexe. This disables any IME interference - // against key inputs, so you cannot use off-the-spot IME input for NaCl apps. - // This makes discrepancy among platforms and therefore we should remove - // this hack when IME API is made available. - // The default for non-Mac platforms is still off-the-spot IME mode. - pp::TextInputController(this).SetTextInputType(PP_TEXTINPUT_TYPE_NONE); -#endif - - // Remember the embed/object argn/argv pairs. - argn_ = new char*[argc]; - argv_ = new char*[argc]; - argc_ = 0; - for (int i = 0; i < argc; ++i) { - if (NULL != argn_ && NULL != argv_) { - argn_[argc_] = strdup(argn[i]); - argv_[argc_] = strdup(argv[i]); - if (NULL == argn_[argc_] || NULL == argv_[argc_]) { - // Give up on passing arguments. - free(argn_[argc_]); - free(argv_[argc_]); - continue; - } - ++argc_; - } - } - // TODO(sehr): this leaks strings if there is a subsequent failure. - - // Set up the factory used to produce DescWrappers. - wrapper_factory_ = new nacl::DescWrapperFactory(); - if (NULL == wrapper_factory_) { - return false; - } - PLUGIN_PRINTF(("Plugin::Init (wrapper_factory=%p)\n", - static_cast<void*>(wrapper_factory_))); - - PLUGIN_PRINTF(("Plugin::Init (return 1)\n")); - // Return success. - return true; -} - -void Plugin::ShutDownSubprocesses() { - PLUGIN_PRINTF(("Plugin::ShutDownSubprocesses (this=%p)\n", - static_cast<void*>(this))); - PLUGIN_PRINTF(("Plugin::ShutDownSubprocesses (%s)\n", - main_subprocess_.detailed_description().c_str())); - - // Shut down service runtime. This must be done before all other calls so - // they don't block forever when waiting for the upcall thread to exit. - main_subprocess_.Shutdown(); - - PLUGIN_PRINTF(("Plugin::ShutDownSubprocess (this=%p, return)\n", - static_cast<void*>(this))); -} - -void Plugin::StartSelLdrOnMainThread(int32_t pp_error, - ServiceRuntime* service_runtime, - const SelLdrStartParams& params, - bool* success) { - if (pp_error != PP_OK) { - PLUGIN_PRINTF(("Plugin::StartSelLdrOnMainThread: non-PP_OK arg " - "-- SHOULD NOT HAPPEN\n")); - *success = false; - return; - } - *success = service_runtime->StartSelLdr(params); - // Signal outside of StartSelLdr here, so that the write to *success - // is done before signaling. - service_runtime->SignalStartSelLdrDone(); -} - bool Plugin::LoadNaClModuleCommon(nacl::DescWrapper* wrapper, NaClSubprocess* subprocess, const Manifest* manifest, @@ -374,6 +338,22 @@ bool Plugin::LoadNaClModuleCommon(nacl::DescWrapper* wrapper, return true; } +void Plugin::StartSelLdrOnMainThread(int32_t pp_error, + ServiceRuntime* service_runtime, + const SelLdrStartParams& params, + bool* success) { + if (pp_error != PP_OK) { + PLUGIN_PRINTF(("Plugin::StartSelLdrOnMainThread: non-PP_OK arg " + "-- SHOULD NOT HAPPEN\n")); + *success = false; + return; + } + *success = service_runtime->StartSelLdr(params); + // Signal outside of StartSelLdr here, so that the write to *success + // is done before signaling. + service_runtime->SignalStartSelLdrDone(); +} + bool Plugin::LoadNaClModule(nacl::DescWrapper* wrapper, ErrorInfo* error_info, bool enable_dyncode_syscalls, @@ -651,7 +631,8 @@ Plugin::Plugin(PP_Instance pp_instance) nexe_size_(0), time_of_last_progress_event_(0), exit_status_(-1), - nacl_interface_(NULL) { + nacl_interface_(NULL), + uma_interface_(this) { PLUGIN_PRINTF(("Plugin::Plugin (this=%p, pp_instance=%" NACL_PRId32 ")\n", static_cast<void*>(this), pp_instance)); callback_factory_.Initialize(this); @@ -1309,7 +1290,6 @@ void Plugin::ReportLoadSuccess(LengthComputable length_computable, } -// TODO(ncbray): report UMA stats void Plugin::ReportLoadError(const ErrorInfo& error_info) { PLUGIN_PRINTF(("Plugin::ReportLoadError (error='%s')\n", error_info.message().c_str())); |