Backed out 2 changesets (bug 1190252) for windows gtest permafails
authorWes Kocher <wkocher@mozilla.com>
Mon, 03 Aug 2015 16:00:53 -0700
changeset 287661 fa8755511ac220f1d0960df39276203cf84b05cb
parent 287660 fb5980199e219ff828262be3415994249f1c3753
child 287662 48a62f1685e111e3e79b963375374acddbf5cee4
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1190252
milestone42.0a1
backs out880fc4c49f7e870956ae23f1b5d159ab9d3afcb5
ba77cb6046b78898945248da5fd459a98f97f19c
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out 2 changesets (bug 1190252) for windows gtest permafails Backed out changeset 880fc4c49f7e (bug 1190252) Backed out changeset ba77cb6046b7 (bug 1190252)
dom/media/gmp/GMPChild.cpp
dom/media/gmp/GMPChild.h
dom/media/gmp/GMPProcessChild.cpp
--- a/dom/media/gmp/GMPChild.cpp
+++ b/dom/media/gmp/GMPChild.cpp
@@ -14,25 +14,20 @@
 #include "GMPVideoHost.h"
 #include "nsDebugImpl.h"
 #include "nsIFile.h"
 #include "nsXULAppAPI.h"
 #include "gmp-video-decode.h"
 #include "gmp-video-encode.h"
 #include "GMPPlatform.h"
 #include "mozilla/dom/CrashReporterChild.h"
-#include "nsPrintfCString.h"
-#include "mozilla/Tokenizer.h"
-#include "nsIInputStream.h"
-#include "nsILineInputStream.h"
-#include "nsNetUtil.h"
 #ifdef XP_WIN
 #include "nsCRT.h"
 #endif
-#include "prio.h"
+#include <fstream>
 
 using mozilla::dom::CrashReporterChild;
 
 static const int MAX_VOUCHER_LENGTH = 500000;
 
 #ifdef XP_WIN
 #include <stdlib.h> // for _exit()
 #else
@@ -73,24 +68,26 @@ GMPChild::GMPChild()
 }
 
 GMPChild::~GMPChild()
 {
   LOGD("GMPChild dtor");
 }
 
 static bool
