bug 539552 - make PluginModuleParent write out more data to .extra file. r=bsmedberg

--HG--
extra : transplant_source : %C1P%99%80%8E%2C%92%7B%8C%BF%40c%40%FD%18%1F%AE%0E%D8%D9
This commit is contained in:
Ted Mielczarek 2010-01-13 20:20:00 -05:00
Родитель f69b89b495
Коммит cca33bca9a
3 изменённых файлов: 77 добавлений и 2 удалений

Просмотреть файл

@ -39,6 +39,7 @@
#include "mozilla/plugins/PluginModuleParent.h"
#include "mozilla/plugins/BrowserStreamParent.h"
#include "nsCRT.h"
#include "nsNPAPIPlugin.h"
using mozilla::PluginLibrary;
@ -70,6 +71,7 @@ PluginModuleParent::PluginModuleParent(const char* aFilePath)
, mShutdown(false)
, mNPNIface(NULL)
, mPlugin(NULL)
, mProcessStartTime(time(NULL))
{
NS_ASSERTION(mSubprocess, "Out of memory!");
@ -93,11 +95,76 @@ PluginModuleParent::~PluginModuleParent()
}
}
void
PluginModuleParent::WriteExtraDataEntry(nsIFileOutputStream* stream,
const char* key,
const char* value)
{
PRUint32 written;
stream->Write(key, strlen(key), &written);
stream->Write("=", 1, &written);
stream->Write(value, strlen(value), &written);
stream->Write("\n", 1, &written);
}
void
PluginModuleParent::WriteExtraDataForMinidump(nsIFile* dumpFile)
{
// get a reference to the extra file, and add some more entries
nsCOMPtr<nsIFile> extraFile;
nsresult rv = dumpFile->Clone(getter_AddRefs(extraFile));
if (NS_FAILED(rv))
return;
nsAutoString leafName;
rv = extraFile->GetLeafName(leafName);
if (NS_FAILED(rv))
return;
leafName.Replace(leafName.Length() - 3, 3,
NS_LITERAL_STRING("extra"));
rv = extraFile->SetLeafName(leafName);
if (NS_FAILED(rv))
return;
nsCOMPtr<nsIFileOutputStream> stream =
do_CreateInstance("@mozilla.org/network/file-output-stream;1");
// PR_WRONLY | PR_APPEND
rv = stream->Init(extraFile, 0x12, 0600, 0);
if (NS_FAILED(rv))
return;
WriteExtraDataEntry(stream, "ProcessType", "plugin");
char startTime[32];
sprintf(startTime, "%lld", static_cast<PRInt64>(mProcessStartTime));
WriteExtraDataEntry(stream, "StartupTime", startTime);
// Get the plugin filename, try to get just the file leafname
const std::string& pluginFile = mSubprocess->GetPluginFilePath();
size_t filePos = pluginFile.rfind(FILE_PATH_SEPARATOR);
if (filePos == std::string::npos)
filePos = 0;
else
filePos++;
WriteExtraDataEntry(stream, "PluginFilename",
pluginFile.substr(filePos).c_str());
//TODO: add plugin name and version: bug 539841
// (as PluginName, PluginVersion)
stream->Close();
}
void
PluginModuleParent::ActorDestroy(ActorDestroyReason why)
{
switch (why) {
case AbnormalShutdown:
case AbnormalShutdown: {
nsCOMPtr<nsIFile> dump;
if (GetMinidump(getter_AddRefs(dump))) {
WriteExtraDataForMinidump(dump);
}
else {
NS_WARNING("[PluginModuleParent::ActorDestroy] abnormal shutdown without minidump!");
}
mShutdown = true;
// Defer the PluginCrashed method so that we don't re-enter
// and potentially modify the actor child list while enumerating it.
@ -108,7 +175,7 @@ PluginModuleParent::ActorDestroy(ActorDestroyReason why)
NS_DispatchToMainThread(r);
}
break;
}
case NormalShutdown:
mShutdown = true;
break;

Просмотреть файл

@ -58,6 +58,7 @@
#include "nsAutoPtr.h"
#include "nsTHashtable.h"
#include "nsHashKeys.h"
#include "nsIFileStreams.h"
namespace mozilla {
namespace plugins {
@ -210,11 +211,16 @@ private:
char* argv[], NPSavedData* saved,
NPError* error);
private:
void WriteExtraDataForMinidump(nsIFile* dumpFile);
void WriteExtraDataEntry(nsIFileOutputStream* stream,
const char* key,
const char* value);
PluginProcessParent* mSubprocess;
bool mShutdown;
const NPNetscapeFuncs* mNPNIface;
nsTHashtable<nsVoidPtrHashKey> mValidIdentifiers;
nsNPAPIPlugin* mPlugin;
time_t mProcessStartTime;
};
} // namespace plugins

Просмотреть файл

@ -72,6 +72,8 @@ public:
return true;
}
const std::string& GetPluginFilePath() { return mPluginFilePath; }
using mozilla::ipc::GeckoChildProcessHost::GetShutDownEvent;
using mozilla::ipc::GeckoChildProcessHost::GetChannel;
using mozilla::ipc::GeckoChildProcessHost::GetChildProcessHandle;