This source file includes following definitions.
- OnCallSucceededHelper
- OnCallFailed
- OnCallCompletedHelper
- at_exit_manager_
- New
- OnCallSucceeded
- Destroy
- OnCallCompleted
#define UNIT_TEST  
#include "base/at_exit.h"
#include "content/test/plugin/plugin_thread_async_call_test.h"
#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "base/strings/string_util.h"
#include "base/threading/thread.h"
#include "content/test/plugin/plugin_client.h"
namespace NPAPIClient {
namespace {
PluginThreadAsyncCallTest* g_short_lived_instance;
PluginThreadAsyncCallTest* g_long_lived_instance;
void OnCallSucceededHelper(void* data) {
  static_cast<PluginThreadAsyncCallTest*>(data)->OnCallSucceeded();
}
void OnCallFailed(void* data) {
  g_long_lived_instance->SetError("Async callback invoked after NPP_Destroy");
}
void OnCallCompletedHelper(void* data) {
  static_cast<PluginThreadAsyncCallTest*>(data)->OnCallCompleted();
}
}
PluginThreadAsyncCallTest::PluginThreadAsyncCallTest(
    NPP id, NPNetscapeFuncs *host_functions)
    : PluginTest(id, host_functions), at_exit_manager_(NULL) {
}
PluginThreadAsyncCallTest::~PluginThreadAsyncCallTest() {
  delete at_exit_manager_;
}
NPError PluginThreadAsyncCallTest::New(
    uint16 mode, int16 argc, const char* argn[], const char* argv[],
    NPSavedData* saved) {
  NPError error = PluginTest::New(mode, argc, argn, argv, saved);
  if (error != NPERR_NO_ERROR)
    return error;
  
  for (int i = 0; i < argc; ++i) {
    if (base::strcasecmp(argn[i], "short_lived") == 0) {
      if (base::strcasecmp(argv[i], "true") == 0) {
        g_short_lived_instance = this;
      } else {
        g_long_lived_instance = this;
      }
    }
  }
  
  
  if (this == g_short_lived_instance) {
    
    
    
    at_exit_manager_ = new base::ShadowingAtExitManager();
    base::Thread random_thread("random_thread");
    random_thread.Start();
    random_thread.message_loop()->PostTask(
        FROM_HERE, base::Bind(&PluginThreadAsyncCallTest::AsyncCall,
                              base::Unretained(this)));
  }
  return NPERR_NO_ERROR;
}
void PluginThreadAsyncCallTest::AsyncCall() {
  HostFunctions()->pluginthreadasynccall(id(), OnCallSucceededHelper, this);
}
void PluginThreadAsyncCallTest::OnCallSucceeded() {
  
  NPIdentifier delete_id = HostFunctions()->getstringidentifier(
      "deleteShortLivedInstance");
  NPObject *window_obj = NULL;
  HostFunctions()->getvalue(id(), NPNVWindowNPObject, &window_obj);
  NPVariant result;
  HostFunctions()->invoke(id(), window_obj, delete_id, NULL, 0, &result);
}
NPError PluginThreadAsyncCallTest::Destroy() {
  if (this == g_short_lived_instance) {
    
    HostFunctions()->pluginthreadasynccall(id(), OnCallFailed, NULL);
    
    HostFunctions()->pluginthreadasynccall(g_long_lived_instance->id(),
                                           OnCallCompletedHelper,
                                           g_long_lived_instance);
  }
  return NPERR_NO_ERROR;
}
void PluginThreadAsyncCallTest::OnCallCompleted() {
  SignalTestCompleted();
}
}