-GetFileBase(const nsAString& aPluginPath,
+GetFileBase(const std::string& aPluginPath,
 #if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
             nsCOMPtr<nsIFile>& aLibDirectory,
 #endif
             nsCOMPtr<nsIFile>& aFileBase,
             nsAutoString& aBaseName)
 {
-  nsresult rv = NS_NewLocalFile(aPluginPath,
+  nsDependentCString pluginPath(aPluginPath.c_str());
+
+  nsresult rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(pluginPath),
                                 true, getter_AddRefs(aFileBase));
   if (NS_FAILED(rv)) {
     return false;
   }
 
 #if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
   if (NS_FAILED(aFileBase->Clone(getter_AddRefs(aLibDirectory)))) {
     return false;
@@ -111,17 +108,17 @@ GetFileBase(const nsAString& aPluginPath
 
   aBaseName = Substring(parentLeafName,
                         4,
                         parentLeafName.Length() - 1);
   return true;
 }
 
 static bool
-GetPluginFile(const nsAString& aPluginPath,
+GetPluginFile(const std::string& aPluginPath,
 #if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
               nsCOMPtr<nsIFile>& aLibDirectory,
 #endif
               nsCOMPtr<nsIFile>& aLibFile)
 {
   nsAutoString baseName;
 #if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
   GetFileBase(aPluginPath, aLibDirectory, aLibFile, baseName);
@@ -139,30 +136,30 @@ GetPluginFile(const nsAString& aPluginPa
 #error not defined
 #endif
   aLibFile->AppendRelativePath(binaryName);
   return true;
 }
 
 #ifdef XP_WIN
 static bool
-GetInfoFile(const nsAString& aPluginPath,
+GetInfoFile(const std::string& aPluginPath,
             nsCOMPtr<nsIFile>& aInfoFile)
 {
   nsAutoString baseName;
   GetFileBase(aPluginPath, aInfoFile, baseName);
   nsAutoString infoFileName = baseName + NS_LITERAL_STRING(".info");
   aInfoFile->AppendRelativePath(infoFileName);
   return true;
 }
 #endif
 
 #if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
 static bool
-GetPluginPaths(const nsAString& aPluginPath,
+GetPluginPaths(const std::string& aPluginPath,
                nsCString &aPluginDirectoryPath,
                nsCString &aPluginFilePath)
 {
   nsCOMPtr<nsIFile> libDirectory, libFile;
   if (!GetPluginFile(aPluginPath, libDirectory, libFile)) {
     return false;
   }
 
@@ -257,23 +254,23 @@ GMPChild::SetMacSandboxInfo()
   info.appBinaryPath.assign(appBinaryPath.get());
 
   mGMPLoader->SetSandboxInfo(&info);
   return true;
 }
 #endif // XP_MACOSX && MOZ_GMP_SANDBOX
 
 bool
-GMPChild::Init(const nsAString& aPluginPath,
-               const nsAString& aVoucherPath,
+GMPChild::Init(const std::string& aPluginPath,
+               const std::string& aVoucherPath,
                base::ProcessId aParentPid,
                MessageLoop* aIOLoop,
                IPC::Channel* aChannel)
 {
-  LOGD("%s pluginPath=%s", __FUNCTION__, NS_ConvertUTF16toUTF8(aPluginPath).get());
+  LOGD("%s pluginPath=%s", __FUNCTION__, aPluginPath.c_str());
 
   if (NS_WARN_IF(!Open(aChannel, aParentPid, aIOLoop))) {
     return false;
   }
 
 #ifdef MOZ_CRASHREPORTER
   SendPCrashReporterConstructor(CrashReporter::CurrentThreadId());
 #endif
@@ -286,143 +283,93 @@ GMPChild::Init(const nsAString& aPluginP
 bool
 GMPChild::RecvSetNodeId(const nsCString& aNodeId)
 {
   LOGD("%s nodeId=%s", __FUNCTION__, aNodeId.Data());
 
   // Store the per origin salt for the node id. Note: we do this in a
   // separate message than RecvStartPlugin() so that the string is not
   // sitting in a string on the IPC code's call stack.
-  mNodeId = aNodeId;
+  mNodeId = std::string(aNodeId.BeginReading(), aNodeId.EndReading());
   return true;
 }
 
 GMPErr
 GMPChild::GetAPI(const char* aAPIName, void* aHostAPI, void** aPluginAPI)
 {
   if (!mGMPLoader) {
     return GMPGenericErr;
   }
   return mGMPLoader->GetAPI(aAPIName, aHostAPI, aPluginAPI);
 }
 
-static bool
-ReadIntoArray(nsIFile* aFile,
-              nsTArray<uint8_t>& aOutDst,
-              size_t aMaxLength)
-{
-  if (!FileExists(aFile)) {
-    return false;
-  }
-
-  PRFileDesc* fd = nullptr;
-  nsresult rv = aFile->OpenNSPRFileDesc(PR_RDONLY, 0, &fd);
-  if (NS_FAILED(rv)) {
-    return false;
-  }
-
-  int32_t length = PR_Seek(fd, 0, PR_SEEK_END);
-  PR_Seek(fd, 0, PR_SEEK_SET);
-
-  if (length < 0 || (size_t)length > aMaxLength) {
-    NS_WARNING("EME file is longer than maximum allowed length");
-    PR_Close(fd);
-    return false;
-  }
-  aOutDst.SetLength(length);
-  int32_t bytesRead = PR_Read(fd, aOutDst.Elements(), length);
-  PR_Close(fd);
-  return (bytesRead == length);
-}
-
 #ifdef XP_WIN
-static bool
-ReadIntoString(nsIFile* aFile,
-               nsCString& aOutDst,
-               size_t aMaxLength)
-{
-  nsTArray<uint8_t> buf;
-  bool rv = ReadIntoArray(aFile, buf, aMaxLength);
-  if (rv) {
-    aOutDst = nsDependentCString((const char*)buf.Elements(), buf.Length());
-  }
-  return rv;
-}
-
-static nsTArray<nsCString>
-SplitAt(Tokenizer::Token aDelim, const nsACString& aInput)
-{
-  nsTArray<nsCString> tokens;
-  Tokenizer tokenizer(aInput);
-
-  while (!tokenizer.HasFailed()) {
-    tokenizer.Record();
-    Tokenizer::Token token;
-    while (tokenizer.Next(token) && !token.Equals(aDelim))
-      ; // Skip up to next delimeter, or EOF.
-    nsAutoCString value;
-    tokenizer.Claim(value);
-    tokens.AppendElement(value);
-  }
-  return tokens;
-}
-
 // Pre-load DLLs that need to be used by the EME plugin but that can't be
 // loaded after the sandbox has started
 bool
-GMPChild::PreLoadLibraries(const nsAString& aPluginPath)
+GMPChild::PreLoadLibraries(const std::string& aPluginPath)
 {
   // This must be in sorted order and lowercase!
-  static const char* whitelist[] = {
-    "d3d9.dll", // Create an `IDirect3D9` to get adapter information
-    "dxva2.dll", // Get monitor information
-    "evr.dll", // MFGetStrideForBitmapInfoHeader
-    "mfh264dec.dll", // H.264 decoder (on Windows Vista)
-    "mfheaacdec.dll", // AAC decoder (on Windows Vista)
-    "mfplat.dll", // MFCreateSample, MFCreateAlignedMemoryBuffer, MFCreateMediaType
-    "msauddecmft.dll", // AAC decoder (on Windows 8)
-    "msmpeg2adec.dll", // AAC decoder (on Windows 7)
-    "msmpeg2vdec.dll", // H.264 decoder
-  };
+  static const char* whitelist[] =
+    {
+       "d3d9.dll", // Create an `IDirect3D9` to get adapter information
+       "dxva2.dll", // Get monitor information
+       "evr.dll", // MFGetStrideForBitmapInfoHeader
+       "mfh264dec.dll", // H.264 decoder (on Windows Vista)
+       "mfheaacdec.dll", // AAC decoder (on Windows Vista)
+       "mfplat.dll", // MFCreateSample, MFCreateAlignedMemoryBuffer, MFCreateMediaType
+       "msauddecmft.dll", // AAC decoder (on Windows 8)
+       "msmpeg2adec.dll", // AAC decoder (on Windows 7)
+       "msmpeg2vdec.dll", // H.264 decoder
+    };
+  static const int whitelistLen = sizeof(whitelist) / sizeof(whitelist[0]);
 
   nsCOMPtr<nsIFile> infoFile;
   GetInfoFile(aPluginPath, infoFile);
 
-  static const size_t MAX_GMP_INFO_FILE_LENGTH = 5 * 1024;
-  nsAutoCString info;
-  if (!ReadIntoString(infoFile, info, MAX_GMP_INFO_FILE_LENGTH)) {
-    NS_WARNING("Failed to read info file in GMP process.");
+  nsString path;
+  infoFile->GetPath(path);
+
+  std::ifstream stream;
+#ifdef _MSC_VER
+  // Must use UTF16 for Windows for paths for non-Latin characters.
+  stream.open(static_cast<const wchar_t*>(path.get()));
+#else
+  stream.open(NS_ConvertUTF16toUTF8(path).get());
+#endif
+  if (!stream.good()) {
+    NS_WARNING("Failure opening info file for required DLLs");
     return false;
   }
 
-  nsTArray<nsCString> lines = SplitAt(Tokenizer::Token::NewLine(), info);
-  for (nsCString line : lines) {
-    // Make lowercase.
-    std::transform(line.BeginWriting(),
-                   line.EndWriting(),
-                   line.BeginWriting(),
-                   tolower);
-
-    int32_t offset = line.Find("libraries:", false, 0);
-    if (offset == kNotFound) {
-      continue;
+  do {
+    std::string line;
+    getline(stream, line);
+    if (stream.fail()) {
+      NS_WARNING("Failure reading info file for required DLLs");
+      return false;
     }
-    // Line starts with "libraries:".
-    nsTArray<nsCString> libs = SplitAt(Tokenizer::Token::Char(','),
-                                       Substring(line, offset));
-    for (nsCString lib : libs) {
-      lib.Trim(" ");
-      for (const char* whiteListedLib : whitelist) {
-        if (lib.EqualsASCII(whiteListedLib)) {
-          LoadLibraryA(lib.get());
-          break;
+    std::transform(line.begin(), line.end(), line.begin(), tolower);
+    static const char* prefix = "libraries:";
+    static const int prefixLen = strlen(prefix);
+    if (0 == line.compare(0, prefixLen, prefix)) {
+      char* lineCopy = strdup(line.c_str() + prefixLen);
+      char* start = lineCopy;
+      while (char* tok = nsCRT::strtok(start, ", ", &start)) {
+        for (int i = 0; i < whitelistLen; i++) {
+          if (0 == strcmp(whitelist[i], tok)) {
+            LoadLibraryA(tok);
+            break;
+          }
         }
       }
+      free(lineCopy);
+      break;
     }
-  }
+  } while (!stream.eof());
 
   return true;
 }
 #endif
 
 bool
 GMPChild::GetUTF8LibPath(nsACString& aOutLibPath)
 {
@@ -455,17 +402,17 @@ GMPChild::GetUTF8LibPath(nsACString& aOu
 bool
 GMPChild::RecvStartPlugin()
 {
   LOGD("%s", __FUNCTION__);
 
 #if defined(XP_WIN)
   PreLoadLibraries(mPluginPath);
 #endif
-  if (!PreLoadPluginVoucher()) {
+  if (!PreLoadPluginVoucher(mPluginPath)) {
     NS_WARNING("Plugin voucher failed to load!");
     return false;
   }
   PreLoadSandboxVoucher();
 
   nsCString libPath;
   if (!GetUTF8LibPath(libPath)) {
     return false;
@@ -486,18 +433,18 @@ GMPChild::RecvStartPlugin()
     NS_WARNING("Failed to set Mac GMP sandbox info");
     delete platformAPI;
     return false;
   }
 #endif
 
   if (!mGMPLoader->Load(libPath.get(),
                         libPath.Length(),
-                        mNodeId.BeginWriting(),
-                        mNodeId.Length(),
+                        &mNodeId[0],
+                        mNodeId.size(),
                         platformAPI)) {
     NS_WARNING("Failed to load GMP");
     delete platformAPI;
     return false;
   }
 
   void* sh = nullptr;
   GMPAsyncShutdownHost* host = static_cast<GMPAsyncShutdownHost*>(this);
@@ -660,59 +607,109 @@ void
 GMPChild::ShutdownComplete()
 {
   LOGD("%s", __FUNCTION__);
   MOZ_ASSERT(mGMPMessageLoop == MessageLoop::current());
   mAsyncShutdown = nullptr;
   SendAsyncShutdownComplete();
 }
 
-static void
-GetPluginVoucherFile(const nsAString& aPluginPath,
+static bool
+GetPluginVoucherFile(const std::string& aPluginPath,
                      nsCOMPtr<nsIFile>& aOutVoucherFile)
 {
   nsAutoString baseName;
 #if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
   nsCOMPtr<nsIFile> libDir;
   GetFileBase(aPluginPath, aOutVoucherFile, libDir, baseName);
 #else
   GetFileBase(aPluginPath, aOutVoucherFile, baseName);
 #endif
   nsAutoString infoFileName = baseName + NS_LITERAL_STRING(".voucher");
   aOutVoucherFile->AppendRelativePath(infoFileName);
+  return true;
 }
 
 bool
-GMPChild::PreLoadPluginVoucher()
+GMPChild::PreLoadPluginVoucher(const std::string& aPluginPath)
 {
   nsCOMPtr<nsIFile> voucherFile;
-  GetPluginVoucherFile(mPluginPath, voucherFile);
+  GetPluginVoucherFile(aPluginPath, voucherFile);
+
   if (!FileExists(voucherFile)) {
-    // Assume missing file is not fatal; that would break OpenH264.
     return true;
   }
-  return ReadIntoArray(voucherFile, mPluginVoucher, MAX_VOUCHER_LENGTH);
+
+  nsString path;
+  voucherFile->GetPath(path);
+
+  std::ifstream stream;
+  #ifdef _MSC_VER
+  // Must use UTF16 for Windows for paths for non-Latin characters.
+  stream.open(static_cast<const wchar_t*>(path.get()), std::ios::binary);
+  #else
+  stream.open(NS_ConvertUTF16toUTF8(path).get(), std::ios::binary);
+  #endif
+  if (!stream.good()) {
+    return false;
+  }
+
+  std::streampos start = stream.tellg();
+  stream.seekg (0, std::ios::end);
+  std::streampos end = stream.tellg();
+  stream.seekg (0, std::ios::beg);
+  auto length = end - start;
+  if (length > MAX_VOUCHER_LENGTH) {
+    NS_WARNING("Plugin voucher file too big!");
+    return false;
+  }
+
+  mPluginVoucher.SetLength(length);
+  stream.read((char*)mPluginVoucher.Elements(), length);
+  if (!stream) {
+    NS_WARNING("Failed to read plugin voucher file!");
+    return false;
+  }
+
+  return true;
 }
 
 void
 GMPChild::PreLoadSandboxVoucher()
 {
-  nsCOMPtr<nsIFile> f;
-  nsresult rv = NS_NewLocalFile(mSandboxVoucherPath, true, getter_AddRefs(f));
-  if (NS_FAILED(rv)) {
-    NS_WARNING("Can't create nsIFile for sandbox voucher");
-    return;
-  }
-  if (!FileExists(f)) {
-    // Assume missing file is not fatal; that would break OpenH264.
+  std::ifstream stream;
+  #ifdef _MSC_VER
+  // Must use UTF16 for Windows for paths for non-Latin characters.
+  nsDependentCString utf8Path(mSandboxVoucherPath.c_str(),
+                              mSandboxVoucherPath.size());
+  NS_ConvertUTF8toUTF16 utf16Path(utf8Path);
+  stream.open(static_cast<const wchar_t*>(utf16Path.get()), std::ios::binary);
+  #else
+  stream.open(mSandboxVoucherPath.c_str(), std::ios::binary);
+  #endif
+  if (!stream.good()) {
+    NS_WARNING("PreLoadSandboxVoucher can't find sandbox voucher file!");
     return;
   }
 
-  if (!ReadIntoArray(f, mSandboxVoucher, MAX_VOUCHER_LENGTH)) {
-    NS_WARNING("Failed to read sandbox voucher");
+  std::streampos start = stream.tellg();
+  stream.seekg (0, std::ios::end);
+  std::streampos end = stream.tellg();
+  stream.seekg (0, std::ios::beg);
+  auto length = end - start;
+  if (length > MAX_VOUCHER_LENGTH) {
+    NS_WARNING("PreLoadSandboxVoucher sandbox voucher file too big!");
+    return;
+  }
+
+  mSandboxVoucher.SetLength(length);
+  stream.read((char*)mSandboxVoucher.Elements(), length);
+  if (!stream) {
+    NS_WARNING("PreLoadSandboxVoucher failed to read plugin voucher file!");
+    return;
   }
 }
 
 PGMPContentChild*
 GMPChild::AllocPGMPContentChild(Transport* aTransport,
                                 ProcessId aOtherPid)
 {
   GMPContentChild* child =
--- a/dom/media/gmp/GMPChild.h
+++ b/dom/media/gmp/GMPChild.h
@@ -21,23 +21,23 @@ class GMPContentChild;
 
 class GMPChild : public PGMPChild
                , public GMPAsyncShutdownHost
 {
 public:
   GMPChild();
   virtual ~GMPChild();
 
-  bool Init(const nsAString& aPluginPath,
-            const nsAString& aVoucherPath,
+  bool Init(const std::string& aPluginPath,
+            const std::string& aVoucherPath,
             base::ProcessId aParentPid,
             MessageLoop* aIOLoop,
             IPC::Channel* aChannel);
 #ifdef XP_WIN
-  bool PreLoadLibraries(const nsAString& aPluginPath);
+  bool PreLoadLibraries(const std::string& aPluginPath);
 #endif
   MessageLoop* GMPMessageLoop();
 
   // Main thread only.
   GMPTimerChild* GetGMPTimers();
   GMPStorageChild* GetGMPStorage();
 
   // GMPAsyncShutdownHost
@@ -45,17 +45,17 @@ public:
 
 #if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
   bool SetMacSandboxInfo();
 #endif
 
 private:
   friend class GMPContentChild;
 
-  bool PreLoadPluginVoucher();
+  bool PreLoadPluginVoucher(const std::string& aPluginPath);
   void PreLoadSandboxVoucher();
 
   bool GetUTF8LibPath(nsACString& aOutLibPath);
 
   virtual bool RecvSetNodeId(const nsCString& aNodeId) override;
   virtual bool RecvStartPlugin() override;
 
   virtual PCrashReporterChild* AllocPCrashReporterChild(const NativeThreadId& aThread) override;
@@ -82,19 +82,19 @@ private:
 
   nsTArray<UniquePtr<GMPContentChild>> mGMPContentChildren;
 
   GMPAsyncShutdown* mAsyncShutdown;
   nsRefPtr<GMPTimerChild> mTimerChild;
   nsRefPtr<GMPStorageChild> mStorage;
 
   MessageLoop* mGMPMessageLoop;
-  nsString mPluginPath;
-  nsString mSandboxVoucherPath;
-  nsCString mNodeId;
+  std::string mPluginPath;
+  std::string mSandboxVoucherPath;
+  std::string mNodeId;
   GMPLoader* mGMPLoader;
   nsTArray<uint8_t> mPluginVoucher;
   nsTArray<uint8_t> mSandboxVoucher;
 };
 
 } // namespace gmp
 } // namespace mozilla
 
--- a/dom/media/gmp/GMPProcessChild.cpp
+++ b/dom/media/gmp/GMPProcessChild.cpp
@@ -23,32 +23,32 @@ GMPProcessChild::GMPProcessChild(Process
 
 GMPProcessChild::~GMPProcessChild()
 {
 }
 
 bool
 GMPProcessChild::Init()
 {
-  nsAutoString pluginFilename;
-  nsAutoString voucherFilename;
+  std::string pluginFilename;
+  std::string voucherFilename;
 
 #if defined(OS_POSIX)
   // NB: need to be very careful in ensuring that the first arg
   // (after the binary name) here is indeed the plugin module path.
   // Keep in sync with dom/plugins/PluginModuleParent.
   std::vector<std::string> values = CommandLine::ForCurrentProcess()->argv();
   MOZ_ASSERT(values.size() >= 3, "not enough args");
-  pluginFilename = NS_ConvertUTF8toUTF16(nsDependentCString(values[1].c_str()));
-  voucherFilename = NS_ConvertUTF8toUTF16(nsDependentCString(values[2].c_str()));
+  pluginFilename = values[1];
+  voucherFilename = values[2];
 #elif defined(OS_WIN)
   std::vector<std::wstring> values = CommandLine::ForCurrentProcess()->GetLooseValues();
   MOZ_ASSERT(values.size() >= 2, "not enough loose args");
-  pluginFilename = nsDependentString(values[0].c_str());
-  voucherFilename = nsDependentString(values[1].c_str());
+  pluginFilename = WideToUTF8(values[0]);
+  voucherFilename = WideToUTF8(values[1]);
 #else
 #error Not implemented
 #endif
 
   BackgroundHangMonitor::Startup();
 
   return mPlugin.Init(pluginFilename,
                       voucherFilename,