Bug 1190252 - Remove std::string from GMPChild and friends. r=edwin
authorChris Pearce <cpearce@mozilla.com>
Tue, 04 Aug 2015 16:06:32 +1200
changeset 287689 064871541f3d59b13e9d45fc8117b922e0141637
parent 287688 48d5d4b398c21fdff339419b75e677f890179b4c
child 287690 ad6eae12a1957a900d2fd8a22cf3e7f8a74159cd
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)
reviewersedwin
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 - Remove std::string from GMPChild and friends. r=edwin
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
@@ -68,26 +68,24 @@ GMPChild::GMPChild()
 }
 
 GMPChild::~GMPChild()
 {
   LOGD("GMPChild dtor");
 }
 
 static bool
-GetFileBase(const std::string& aPluginPath,
+GetFileBase(const nsAString& aPluginPath,
 #if defined(XP_MACOSX) && defined(MOZ_GMP_SANDBOX)
             nsCOMPtr<nsIFile>& aLibDirectory,
 #endif
             nsCOMPtr<nsIFile>& aFileBase,
             nsAutoString& aBaseName)
 {
-  nsDependentCString pluginPath(aPluginPath.c_str());
-
-  nsresult rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(pluginPath),
+  nsresult rv = NS_NewLocalFile(aPluginPath,
                                 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;
@@ -108,17 +106,17 @@ GetFileBase(const std::string& aPluginPa
 
   aBaseName = Substring(parentLeafName,
                         4,
                         parentLeafName.Length() - 1);
   return true;
 }
 
 static bool
-GetPluginFile(const std::string& aPluginPath,
+GetPluginFile(const nsAString& 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);
@@ -136,30 +134,30 @@ GetPluginFile(const std::string& aPlugin
 #error not defined
 #endif
   aLibFile->AppendRelativePath(binaryName);
   return true;
 }
 
 #ifdef XP_WIN
 static bool
-GetInfoFile(const std::string& aPluginPath,
+GetInfoFile(const nsAString& 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 std::string& aPluginPath,
+GetPluginPaths(const nsAString& aPluginPath,
                nsCString &aPluginDirectoryPath,
                nsCString &aPluginFilePath)
 {
   nsCOMPtr<nsIFile> libDirectory, libFile;
   if (!GetPluginFile(aPluginPath, libDirectory, libFile)) {
     return false;
   }
 
@@ -254,23 +252,23 @@ GMPChild::SetMacSandboxInfo()
   info.appBinaryPath.assign(appBinaryPath.get());
 
   mGMPLoader->SetSandboxInfo(&info);
   return true;
 }
 #endif // XP_MACOSX && MOZ_GMP_SANDBOX
 
 bool
-GMPChild::Init(const std::string& aPluginPath,
-               const std::string& aVoucherPath,
+GMPChild::Init(const nsAString& aPluginPath,
+               const nsAString& aVoucherPath,
                base::ProcessId aParentPid,
                MessageLoop* aIOLoop,
                IPC::Channel* aChannel)
 {
-  LOGD("%s pluginPath=%s", __FUNCTION__, aPluginPath.c_str());
+  LOGD("%s pluginPath=%s", __FUNCTION__, NS_ConvertUTF16toUTF8(aPluginPath).get());
 
   if (NS_WARN_IF(!Open(aChannel, aParentPid, aIOLoop))) {
     return false;
   }
 
 #ifdef MOZ_CRASHREPORTER
   SendPCrashReporterConstructor(CrashReporter::CurrentThreadId());
 #endif
@@ -283,34 +281,34 @@ GMPChild::Init(const std::string& aPlugi
 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 = std::string(aNodeId.BeginReading(), aNodeId.EndReading());
+  mNodeId = aNodeId;
   return true;
 }
 
 GMPErr
 GMPChild::GetAPI(const char* aAPIName, void* aHostAPI, void** aPluginAPI)
 {
   if (!mGMPLoader) {
     return GMPGenericErr;
   }
   return mGMPLoader->GetAPI(aAPIName, aHostAPI, aPluginAPI);
 }
 
 #ifdef XP_WIN
 // 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 std::string& aPluginPath)
+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
        "dxva2.dll", // Get monitor information
        "evr.dll", // MFGetStrideForBitmapInfoHeader
        "mfh264dec.dll", // H.264 decoder (on Windows Vista)
@@ -433,18 +431,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[0],
-                        mNodeId.size(),
+                        mNodeId.BeginWriting(),
+                        mNodeId.Length(),
                         platformAPI)) {
     NS_WARNING("Failed to load GMP");
     delete platformAPI;
     return false;
   }
 
   void* sh = nullptr;
   GMPAsyncShutdownHost* host = static_cast<GMPAsyncShutdownHost*>(this);
@@ -608,33 +606,33 @@ GMPChild::ShutdownComplete()
 {
   LOGD("%s", __FUNCTION__);
   MOZ_ASSERT(mGMPMessageLoop == MessageLoop::current());
   mAsyncShutdown = nullptr;
   SendAsyncShutdownComplete();
 }
 
 static bool
-GetPluginVoucherFile(const std::string& aPluginPath,
+GetPluginVoucherFile(const nsAString& 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(const std::string& aPluginPath)
+GMPChild::PreLoadPluginVoucher(const nsAString& aPluginPath)
 {
   nsCOMPtr<nsIFile> voucherFile;
   GetPluginVoucherFile(aPluginPath, voucherFile);
 
   if (!FileExists(voucherFile)) {
     return true;
   }
 
@@ -673,22 +671,19 @@ GMPChild::PreLoadPluginVoucher(const std
 }
 
 void
 GMPChild::PreLoadSandboxVoucher()
 {
   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);
+  stream.open(static_cast<const wchar_t*>(mSandboxVoucherPath.get()), std::ios::binary);
   #else
-  stream.open(mSandboxVoucherPath.c_str(), std::ios::binary);
+  stream.open(NS_ConvertUTF16toUTF8(mSandboxVoucherPath).get(), std::ios::binary);
   #endif
   if (!stream.good()) {
     NS_WARNING("PreLoadSandboxVoucher can't find sandbox voucher file!");
     return;
   }
 
   std::streampos start = stream.tellg();
   stream.seekg (0, std::ios::end);
--- 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 std::string& aPluginPath,
-            const std::string& aVoucherPath,
+  bool Init(const nsAString& aPluginPath,
+            const nsAString& aVoucherPath,
             base::ProcessId aParentPid,
             MessageLoop* aIOLoop,
             IPC::Channel* aChannel);
 #ifdef XP_WIN
-  bool PreLoadLibraries(const std::string& aPluginPath);
+  bool PreLoadLibraries(const nsAString& 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(const std::string& aPluginPath);
+  bool PreLoadPluginVoucher(const nsAString& 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;
-  std::string mPluginPath;
-  std::string mSandboxVoucherPath;
-  std::string mNodeId;
+  nsString mPluginPath;
+  nsString mSandboxVoucherPath;
+  nsCString 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()
 {
-  std::string pluginFilename;
-  std::string voucherFilename;
+  nsAutoString pluginFilename;
+  nsAutoString 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 = values[1];
-  voucherFilename = values[2];
+  pluginFilename = NS_ConvertUTF8toUTF16(nsDependentCString(values[1].c_str()));
+  voucherFilename = NS_ConvertUTF8toUTF16(nsDependentCString(values[2].c_str()));
 #elif defined(OS_WIN)
   std::vector<std::wstring> values = CommandLine::ForCurrentProcess()->GetLooseValues();
   MOZ_ASSERT(values.size() >= 2, "not enough loose args");
-  pluginFilename = WideToUTF8(values[0]);
-  voucherFilename = WideToUTF8(values[1]);
+  pluginFilename = nsDependentString(values[0].c_str());
+  voucherFilename = nsDependentString(values[1].c_str());
 #else
 #error Not implemented
 #endif
 
   BackgroundHangMonitor::Startup();
 
   return mPlugin.Init(pluginFilename,
                       voucherFilename,