Bug 1190252. Backed out changeset d697030f7d59. r=backout
authorChris Pearce <cpearce@mozilla.com>
Mon, 10 Aug 2015 13:38:03 +1200
changeset 288695 6ac77d3c4dc3b0ae936ae2bcabd23b20e737d65f
parent 288694 d697030f7d59983bec3b98c24577ff27194641a2
child 288696 f77ab4c12d923e997e5e9db6116766e3ab9f3339
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)
reviewersbackout
bugs1190252
milestone42.0a1
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
Bug 1190252. Backed out changeset d697030f7d59. r=backout
dom/media/gmp/GMPChild.cpp
dom/media/gmp/GMPUtils.cpp
dom/media/gmp/GMPUtils.h
dom/media/gtest/TestGMPUtils.cpp
dom/media/gtest/moz.build
--- a/dom/media/gmp/GMPChild.cpp
+++ b/dom/media/gmp/GMPChild.cpp
@@ -14,17 +14,17 @@
 #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 "GMPUtils.h"
+#include "mozilla/Tokenizer.h"
 #include "prio.h"
 
 using mozilla::dom::CrashReporterChild;
 
 static const int MAX_VOUCHER_LENGTH = 500000;
 
 #ifdef XP_WIN
 #include <stdlib.h> // for _exit()
@@ -336,16 +336,34 @@ ReadIntoString(nsIFile* aFile,
   bool rv = ReadIntoArray(aFile, buf, aMaxLength);
   if (rv) {
     buf.AppendElement(0); // Append null terminator, required by nsC*String.
     aOutDst = nsDependentCString((const char*)buf.Elements(), buf.Length() - 1);
   }
   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)
 {
   // This must be in sorted order and lowercase!
   static const char* whitelist[] = {
     "d3d9.dll", // Create an `IDirect3D9` to get adapter information
@@ -364,34 +382,32 @@ GMPChild::PreLoadLibraries(const nsAStri
 
   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.");
     return false;
   }
 
-  // Note: we pass "\r\n" to SplitAt so that we'll split lines delimited
-  // by \n (Unix), \r\n (Windows) and \r (old MacOSX).
-  nsTArray<nsCString> lines = SplitAt("\r\n", info);
+  nsTArray<nsCString> lines = SplitAt(Tokenizer::Token::NewLine(), info);
   for (nsCString line : lines) {
     // Make lowercase.
     std::transform(line.BeginWriting(),
                    line.EndWriting(),
                    line.BeginWriting(),
                    tolower);
 
     const char* libraries = "libraries:";
     int32_t offset = line.Find(libraries, false, 0);
     if (offset == kNotFound) {
       continue;
     }
     // Line starts with "libraries:".
-    nsTArray<nsCString> libs =
-      SplitAt(",", Substring(line, offset + strlen(libraries)));
+    nsTArray<nsCString> libs = SplitAt(Tokenizer::Token::Char(','),
+                                       Substring(line, offset + strlen(libraries)));
     for (nsCString lib : libs) {
       lib.Trim(" ");
       for (const char* whiteListedLib : whitelist) {
         if (lib.EqualsASCII(whiteListedLib)) {
           LoadLibraryA(lib.get());
           break;
         }
       }
--- a/dom/media/gmp/GMPUtils.cpp
+++ b/dom/media/gmp/GMPUtils.cpp
@@ -4,18 +4,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "GMPUtils.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsIFile.h"
 #include "nsCOMPtr.h"
 #include "nsLiteralString.h"
-#include "nsCRTGlue.h"
-#include "nsTArray.h"
 
 namespace mozilla {
 
 bool
 GetEMEVoucherPath(nsIFile** aPath)
 {
   nsCOMPtr<nsIFile> path;
   NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(path));
@@ -33,22 +31,9 @@ EMEVoucherFileExists()
 {
   nsCOMPtr<nsIFile> path;
   bool exists;
   return GetEMEVoucherPath(getter_AddRefs(path)) &&
          NS_SUCCEEDED(path->Exists(&exists)) &&
          exists;
 }
 
-nsTArray<nsCString>
-SplitAt(const char* aDelims, const nsACString& aInput)
-{
-  nsTArray<nsCString> tokens;
-  nsAutoCString str(aInput);
-  char* end = str.BeginWriting();
-  const char* start = nullptr;
-  while (!!(start = NS_strtok(aDelims, &end))) {
-    tokens.AppendElement(nsCString(start));
-  }
-  return tokens;
-}
-
 } // namespace mozilla
--- a/dom/media/gmp/GMPUtils.h
+++ b/dom/media/gmp/GMPUtils.h
@@ -22,14 +22,11 @@ struct DestroyPolicy
 
 template<typename T>
 using GMPUniquePtr = mozilla::UniquePtr<T, DestroyPolicy<T>>;
 
 bool GetEMEVoucherPath(nsIFile** aPath);
 
 bool EMEVoucherFileExists();
 
-nsTArray<nsCString>
-SplitAt(const char* aDelims, const nsACString& aInput);
-
 } // namespace mozilla
 
 #endif
deleted file mode 100644
--- a/dom/media/gtest/TestGMPUtils.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=8 sts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
-* License, v. 2.0. If a copy of the MPL was not distributed with this
-* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "gtest/gtest.h"
-#include "GMPUtils.h"
-
-#include <string>
-#include <vector>
-
-using namespace std;
-using namespace mozilla;
-
-struct SplitAtTest {
-  string mInput;
-  const char* mDelims;
-  vector<string> mTokens;
-};
-
-static const SplitAtTest sSplitAtTests[] {
-  {
-    "1,2,3,4",
-    ",",
-    { "1", "2", "3", "4" },
-  }, {
-    "a simple, comma, seperated, list",
-    ",",
-    {"a simple", " comma", " seperated", " list"},
-  }, {
-    // Various platform line endings...
-    "line1\r\n" // Windows
-    "line2\r" // Old MacOSX
-    "line3\n" // Unix
-    "line4",
-    "\r\n",
-    { "line1", "line2", "line3", "line4" },
-  },
-};
-
-TEST(GeckoMediaPlugins, GMPUtils) {
-  for (const SplitAtTest& test : sSplitAtTests) {
-    nsCString input(test.mInput.c_str(), test.mInput.size());
-    nsTArray<nsCString> tokens = SplitAt(test.mDelims, input);
-    EXPECT_EQ(tokens.Length(), test.mTokens.size()) << "Should get expected number of tokens";
-    for (size_t i = 0; i < tokens.Length(); i++) {
-      EXPECT_TRUE(tokens[i].EqualsASCII(test.mTokens[i].c_str()))
-        << "Tokenize fail; expected=" << test.mTokens[i] << " got=" <<
-        tokens[i].BeginReading();
-    }
-  }
-}
--- a/dom/media/gtest/moz.build
+++ b/dom/media/gtest/moz.build
@@ -4,17 +4,16 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 UNIFIED_SOURCES += [
     'MockMediaResource.cpp',
     'TestAudioCompactor.cpp',
     'TestGMPCrossOrigin.cpp',
     'TestGMPRemoveAndDelete.cpp',
-    'TestGMPUtils.cpp',
     'TestIntervalSet.cpp',
     'TestMediaEventSource.cpp',
     'TestMozPromise.cpp',
     'TestMP3Demuxer.cpp',
     'TestMP4Demuxer.cpp',
     # 'TestMP4Reader.cpp', disabled so we can turn check tests back on (bug 1175752)
     'TestTrackEncoder.cpp',
     'TestVideoSegment.cpp',