From 342c2515414567f07bd58991acc98745fc5ccca6 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 10 Jul 2014 02:56:36 -0400 Subject: [PATCH] Bug 965413 part 1. Rename the WebRTC-private LoadInfo class to RTCLoadInfo so it won't interfere with adding mozilla::LoadInfo. r=jesup --- content/media/webrtc/LoadMonitor.cpp | 52 ++++++++++++++++++---------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/content/media/webrtc/LoadMonitor.cpp b/content/media/webrtc/LoadMonitor.cpp index 37733de14fa8..aa96594fdb71 100644 --- a/content/media/webrtc/LoadMonitor.cpp +++ b/content/media/webrtc/LoadMonitor.cpp @@ -274,10 +274,16 @@ nsresult WinProcMon::QuerySystemLoad(float* load_percent) } #endif -class LoadStats +// Use a non-generic class name, because otherwise we can get name collisions +// with other classes in the codebase. The normal way of dealing with that is +// to put the class in an anonymous namespace, but this class is used as a +// member of RTCLoadInfo, which can't be in the anonymous namespace, so it also +// can't be in an anonymous namespace: gcc warns about that setup and this +// directory is fail-on-warnings. +class RTCLoadStats { public: - LoadStats() : + RTCLoadStats() : mPrevTotalTimes(0), mPrevCpuTimes(0), mPrevLoad(0) {}; @@ -289,11 +295,17 @@ public: float mPrevLoad; // Previous load value. }; -class LoadInfo : public mozilla::RefCounted +// Use a non-generic class name, because otherwise we can get name collisions +// with other classes in the codebase. The normal way of dealing with that is +// to put the class in an anonymous namespace, but this class is used as a +// member of LoadInfoCollectRunner, which can't be in the anonymous namespace, +// so it also can't be in an anonymous namespace: gcc warns about that setup +// and this directory is fail-on-warnings. +class RTCLoadInfo : public mozilla::RefCounted { public: - MOZ_DECLARE_REFCOUNTED_TYPENAME(LoadInfo) - LoadInfo(): mLoadUpdateInterval(0) {}; + MOZ_DECLARE_REFCOUNTED_TYPENAME(RTCLoadInfo) + RTCLoadInfo(): mLoadUpdateInterval(0) {}; nsresult Init(int aLoadUpdateInterval); double GetSystemLoad() { return mSystemLoad.GetLoad(); }; double GetProcessLoad() { return mProcessLoad.GetLoad(); }; @@ -304,19 +316,19 @@ private: void UpdateCpuLoad(uint64_t ticks_per_interval, uint64_t current_total_times, uint64_t current_cpu_times, - LoadStats* loadStat); + RTCLoadStats* loadStat); #ifdef XP_WIN WinProcMon mSysMon; HANDLE mProcHandle; int mNumProcessors; #endif - LoadStats mSystemLoad; - LoadStats mProcessLoad; + RTCLoadStats mSystemLoad; + RTCLoadStats mProcessLoad; uint64_t mTicksPerInterval; int mLoadUpdateInterval; }; -nsresult LoadInfo::Init(int aLoadUpdateInterval) +nsresult RTCLoadInfo::Init(int aLoadUpdateInterval) { mLoadUpdateInterval = aLoadUpdateInterval; #ifdef XP_WIN @@ -331,10 +343,10 @@ nsresult LoadInfo::Init(int aLoadUpdateInterval) #endif } -void LoadInfo::UpdateCpuLoad(uint64_t ticks_per_interval, - uint64_t current_total_times, - uint64_t current_cpu_times, - LoadStats *loadStat) { +void RTCLoadInfo::UpdateCpuLoad(uint64_t ticks_per_interval, + uint64_t current_total_times, + uint64_t current_cpu_times, + RTCLoadStats *loadStat) { // Check if we get an inconsistent number of ticks. if (((current_total_times - loadStat->mPrevTotalTimes) > (ticks_per_interval * 10)) @@ -366,7 +378,7 @@ void LoadInfo::UpdateCpuLoad(uint64_t ticks_per_interval, loadStat->mPrevCpuTimes = current_cpu_times; } -nsresult LoadInfo::UpdateSystemLoad() +nsresult RTCLoadInfo::UpdateSystemLoad() { #if defined(LINUX) || defined(ANDROID) nsCOMPtr procStatFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID); @@ -472,7 +484,7 @@ nsresult LoadInfo::UpdateSystemLoad() #endif } -nsresult LoadInfo::UpdateProcessLoad() { +nsresult RTCLoadInfo::UpdateProcessLoad() { #if defined(XP_UNIX) struct timeval tv; gettimeofday(&tv, nullptr); @@ -518,11 +530,13 @@ nsresult LoadInfo::UpdateProcessLoad() { return NS_OK; } +// Note: This class can't be in the anonymous namespace, because then we can't +// declare it as a friend of LoadMonitor. class LoadInfoCollectRunner : public nsRunnable { public: LoadInfoCollectRunner(nsRefPtr loadMonitor, - RefPtr loadInfo, + RefPtr loadInfo, nsIThread *loadInfoThread) : mThread(loadInfoThread), mLoadUpdateInterval(loadMonitor->mLoadUpdateInterval), @@ -571,7 +585,7 @@ public: private: nsCOMPtr mThread; - RefPtr mLoadInfo; + RefPtr mLoadInfo; nsRefPtr mLoadMonitor; int mLoadUpdateInterval; int mLoadNoiseCounter; @@ -615,11 +629,11 @@ LoadMonitor::Init(nsRefPtr &self) { LOG(("Initializing LoadMonitor")); - RefPtr load_info = new LoadInfo(); + RefPtr load_info = new RTCLoadInfo(); nsresult rv = load_info->Init(mLoadUpdateInterval); if (NS_FAILED(rv)) { - LOG(("LoadInfo::Init error")); + LOG(("RTCLoadInfo::Init error")); return rv; }