From 612ab27cbaa231630421b6e9464fdbf0dff4ef20 Mon Sep 17 00:00:00 2001 From: B2G Bumper Bot Date: Mon, 18 May 2015 23:00:27 -0700 Subject: [PATCH 01/39] Bumping gaia.json for 2 gaia revision(s) a=gaia-bump ======== https://hg.mozilla.org/integration/gaia-central/rev/6206fc1b4a65 Author: Kevin Grandon Desc: Merge pull request #30109 from KevinGrandon/bug_1160110_localization_follow_up Bug 1160110 - Follow-up, simplify translation logic by using translateFragment ======== https://hg.mozilla.org/integration/gaia-central/rev/8b4c8491b088 Author: Kevin Grandon Desc: Bug 1160110 - Follow-up, simplify translation logic by using translateFragment --- b2g/config/gaia.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/b2g/config/gaia.json b/b2g/config/gaia.json index 871f6ede654..692ccfb1545 100644 --- a/b2g/config/gaia.json +++ b/b2g/config/gaia.json @@ -1,9 +1,9 @@ { "git": { - "git_revision": "97dc139f1a690224e98533a86526c4165eed1db5", + "git_revision": "099b611c0076ed9d8f68c569bba8c17f66a67f05", "remote": "https://git.mozilla.org/releases/gaia.git", "branch": "" }, - "revision": "8fa0242e0aa7c8e126dec5fb6811f6137616c87e", + "revision": "6206fc1b4a6580aea954a5c9fc52a5649d532a96", "repo_path": "integration/gaia-central" } From 60105438c5d338f5ae43ebf2c3ace209ef36ddd9 Mon Sep 17 00:00:00 2001 From: B2G Bumper Bot Date: Mon, 18 May 2015 23:02:22 -0700 Subject: [PATCH 02/39] Bumping manifests a=b2g-bump --- b2g/config/aries/sources.xml | 2 +- b2g/config/dolphin/sources.xml | 2 +- b2g/config/emulator-ics/sources.xml | 2 +- b2g/config/emulator-jb/sources.xml | 2 +- b2g/config/emulator-kk/sources.xml | 2 +- b2g/config/emulator-l/sources.xml | 2 +- b2g/config/emulator/sources.xml | 2 +- b2g/config/flame-kk/sources.xml | 2 +- b2g/config/nexus-4/sources.xml | 2 +- b2g/config/nexus-5-l/sources.xml | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/b2g/config/aries/sources.xml b/b2g/config/aries/sources.xml index f4725639949..f05e1a9506e 100644 --- a/b2g/config/aries/sources.xml +++ b/b2g/config/aries/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/dolphin/sources.xml b/b2g/config/dolphin/sources.xml index 218c4d5fd5f..fb7a4007724 100644 --- a/b2g/config/dolphin/sources.xml +++ b/b2g/config/dolphin/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/emulator-ics/sources.xml b/b2g/config/emulator-ics/sources.xml index 0a0a3c36ea8..b419f7745ab 100644 --- a/b2g/config/emulator-ics/sources.xml +++ b/b2g/config/emulator-ics/sources.xml @@ -19,7 +19,7 @@ - + diff --git a/b2g/config/emulator-jb/sources.xml b/b2g/config/emulator-jb/sources.xml index 508f0bb9107..5fa68970680 100644 --- a/b2g/config/emulator-jb/sources.xml +++ b/b2g/config/emulator-jb/sources.xml @@ -17,7 +17,7 @@ - + diff --git a/b2g/config/emulator-kk/sources.xml b/b2g/config/emulator-kk/sources.xml index 39f45586c70..1360b80e698 100644 --- a/b2g/config/emulator-kk/sources.xml +++ b/b2g/config/emulator-kk/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/emulator-l/sources.xml b/b2g/config/emulator-l/sources.xml index 2bd4ee19062..91cf29da643 100644 --- a/b2g/config/emulator-l/sources.xml +++ b/b2g/config/emulator-l/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/emulator/sources.xml b/b2g/config/emulator/sources.xml index 0a0a3c36ea8..b419f7745ab 100644 --- a/b2g/config/emulator/sources.xml +++ b/b2g/config/emulator/sources.xml @@ -19,7 +19,7 @@ - + diff --git a/b2g/config/flame-kk/sources.xml b/b2g/config/flame-kk/sources.xml index f3cd317a8d4..4cba60e0e98 100644 --- a/b2g/config/flame-kk/sources.xml +++ b/b2g/config/flame-kk/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/nexus-4/sources.xml b/b2g/config/nexus-4/sources.xml index 096d920cf79..94cc6320bc5 100644 --- a/b2g/config/nexus-4/sources.xml +++ b/b2g/config/nexus-4/sources.xml @@ -17,7 +17,7 @@ - + diff --git a/b2g/config/nexus-5-l/sources.xml b/b2g/config/nexus-5-l/sources.xml index 048db8d119e..19fd01803bb 100644 --- a/b2g/config/nexus-5-l/sources.xml +++ b/b2g/config/nexus-5-l/sources.xml @@ -15,7 +15,7 @@ - + From 013642758159a8cfeabbd914d9fa184d80b87ed5 Mon Sep 17 00:00:00 2001 From: Cervantes Yu Date: Tue, 19 May 2015 11:26:21 +0800 Subject: [PATCH 03/39] Bug 1151672: Remove the calls to nsThreadManager::SetThreadWorking() and nsThreadManager::SetThreadIdle() due to backout of bug 970307. r=seth --- image/DecodePool.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/image/DecodePool.cpp b/image/DecodePool.cpp index 5e53350ae31..d5ac056556d 100644 --- a/image/DecodePool.cpp +++ b/image/DecodePool.cpp @@ -237,10 +237,6 @@ public: return work; } -#ifdef MOZ_NUWA_PROCESS - nsThreadManager::get()->SetThreadIdle(nullptr); -#endif // MOZ_NUWA_PROCESS - // Nothing to do; block until some work is available. mMonitor.Wait(); } while (true); @@ -256,10 +252,6 @@ private: work.mDecoder = aQueue.ElementAt(0); aQueue.RemoveElementAt(0); -#ifdef MOZ_NUWA_PROCESS - nsThreadManager::get()->SetThreadWorking(); -#endif // MOZ_NUWA_PROCESS - return work; } From 11b55812b122345f243f6110c0cdafd02dd5acee Mon Sep 17 00:00:00 2001 From: Cervantes Yu Date: Tue, 19 May 2015 14:31:18 +0800 Subject: [PATCH 04/39] Backout change 3f62597c7e66 due to backout of bug 970307. --- dom/indexedDB/ActorsParent.cpp | 77 ---------------------------------- 1 file changed, 77 deletions(-) diff --git a/dom/indexedDB/ActorsParent.cpp b/dom/indexedDB/ActorsParent.cpp index 28b6f5a3dbd..e7e16b9711c 100644 --- a/dom/indexedDB/ActorsParent.cpp +++ b/dom/indexedDB/ActorsParent.cpp @@ -92,10 +92,6 @@ #include "ReportInternalError.h" #include "snappy/snappy.h" -#ifdef MOZ_NUWA_PROCESS -#include "nsThread.h" -#endif - #define DISABLE_ASSERTS_FOR_FUZZING 0 #if DISABLE_ASSERTS_FOR_FUZZING @@ -4802,9 +4798,6 @@ struct ConnectionPool::ThreadInfo { nsCOMPtr mThread; nsRefPtr mRunnable; -#ifdef MOZ_NUWA_PROCESS - bool mNuwaWorking; -#endif ThreadInfo(); @@ -4812,17 +4805,6 @@ struct ConnectionPool::ThreadInfo ThreadInfo(const ThreadInfo& aOther); ~ThreadInfo(); - - void - NuwaSetWorking(bool aWorking) -#ifdef MOZ_NUWA_PROCESS - ; -#else - { - AssertIsOnBackgroundThread(); - MOZ_ASSERT(mThread); - } -#endif }; struct ConnectionPool::DatabaseInfo final @@ -9842,8 +9824,6 @@ ConnectionPool::ShutdownThread(ThreadInfo& aThreadInfo) MOZ_ASSERT(aThreadInfo.mRunnable); MOZ_ASSERT(mTotalThreadCount); - aThreadInfo.NuwaSetWorking(/* aWorking */ false); - nsRefPtr runnable; aThreadInfo.mRunnable.swap(runnable); @@ -9972,8 +9952,6 @@ ConnectionPool::ScheduleTransaction(TransactionInfo* aTransactionInfo, AdjustIdleTimer(); } - - dbInfo->mThreadInfo.NuwaSetWorking(/* aWorking */ true); } MOZ_ASSERT(dbInfo->mThreadInfo.mThread); @@ -10193,8 +10171,6 @@ ConnectionPool::NoteIdleDatabase(DatabaseInfo* aDatabaseInfo) return; } - aDatabaseInfo->mThreadInfo.NuwaSetWorking(/* aWorking */ false); - mIdleDatabases.InsertElementSorted(aDatabaseInfo); AdjustIdleTimer(); @@ -10238,8 +10214,6 @@ ConnectionPool::NoteClosedDatabase(DatabaseInfo* aDatabaseInfo) } else { MOZ_ASSERT(!mIdleThreads.Contains(aDatabaseInfo->mThreadInfo)); - aDatabaseInfo->mThreadInfo.NuwaSetWorking(/* aWorking */ false); - mIdleThreads.InsertElementSorted(aDatabaseInfo->mThreadInfo); aDatabaseInfo->mThreadInfo.mRunnable = nullptr; @@ -10372,8 +10346,6 @@ ConnectionPool::CloseDatabase(DatabaseInfo* aDatabaseInfo) nsCOMPtr runnable = new CloseConnectionRunnable(aDatabaseInfo); - aDatabaseInfo->mThreadInfo.NuwaSetWorking(/* aWorking */ true); - MOZ_ALWAYS_TRUE(NS_SUCCEEDED( aDatabaseInfo->mThreadInfo.mThread->Dispatch(runnable, NS_DISPATCH_NORMAL))); @@ -10722,9 +10694,6 @@ ThreadRunnable::Run() ConnectionPool:: ThreadInfo::ThreadInfo() -#ifdef MOZ_NUWA_PROCESS - : mNuwaWorking(false) -#endif { AssertIsOnBackgroundThread(); @@ -10735,9 +10704,6 @@ ConnectionPool:: ThreadInfo::ThreadInfo(const ThreadInfo& aOther) : mThread(aOther.mThread) , mRunnable(aOther.mRunnable) -#ifdef MOZ_NUWA_PROCESS - , mNuwaWorking(false) -#endif { AssertIsOnBackgroundThread(); MOZ_ASSERT(aOther.mThread); @@ -10751,52 +10717,9 @@ ThreadInfo::~ThreadInfo() { AssertIsOnBackgroundThread(); -#ifdef MOZ_NUWA_PROCESS - MOZ_ASSERT(!mNuwaWorking); -#endif - MOZ_COUNT_DTOR(ConnectionPool::ThreadInfo); } -#ifdef MOZ_NUWA_PROCESS - -void -ConnectionPool:: -ThreadInfo::NuwaSetWorking(bool aWorking) -{ - AssertIsOnBackgroundThread(); - MOZ_ASSERT(mThread); - - if (mNuwaWorking == aWorking) { - return; - } - - nsCOMPtr runnable = NS_NewRunnableFunction( - [aWorking] - { - MOZ_ASSERT(!IsOnBackgroundThread()); - MOZ_ASSERT(!NS_IsMainThread()); - - auto* thread = static_cast(NS_GetCurrentThread()); - MOZ_ASSERT(thread); - - if (aWorking) { - thread->SetWorking(); - } else { - thread->SetIdle(); - } - } - ); - MOZ_ASSERT(runnable); - - MOZ_ALWAYS_TRUE(NS_SUCCEEDED( - mThread->Dispatch(runnable, NS_DISPATCH_NORMAL))); - - mNuwaWorking = aWorking; -} - -#endif // MOZ_NUWA_PROCESS - ConnectionPool:: IdleResource::IdleResource(const TimeStamp& aIdleTime) : mIdleTime(aIdleTime) From a1af0f3b2a5320fad899a7e52c9514952edd22ef Mon Sep 17 00:00:00 2001 From: Cervantes Yu Date: Tue, 19 May 2015 14:31:20 +0800 Subject: [PATCH 05/39] Backout change b371db089894 (bug 1138620) due to backout of bug 970307. --- xpcom/threads/nsIThreadManager.idl | 9 +-------- xpcom/threads/nsThreadManager.cpp | 9 ++------- xpcom/threads/nsThreadManager.h | 2 ++ 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/xpcom/threads/nsIThreadManager.idl b/xpcom/threads/nsIThreadManager.idl index 1a5d4705839..9b4fc126f9b 100644 --- a/xpcom/threads/nsIThreadManager.idl +++ b/xpcom/threads/nsIThreadManager.idl @@ -13,7 +13,7 @@ interface nsIThread; /** * An interface for creating and locating nsIThread instances. */ -[scriptable, uuid(04092259-4498-4c82-ac52-f9225eb114d0)] +[scriptable, uuid(1be89eca-e2f7-453b-8d38-c11ba247f6f3)] interface nsIThreadManager : nsISupports { /** @@ -65,11 +65,4 @@ interface nsIThreadManager : nsISupports * application process. */ readonly attribute boolean isMainThread; - - /** - * Informs the thread manager to not monitor the status of the current thread. - * This method only works on platforms with Nuwa enabled; on other platforms, - * it throws an error. - */ - [noscript] void setIgnoreThreadStatus(); }; diff --git a/xpcom/threads/nsThreadManager.cpp b/xpcom/threads/nsThreadManager.cpp index 72b4aeb2c03..de3a7a4a17d 100644 --- a/xpcom/threads/nsThreadManager.cpp +++ b/xpcom/threads/nsThreadManager.cpp @@ -430,18 +430,13 @@ nsThreadManager::GetHighestNumberOfThreads() return mHighestNumberOfThreads; } -NS_IMETHODIMP +#ifdef MOZ_NUWA_PROCESS +void nsThreadManager::SetIgnoreThreadStatus() { -#ifdef MOZ_NUWA_PROCESS GetCurrentThreadStatusInfo()->mIgnored = true; - return NS_OK; -#else - return NS_ERROR_NOT_IMPLEMENTED; -#endif } -#ifdef MOZ_NUWA_PROCESS void nsThreadManager::SetThreadIdle(nsIRunnable **aReturnRunnable) { diff --git a/xpcom/threads/nsThreadManager.h b/xpcom/threads/nsThreadManager.h index 34bab9f01f5..32ffda818c3 100644 --- a/xpcom/threads/nsThreadManager.h +++ b/xpcom/threads/nsThreadManager.h @@ -72,6 +72,8 @@ public: } #ifdef MOZ_NUWA_PROCESS + void SetIgnoreThreadStatus(); + // |SetThreadWorking| and |SetThreadIdle| set status of thread that is // currently running. They get thread status information from TLS and pass // the information to |SetThreadIsWorking|. From 27bd72ca5308b1e4e0545a61db1dfa8b50143968 Mon Sep 17 00:00:00 2001 From: Cervantes Yu Date: Tue, 19 May 2015 14:31:22 +0800 Subject: [PATCH 06/39] Backout change 3285d8bef13f (bug 1113429) due to backout of bug 970307. --- dom/workers/WorkerPrivate.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index 1d46a267a2f..f4c7783554a 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -85,6 +85,7 @@ #include "nsQueryObject.h" #include "nsSandboxFlags.h" #include "prthread.h" +#include "nsThread.h" #include "xpcpublic.h" #ifdef ANDROID @@ -5106,6 +5107,17 @@ WorkerPrivate::DoRunLoop(JSContext* aCx) { MutexAutoLock lock(mMutex); +#ifdef MOZ_NUWA_PROCESS + { + nsThread *thr = static_cast(NS_GetCurrentThread()); + ReentrantMonitorAutoEnter mon(thr->ThreadStatusMonitor()); + if (mControlQueue.IsEmpty() && + !(normalRunnablesPending = NS_HasPendingEvents(mThread))) { + thr->SetIdle(); + } + } +#endif // MOZ_NUWA_PROCESS + while (mControlQueue.IsEmpty() && !(debuggerRunnablesPending = !mDebuggerQueue.IsEmpty()) && !(normalRunnablesPending = NS_HasPendingEvents(mThread))) { @@ -5642,15 +5654,6 @@ WorkerPrivate::WaitForWorkerEvents(PRIntervalTime aInterval) // The main thread may be waiting so we must notify. mMemoryReportCondVar.Notify(); -#ifdef MOZ_NUWA_PROCESS - { - MOZ_ASSERT(mThread); - - ReentrantMonitorAutoEnter mon(mThread->ThreadStatusMonitor()); - mThread->SetIdle(); - } -#endif // MOZ_NUWA_PROCESS - // Now wait for an actual worker event. mCondVar.Wait(aInterval); From 3898d7c9f01d8cd74ac3a695b7d3373a7f052fbf Mon Sep 17 00:00:00 2001 From: Cervantes Yu Date: Tue, 19 May 2015 14:31:25 +0800 Subject: [PATCH 07/39] Backout change 39e167bbd14c, a80140872ea5, adae9be2294d and b71ccef9c674 (bug 970307). --- dom/apps/AppsServiceChild.jsm | 9 +- dom/ipc/ContentChild.cpp | 79 ++---- dom/ipc/ContentChild.h | 2 - dom/ipc/ContentParent.cpp | 40 +-- dom/ipc/ContentParent.h | 8 +- dom/ipc/PContent.ipdl | 4 - dom/ipc/TabChild.cpp | 15 -- dom/ipc/TabChild.h | 1 - dom/ipc/jar.mn | 1 - dom/ipc/post-fork-preload.js | 20 -- dom/ipc/preload.js | 2 +- dom/wifi/WifiProxyService.cpp | 3 - dom/workers/WorkerPrivate.cpp | 12 - netwerk/base/nsSocketTransportService2.cpp | 1 - widget/gonk/GonkMemoryPressureMonitoring.cpp | 2 - xpcom/glue/nsThreadUtils.cpp | 8 - xpcom/glue/nsThreadUtils.h | 15 -- xpcom/threads/TimerThread.cpp | 1 - xpcom/threads/nsThread.cpp | 63 +---- xpcom/threads/nsThread.h | 15 -- xpcom/threads/nsThreadManager.cpp | 250 ------------------- xpcom/threads/nsThreadManager.h | 60 ----- xpcom/threads/nsThreadPool.cpp | 7 +- xpcom/threads/nsTimerImpl.cpp | 7 - 24 files changed, 27 insertions(+), 598 deletions(-) delete mode 100644 dom/ipc/post-fork-preload.js diff --git a/dom/apps/AppsServiceChild.jsm b/dom/apps/AppsServiceChild.jsm index 86816225227..8ff625ee924 100644 --- a/dom/apps/AppsServiceChild.jsm +++ b/dom/apps/AppsServiceChild.jsm @@ -103,12 +103,6 @@ this.DOMApplicationRegistry = { this.cpmm.addMessageListener(aMsgName, this); }).bind(this)); - this.resetList(); - - Services.obs.addObserver(this, "xpcom-shutdown", false); - }, - - resetList: function() { this.cpmm.sendAsyncMessage("Webapps:RegisterForMessages", { messages: APPS_IPC_MSG_NAMES }); @@ -116,7 +110,6 @@ this.DOMApplicationRegistry = { // We need to prime the cache with the list of apps. let list = this.cpmm.sendSyncMessage("Webapps:GetList", { })[0]; this.webapps = list.webapps; - // We need a fast mapping from localId -> app, so we add an index. // We also add the manifest to the app object. this.localIdIndex = { }; @@ -125,6 +118,8 @@ this.DOMApplicationRegistry = { this.localIdIndex[app.localId] = app; app.manifest = list.manifests[id]; } + + Services.obs.addObserver(this, "xpcom-shutdown", false); }, observe: function(aSubject, aTopic, aData) { diff --git a/dom/ipc/ContentChild.cpp b/dom/ipc/ContentChild.cpp index 1f3aae0bedc..b2e6846e554 100644 --- a/dom/ipc/ContentChild.cpp +++ b/dom/ipc/ContentChild.cpp @@ -538,12 +538,6 @@ NS_IMPL_ISUPPORTS(BackgroundChildPrimer, nsIIPCBackgroundChildCreateCallback) ContentChild* ContentChild::sSingleton; -static void -PostForkPreload() -{ - TabChild::PostForkPreload(); -} - // Performs initialization that is not fork-safe, i.e. that must be done after // forking from the Nuwa process. static void @@ -554,7 +548,6 @@ InitOnContentProcessCreated() if (IsNuwaProcess()) { return; } - PostForkPreload(); nsCOMPtr permManager = services::GetPermissionManager(); @@ -1356,6 +1349,7 @@ ContentChild::RecvPBrowserConstructor(PBrowserChild* aActor, { // This runs after AllocPBrowserChild() returns and the IPC machinery for this // PBrowserChild has been set up. + nsCOMPtr os = services::GetObserverService(); if (os) { nsITabChild* tc = @@ -2201,11 +2195,8 @@ bool ContentChild::RecvFlushMemory(const nsString& reason) { #ifdef MOZ_NUWA_PROCESS - if (IsNuwaProcess() || ManagedPBrowserChild().Length() == 0) { + if (IsNuwaProcess()) { // Don't flush memory in the nuwa process: the GC thread could be frozen. - // If there's no PBrowser child, don't flush memory, either. GC writes - // to copy-on-write pages and makes preallocated process take more memory - // before it actually becomes an app. return true; } #endif @@ -2299,28 +2290,12 @@ ContentChild::RecvAppInit() // BrowserElementChild.js. if ((mIsForApp || mIsForBrowser) #ifdef MOZ_NUWA_PROCESS - && IsNuwaProcess() + && !IsNuwaProcess() #endif ) { PreloadSlowThings(); -#ifndef MOZ_NUWA_PROCESS - PostForkPreload(); -#endif } -#ifdef MOZ_NUWA_PROCESS - // Some modules are initialized in preloading. We need to wait until the - // tasks they dispatched to chrome process are done. - if (IsNuwaProcess()) { - SendNuwaWaitForFreeze(); - } -#endif - return true; -} - -bool -ContentChild::RecvNuwaFreeze() -{ #ifdef MOZ_NUWA_PROCESS if (IsNuwaProcess()) { ContentChild::GetSingleton()->RecvGarbageCollect(); @@ -2328,6 +2303,7 @@ ContentChild::RecvNuwaFreeze() FROM_HERE, NewRunnableFunction(OnFinishNuwaPreparation)); } #endif + return true; } @@ -2604,36 +2580,6 @@ RunNuwaFork() DoNuwaFork(); } } - -class NuwaForkCaller: public nsRunnable -{ -public: - NS_IMETHODIMP - Run() { - // We want to ensure that the PBackground actor gets cloned in the Nuwa - // process before we freeze. Also, we have to do this to avoid deadlock. - // Protocols that are "opened" (e.g. PBackground, PCompositor) block the - // main thread to wait for the IPC thread during the open operation. - // NuwaSpawnWait() blocks the IPC thread to wait for the main thread when - // the Nuwa process is forked. Unless we ensure that the two cannot happen - // at the same time then we risk deadlock. Spinning the event loop here - // guarantees the ordering is safe for PBackground. - if (!BackgroundChild::GetForCurrentThread()) { - // Dispatch ourself again. - NS_DispatchToMainThread(this, NS_DISPATCH_NORMAL); - } else { - MessageLoop* ioloop = XRE_GetIOMessageLoop(); - ioloop->PostTask(FROM_HERE, NewRunnableFunction(RunNuwaFork)); - } - return NS_OK; - } -private: - virtual - ~NuwaForkCaller() - { - } -}; - #endif bool @@ -2645,9 +2591,22 @@ ContentChild::RecvNuwaFork() } sNuwaForking = true; - nsRefPtr runnable = new NuwaForkCaller(); - NS_DispatchToMainThread(runnable, NS_DISPATCH_NORMAL); + // We want to ensure that the PBackground actor gets cloned in the Nuwa + // process before we freeze. Also, we have to do this to avoid deadlock. + // Protocols that are "opened" (e.g. PBackground, PCompositor) block the + // main thread to wait for the IPC thread during the open operation. + // NuwaSpawnWait() blocks the IPC thread to wait for the main thread when + // the Nuwa process is forked. Unless we ensure that the two cannot happen + // at the same time then we risk deadlock. Spinning the event loop here + // guarantees the ordering is safe for PBackground. + while (!BackgroundChild::GetForCurrentThread()) { + if (NS_WARN_IF(!NS_ProcessNextEvent())) { + return false; + } + } + MessageLoop* ioloop = XRE_GetIOMessageLoop(); + ioloop->PostTask(FROM_HERE, NewRunnableFunction(RunNuwaFork)); return true; #else return false; // Makes the underlying IPC channel abort. diff --git a/dom/ipc/ContentChild.h b/dom/ipc/ContentChild.h index 9470da9b4c0..240bb52429d 100644 --- a/dom/ipc/ContentChild.h +++ b/dom/ipc/ContentChild.h @@ -379,8 +379,6 @@ public: virtual bool RecvNotifyPhoneStateChange(const nsString& state) override; - virtual bool RecvNuwaFreeze() override; - void AddIdleObserver(nsIObserver* aObserver, uint32_t aIdleTimeInS); void RemoveIdleObserver(nsIObserver* aObserver, uint32_t aIdleTimeInS); virtual bool RecvNotifyIdleObserver(const uint64_t& aObserver, diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index 1ed14e0b9ba..c82390d159b 100755 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -140,7 +140,6 @@ #include "nsServiceManagerUtils.h" #include "nsStyleSheetService.h" #include "nsThreadUtils.h" -#include "nsThreadManager.h" #include "nsToolkitCompsCID.h" #include "nsWidgetsCID.h" #include "PreallocatedProcessManager.h" @@ -1563,28 +1562,6 @@ StaticAutoPtr > NS_IMPL_ISUPPORTS(SystemMessageHandledListener, nsITimerCallback) -#ifdef MOZ_NUWA_PROCESS -class NuwaFreezeListener : public nsThreadManager::AllThreadsWereIdleListener -{ -public: - NuwaFreezeListener(ContentParent* parent) - : mParent(parent) - { - } - - void OnAllThreadsWereIdle() - { - unused << mParent->SendNuwaFreeze(); - nsThreadManager::get()->RemoveAllThreadsWereIdleListener(this); - } -private: - nsRefPtr mParent; - virtual ~NuwaFreezeListener() - { - } -}; -#endif // MOZ_NUWA_PROCESS - } // anonymous namespace void @@ -2362,8 +2339,6 @@ ContentParent::ContentParent(ContentParent* aTemplate, priority = PROCESS_PRIORITY_FOREGROUND; } - mSendPermissionUpdates = aTemplate->mSendPermissionUpdates; - InitInternal(priority, false, /* Setup Off-main thread compositing */ false /* Send registered chrome */); @@ -2527,7 +2502,7 @@ ContentParent::IsForApp() #ifdef MOZ_NUWA_PROCESS bool -ContentParent::IsNuwaProcess() const +ContentParent::IsNuwaProcess() { return mIsNuwaProcess; } @@ -2902,19 +2877,6 @@ ContentParent::RecvNuwaReady() #endif } -bool -ContentParent::RecvNuwaWaitForFreeze() -{ -#ifdef MOZ_NUWA_PROCESS - nsRefPtr listener = new NuwaFreezeListener(this); - nsThreadManager::get()->AddAllThreadsWereIdleListener(listener); - return true; -#else // MOZ_NUWA_PROCESS - NS_ERROR("ContentParent::RecvNuwaWaitForFreeze() not implemented!"); - return false; -#endif // MOZ_NUWA_PROCESS -} - bool ContentParent::RecvAddNewProcess(const uint32_t& aPid, InfallibleTArray&& aFds) diff --git a/dom/ipc/ContentParent.h b/dom/ipc/ContentParent.h index bb925615ced..1f04b50f207 100644 --- a/dom/ipc/ContentParent.h +++ b/dom/ipc/ContentParent.h @@ -233,7 +233,7 @@ public: return mIsForBrowser; } #ifdef MOZ_NUWA_PROCESS - bool IsNuwaProcess() const; + bool IsNuwaProcess(); #endif GeckoChildProcessHost* Process() { @@ -247,11 +247,7 @@ public: } bool NeedsPermissionsUpdate() const { -#ifdef MOZ_NUWA_PROCESS - return !IsNuwaProcess() && mSendPermissionUpdates; -#else return mSendPermissionUpdates; -#endif } bool NeedsDataStoreInfos() const { @@ -783,8 +779,6 @@ private: virtual bool RecvNuwaReady() override; - virtual bool RecvNuwaWaitForFreeze() override; - virtual bool RecvAddNewProcess(const uint32_t& aPid, InfallibleTArray&& aFds) override; diff --git a/dom/ipc/PContent.ipdl b/dom/ipc/PContent.ipdl index 82729326978..c380274e661 100644 --- a/dom/ipc/PContent.ipdl +++ b/dom/ipc/PContent.ipdl @@ -632,7 +632,6 @@ child: InvokeDragSession(IPCDataTransfer[] transfers, uint32_t action); EndDragSession(bool aDoneDrag, bool aUserCancelled); - NuwaFreeze(); async DomainSetChanged(uint32_t aSetType, uint32_t aChangeType, OptionalURIParams aDomain); @@ -899,9 +898,6 @@ parent: async SystemMessageHandled(); NuwaReady(); - // Sent when nuwa finished its initialization process and is waiting for - // parent's signal to make it freeze. - NuwaWaitForFreeze(); sync AddNewProcess(uint32_t pid, ProtocolFdMapping[] aFds); diff --git a/dom/ipc/TabChild.cpp b/dom/ipc/TabChild.cpp index 0389bd7d494..865c740665c 100644 --- a/dom/ipc/TabChild.cpp +++ b/dom/ipc/TabChild.cpp @@ -775,21 +775,6 @@ TabChild::PreloadSlowThings() ClearOnShutdown(&sPreallocatedTab); } -/*static*/ void -TabChild::PostForkPreload() -{ - // Preallocated Tab can be null if we are forked directly from b2g. In such - // case we don't need to preload anything, just return. - if (!sPreallocatedTab) { - return; - } - - // Rebuild connections to parent. - sPreallocatedTab->RecvLoadRemoteScript( - NS_LITERAL_STRING("chrome://global/content/post-fork-preload.js"), - true); -} - /*static*/ already_AddRefed TabChild::Create(nsIContentChild* aManager, const TabId& aTabId, diff --git a/dom/ipc/TabChild.h b/dom/ipc/TabChild.h index ba38d95ddb1..d3b0f33eab2 100644 --- a/dom/ipc/TabChild.h +++ b/dom/ipc/TabChild.h @@ -263,7 +263,6 @@ public: * on the critical path. */ static void PreloadSlowThings(); - static void PostForkPreload(); /** Return a TabChild with the given attributes. */ static already_AddRefed diff --git a/dom/ipc/jar.mn b/dom/ipc/jar.mn index f71d7ffc8f3..b3f1bc88e0e 100644 --- a/dom/ipc/jar.mn +++ b/dom/ipc/jar.mn @@ -12,4 +12,3 @@ toolkit.jar: content/global/manifestMessages.js (manifestMessages.js) content/global/PushServiceChildPreload.js (../push/PushServiceChildPreload.js) content/global/preload.js (preload.js) - content/global/post-fork-preload.js (post-fork-preload.js) diff --git a/dom/ipc/post-fork-preload.js b/dom/ipc/post-fork-preload.js deleted file mode 100644 index f5238beb2cd..00000000000 --- a/dom/ipc/post-fork-preload.js +++ /dev/null @@ -1,20 +0,0 @@ -/* 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/. */ - -// Preload some things, in an attempt to make app startup faster. -// -// This script is run when the preallocated process starts. It is injected as -// a frame script. -// If Nuwa process is enabled, this script will run in preallocated process -// forked by Nuwa. - -(function (global) { - "use strict"; - - Components.utils.import("resource://gre/modules/AppsServiceChild.jsm"); - Components.classes["@mozilla.org/network/protocol-proxy-service;1"]. - getService(Ci["nsIProtocolProxyService"]); - - DOMApplicationRegistry.resetList(); -})(this); diff --git a/dom/ipc/preload.js b/dom/ipc/preload.js index 0c59d94d4e1..7e613cffd7f 100644 --- a/dom/ipc/preload.js +++ b/dom/ipc/preload.js @@ -6,7 +6,6 @@ // // This script is run when the preallocated process starts. It is injected as // a frame script. -// If nuwa is enabled, this script will run in Nuwa process before frozen. const BrowserElementIsPreloaded = true; @@ -59,6 +58,7 @@ const BrowserElementIsPreloaded = true; Cc["@mozilla.org/network/idn-service;1"].getService(Ci["nsIIDNService"]); Cc["@mozilla.org/network/io-service;1"].getService(Ci["nsIIOService2"]); Cc["@mozilla.org/network/mime-hdrparam;1"].getService(Ci["nsIMIMEHeaderParam"]); + Cc["@mozilla.org/network/protocol-proxy-service;1"].getService(Ci["nsIProtocolProxyService"]); Cc["@mozilla.org/network/socket-transport-service;1"].getService(Ci["nsISocketTransportService"]); Cc["@mozilla.org/network/stream-transport-service;1"].getService(Ci["nsIStreamTransportService"]); Cc["@mozilla.org/network/url-parser;1?auth=maybe"].getService(Ci["nsIURLParser"]); diff --git a/dom/wifi/WifiProxyService.cpp b/dom/wifi/WifiProxyService.cpp index 6efd7df7c08..3257abedeea 100644 --- a/dom/wifi/WifiProxyService.cpp +++ b/dom/wifi/WifiProxyService.cpp @@ -67,9 +67,6 @@ public: NS_IMETHOD Run() { MOZ_ASSERT(!NS_IsMainThread()); -#ifdef MOZ_NUWA_PROCESS - NS_SetIgnoreStatusOfCurrentThread(); -#endif nsAutoString event; gWpaSupplicant->WaitForEvent(event, mInterface); if (!event.IsEmpty()) { diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index f4c7783554a..c3434fc2a30 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -85,7 +85,6 @@ #include "nsQueryObject.h" #include "nsSandboxFlags.h" #include "prthread.h" -#include "nsThread.h" #include "xpcpublic.h" #ifdef ANDROID @@ -5107,17 +5106,6 @@ WorkerPrivate::DoRunLoop(JSContext* aCx) { MutexAutoLock lock(mMutex); -#ifdef MOZ_NUWA_PROCESS - { - nsThread *thr = static_cast(NS_GetCurrentThread()); - ReentrantMonitorAutoEnter mon(thr->ThreadStatusMonitor()); - if (mControlQueue.IsEmpty() && - !(normalRunnablesPending = NS_HasPendingEvents(mThread))) { - thr->SetIdle(); - } - } -#endif // MOZ_NUWA_PROCESS - while (mControlQueue.IsEmpty() && !(debuggerRunnablesPending = !mDebuggerQueue.IsEmpty()) && !(normalRunnablesPending = NS_HasPendingEvents(mThread))) { diff --git a/netwerk/base/nsSocketTransportService2.cpp b/netwerk/base/nsSocketTransportService2.cpp index 0c4d4b9f685..99663532024 100644 --- a/netwerk/base/nsSocketTransportService2.cpp +++ b/netwerk/base/nsSocketTransportService2.cpp @@ -753,7 +753,6 @@ nsSocketTransportService::Run() if (IsNuwaProcess()) { NuwaMarkCurrentThread(nullptr, nullptr); } - NS_SetIgnoreStatusOfCurrentThread(); #endif SOCKET_LOG(("STS thread init\n")); diff --git a/widget/gonk/GonkMemoryPressureMonitoring.cpp b/widget/gonk/GonkMemoryPressureMonitoring.cpp index 374ef85353b..52aa7db2e1c 100644 --- a/widget/gonk/GonkMemoryPressureMonitoring.cpp +++ b/widget/gonk/GonkMemoryPressureMonitoring.cpp @@ -127,8 +127,6 @@ public: } #endif - NS_SetIgnoreStatusOfCurrentThread(); - int lowMemFd = open("/sys/kernel/mm/lowmemkiller/notify_trigger_active", O_RDONLY | O_CLOEXEC); NS_ENSURE_STATE(lowMemFd != -1); diff --git a/xpcom/glue/nsThreadUtils.cpp b/xpcom/glue/nsThreadUtils.cpp index 9346bd1b550..4e33fc4cef3 100644 --- a/xpcom/glue/nsThreadUtils.cpp +++ b/xpcom/glue/nsThreadUtils.cpp @@ -375,11 +375,3 @@ nsAutoLowPriorityIO::~nsAutoLowPriorityIO() #endif } -#ifdef MOZ_NUWA_PROCESS -#ifdef MOZILLA_INTERNAL_API -void -NS_SetIgnoreStatusOfCurrentThread() { - nsThreadManager::get()->SetIgnoreThreadStatus(); -} -#endif // MOZILLA_INTERNAL_API -#endif // MOZ_NUWA_PROCESS diff --git a/xpcom/glue/nsThreadUtils.h b/xpcom/glue/nsThreadUtils.h index 4b173ed4585..e143c6cef9b 100644 --- a/xpcom/glue/nsThreadUtils.h +++ b/xpcom/glue/nsThreadUtils.h @@ -1019,19 +1019,4 @@ private: void NS_SetMainThread(); -/** - * Helpers for thread to report their status when compiled with Nuwa. - */ -#ifdef MOZILLA_INTERNAL_API -#ifdef MOZ_NUWA_PROCESS -extern void -NS_SetIgnoreStatusOfCurrentThread(); -#else // MOZ_NUWA_PROCESS -inline void -NS_SetIgnoreStatusOfCurrentThread() -{ -} -#endif // MOZ_NUWA_PROCESS -#endif // MOZILLA_INTERNAL_API - #endif // nsThreadUtils_h__ diff --git a/xpcom/threads/TimerThread.cpp b/xpcom/threads/TimerThread.cpp index 8d9ba434566..fbdc810597d 100644 --- a/xpcom/threads/TimerThread.cpp +++ b/xpcom/threads/TimerThread.cpp @@ -205,7 +205,6 @@ TimerThread::Run() } #endif - NS_SetIgnoreStatusOfCurrentThread(); MonitorAutoLock lock(mMonitor); // We need to know how many microseconds give a positive PRIntervalTime. This diff --git a/xpcom/threads/nsThread.cpp b/xpcom/threads/nsThread.cpp index d6b9df70766..e69665685ff 100644 --- a/xpcom/threads/nsThread.cpp +++ b/xpcom/threads/nsThread.cpp @@ -15,6 +15,7 @@ #undef LOG #endif +#include "mozilla/ReentrantMonitor.h" #include "nsMemoryPressure.h" #include "nsThreadManager.h" #include "nsIClassInfoImpl.h" @@ -330,10 +331,6 @@ nsThread::ThreadFunc(void* aArg) // Inform the ThreadManager nsThreadManager::get()->RegisterCurrentThread(self); -#ifdef MOZ_NUWA_PROCESS - self->mThreadStatusInfo = - static_cast(nsThreadManager::get()->GetCurrentThreadStatusInfo()); -#endif #if !defined(MOZILLA_XPCOMRT_API) mozilla::IOInterposer::RegisterCurrentThread(); @@ -451,10 +448,6 @@ nsThread::nsThread(MainThreadFlag aMainThread, uint32_t aStackSize) , mShutdownRequired(false) , mEventsAreDoomed(false) , mIsMainThread(aMainThread) -#ifdef MOZ_NUWA_PROCESS - , mThreadStatusMonitor("nsThread.mThreadStatusLock") - , mThreadStatusInfo(nullptr) -#endif { } @@ -502,11 +495,6 @@ nsThread::InitCurrentThread() SetupCurrentThreadForChaosMode(); nsThreadManager::get()->RegisterCurrentThread(this); -#ifdef MOZ_NUWA_PROCESS - mThreadStatusInfo = - static_cast(nsThreadManager::get()->GetCurrentThreadStatusInfo()); -#endif - return NS_OK; } @@ -522,15 +510,7 @@ nsThread::PutEvent(nsIRunnable* aEvent, nsNestedEventTarget* aTarget) NS_WARNING("An event was posted to a thread that will never run it (rejected)"); return NS_ERROR_UNEXPECTED; } -#ifdef MOZ_NUWA_PROCESS - { - ReentrantMonitorAutoEnter mon(mThreadStatusMonitor); - SetWorking(); -#endif // MOZ_NUWA_PROCESS - queue->PutEvent(aEvent); -#ifdef MOZ_NUWA_PROCESS - } -#endif // MOZ_NUWA_PROCESS + queue->PutEvent(aEvent); // Make sure to grab the observer before dropping the lock, otherwise the // event that we just placed into the queue could run and eventually delete @@ -873,27 +853,6 @@ nsThread::ProcessNextEvent(bool aMayWait, bool* aResult) --mNestedEventLoopDepth; -#ifdef MOZ_NUWA_PROCESS - nsCOMPtr notifyAllIdleRunnable; - { - ReentrantMonitorAutoEnter mon(mThreadStatusMonitor); - if ((!mEvents->GetEvent(false, nullptr)) && (mNestedEventLoopDepth == 0)) { - nsThreadManager::get()->SetThreadIsWorking( - static_cast(mThreadStatusInfo), - false, getter_AddRefs(notifyAllIdleRunnable)); - } - } - if (notifyAllIdleRunnable) { - // Dispatching a task leads us to acquire |mLock| of the thread. If we - // dispatch to main thread while holding main thread's - // |mThreadStatusMonitor|, deadlock could happen if other thread is - // blocked by main thread's |mThreadStatusMonitor| and is holding - // main thread's |mLock|. - Dispatch(notifyAllIdleRunnable, NS_DISPATCH_NORMAL); - nsThreadManager::get()->ResetIsDispatchingToMainThread(); - } -#endif // MOZ_NUWA_PROCESS - NOTIFY_EVENT_OBSERVERS(AfterProcessNextEvent, (this, mNestedEventLoopDepth, *aResult)); @@ -1104,24 +1063,6 @@ nsThread::SetMainThreadObserver(nsIThreadObserver* aObserver) return NS_OK; } -#ifdef MOZ_NUWA_PROCESS -void -nsThread::SetWorking() -{ - nsThreadManager::get()->SetThreadIsWorking( - static_cast(mThreadStatusInfo), - true, nullptr); -} - -void -nsThread::SetIdle() -{ - nsThreadManager::get()->SetThreadIsWorking( - static_cast(mThreadStatusInfo), - false, nullptr); -} -#endif - //----------------------------------------------------------------------------- NS_IMETHODIMP diff --git a/xpcom/threads/nsThread.h b/xpcom/threads/nsThread.h index 2f58cb3be60..67e5516a3e8 100644 --- a/xpcom/threads/nsThread.h +++ b/xpcom/threads/nsThread.h @@ -16,7 +16,6 @@ #include "nsTObserverArray.h" #include "mozilla/Attributes.h" #include "nsAutoPtr.h" -#include "mozilla/ReentrantMonitor.h" // A native thread class nsThread @@ -66,14 +65,6 @@ public: static nsresult SetMainThreadObserver(nsIThreadObserver* aObserver); -#ifdef MOZ_NUWA_PROCESS - void SetWorking(); - void SetIdle(); - mozilla::ReentrantMonitor& ThreadStatusMonitor() { - return mThreadStatusMonitor; - } -#endif - protected: static nsIThreadObserver* sMainThreadObserver; @@ -191,12 +182,6 @@ protected: // Set to true when events posted to this thread will never run. bool mEventsAreDoomed; MainThreadFlag mIsMainThread; -#ifdef MOZ_NUWA_PROCESS - mozilla::ReentrantMonitor mThreadStatusMonitor; - // The actual type is defined in nsThreadManager.h which is not exposed to - // file out of thread module. - void* mThreadStatusInfo; -#endif }; //----------------------------------------------------------------------------- diff --git a/xpcom/threads/nsThreadManager.cpp b/xpcom/threads/nsThreadManager.cpp index de3a7a4a17d..bf2868a3691 100644 --- a/xpcom/threads/nsThreadManager.cpp +++ b/xpcom/threads/nsThreadManager.cpp @@ -11,7 +11,6 @@ #include "nsTArray.h" #include "nsAutoPtr.h" #include "mozilla/ThreadLocal.h" -#include "mozilla/ReentrantMonitor.h" #ifdef MOZ_CANARY #include #include @@ -41,45 +40,6 @@ NS_SetMainThread() typedef nsTArray> nsThreadArray; -#ifdef MOZ_NUWA_PROCESS -class NotifyAllThreadsWereIdle: public nsRunnable -{ -public: - - NotifyAllThreadsWereIdle( - nsTArray>* aListeners) - : mListeners(aListeners) - { - } - - virtual NS_IMETHODIMP - Run() { - // Copy listener array, which may be modified during call back. - nsTArray> arr(*mListeners); - for (size_t i = 0; i < arr.Length(); i++) { - arr[i]->OnAllThreadsWereIdle(); - } - return NS_OK; - } - -private: - // Raw pointer, since it's pointing to a member of thread manager. - nsTArray>* mListeners; -}; - -struct nsThreadManager::ThreadStatusInfo { - Atomic mWorking; - Atomic mWillBeWorking; - bool mIgnored; - ThreadStatusInfo() - : mWorking(false) - , mWillBeWorking(false) - , mIgnored(false) - { - } -}; -#endif // MOZ_NUWA_PROCESS - //----------------------------------------------------------------------------- static void @@ -88,24 +48,6 @@ ReleaseObject(void* aData) static_cast(aData)->Release(); } -#ifdef MOZ_NUWA_PROCESS -void -nsThreadManager::DeleteThreadStatusInfo(void* aData) -{ - nsThreadManager* mgr = nsThreadManager::get(); - nsThreadManager::ThreadStatusInfo* thrInfo = - static_cast(aData); - { - ReentrantMonitorAutoEnter mon(*(mgr->mMonitor)); - mgr->mThreadStatusInfos.RemoveElement(thrInfo); - if (NS_IsMainThread()) { - mgr->mMainThreadStatusInfo = nullptr; - } - } - delete thrInfo; -} -#endif - static PLDHashOperator AppendAndRemoveThread(PRThread* aKey, nsRefPtr& aThread, void* aArg) { @@ -147,17 +89,6 @@ nsThreadManager::Init() return NS_ERROR_FAILURE; } -#ifdef MOZ_NUWA_PROCESS - if (PR_NewThreadPrivateIndex( - &mThreadStatusInfoIndex, - nsThreadManager::DeleteThreadStatusInfo) == PR_FAILURE) { - return NS_ERROR_FAILURE; - } -#endif // MOZ_NUWA_PROCESS - -#ifdef MOZ_NUWA_PROCESS - mMonitor = MakeUnique("nsThreadManager.mMonitor"); -#endif // MOZ_NUWA_PROCESS #ifdef MOZ_CANARY const int flags = O_WRONLY | O_APPEND | O_CREAT | O_NONBLOCK; @@ -250,9 +181,6 @@ nsThreadManager::Shutdown() // Remove the TLS entry for the main thread. PR_SetThreadPrivate(mCurThreadIndex, nullptr); -#ifdef MOZ_NUWA_PROCESS - PR_SetThreadPrivate(mThreadStatusInfoIndex, nullptr); -#endif } void @@ -285,9 +213,6 @@ nsThreadManager::UnregisterCurrentThread(nsThread* aThread) PR_SetThreadPrivate(mCurThreadIndex, nullptr); // Ref-count balanced via ReleaseObject -#ifdef MOZ_NUWA_PROCESS - PR_SetThreadPrivate(mThreadStatusInfoIndex, nullptr); -#endif } nsThread* @@ -312,27 +237,6 @@ nsThreadManager::GetCurrentThread() return thread.get(); // reference held in TLS } -#ifdef MOZ_NUWA_PROCESS -nsThreadManager::ThreadStatusInfo* -nsThreadManager::GetCurrentThreadStatusInfo() -{ - void* data = PR_GetThreadPrivate(mThreadStatusInfoIndex); - if (!data) { - ThreadStatusInfo *thrInfo = new ThreadStatusInfo(); - PR_SetThreadPrivate(mThreadStatusInfoIndex, thrInfo); - data = thrInfo; - - ReentrantMonitorAutoEnter mon(*mMonitor); - mThreadStatusInfos.AppendElement(thrInfo); - if (NS_IsMainThread()) { - mMainThreadStatusInfo = thrInfo; - } - } - - return static_cast(data); -} -#endif - NS_IMETHODIMP nsThreadManager::NewThread(uint32_t aCreationFlags, uint32_t aStackSize, @@ -429,157 +333,3 @@ nsThreadManager::GetHighestNumberOfThreads() OffTheBooksMutexAutoLock lock(mLock); return mHighestNumberOfThreads; } - -#ifdef MOZ_NUWA_PROCESS -void -nsThreadManager::SetIgnoreThreadStatus() -{ - GetCurrentThreadStatusInfo()->mIgnored = true; -} - -void -nsThreadManager::SetThreadIdle(nsIRunnable **aReturnRunnable) -{ - SetThreadIsWorking(GetCurrentThreadStatusInfo(), false, aReturnRunnable); -} - -void -nsThreadManager::SetThreadWorking() -{ - SetThreadIsWorking(GetCurrentThreadStatusInfo(), true, nullptr); -} - -void -nsThreadManager::SetThreadIsWorking(ThreadStatusInfo* aInfo, - bool aIsWorking, - nsIRunnable **aReturnRunnable) -{ - aInfo->mWillBeWorking = aIsWorking; - if (mThreadsIdledListeners.Length() > 0) { - - // A race condition occurs since we don't want threads to try to enter the - // monitor (nsThreadManager::mMonitor) when no one cares about their status. - // And thus the race can happen when we put the first listener into - // |mThreadsIdledListeners|: - // - // (1) Thread A wants to dispatch a task to Thread B. - // (2) Thread A checks |mThreadsIdledListeners|, and nothing is in the - // list. So Thread A decides not to enter |mMonitor| when updating B's - // status. - // (3) Thread A is suspended just before it changed status of B. - // (4) A listener is added to |mThreadsIdledListeners| - // (5) Now is Thread C's turn to run. Thread C finds there's something in - // |mThreadsIdledListeners|, so it enters |mMonitor| and check all - // thread info structs in |mThreadStatusInfos| while A is in the middle - // of changing B's status. - // - // Then C may find Thread B is an idle thread (which is not correct, because - // A attempted to change B's status prior to C starting to walk throught - // |mThreadStatusInfo|), but the fact that thread A is working (thread A - // hasn't finished dispatching a task to thread B) can prevent thread C from - // firing a bogus notification. - // - // If the state transition that happens outside the monitor is in the other - // direction, the race condition could be: - // - // (1) Thread D has just finished its jobs and wants to set its status to idle. - // (2) Thread D checks |mThreadsIdledListeners|, and nothing is in the list. - // So Thread D decides not to enter |mMonitor|. - // (3) Thread D is is suspended before it updates its own status. - // (4) A listener is put into |mThreadsIdledListeners|. - // (5) Thread C wants to changes status of itself. It checks - // |mThreadsIdledListeners| and finds something inside the list. Thread C - // then enters |mMonitor|, updates its status and checks thread info in - // |mThreadStatusInfos| while D is changing status of itself out of monitor. - // - // Thread C will find that thread D is working (D actually wants to change its - // status to idle before C starting to check), then C returns without firing - // any notification. Finding that thread D is working can make our checking - // mechanism miss a chance to fire a notification: because thread D thought - // there's nothing in |mThreadsIdledListeners| and thus won't check the - // |mThreadStatusInfos| after changing the status of itself. - // - // |mWillBeWorking| can be used to address this problem. We require each - // thread to put the value that is going to be set to |mWorking| to - // |mWillBeWorking| before the thread decide whether it should enter - // |mMonitor| to change status or not. Thus C finds that D is working while - // D's |mWillBeWorking| is false, and C realizes that D is just updating and - // can treat D as an idle thread. - // - // It doesn't matter whether D will check thread status after changing its - // own status or not. If D checks, which means D will enter the monitor - // before updating status, thus D must be blocked until C has finished - // dispatching the notification task to main thread, and D will find that main - // thread is working and will not fire an additional event. On the other hand, - // if D doesn't check |mThreadStatusInfos|, it's still ok, because C has - // treated D as an idle thread already. - - bool hasWorkingThread = false; - nsRefPtr runnable; - { - ReentrantMonitorAutoEnter mon(*mMonitor); - // Get data structure of thread info. - aInfo->mWorking = aIsWorking; - if (aIsWorking) { - // We are working, so there's no need to check futher. - return; - } - - for (size_t i = 0; i < mThreadStatusInfos.Length(); i++) { - ThreadStatusInfo *info = mThreadStatusInfos[i]; - if (!info->mIgnored) { - if (info->mWorking) { - if (info->mWillBeWorking) { - hasWorkingThread = true; - break; - } - } - } - } - if (!hasWorkingThread && !mDispatchingToMainThread) { - runnable = new NotifyAllThreadsWereIdle(&mThreadsIdledListeners); - mDispatchingToMainThread = true; - } - } - - if (runnable) { - if (NS_IsMainThread()) { - // We are holding the main thread's |nsThread::mThreadStatusMonitor|. - // If we dispatch a task to ourself, then we are in danger of causing - // deadlock. Instead, return the task, and let the caller dispatch it - // for us. - MOZ_ASSERT(aReturnRunnable, - "aReturnRunnable must be provided on main thread"); - runnable.forget(aReturnRunnable); - } else { - NS_DispatchToMainThread(runnable); - ResetIsDispatchingToMainThread(); - } - } - } else { - // Update thread info without holding any lock. - aInfo->mWorking = aIsWorking; - } -} - -void -nsThreadManager::ResetIsDispatchingToMainThread() -{ - ReentrantMonitorAutoEnter mon(*mMonitor); - mDispatchingToMainThread = false; -} - -void -nsThreadManager::AddAllThreadsWereIdleListener(AllThreadsWereIdleListener *listener) -{ - MOZ_ASSERT(GetCurrentThreadStatusInfo()->mWorking); - mThreadsIdledListeners.AppendElement(listener); -} - -void -nsThreadManager::RemoveAllThreadsWereIdleListener(AllThreadsWereIdleListener *listener) -{ - mThreadsIdledListeners.RemoveElement(listener); -} - -#endif // MOZ_NUWA_PROCESS diff --git a/xpcom/threads/nsThreadManager.h b/xpcom/threads/nsThreadManager.h index 32ffda818c3..4acec42213a 100644 --- a/xpcom/threads/nsThreadManager.h +++ b/xpcom/threads/nsThreadManager.h @@ -14,26 +14,9 @@ class nsIRunnable; -namespace mozilla { -class ReentrantMonitor; -} - class nsThreadManager : public nsIThreadManager { public: -#ifdef MOZ_NUWA_PROCESS - struct ThreadStatusInfo; - class AllThreadsWereIdleListener { - public: - NS_INLINE_DECL_REFCOUNTING(AllThreadsWereIdleListener); - virtual void OnAllThreadsWereIdle() = 0; - protected: - virtual ~AllThreadsWereIdleListener() - { - } - }; -#endif // MOZ_NUWA_PROCESS - NS_DECL_ISUPPORTS NS_DECL_NSITHREADMANAGER @@ -71,31 +54,6 @@ public: { } -#ifdef MOZ_NUWA_PROCESS - void SetIgnoreThreadStatus(); - - // |SetThreadWorking| and |SetThreadIdle| set status of thread that is - // currently running. They get thread status information from TLS and pass - // the information to |SetThreadIsWorking|. - void SetThreadIdle(nsIRunnable** aReturnRunnable); - void SetThreadWorking(); - - // |SetThreadIsWorking| is where is status actually changed. Thread status - // information is passed as a argument so caller must obtain the structure - // by itself. If this method is invoked on main thread, |aReturnRunnable| - // should be provided to receive the runnable of notifying listeners. - // |ResetIsDispatchingToMainThread| should be invoked after caller on main - // thread dispatched the task to main thread's queue. - void SetThreadIsWorking(ThreadStatusInfo* aInfo, - bool aIsWorking, - nsIRunnable** aReturnRunnable); - void ResetIsDispatchingToMainThread(); - - void AddAllThreadsWereIdleListener(AllThreadsWereIdleListener *listener); - void RemoveAllThreadsWereIdleListener(AllThreadsWereIdleListener *listener); - ThreadStatusInfo* GetCurrentThreadStatusInfo(); -#endif // MOZ_NUWA_PROCESS - private: nsThreadManager() : mCurThreadIndex(0) @@ -104,11 +62,6 @@ private: , mInitialized(false) , mCurrentNumberOfThreads(1) , mHighestNumberOfThreads(1) -#ifdef MOZ_NUWA_PROCESS - , mMonitor(nullptr) - , mMainThreadStatusInfo(nullptr) - , mDispatchingToMainThread(nullptr) -#endif { } @@ -123,19 +76,6 @@ private: uint32_t mCurrentNumberOfThreads; // The highest number of threads encountered so far during the session uint32_t mHighestNumberOfThreads; - -#ifdef MOZ_NUWA_PROCESS - static void DeleteThreadStatusInfo(void *aData); - unsigned mThreadStatusInfoIndex; - nsTArray> mThreadsIdledListeners; - nsTArray mThreadStatusInfos; - mozilla::UniquePtr mMonitor; - ThreadStatusInfo* mMainThreadStatusInfo; - // |mDispatchingToMainThread| is set when all thread are found to be idle - // before task of notifying all listeners are dispatched to main thread. - // The flag is protected by |mMonitor|. - bool mDispatchingToMainThread; -#endif // MOZ_NUWA_PROCESS }; #define NS_THREADMANAGER_CID \ diff --git a/xpcom/threads/nsThreadPool.cpp b/xpcom/threads/nsThreadPool.cpp index 27538fc8e2b..97fb4a42884 100644 --- a/xpcom/threads/nsThreadPool.cpp +++ b/xpcom/threads/nsThreadPool.cpp @@ -151,6 +151,7 @@ NS_IMETHODIMP nsThreadPool::Run() { LOG(("THRD-P(%p) enter\n", this)); + mThreadNaming.SetThreadPoolName(mName); nsCOMPtr current; @@ -208,9 +209,6 @@ nsThreadPool::Run() } else { PRIntervalTime delta = timeout - (now - idleSince); LOG(("THRD-P(%p) waiting [%d]\n", this, delta)); -#ifdef MOZ_NUWA_PROCESS - nsThreadManager::get()->SetThreadIdle(nullptr); -#endif // MOZ_NUWA_PROCESS mon.Wait(delta); } } else if (wasIdle) { @@ -220,9 +218,6 @@ nsThreadPool::Run() } if (event) { LOG(("THRD-P(%p) running [%p]\n", this, event.get())); -#ifdef MOZ_NUWA_PROCESS - nsThreadManager::get()->SetThreadWorking(); -#endif // MOZ_NUWA_PROCESS event->Run(); } } while (!exitThread); diff --git a/xpcom/threads/nsTimerImpl.cpp b/xpcom/threads/nsTimerImpl.cpp index 5133e63b275..f10fb4dcb6f 100644 --- a/xpcom/threads/nsTimerImpl.cpp +++ b/xpcom/threads/nsTimerImpl.cpp @@ -549,13 +549,6 @@ nsTimerImpl::Fire() return; } -#ifdef MOZ_NUWA_PROCESS - if (IsNuwaProcess() && IsNuwaReady()) { - // A timer event fired after Nuwa frozen can freeze main thread. - return; - } -#endif - #if !defined(MOZILLA_XPCOMRT_API) PROFILER_LABEL("Timer", "Fire", js::ProfileEntry::Category::OTHER); From 0900ad477044a36dbac8bee1893e49c9b9d93b47 Mon Sep 17 00:00:00 2001 From: B2G Bumper Bot Date: Mon, 18 May 2015 23:50:19 -0700 Subject: [PATCH 08/39] Bumping gaia.json for 6 gaia revision(s) a=gaia-bump ======== https://hg.mozilla.org/integration/gaia-central/rev/f5d9050ae643 Author: autolander Desc: Bug 1164346 - merge pull request #30097 from EragonJ:bug-1164346-another to mozilla-b2g:master ======== https://hg.mozilla.org/integration/gaia-central/rev/7b323f925e58 Author: EragonJ Desc: Bug 1164346 - Add a locale id check hook ======== https://hg.mozilla.org/integration/gaia-central/rev/e01ed9222306 Author: autolander Desc: Bug 1161985 - merge pull request #30022 from steveck-chung:new-message-recipient-css to mozilla-b2g:master ======== https://hg.mozilla.org/integration/gaia-central/rev/c7dd3c741020 Author: Steve Chung Desc: Bug 1161985 - [Messages][NG] Split recipient and non-compose related styling from compose.css, r=azasypkin ======== https://hg.mozilla.org/integration/gaia-central/rev/57dc5b6d0e1e Author: autolander Desc: Bug 1158351 - merge pull request #29846 from aron-bordin:wifi_helper_is_valid_input_tests to mozilla-b2g:master ======== https://hg.mozilla.org/integration/gaia-central/rev/0a0ba417e523 Author: Aron Bordin Desc: Bug 1158351 - Add unit tests for WifiHelper.isValidInput R=aron.bordin --- b2g/config/gaia.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/b2g/config/gaia.json b/b2g/config/gaia.json index 692ccfb1545..05638911bba 100644 --- a/b2g/config/gaia.json +++ b/b2g/config/gaia.json @@ -1,9 +1,9 @@ { "git": { - "git_revision": "099b611c0076ed9d8f68c569bba8c17f66a67f05", + "git_revision": "0cbf7620e8e3025b0cdaa13dbfeea922e941efa7", "remote": "https://git.mozilla.org/releases/gaia.git", "branch": "" }, - "revision": "6206fc1b4a6580aea954a5c9fc52a5649d532a96", + "revision": "f5d9050ae6439aa72a1b5c2aaa86386fa4429275", "repo_path": "integration/gaia-central" } From 678fb9e9bbc9959eb1b96240be0db8e5937fd66f Mon Sep 17 00:00:00 2001 From: B2G Bumper Bot Date: Mon, 18 May 2015 23:52:13 -0700 Subject: [PATCH 09/39] Bumping manifests a=b2g-bump --- b2g/config/aries/sources.xml | 2 +- b2g/config/dolphin/sources.xml | 2 +- b2g/config/emulator-ics/sources.xml | 2 +- b2g/config/emulator-jb/sources.xml | 2 +- b2g/config/emulator-kk/sources.xml | 2 +- b2g/config/emulator-l/sources.xml | 2 +- b2g/config/emulator/sources.xml | 2 +- b2g/config/flame-kk/sources.xml | 2 +- b2g/config/nexus-4/sources.xml | 2 +- b2g/config/nexus-5-l/sources.xml | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/b2g/config/aries/sources.xml b/b2g/config/aries/sources.xml index f05e1a9506e..28e0284094a 100644 --- a/b2g/config/aries/sources.xml +++ b/b2g/config/aries/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/dolphin/sources.xml b/b2g/config/dolphin/sources.xml index fb7a4007724..73118e8cb67 100644 --- a/b2g/config/dolphin/sources.xml +++ b/b2g/config/dolphin/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/emulator-ics/sources.xml b/b2g/config/emulator-ics/sources.xml index b419f7745ab..86e9a7d80e6 100644 --- a/b2g/config/emulator-ics/sources.xml +++ b/b2g/config/emulator-ics/sources.xml @@ -19,7 +19,7 @@ - + diff --git a/b2g/config/emulator-jb/sources.xml b/b2g/config/emulator-jb/sources.xml index 5fa68970680..9ee5bf76385 100644 --- a/b2g/config/emulator-jb/sources.xml +++ b/b2g/config/emulator-jb/sources.xml @@ -17,7 +17,7 @@ - + diff --git a/b2g/config/emulator-kk/sources.xml b/b2g/config/emulator-kk/sources.xml index 1360b80e698..63290b2c073 100644 --- a/b2g/config/emulator-kk/sources.xml +++ b/b2g/config/emulator-kk/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/emulator-l/sources.xml b/b2g/config/emulator-l/sources.xml index 91cf29da643..f18471bb19f 100644 --- a/b2g/config/emulator-l/sources.xml +++ b/b2g/config/emulator-l/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/emulator/sources.xml b/b2g/config/emulator/sources.xml index b419f7745ab..86e9a7d80e6 100644 --- a/b2g/config/emulator/sources.xml +++ b/b2g/config/emulator/sources.xml @@ -19,7 +19,7 @@ - + diff --git a/b2g/config/flame-kk/sources.xml b/b2g/config/flame-kk/sources.xml index 4cba60e0e98..77eb5611011 100644 --- a/b2g/config/flame-kk/sources.xml +++ b/b2g/config/flame-kk/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/nexus-4/sources.xml b/b2g/config/nexus-4/sources.xml index 94cc6320bc5..5b8cb56c093 100644 --- a/b2g/config/nexus-4/sources.xml +++ b/b2g/config/nexus-4/sources.xml @@ -17,7 +17,7 @@ - + diff --git a/b2g/config/nexus-5-l/sources.xml b/b2g/config/nexus-5-l/sources.xml index 19fd01803bb..a3cdeebe213 100644 --- a/b2g/config/nexus-5-l/sources.xml +++ b/b2g/config/nexus-5-l/sources.xml @@ -15,7 +15,7 @@ - + From f8bf61881cf20a0d6c74f5d1c50df1d6586df509 Mon Sep 17 00:00:00 2001 From: B2G Bumper Bot Date: Tue, 19 May 2015 00:10:31 -0700 Subject: [PATCH 10/39] Bumping gaia.json for 2 gaia revision(s) a=gaia-bump ======== https://hg.mozilla.org/integration/gaia-central/rev/0b103015272b Author: Evan Tseng Desc: Merge pull request #29855 from evanxd/bug-1157140 Bug 1157140 - Add MozChromeEvent and MozContentEvent to control the audio channels in System app r=alive, dkuo ======== https://hg.mozilla.org/integration/gaia-central/rev/11d581d3808f Author: Evan Xd Desc: Bug 1157140 - Add MozChromeEvent and MozContentEvent to control the audio channels in System app r=alive, dkuo --- b2g/config/gaia.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/b2g/config/gaia.json b/b2g/config/gaia.json index 05638911bba..5fc9de5af2e 100644 --- a/b2g/config/gaia.json +++ b/b2g/config/gaia.json @@ -1,9 +1,9 @@ { "git": { - "git_revision": "0cbf7620e8e3025b0cdaa13dbfeea922e941efa7", + "git_revision": "117e5c4e22f51c756ae6198dea0d6123a4396cc8", "remote": "https://git.mozilla.org/releases/gaia.git", "branch": "" }, - "revision": "f5d9050ae6439aa72a1b5c2aaa86386fa4429275", + "revision": "0b103015272b6bdddd46522ca38e87c1d0303d76", "repo_path": "integration/gaia-central" } From bc08a317284ab8951b3976621ae39a6336ae8a36 Mon Sep 17 00:00:00 2001 From: B2G Bumper Bot Date: Tue, 19 May 2015 00:12:51 -0700 Subject: [PATCH 11/39] Bumping manifests a=b2g-bump --- b2g/config/aries/sources.xml | 2 +- b2g/config/dolphin/sources.xml | 2 +- b2g/config/emulator-ics/sources.xml | 2 +- b2g/config/emulator-jb/sources.xml | 2 +- b2g/config/emulator-kk/sources.xml | 2 +- b2g/config/emulator-l/sources.xml | 2 +- b2g/config/emulator/sources.xml | 2 +- b2g/config/flame-kk/sources.xml | 2 +- b2g/config/nexus-4/sources.xml | 2 +- b2g/config/nexus-5-l/sources.xml | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/b2g/config/aries/sources.xml b/b2g/config/aries/sources.xml index 28e0284094a..8d01f87705f 100644 --- a/b2g/config/aries/sources.xml +++ b/b2g/config/aries/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/dolphin/sources.xml b/b2g/config/dolphin/sources.xml index 73118e8cb67..6e7e77b8493 100644 --- a/b2g/config/dolphin/sources.xml +++ b/b2g/config/dolphin/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/emulator-ics/sources.xml b/b2g/config/emulator-ics/sources.xml index 86e9a7d80e6..df5a57d6d20 100644 --- a/b2g/config/emulator-ics/sources.xml +++ b/b2g/config/emulator-ics/sources.xml @@ -19,7 +19,7 @@ - + diff --git a/b2g/config/emulator-jb/sources.xml b/b2g/config/emulator-jb/sources.xml index 9ee5bf76385..e579400587f 100644 --- a/b2g/config/emulator-jb/sources.xml +++ b/b2g/config/emulator-jb/sources.xml @@ -17,7 +17,7 @@ - + diff --git a/b2g/config/emulator-kk/sources.xml b/b2g/config/emulator-kk/sources.xml index 63290b2c073..15f71626da3 100644 --- a/b2g/config/emulator-kk/sources.xml +++ b/b2g/config/emulator-kk/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/emulator-l/sources.xml b/b2g/config/emulator-l/sources.xml index f18471bb19f..57c4dbe5a1a 100644 --- a/b2g/config/emulator-l/sources.xml +++ b/b2g/config/emulator-l/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/emulator/sources.xml b/b2g/config/emulator/sources.xml index 86e9a7d80e6..df5a57d6d20 100644 --- a/b2g/config/emulator/sources.xml +++ b/b2g/config/emulator/sources.xml @@ -19,7 +19,7 @@ - + diff --git a/b2g/config/flame-kk/sources.xml b/b2g/config/flame-kk/sources.xml index 77eb5611011..a7b41b010d5 100644 --- a/b2g/config/flame-kk/sources.xml +++ b/b2g/config/flame-kk/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/nexus-4/sources.xml b/b2g/config/nexus-4/sources.xml index 5b8cb56c093..81131e77cc8 100644 --- a/b2g/config/nexus-4/sources.xml +++ b/b2g/config/nexus-4/sources.xml @@ -17,7 +17,7 @@ - + diff --git a/b2g/config/nexus-5-l/sources.xml b/b2g/config/nexus-5-l/sources.xml index a3cdeebe213..4d498436c78 100644 --- a/b2g/config/nexus-5-l/sources.xml +++ b/b2g/config/nexus-5-l/sources.xml @@ -15,7 +15,7 @@ - + From da2820c9f9acd4ce6ead6a5976fb46c9cae68fec Mon Sep 17 00:00:00 2001 From: Edgar Chen Date: Tue, 19 May 2015 12:06:16 +0800 Subject: [PATCH 12/39] Bug 1166149 - Make test_ril_code_quality.py can be ran via mach command. r=aknow --- dom/system/gonk/tests/marionette/test_ril_code_quality.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dom/system/gonk/tests/marionette/test_ril_code_quality.py b/dom/system/gonk/tests/marionette/test_ril_code_quality.py index 1002b99486f..a7705e4c5e9 100644 --- a/dom/system/gonk/tests/marionette/test_ril_code_quality.py +++ b/dom/system/gonk/tests/marionette/test_ril_code_quality.py @@ -31,7 +31,7 @@ The above merge way ensures the correct scope of 'strict mode.' """ -from marionette_test import MarionetteTestCase +from marionette.marionette_test import MarionetteTestCase import bisect import inspect import os From f5f5b9ee8f7a0e507749be7887cff7909cd2e1c5 Mon Sep 17 00:00:00 2001 From: "Carsten \"Tomcat\" Book" Date: Tue, 19 May 2015 11:44:27 +0200 Subject: [PATCH 13/39] Backed out changeset 4d2839eea957 (bug 970307) --- dom/apps/AppsServiceChild.jsm | 9 +- dom/ipc/ContentChild.cpp | 79 ++++-- dom/ipc/ContentChild.h | 2 + dom/ipc/ContentParent.cpp | 40 ++- dom/ipc/ContentParent.h | 8 +- dom/ipc/PContent.ipdl | 4 + dom/ipc/TabChild.cpp | 15 ++ dom/ipc/TabChild.h | 1 + dom/ipc/jar.mn | 1 + dom/ipc/post-fork-preload.js | 20 ++ dom/ipc/preload.js | 2 +- dom/wifi/WifiProxyService.cpp | 3 + dom/workers/WorkerPrivate.cpp | 12 + netwerk/base/nsSocketTransportService2.cpp | 1 + widget/gonk/GonkMemoryPressureMonitoring.cpp | 2 + xpcom/glue/nsThreadUtils.cpp | 8 + xpcom/glue/nsThreadUtils.h | 15 ++ xpcom/threads/TimerThread.cpp | 1 + xpcom/threads/nsThread.cpp | 63 ++++- xpcom/threads/nsThread.h | 15 ++ xpcom/threads/nsThreadManager.cpp | 250 +++++++++++++++++++ xpcom/threads/nsThreadManager.h | 60 +++++ xpcom/threads/nsThreadPool.cpp | 7 +- xpcom/threads/nsTimerImpl.cpp | 7 + 24 files changed, 598 insertions(+), 27 deletions(-) create mode 100644 dom/ipc/post-fork-preload.js diff --git a/dom/apps/AppsServiceChild.jsm b/dom/apps/AppsServiceChild.jsm index 8ff625ee924..86816225227 100644 --- a/dom/apps/AppsServiceChild.jsm +++ b/dom/apps/AppsServiceChild.jsm @@ -103,6 +103,12 @@ this.DOMApplicationRegistry = { this.cpmm.addMessageListener(aMsgName, this); }).bind(this)); + this.resetList(); + + Services.obs.addObserver(this, "xpcom-shutdown", false); + }, + + resetList: function() { this.cpmm.sendAsyncMessage("Webapps:RegisterForMessages", { messages: APPS_IPC_MSG_NAMES }); @@ -110,6 +116,7 @@ this.DOMApplicationRegistry = { // We need to prime the cache with the list of apps. let list = this.cpmm.sendSyncMessage("Webapps:GetList", { })[0]; this.webapps = list.webapps; + // We need a fast mapping from localId -> app, so we add an index. // We also add the manifest to the app object. this.localIdIndex = { }; @@ -118,8 +125,6 @@ this.DOMApplicationRegistry = { this.localIdIndex[app.localId] = app; app.manifest = list.manifests[id]; } - - Services.obs.addObserver(this, "xpcom-shutdown", false); }, observe: function(aSubject, aTopic, aData) { diff --git a/dom/ipc/ContentChild.cpp b/dom/ipc/ContentChild.cpp index b2e6846e554..1f3aae0bedc 100644 --- a/dom/ipc/ContentChild.cpp +++ b/dom/ipc/ContentChild.cpp @@ -538,6 +538,12 @@ NS_IMPL_ISUPPORTS(BackgroundChildPrimer, nsIIPCBackgroundChildCreateCallback) ContentChild* ContentChild::sSingleton; +static void +PostForkPreload() +{ + TabChild::PostForkPreload(); +} + // Performs initialization that is not fork-safe, i.e. that must be done after // forking from the Nuwa process. static void @@ -548,6 +554,7 @@ InitOnContentProcessCreated() if (IsNuwaProcess()) { return; } + PostForkPreload(); nsCOMPtr permManager = services::GetPermissionManager(); @@ -1349,7 +1356,6 @@ ContentChild::RecvPBrowserConstructor(PBrowserChild* aActor, { // This runs after AllocPBrowserChild() returns and the IPC machinery for this // PBrowserChild has been set up. - nsCOMPtr os = services::GetObserverService(); if (os) { nsITabChild* tc = @@ -2195,8 +2201,11 @@ bool ContentChild::RecvFlushMemory(const nsString& reason) { #ifdef MOZ_NUWA_PROCESS - if (IsNuwaProcess()) { + if (IsNuwaProcess() || ManagedPBrowserChild().Length() == 0) { // Don't flush memory in the nuwa process: the GC thread could be frozen. + // If there's no PBrowser child, don't flush memory, either. GC writes + // to copy-on-write pages and makes preallocated process take more memory + // before it actually becomes an app. return true; } #endif @@ -2290,12 +2299,28 @@ ContentChild::RecvAppInit() // BrowserElementChild.js. if ((mIsForApp || mIsForBrowser) #ifdef MOZ_NUWA_PROCESS - && !IsNuwaProcess() + && IsNuwaProcess() #endif ) { PreloadSlowThings(); +#ifndef MOZ_NUWA_PROCESS + PostForkPreload(); +#endif } +#ifdef MOZ_NUWA_PROCESS + // Some modules are initialized in preloading. We need to wait until the + // tasks they dispatched to chrome process are done. + if (IsNuwaProcess()) { + SendNuwaWaitForFreeze(); + } +#endif + return true; +} + +bool +ContentChild::RecvNuwaFreeze() +{ #ifdef MOZ_NUWA_PROCESS if (IsNuwaProcess()) { ContentChild::GetSingleton()->RecvGarbageCollect(); @@ -2303,7 +2328,6 @@ ContentChild::RecvAppInit() FROM_HERE, NewRunnableFunction(OnFinishNuwaPreparation)); } #endif - return true; } @@ -2580,6 +2604,36 @@ RunNuwaFork() DoNuwaFork(); } } + +class NuwaForkCaller: public nsRunnable +{ +public: + NS_IMETHODIMP + Run() { + // We want to ensure that the PBackground actor gets cloned in the Nuwa + // process before we freeze. Also, we have to do this to avoid deadlock. + // Protocols that are "opened" (e.g. PBackground, PCompositor) block the + // main thread to wait for the IPC thread during the open operation. + // NuwaSpawnWait() blocks the IPC thread to wait for the main thread when + // the Nuwa process is forked. Unless we ensure that the two cannot happen + // at the same time then we risk deadlock. Spinning the event loop here + // guarantees the ordering is safe for PBackground. + if (!BackgroundChild::GetForCurrentThread()) { + // Dispatch ourself again. + NS_DispatchToMainThread(this, NS_DISPATCH_NORMAL); + } else { + MessageLoop* ioloop = XRE_GetIOMessageLoop(); + ioloop->PostTask(FROM_HERE, NewRunnableFunction(RunNuwaFork)); + } + return NS_OK; + } +private: + virtual + ~NuwaForkCaller() + { + } +}; + #endif bool @@ -2591,22 +2645,9 @@ ContentChild::RecvNuwaFork() } sNuwaForking = true; - // We want to ensure that the PBackground actor gets cloned in the Nuwa - // process before we freeze. Also, we have to do this to avoid deadlock. - // Protocols that are "opened" (e.g. PBackground, PCompositor) block the - // main thread to wait for the IPC thread during the open operation. - // NuwaSpawnWait() blocks the IPC thread to wait for the main thread when - // the Nuwa process is forked. Unless we ensure that the two cannot happen - // at the same time then we risk deadlock. Spinning the event loop here - // guarantees the ordering is safe for PBackground. - while (!BackgroundChild::GetForCurrentThread()) { - if (NS_WARN_IF(!NS_ProcessNextEvent())) { - return false; - } - } + nsRefPtr runnable = new NuwaForkCaller(); + NS_DispatchToMainThread(runnable, NS_DISPATCH_NORMAL); - MessageLoop* ioloop = XRE_GetIOMessageLoop(); - ioloop->PostTask(FROM_HERE, NewRunnableFunction(RunNuwaFork)); return true; #else return false; // Makes the underlying IPC channel abort. diff --git a/dom/ipc/ContentChild.h b/dom/ipc/ContentChild.h index 240bb52429d..9470da9b4c0 100644 --- a/dom/ipc/ContentChild.h +++ b/dom/ipc/ContentChild.h @@ -379,6 +379,8 @@ public: virtual bool RecvNotifyPhoneStateChange(const nsString& state) override; + virtual bool RecvNuwaFreeze() override; + void AddIdleObserver(nsIObserver* aObserver, uint32_t aIdleTimeInS); void RemoveIdleObserver(nsIObserver* aObserver, uint32_t aIdleTimeInS); virtual bool RecvNotifyIdleObserver(const uint64_t& aObserver, diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index c82390d159b..1ed14e0b9ba 100755 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -140,6 +140,7 @@ #include "nsServiceManagerUtils.h" #include "nsStyleSheetService.h" #include "nsThreadUtils.h" +#include "nsThreadManager.h" #include "nsToolkitCompsCID.h" #include "nsWidgetsCID.h" #include "PreallocatedProcessManager.h" @@ -1562,6 +1563,28 @@ StaticAutoPtr > NS_IMPL_ISUPPORTS(SystemMessageHandledListener, nsITimerCallback) +#ifdef MOZ_NUWA_PROCESS +class NuwaFreezeListener : public nsThreadManager::AllThreadsWereIdleListener +{ +public: + NuwaFreezeListener(ContentParent* parent) + : mParent(parent) + { + } + + void OnAllThreadsWereIdle() + { + unused << mParent->SendNuwaFreeze(); + nsThreadManager::get()->RemoveAllThreadsWereIdleListener(this); + } +private: + nsRefPtr mParent; + virtual ~NuwaFreezeListener() + { + } +}; +#endif // MOZ_NUWA_PROCESS + } // anonymous namespace void @@ -2339,6 +2362,8 @@ ContentParent::ContentParent(ContentParent* aTemplate, priority = PROCESS_PRIORITY_FOREGROUND; } + mSendPermissionUpdates = aTemplate->mSendPermissionUpdates; + InitInternal(priority, false, /* Setup Off-main thread compositing */ false /* Send registered chrome */); @@ -2502,7 +2527,7 @@ ContentParent::IsForApp() #ifdef MOZ_NUWA_PROCESS bool -ContentParent::IsNuwaProcess() +ContentParent::IsNuwaProcess() const { return mIsNuwaProcess; } @@ -2877,6 +2902,19 @@ ContentParent::RecvNuwaReady() #endif } +bool +ContentParent::RecvNuwaWaitForFreeze() +{ +#ifdef MOZ_NUWA_PROCESS + nsRefPtr listener = new NuwaFreezeListener(this); + nsThreadManager::get()->AddAllThreadsWereIdleListener(listener); + return true; +#else // MOZ_NUWA_PROCESS + NS_ERROR("ContentParent::RecvNuwaWaitForFreeze() not implemented!"); + return false; +#endif // MOZ_NUWA_PROCESS +} + bool ContentParent::RecvAddNewProcess(const uint32_t& aPid, InfallibleTArray&& aFds) diff --git a/dom/ipc/ContentParent.h b/dom/ipc/ContentParent.h index 1f04b50f207..bb925615ced 100644 --- a/dom/ipc/ContentParent.h +++ b/dom/ipc/ContentParent.h @@ -233,7 +233,7 @@ public: return mIsForBrowser; } #ifdef MOZ_NUWA_PROCESS - bool IsNuwaProcess(); + bool IsNuwaProcess() const; #endif GeckoChildProcessHost* Process() { @@ -247,7 +247,11 @@ public: } bool NeedsPermissionsUpdate() const { +#ifdef MOZ_NUWA_PROCESS + return !IsNuwaProcess() && mSendPermissionUpdates; +#else return mSendPermissionUpdates; +#endif } bool NeedsDataStoreInfos() const { @@ -779,6 +783,8 @@ private: virtual bool RecvNuwaReady() override; + virtual bool RecvNuwaWaitForFreeze() override; + virtual bool RecvAddNewProcess(const uint32_t& aPid, InfallibleTArray&& aFds) override; diff --git a/dom/ipc/PContent.ipdl b/dom/ipc/PContent.ipdl index c380274e661..82729326978 100644 --- a/dom/ipc/PContent.ipdl +++ b/dom/ipc/PContent.ipdl @@ -632,6 +632,7 @@ child: InvokeDragSession(IPCDataTransfer[] transfers, uint32_t action); EndDragSession(bool aDoneDrag, bool aUserCancelled); + NuwaFreeze(); async DomainSetChanged(uint32_t aSetType, uint32_t aChangeType, OptionalURIParams aDomain); @@ -898,6 +899,9 @@ parent: async SystemMessageHandled(); NuwaReady(); + // Sent when nuwa finished its initialization process and is waiting for + // parent's signal to make it freeze. + NuwaWaitForFreeze(); sync AddNewProcess(uint32_t pid, ProtocolFdMapping[] aFds); diff --git a/dom/ipc/TabChild.cpp b/dom/ipc/TabChild.cpp index 865c740665c..0389bd7d494 100644 --- a/dom/ipc/TabChild.cpp +++ b/dom/ipc/TabChild.cpp @@ -775,6 +775,21 @@ TabChild::PreloadSlowThings() ClearOnShutdown(&sPreallocatedTab); } +/*static*/ void +TabChild::PostForkPreload() +{ + // Preallocated Tab can be null if we are forked directly from b2g. In such + // case we don't need to preload anything, just return. + if (!sPreallocatedTab) { + return; + } + + // Rebuild connections to parent. + sPreallocatedTab->RecvLoadRemoteScript( + NS_LITERAL_STRING("chrome://global/content/post-fork-preload.js"), + true); +} + /*static*/ already_AddRefed TabChild::Create(nsIContentChild* aManager, const TabId& aTabId, diff --git a/dom/ipc/TabChild.h b/dom/ipc/TabChild.h index d3b0f33eab2..ba38d95ddb1 100644 --- a/dom/ipc/TabChild.h +++ b/dom/ipc/TabChild.h @@ -263,6 +263,7 @@ public: * on the critical path. */ static void PreloadSlowThings(); + static void PostForkPreload(); /** Return a TabChild with the given attributes. */ static already_AddRefed diff --git a/dom/ipc/jar.mn b/dom/ipc/jar.mn index b3f1bc88e0e..f71d7ffc8f3 100644 --- a/dom/ipc/jar.mn +++ b/dom/ipc/jar.mn @@ -12,3 +12,4 @@ toolkit.jar: content/global/manifestMessages.js (manifestMessages.js) content/global/PushServiceChildPreload.js (../push/PushServiceChildPreload.js) content/global/preload.js (preload.js) + content/global/post-fork-preload.js (post-fork-preload.js) diff --git a/dom/ipc/post-fork-preload.js b/dom/ipc/post-fork-preload.js new file mode 100644 index 00000000000..f5238beb2cd --- /dev/null +++ b/dom/ipc/post-fork-preload.js @@ -0,0 +1,20 @@ +/* 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/. */ + +// Preload some things, in an attempt to make app startup faster. +// +// This script is run when the preallocated process starts. It is injected as +// a frame script. +// If Nuwa process is enabled, this script will run in preallocated process +// forked by Nuwa. + +(function (global) { + "use strict"; + + Components.utils.import("resource://gre/modules/AppsServiceChild.jsm"); + Components.classes["@mozilla.org/network/protocol-proxy-service;1"]. + getService(Ci["nsIProtocolProxyService"]); + + DOMApplicationRegistry.resetList(); +})(this); diff --git a/dom/ipc/preload.js b/dom/ipc/preload.js index 7e613cffd7f..0c59d94d4e1 100644 --- a/dom/ipc/preload.js +++ b/dom/ipc/preload.js @@ -6,6 +6,7 @@ // // This script is run when the preallocated process starts. It is injected as // a frame script. +// If nuwa is enabled, this script will run in Nuwa process before frozen. const BrowserElementIsPreloaded = true; @@ -58,7 +59,6 @@ const BrowserElementIsPreloaded = true; Cc["@mozilla.org/network/idn-service;1"].getService(Ci["nsIIDNService"]); Cc["@mozilla.org/network/io-service;1"].getService(Ci["nsIIOService2"]); Cc["@mozilla.org/network/mime-hdrparam;1"].getService(Ci["nsIMIMEHeaderParam"]); - Cc["@mozilla.org/network/protocol-proxy-service;1"].getService(Ci["nsIProtocolProxyService"]); Cc["@mozilla.org/network/socket-transport-service;1"].getService(Ci["nsISocketTransportService"]); Cc["@mozilla.org/network/stream-transport-service;1"].getService(Ci["nsIStreamTransportService"]); Cc["@mozilla.org/network/url-parser;1?auth=maybe"].getService(Ci["nsIURLParser"]); diff --git a/dom/wifi/WifiProxyService.cpp b/dom/wifi/WifiProxyService.cpp index 3257abedeea..6efd7df7c08 100644 --- a/dom/wifi/WifiProxyService.cpp +++ b/dom/wifi/WifiProxyService.cpp @@ -67,6 +67,9 @@ public: NS_IMETHOD Run() { MOZ_ASSERT(!NS_IsMainThread()); +#ifdef MOZ_NUWA_PROCESS + NS_SetIgnoreStatusOfCurrentThread(); +#endif nsAutoString event; gWpaSupplicant->WaitForEvent(event, mInterface); if (!event.IsEmpty()) { diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index c3434fc2a30..f4c7783554a 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -85,6 +85,7 @@ #include "nsQueryObject.h" #include "nsSandboxFlags.h" #include "prthread.h" +#include "nsThread.h" #include "xpcpublic.h" #ifdef ANDROID @@ -5106,6 +5107,17 @@ WorkerPrivate::DoRunLoop(JSContext* aCx) { MutexAutoLock lock(mMutex); +#ifdef MOZ_NUWA_PROCESS + { + nsThread *thr = static_cast(NS_GetCurrentThread()); + ReentrantMonitorAutoEnter mon(thr->ThreadStatusMonitor()); + if (mControlQueue.IsEmpty() && + !(normalRunnablesPending = NS_HasPendingEvents(mThread))) { + thr->SetIdle(); + } + } +#endif // MOZ_NUWA_PROCESS + while (mControlQueue.IsEmpty() && !(debuggerRunnablesPending = !mDebuggerQueue.IsEmpty()) && !(normalRunnablesPending = NS_HasPendingEvents(mThread))) { diff --git a/netwerk/base/nsSocketTransportService2.cpp b/netwerk/base/nsSocketTransportService2.cpp index 99663532024..0c4d4b9f685 100644 --- a/netwerk/base/nsSocketTransportService2.cpp +++ b/netwerk/base/nsSocketTransportService2.cpp @@ -753,6 +753,7 @@ nsSocketTransportService::Run() if (IsNuwaProcess()) { NuwaMarkCurrentThread(nullptr, nullptr); } + NS_SetIgnoreStatusOfCurrentThread(); #endif SOCKET_LOG(("STS thread init\n")); diff --git a/widget/gonk/GonkMemoryPressureMonitoring.cpp b/widget/gonk/GonkMemoryPressureMonitoring.cpp index 52aa7db2e1c..374ef85353b 100644 --- a/widget/gonk/GonkMemoryPressureMonitoring.cpp +++ b/widget/gonk/GonkMemoryPressureMonitoring.cpp @@ -127,6 +127,8 @@ public: } #endif + NS_SetIgnoreStatusOfCurrentThread(); + int lowMemFd = open("/sys/kernel/mm/lowmemkiller/notify_trigger_active", O_RDONLY | O_CLOEXEC); NS_ENSURE_STATE(lowMemFd != -1); diff --git a/xpcom/glue/nsThreadUtils.cpp b/xpcom/glue/nsThreadUtils.cpp index 4e33fc4cef3..9346bd1b550 100644 --- a/xpcom/glue/nsThreadUtils.cpp +++ b/xpcom/glue/nsThreadUtils.cpp @@ -375,3 +375,11 @@ nsAutoLowPriorityIO::~nsAutoLowPriorityIO() #endif } +#ifdef MOZ_NUWA_PROCESS +#ifdef MOZILLA_INTERNAL_API +void +NS_SetIgnoreStatusOfCurrentThread() { + nsThreadManager::get()->SetIgnoreThreadStatus(); +} +#endif // MOZILLA_INTERNAL_API +#endif // MOZ_NUWA_PROCESS diff --git a/xpcom/glue/nsThreadUtils.h b/xpcom/glue/nsThreadUtils.h index e143c6cef9b..4b173ed4585 100644 --- a/xpcom/glue/nsThreadUtils.h +++ b/xpcom/glue/nsThreadUtils.h @@ -1019,4 +1019,19 @@ private: void NS_SetMainThread(); +/** + * Helpers for thread to report their status when compiled with Nuwa. + */ +#ifdef MOZILLA_INTERNAL_API +#ifdef MOZ_NUWA_PROCESS +extern void +NS_SetIgnoreStatusOfCurrentThread(); +#else // MOZ_NUWA_PROCESS +inline void +NS_SetIgnoreStatusOfCurrentThread() +{ +} +#endif // MOZ_NUWA_PROCESS +#endif // MOZILLA_INTERNAL_API + #endif // nsThreadUtils_h__ diff --git a/xpcom/threads/TimerThread.cpp b/xpcom/threads/TimerThread.cpp index fbdc810597d..8d9ba434566 100644 --- a/xpcom/threads/TimerThread.cpp +++ b/xpcom/threads/TimerThread.cpp @@ -205,6 +205,7 @@ TimerThread::Run() } #endif + NS_SetIgnoreStatusOfCurrentThread(); MonitorAutoLock lock(mMonitor); // We need to know how many microseconds give a positive PRIntervalTime. This diff --git a/xpcom/threads/nsThread.cpp b/xpcom/threads/nsThread.cpp index e69665685ff..d6b9df70766 100644 --- a/xpcom/threads/nsThread.cpp +++ b/xpcom/threads/nsThread.cpp @@ -15,7 +15,6 @@ #undef LOG #endif -#include "mozilla/ReentrantMonitor.h" #include "nsMemoryPressure.h" #include "nsThreadManager.h" #include "nsIClassInfoImpl.h" @@ -331,6 +330,10 @@ nsThread::ThreadFunc(void* aArg) // Inform the ThreadManager nsThreadManager::get()->RegisterCurrentThread(self); +#ifdef MOZ_NUWA_PROCESS + self->mThreadStatusInfo = + static_cast(nsThreadManager::get()->GetCurrentThreadStatusInfo()); +#endif #if !defined(MOZILLA_XPCOMRT_API) mozilla::IOInterposer::RegisterCurrentThread(); @@ -448,6 +451,10 @@ nsThread::nsThread(MainThreadFlag aMainThread, uint32_t aStackSize) , mShutdownRequired(false) , mEventsAreDoomed(false) , mIsMainThread(aMainThread) +#ifdef MOZ_NUWA_PROCESS + , mThreadStatusMonitor("nsThread.mThreadStatusLock") + , mThreadStatusInfo(nullptr) +#endif { } @@ -495,6 +502,11 @@ nsThread::InitCurrentThread() SetupCurrentThreadForChaosMode(); nsThreadManager::get()->RegisterCurrentThread(this); +#ifdef MOZ_NUWA_PROCESS + mThreadStatusInfo = + static_cast(nsThreadManager::get()->GetCurrentThreadStatusInfo()); +#endif + return NS_OK; } @@ -510,7 +522,15 @@ nsThread::PutEvent(nsIRunnable* aEvent, nsNestedEventTarget* aTarget) NS_WARNING("An event was posted to a thread that will never run it (rejected)"); return NS_ERROR_UNEXPECTED; } - queue->PutEvent(aEvent); +#ifdef MOZ_NUWA_PROCESS + { + ReentrantMonitorAutoEnter mon(mThreadStatusMonitor); + SetWorking(); +#endif // MOZ_NUWA_PROCESS + queue->PutEvent(aEvent); +#ifdef MOZ_NUWA_PROCESS + } +#endif // MOZ_NUWA_PROCESS // Make sure to grab the observer before dropping the lock, otherwise the // event that we just placed into the queue could run and eventually delete @@ -853,6 +873,27 @@ nsThread::ProcessNextEvent(bool aMayWait, bool* aResult) --mNestedEventLoopDepth; +#ifdef MOZ_NUWA_PROCESS + nsCOMPtr notifyAllIdleRunnable; + { + ReentrantMonitorAutoEnter mon(mThreadStatusMonitor); + if ((!mEvents->GetEvent(false, nullptr)) && (mNestedEventLoopDepth == 0)) { + nsThreadManager::get()->SetThreadIsWorking( + static_cast(mThreadStatusInfo), + false, getter_AddRefs(notifyAllIdleRunnable)); + } + } + if (notifyAllIdleRunnable) { + // Dispatching a task leads us to acquire |mLock| of the thread. If we + // dispatch to main thread while holding main thread's + // |mThreadStatusMonitor|, deadlock could happen if other thread is + // blocked by main thread's |mThreadStatusMonitor| and is holding + // main thread's |mLock|. + Dispatch(notifyAllIdleRunnable, NS_DISPATCH_NORMAL); + nsThreadManager::get()->ResetIsDispatchingToMainThread(); + } +#endif // MOZ_NUWA_PROCESS + NOTIFY_EVENT_OBSERVERS(AfterProcessNextEvent, (this, mNestedEventLoopDepth, *aResult)); @@ -1063,6 +1104,24 @@ nsThread::SetMainThreadObserver(nsIThreadObserver* aObserver) return NS_OK; } +#ifdef MOZ_NUWA_PROCESS +void +nsThread::SetWorking() +{ + nsThreadManager::get()->SetThreadIsWorking( + static_cast(mThreadStatusInfo), + true, nullptr); +} + +void +nsThread::SetIdle() +{ + nsThreadManager::get()->SetThreadIsWorking( + static_cast(mThreadStatusInfo), + false, nullptr); +} +#endif + //----------------------------------------------------------------------------- NS_IMETHODIMP diff --git a/xpcom/threads/nsThread.h b/xpcom/threads/nsThread.h index 67e5516a3e8..2f58cb3be60 100644 --- a/xpcom/threads/nsThread.h +++ b/xpcom/threads/nsThread.h @@ -16,6 +16,7 @@ #include "nsTObserverArray.h" #include "mozilla/Attributes.h" #include "nsAutoPtr.h" +#include "mozilla/ReentrantMonitor.h" // A native thread class nsThread @@ -65,6 +66,14 @@ public: static nsresult SetMainThreadObserver(nsIThreadObserver* aObserver); +#ifdef MOZ_NUWA_PROCESS + void SetWorking(); + void SetIdle(); + mozilla::ReentrantMonitor& ThreadStatusMonitor() { + return mThreadStatusMonitor; + } +#endif + protected: static nsIThreadObserver* sMainThreadObserver; @@ -182,6 +191,12 @@ protected: // Set to true when events posted to this thread will never run. bool mEventsAreDoomed; MainThreadFlag mIsMainThread; +#ifdef MOZ_NUWA_PROCESS + mozilla::ReentrantMonitor mThreadStatusMonitor; + // The actual type is defined in nsThreadManager.h which is not exposed to + // file out of thread module. + void* mThreadStatusInfo; +#endif }; //----------------------------------------------------------------------------- diff --git a/xpcom/threads/nsThreadManager.cpp b/xpcom/threads/nsThreadManager.cpp index bf2868a3691..de3a7a4a17d 100644 --- a/xpcom/threads/nsThreadManager.cpp +++ b/xpcom/threads/nsThreadManager.cpp @@ -11,6 +11,7 @@ #include "nsTArray.h" #include "nsAutoPtr.h" #include "mozilla/ThreadLocal.h" +#include "mozilla/ReentrantMonitor.h" #ifdef MOZ_CANARY #include #include @@ -40,6 +41,45 @@ NS_SetMainThread() typedef nsTArray> nsThreadArray; +#ifdef MOZ_NUWA_PROCESS +class NotifyAllThreadsWereIdle: public nsRunnable +{ +public: + + NotifyAllThreadsWereIdle( + nsTArray>* aListeners) + : mListeners(aListeners) + { + } + + virtual NS_IMETHODIMP + Run() { + // Copy listener array, which may be modified during call back. + nsTArray> arr(*mListeners); + for (size_t i = 0; i < arr.Length(); i++) { + arr[i]->OnAllThreadsWereIdle(); + } + return NS_OK; + } + +private: + // Raw pointer, since it's pointing to a member of thread manager. + nsTArray>* mListeners; +}; + +struct nsThreadManager::ThreadStatusInfo { + Atomic mWorking; + Atomic mWillBeWorking; + bool mIgnored; + ThreadStatusInfo() + : mWorking(false) + , mWillBeWorking(false) + , mIgnored(false) + { + } +}; +#endif // MOZ_NUWA_PROCESS + //----------------------------------------------------------------------------- static void @@ -48,6 +88,24 @@ ReleaseObject(void* aData) static_cast(aData)->Release(); } +#ifdef MOZ_NUWA_PROCESS +void +nsThreadManager::DeleteThreadStatusInfo(void* aData) +{ + nsThreadManager* mgr = nsThreadManager::get(); + nsThreadManager::ThreadStatusInfo* thrInfo = + static_cast(aData); + { + ReentrantMonitorAutoEnter mon(*(mgr->mMonitor)); + mgr->mThreadStatusInfos.RemoveElement(thrInfo); + if (NS_IsMainThread()) { + mgr->mMainThreadStatusInfo = nullptr; + } + } + delete thrInfo; +} +#endif + static PLDHashOperator AppendAndRemoveThread(PRThread* aKey, nsRefPtr& aThread, void* aArg) { @@ -89,6 +147,17 @@ nsThreadManager::Init() return NS_ERROR_FAILURE; } +#ifdef MOZ_NUWA_PROCESS + if (PR_NewThreadPrivateIndex( + &mThreadStatusInfoIndex, + nsThreadManager::DeleteThreadStatusInfo) == PR_FAILURE) { + return NS_ERROR_FAILURE; + } +#endif // MOZ_NUWA_PROCESS + +#ifdef MOZ_NUWA_PROCESS + mMonitor = MakeUnique("nsThreadManager.mMonitor"); +#endif // MOZ_NUWA_PROCESS #ifdef MOZ_CANARY const int flags = O_WRONLY | O_APPEND | O_CREAT | O_NONBLOCK; @@ -181,6 +250,9 @@ nsThreadManager::Shutdown() // Remove the TLS entry for the main thread. PR_SetThreadPrivate(mCurThreadIndex, nullptr); +#ifdef MOZ_NUWA_PROCESS + PR_SetThreadPrivate(mThreadStatusInfoIndex, nullptr); +#endif } void @@ -213,6 +285,9 @@ nsThreadManager::UnregisterCurrentThread(nsThread* aThread) PR_SetThreadPrivate(mCurThreadIndex, nullptr); // Ref-count balanced via ReleaseObject +#ifdef MOZ_NUWA_PROCESS + PR_SetThreadPrivate(mThreadStatusInfoIndex, nullptr); +#endif } nsThread* @@ -237,6 +312,27 @@ nsThreadManager::GetCurrentThread() return thread.get(); // reference held in TLS } +#ifdef MOZ_NUWA_PROCESS +nsThreadManager::ThreadStatusInfo* +nsThreadManager::GetCurrentThreadStatusInfo() +{ + void* data = PR_GetThreadPrivate(mThreadStatusInfoIndex); + if (!data) { + ThreadStatusInfo *thrInfo = new ThreadStatusInfo(); + PR_SetThreadPrivate(mThreadStatusInfoIndex, thrInfo); + data = thrInfo; + + ReentrantMonitorAutoEnter mon(*mMonitor); + mThreadStatusInfos.AppendElement(thrInfo); + if (NS_IsMainThread()) { + mMainThreadStatusInfo = thrInfo; + } + } + + return static_cast(data); +} +#endif + NS_IMETHODIMP nsThreadManager::NewThread(uint32_t aCreationFlags, uint32_t aStackSize, @@ -333,3 +429,157 @@ nsThreadManager::GetHighestNumberOfThreads() OffTheBooksMutexAutoLock lock(mLock); return mHighestNumberOfThreads; } + +#ifdef MOZ_NUWA_PROCESS +void +nsThreadManager::SetIgnoreThreadStatus() +{ + GetCurrentThreadStatusInfo()->mIgnored = true; +} + +void +nsThreadManager::SetThreadIdle(nsIRunnable **aReturnRunnable) +{ + SetThreadIsWorking(GetCurrentThreadStatusInfo(), false, aReturnRunnable); +} + +void +nsThreadManager::SetThreadWorking() +{ + SetThreadIsWorking(GetCurrentThreadStatusInfo(), true, nullptr); +} + +void +nsThreadManager::SetThreadIsWorking(ThreadStatusInfo* aInfo, + bool aIsWorking, + nsIRunnable **aReturnRunnable) +{ + aInfo->mWillBeWorking = aIsWorking; + if (mThreadsIdledListeners.Length() > 0) { + + // A race condition occurs since we don't want threads to try to enter the + // monitor (nsThreadManager::mMonitor) when no one cares about their status. + // And thus the race can happen when we put the first listener into + // |mThreadsIdledListeners|: + // + // (1) Thread A wants to dispatch a task to Thread B. + // (2) Thread A checks |mThreadsIdledListeners|, and nothing is in the + // list. So Thread A decides not to enter |mMonitor| when updating B's + // status. + // (3) Thread A is suspended just before it changed status of B. + // (4) A listener is added to |mThreadsIdledListeners| + // (5) Now is Thread C's turn to run. Thread C finds there's something in + // |mThreadsIdledListeners|, so it enters |mMonitor| and check all + // thread info structs in |mThreadStatusInfos| while A is in the middle + // of changing B's status. + // + // Then C may find Thread B is an idle thread (which is not correct, because + // A attempted to change B's status prior to C starting to walk throught + // |mThreadStatusInfo|), but the fact that thread A is working (thread A + // hasn't finished dispatching a task to thread B) can prevent thread C from + // firing a bogus notification. + // + // If the state transition that happens outside the monitor is in the other + // direction, the race condition could be: + // + // (1) Thread D has just finished its jobs and wants to set its status to idle. + // (2) Thread D checks |mThreadsIdledListeners|, and nothing is in the list. + // So Thread D decides not to enter |mMonitor|. + // (3) Thread D is is suspended before it updates its own status. + // (4) A listener is put into |mThreadsIdledListeners|. + // (5) Thread C wants to changes status of itself. It checks + // |mThreadsIdledListeners| and finds something inside the list. Thread C + // then enters |mMonitor|, updates its status and checks thread info in + // |mThreadStatusInfos| while D is changing status of itself out of monitor. + // + // Thread C will find that thread D is working (D actually wants to change its + // status to idle before C starting to check), then C returns without firing + // any notification. Finding that thread D is working can make our checking + // mechanism miss a chance to fire a notification: because thread D thought + // there's nothing in |mThreadsIdledListeners| and thus won't check the + // |mThreadStatusInfos| after changing the status of itself. + // + // |mWillBeWorking| can be used to address this problem. We require each + // thread to put the value that is going to be set to |mWorking| to + // |mWillBeWorking| before the thread decide whether it should enter + // |mMonitor| to change status or not. Thus C finds that D is working while + // D's |mWillBeWorking| is false, and C realizes that D is just updating and + // can treat D as an idle thread. + // + // It doesn't matter whether D will check thread status after changing its + // own status or not. If D checks, which means D will enter the monitor + // before updating status, thus D must be blocked until C has finished + // dispatching the notification task to main thread, and D will find that main + // thread is working and will not fire an additional event. On the other hand, + // if D doesn't check |mThreadStatusInfos|, it's still ok, because C has + // treated D as an idle thread already. + + bool hasWorkingThread = false; + nsRefPtr runnable; + { + ReentrantMonitorAutoEnter mon(*mMonitor); + // Get data structure of thread info. + aInfo->mWorking = aIsWorking; + if (aIsWorking) { + // We are working, so there's no need to check futher. + return; + } + + for (size_t i = 0; i < mThreadStatusInfos.Length(); i++) { + ThreadStatusInfo *info = mThreadStatusInfos[i]; + if (!info->mIgnored) { + if (info->mWorking) { + if (info->mWillBeWorking) { + hasWorkingThread = true; + break; + } + } + } + } + if (!hasWorkingThread && !mDispatchingToMainThread) { + runnable = new NotifyAllThreadsWereIdle(&mThreadsIdledListeners); + mDispatchingToMainThread = true; + } + } + + if (runnable) { + if (NS_IsMainThread()) { + // We are holding the main thread's |nsThread::mThreadStatusMonitor|. + // If we dispatch a task to ourself, then we are in danger of causing + // deadlock. Instead, return the task, and let the caller dispatch it + // for us. + MOZ_ASSERT(aReturnRunnable, + "aReturnRunnable must be provided on main thread"); + runnable.forget(aReturnRunnable); + } else { + NS_DispatchToMainThread(runnable); + ResetIsDispatchingToMainThread(); + } + } + } else { + // Update thread info without holding any lock. + aInfo->mWorking = aIsWorking; + } +} + +void +nsThreadManager::ResetIsDispatchingToMainThread() +{ + ReentrantMonitorAutoEnter mon(*mMonitor); + mDispatchingToMainThread = false; +} + +void +nsThreadManager::AddAllThreadsWereIdleListener(AllThreadsWereIdleListener *listener) +{ + MOZ_ASSERT(GetCurrentThreadStatusInfo()->mWorking); + mThreadsIdledListeners.AppendElement(listener); +} + +void +nsThreadManager::RemoveAllThreadsWereIdleListener(AllThreadsWereIdleListener *listener) +{ + mThreadsIdledListeners.RemoveElement(listener); +} + +#endif // MOZ_NUWA_PROCESS diff --git a/xpcom/threads/nsThreadManager.h b/xpcom/threads/nsThreadManager.h index 4acec42213a..32ffda818c3 100644 --- a/xpcom/threads/nsThreadManager.h +++ b/xpcom/threads/nsThreadManager.h @@ -14,9 +14,26 @@ class nsIRunnable; +namespace mozilla { +class ReentrantMonitor; +} + class nsThreadManager : public nsIThreadManager { public: +#ifdef MOZ_NUWA_PROCESS + struct ThreadStatusInfo; + class AllThreadsWereIdleListener { + public: + NS_INLINE_DECL_REFCOUNTING(AllThreadsWereIdleListener); + virtual void OnAllThreadsWereIdle() = 0; + protected: + virtual ~AllThreadsWereIdleListener() + { + } + }; +#endif // MOZ_NUWA_PROCESS + NS_DECL_ISUPPORTS NS_DECL_NSITHREADMANAGER @@ -54,6 +71,31 @@ public: { } +#ifdef MOZ_NUWA_PROCESS + void SetIgnoreThreadStatus(); + + // |SetThreadWorking| and |SetThreadIdle| set status of thread that is + // currently running. They get thread status information from TLS and pass + // the information to |SetThreadIsWorking|. + void SetThreadIdle(nsIRunnable** aReturnRunnable); + void SetThreadWorking(); + + // |SetThreadIsWorking| is where is status actually changed. Thread status + // information is passed as a argument so caller must obtain the structure + // by itself. If this method is invoked on main thread, |aReturnRunnable| + // should be provided to receive the runnable of notifying listeners. + // |ResetIsDispatchingToMainThread| should be invoked after caller on main + // thread dispatched the task to main thread's queue. + void SetThreadIsWorking(ThreadStatusInfo* aInfo, + bool aIsWorking, + nsIRunnable** aReturnRunnable); + void ResetIsDispatchingToMainThread(); + + void AddAllThreadsWereIdleListener(AllThreadsWereIdleListener *listener); + void RemoveAllThreadsWereIdleListener(AllThreadsWereIdleListener *listener); + ThreadStatusInfo* GetCurrentThreadStatusInfo(); +#endif // MOZ_NUWA_PROCESS + private: nsThreadManager() : mCurThreadIndex(0) @@ -62,6 +104,11 @@ private: , mInitialized(false) , mCurrentNumberOfThreads(1) , mHighestNumberOfThreads(1) +#ifdef MOZ_NUWA_PROCESS + , mMonitor(nullptr) + , mMainThreadStatusInfo(nullptr) + , mDispatchingToMainThread(nullptr) +#endif { } @@ -76,6 +123,19 @@ private: uint32_t mCurrentNumberOfThreads; // The highest number of threads encountered so far during the session uint32_t mHighestNumberOfThreads; + +#ifdef MOZ_NUWA_PROCESS + static void DeleteThreadStatusInfo(void *aData); + unsigned mThreadStatusInfoIndex; + nsTArray> mThreadsIdledListeners; + nsTArray mThreadStatusInfos; + mozilla::UniquePtr mMonitor; + ThreadStatusInfo* mMainThreadStatusInfo; + // |mDispatchingToMainThread| is set when all thread are found to be idle + // before task of notifying all listeners are dispatched to main thread. + // The flag is protected by |mMonitor|. + bool mDispatchingToMainThread; +#endif // MOZ_NUWA_PROCESS }; #define NS_THREADMANAGER_CID \ diff --git a/xpcom/threads/nsThreadPool.cpp b/xpcom/threads/nsThreadPool.cpp index 97fb4a42884..27538fc8e2b 100644 --- a/xpcom/threads/nsThreadPool.cpp +++ b/xpcom/threads/nsThreadPool.cpp @@ -151,7 +151,6 @@ NS_IMETHODIMP nsThreadPool::Run() { LOG(("THRD-P(%p) enter\n", this)); - mThreadNaming.SetThreadPoolName(mName); nsCOMPtr current; @@ -209,6 +208,9 @@ nsThreadPool::Run() } else { PRIntervalTime delta = timeout - (now - idleSince); LOG(("THRD-P(%p) waiting [%d]\n", this, delta)); +#ifdef MOZ_NUWA_PROCESS + nsThreadManager::get()->SetThreadIdle(nullptr); +#endif // MOZ_NUWA_PROCESS mon.Wait(delta); } } else if (wasIdle) { @@ -218,6 +220,9 @@ nsThreadPool::Run() } if (event) { LOG(("THRD-P(%p) running [%p]\n", this, event.get())); +#ifdef MOZ_NUWA_PROCESS + nsThreadManager::get()->SetThreadWorking(); +#endif // MOZ_NUWA_PROCESS event->Run(); } } while (!exitThread); diff --git a/xpcom/threads/nsTimerImpl.cpp b/xpcom/threads/nsTimerImpl.cpp index f10fb4dcb6f..5133e63b275 100644 --- a/xpcom/threads/nsTimerImpl.cpp +++ b/xpcom/threads/nsTimerImpl.cpp @@ -549,6 +549,13 @@ nsTimerImpl::Fire() return; } +#ifdef MOZ_NUWA_PROCESS + if (IsNuwaProcess() && IsNuwaReady()) { + // A timer event fired after Nuwa frozen can freeze main thread. + return; + } +#endif + #if !defined(MOZILLA_XPCOMRT_API) PROFILER_LABEL("Timer", "Fire", js::ProfileEntry::Category::OTHER); From 2fdd046fceba7abb0b76b176a1d2e0e433a4e7ca Mon Sep 17 00:00:00 2001 From: "Carsten \"Tomcat\" Book" Date: Tue, 19 May 2015 11:44:32 +0200 Subject: [PATCH 14/39] Backed out changeset 1b09d2b41795 (bug 1113429) --- dom/workers/WorkerPrivate.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index f4c7783554a..1d46a267a2f 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -85,7 +85,6 @@ #include "nsQueryObject.h" #include "nsSandboxFlags.h" #include "prthread.h" -#include "nsThread.h" #include "xpcpublic.h" #ifdef ANDROID @@ -5107,17 +5106,6 @@ WorkerPrivate::DoRunLoop(JSContext* aCx) { MutexAutoLock lock(mMutex); -#ifdef MOZ_NUWA_PROCESS - { - nsThread *thr = static_cast(NS_GetCurrentThread()); - ReentrantMonitorAutoEnter mon(thr->ThreadStatusMonitor()); - if (mControlQueue.IsEmpty() && - !(normalRunnablesPending = NS_HasPendingEvents(mThread))) { - thr->SetIdle(); - } - } -#endif // MOZ_NUWA_PROCESS - while (mControlQueue.IsEmpty() && !(debuggerRunnablesPending = !mDebuggerQueue.IsEmpty()) && !(normalRunnablesPending = NS_HasPendingEvents(mThread))) { @@ -5654,6 +5642,15 @@ WorkerPrivate::WaitForWorkerEvents(PRIntervalTime aInterval) // The main thread may be waiting so we must notify. mMemoryReportCondVar.Notify(); +#ifdef MOZ_NUWA_PROCESS + { + MOZ_ASSERT(mThread); + + ReentrantMonitorAutoEnter mon(mThread->ThreadStatusMonitor()); + mThread->SetIdle(); + } +#endif // MOZ_NUWA_PROCESS + // Now wait for an actual worker event. mCondVar.Wait(aInterval); From c75514ccc67e55925835c8826282beaac7315499 Mon Sep 17 00:00:00 2001 From: "Carsten \"Tomcat\" Book" Date: Tue, 19 May 2015 11:44:37 +0200 Subject: [PATCH 15/39] Backed out changeset daa19810f688 (bug 1138620) --- xpcom/threads/nsIThreadManager.idl | 9 ++++++++- xpcom/threads/nsThreadManager.cpp | 9 +++++++-- xpcom/threads/nsThreadManager.h | 2 -- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/xpcom/threads/nsIThreadManager.idl b/xpcom/threads/nsIThreadManager.idl index 9b4fc126f9b..1a5d4705839 100644 --- a/xpcom/threads/nsIThreadManager.idl +++ b/xpcom/threads/nsIThreadManager.idl @@ -13,7 +13,7 @@ interface nsIThread; /** * An interface for creating and locating nsIThread instances. */ -[scriptable, uuid(1be89eca-e2f7-453b-8d38-c11ba247f6f3)] +[scriptable, uuid(04092259-4498-4c82-ac52-f9225eb114d0)] interface nsIThreadManager : nsISupports { /** @@ -65,4 +65,11 @@ interface nsIThreadManager : nsISupports * application process. */ readonly attribute boolean isMainThread; + + /** + * Informs the thread manager to not monitor the status of the current thread. + * This method only works on platforms with Nuwa enabled; on other platforms, + * it throws an error. + */ + [noscript] void setIgnoreThreadStatus(); }; diff --git a/xpcom/threads/nsThreadManager.cpp b/xpcom/threads/nsThreadManager.cpp index de3a7a4a17d..72b4aeb2c03 100644 --- a/xpcom/threads/nsThreadManager.cpp +++ b/xpcom/threads/nsThreadManager.cpp @@ -430,13 +430,18 @@ nsThreadManager::GetHighestNumberOfThreads() return mHighestNumberOfThreads; } -#ifdef MOZ_NUWA_PROCESS -void +NS_IMETHODIMP nsThreadManager::SetIgnoreThreadStatus() { +#ifdef MOZ_NUWA_PROCESS GetCurrentThreadStatusInfo()->mIgnored = true; + return NS_OK; +#else + return NS_ERROR_NOT_IMPLEMENTED; +#endif } +#ifdef MOZ_NUWA_PROCESS void nsThreadManager::SetThreadIdle(nsIRunnable **aReturnRunnable) { diff --git a/xpcom/threads/nsThreadManager.h b/xpcom/threads/nsThreadManager.h index 32ffda818c3..34bab9f01f5 100644 --- a/xpcom/threads/nsThreadManager.h +++ b/xpcom/threads/nsThreadManager.h @@ -72,8 +72,6 @@ public: } #ifdef MOZ_NUWA_PROCESS - void SetIgnoreThreadStatus(); - // |SetThreadWorking| and |SetThreadIdle| set status of thread that is // currently running. They get thread status information from TLS and pass // the information to |SetThreadIsWorking|. From 8347026f5d04d1c2105ed702fc2dbda63f3f7961 Mon Sep 17 00:00:00 2001 From: "Carsten \"Tomcat\" Book" Date: Tue, 19 May 2015 11:44:43 +0200 Subject: [PATCH 16/39] Backed out changeset 78b19f9f8da8 (bug 970307) --- dom/indexedDB/ActorsParent.cpp | 77 ++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/dom/indexedDB/ActorsParent.cpp b/dom/indexedDB/ActorsParent.cpp index e7e16b9711c..28b6f5a3dbd 100644 --- a/dom/indexedDB/ActorsParent.cpp +++ b/dom/indexedDB/ActorsParent.cpp @@ -92,6 +92,10 @@ #include "ReportInternalError.h" #include "snappy/snappy.h" +#ifdef MOZ_NUWA_PROCESS +#include "nsThread.h" +#endif + #define DISABLE_ASSERTS_FOR_FUZZING 0 #if DISABLE_ASSERTS_FOR_FUZZING @@ -4798,6 +4802,9 @@ struct ConnectionPool::ThreadInfo { nsCOMPtr mThread; nsRefPtr mRunnable; +#ifdef MOZ_NUWA_PROCESS + bool mNuwaWorking; +#endif ThreadInfo(); @@ -4805,6 +4812,17 @@ struct ConnectionPool::ThreadInfo ThreadInfo(const ThreadInfo& aOther); ~ThreadInfo(); + + void + NuwaSetWorking(bool aWorking) +#ifdef MOZ_NUWA_PROCESS + ; +#else + { + AssertIsOnBackgroundThread(); + MOZ_ASSERT(mThread); + } +#endif }; struct ConnectionPool::DatabaseInfo final @@ -9824,6 +9842,8 @@ ConnectionPool::ShutdownThread(ThreadInfo& aThreadInfo) MOZ_ASSERT(aThreadInfo.mRunnable); MOZ_ASSERT(mTotalThreadCount); + aThreadInfo.NuwaSetWorking(/* aWorking */ false); + nsRefPtr runnable; aThreadInfo.mRunnable.swap(runnable); @@ -9952,6 +9972,8 @@ ConnectionPool::ScheduleTransaction(TransactionInfo* aTransactionInfo, AdjustIdleTimer(); } + + dbInfo->mThreadInfo.NuwaSetWorking(/* aWorking */ true); } MOZ_ASSERT(dbInfo->mThreadInfo.mThread); @@ -10171,6 +10193,8 @@ ConnectionPool::NoteIdleDatabase(DatabaseInfo* aDatabaseInfo) return; } + aDatabaseInfo->mThreadInfo.NuwaSetWorking(/* aWorking */ false); + mIdleDatabases.InsertElementSorted(aDatabaseInfo); AdjustIdleTimer(); @@ -10214,6 +10238,8 @@ ConnectionPool::NoteClosedDatabase(DatabaseInfo* aDatabaseInfo) } else { MOZ_ASSERT(!mIdleThreads.Contains(aDatabaseInfo->mThreadInfo)); + aDatabaseInfo->mThreadInfo.NuwaSetWorking(/* aWorking */ false); + mIdleThreads.InsertElementSorted(aDatabaseInfo->mThreadInfo); aDatabaseInfo->mThreadInfo.mRunnable = nullptr; @@ -10346,6 +10372,8 @@ ConnectionPool::CloseDatabase(DatabaseInfo* aDatabaseInfo) nsCOMPtr runnable = new CloseConnectionRunnable(aDatabaseInfo); + aDatabaseInfo->mThreadInfo.NuwaSetWorking(/* aWorking */ true); + MOZ_ALWAYS_TRUE(NS_SUCCEEDED( aDatabaseInfo->mThreadInfo.mThread->Dispatch(runnable, NS_DISPATCH_NORMAL))); @@ -10694,6 +10722,9 @@ ThreadRunnable::Run() ConnectionPool:: ThreadInfo::ThreadInfo() +#ifdef MOZ_NUWA_PROCESS + : mNuwaWorking(false) +#endif { AssertIsOnBackgroundThread(); @@ -10704,6 +10735,9 @@ ConnectionPool:: ThreadInfo::ThreadInfo(const ThreadInfo& aOther) : mThread(aOther.mThread) , mRunnable(aOther.mRunnable) +#ifdef MOZ_NUWA_PROCESS + , mNuwaWorking(false) +#endif { AssertIsOnBackgroundThread(); MOZ_ASSERT(aOther.mThread); @@ -10717,9 +10751,52 @@ ThreadInfo::~ThreadInfo() { AssertIsOnBackgroundThread(); +#ifdef MOZ_NUWA_PROCESS + MOZ_ASSERT(!mNuwaWorking); +#endif + MOZ_COUNT_DTOR(ConnectionPool::ThreadInfo); } +#ifdef MOZ_NUWA_PROCESS + +void +ConnectionPool:: +ThreadInfo::NuwaSetWorking(bool aWorking) +{ + AssertIsOnBackgroundThread(); + MOZ_ASSERT(mThread); + + if (mNuwaWorking == aWorking) { + return; + } + + nsCOMPtr runnable = NS_NewRunnableFunction( + [aWorking] + { + MOZ_ASSERT(!IsOnBackgroundThread()); + MOZ_ASSERT(!NS_IsMainThread()); + + auto* thread = static_cast(NS_GetCurrentThread()); + MOZ_ASSERT(thread); + + if (aWorking) { + thread->SetWorking(); + } else { + thread->SetIdle(); + } + } + ); + MOZ_ASSERT(runnable); + + MOZ_ALWAYS_TRUE(NS_SUCCEEDED( + mThread->Dispatch(runnable, NS_DISPATCH_NORMAL))); + + mNuwaWorking = aWorking; +} + +#endif // MOZ_NUWA_PROCESS + ConnectionPool:: IdleResource::IdleResource(const TimeStamp& aIdleTime) : mIdleTime(aIdleTime) From 591cf01ac966770f8dcf4eea8cde40c6b6527a8f Mon Sep 17 00:00:00 2001 From: "Carsten \"Tomcat\" Book" Date: Tue, 19 May 2015 11:45:47 +0200 Subject: [PATCH 17/39] Backed out changeset e513640d9995 (bug 1151672) for breaking ics emulator debug tests on a CLOSED TREE --- image/DecodePool.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/image/DecodePool.cpp b/image/DecodePool.cpp index d5ac056556d..5e53350ae31 100644 --- a/image/DecodePool.cpp +++ b/image/DecodePool.cpp @@ -237,6 +237,10 @@ public: return work; } +#ifdef MOZ_NUWA_PROCESS + nsThreadManager::get()->SetThreadIdle(nullptr); +#endif // MOZ_NUWA_PROCESS + // Nothing to do; block until some work is available. mMonitor.Wait(); } while (true); @@ -252,6 +256,10 @@ private: work.mDecoder = aQueue.ElementAt(0); aQueue.RemoveElementAt(0); +#ifdef MOZ_NUWA_PROCESS + nsThreadManager::get()->SetThreadWorking(); +#endif // MOZ_NUWA_PROCESS + return work; } From 3cdeb55edbe41819b335a2d4712936bcf05d1984 Mon Sep 17 00:00:00 2001 From: B2G Bumper Bot Date: Tue, 19 May 2015 02:51:29 -0700 Subject: [PATCH 18/39] Bumping gaia.json for 6 gaia revision(s) a=gaia-bump ======== https://hg.mozilla.org/integration/gaia-central/rev/9985ff19b864 Author: autolander Desc: Bug 1149469 - merge pull request #30059 from dwi2:bug1149469 to mozilla-b2g:master ======== https://hg.mozilla.org/integration/gaia-central/rev/9977770bcd6e Author: Tzu-Lin Huang Desc: Bug 1149469 - Implement card filtering by group ======== https://hg.mozilla.org/integration/gaia-central/rev/e45632c2eaab Author: Sherman Chen Desc: Merge pull request #30118 from shamenchens/Bug1166148-UpdateGaiaNodeModules Bug 1166148 - Bump marionette-js-runner version to 1.0.17, r=evanxd ======== https://hg.mozilla.org/integration/gaia-central/rev/cfd6131ce27c Author: Sherman Chen Desc: Bug 1166148 - Bump marionette-js-runner version to 1.0.17 ======== https://hg.mozilla.org/integration/gaia-central/rev/0c3d64bdf988 Author: EragonJ (E.J.) Desc: Merge pull request #29997 from EragonJ/bug-1159177 Bug 1159177 - [Wifi] disable submit button if no ssid, r=Arthur ======== https://hg.mozilla.org/integration/gaia-central/rev/a4f9e64a7bd6 Author: EragonJ Desc: Bug 1159177 - [Wifi] disable submit button if no ssid, r=Arthur --- b2g/config/gaia.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/b2g/config/gaia.json b/b2g/config/gaia.json index 5fc9de5af2e..129c8450a07 100644 --- a/b2g/config/gaia.json +++ b/b2g/config/gaia.json @@ -1,9 +1,9 @@ { "git": { - "git_revision": "117e5c4e22f51c756ae6198dea0d6123a4396cc8", + "git_revision": "6fbb088da67e3efce11ab4d362e9bc972babe97e", "remote": "https://git.mozilla.org/releases/gaia.git", "branch": "" }, - "revision": "0b103015272b6bdddd46522ca38e87c1d0303d76", + "revision": "9985ff19b86496b1c6aa00ac08af21c5c52c6149", "repo_path": "integration/gaia-central" } From efd925b1113ca1d49759f8135572526beecfd51f Mon Sep 17 00:00:00 2001 From: B2G Bumper Bot Date: Tue, 19 May 2015 02:53:24 -0700 Subject: [PATCH 19/39] Bumping manifests a=b2g-bump --- b2g/config/aries/sources.xml | 2 +- b2g/config/dolphin/sources.xml | 2 +- b2g/config/emulator-ics/sources.xml | 2 +- b2g/config/emulator-jb/sources.xml | 2 +- b2g/config/emulator-kk/sources.xml | 2 +- b2g/config/emulator-l/sources.xml | 2 +- b2g/config/emulator/sources.xml | 2 +- b2g/config/flame-kk/sources.xml | 2 +- b2g/config/nexus-4/sources.xml | 2 +- b2g/config/nexus-5-l/sources.xml | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/b2g/config/aries/sources.xml b/b2g/config/aries/sources.xml index 8d01f87705f..37c74394ff7 100644 --- a/b2g/config/aries/sources.xml +++ b/b2g/config/aries/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/dolphin/sources.xml b/b2g/config/dolphin/sources.xml index 6e7e77b8493..c04c56b97ee 100644 --- a/b2g/config/dolphin/sources.xml +++ b/b2g/config/dolphin/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/emulator-ics/sources.xml b/b2g/config/emulator-ics/sources.xml index df5a57d6d20..a99065c2460 100644 --- a/b2g/config/emulator-ics/sources.xml +++ b/b2g/config/emulator-ics/sources.xml @@ -19,7 +19,7 @@ - + diff --git a/b2g/config/emulator-jb/sources.xml b/b2g/config/emulator-jb/sources.xml index e579400587f..628fde04dbe 100644 --- a/b2g/config/emulator-jb/sources.xml +++ b/b2g/config/emulator-jb/sources.xml @@ -17,7 +17,7 @@ - + diff --git a/b2g/config/emulator-kk/sources.xml b/b2g/config/emulator-kk/sources.xml index 15f71626da3..3346a96467a 100644 --- a/b2g/config/emulator-kk/sources.xml +++ b/b2g/config/emulator-kk/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/emulator-l/sources.xml b/b2g/config/emulator-l/sources.xml index 57c4dbe5a1a..a72b0235d3b 100644 --- a/b2g/config/emulator-l/sources.xml +++ b/b2g/config/emulator-l/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/emulator/sources.xml b/b2g/config/emulator/sources.xml index df5a57d6d20..a99065c2460 100644 --- a/b2g/config/emulator/sources.xml +++ b/b2g/config/emulator/sources.xml @@ -19,7 +19,7 @@ - + diff --git a/b2g/config/flame-kk/sources.xml b/b2g/config/flame-kk/sources.xml index a7b41b010d5..4de4a3e2999 100644 --- a/b2g/config/flame-kk/sources.xml +++ b/b2g/config/flame-kk/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/nexus-4/sources.xml b/b2g/config/nexus-4/sources.xml index 81131e77cc8..6b1f40353cd 100644 --- a/b2g/config/nexus-4/sources.xml +++ b/b2g/config/nexus-4/sources.xml @@ -17,7 +17,7 @@ - + diff --git a/b2g/config/nexus-5-l/sources.xml b/b2g/config/nexus-5-l/sources.xml index 4d498436c78..68e80304e97 100644 --- a/b2g/config/nexus-5-l/sources.xml +++ b/b2g/config/nexus-5-l/sources.xml @@ -15,7 +15,7 @@ - + From 99b6b7775335f919930501ba1fefec807a7ef45d Mon Sep 17 00:00:00 2001 From: B2G Bumper Bot Date: Tue, 19 May 2015 03:25:27 -0700 Subject: [PATCH 20/39] Bumping gaia.json for 2 gaia revision(s) a=gaia-bump ======== https://hg.mozilla.org/integration/gaia-central/rev/e09b00b0e18b Author: John Hu Desc: Merge pull request #30116 from huchengtw-moz/bug-1164353-browser-context-menu-smart-modal-dialog Bug 1164353 - migrate browser context menu to use smart-modal-dialog, r=rexboy, r=sungchiu ======== https://hg.mozilla.org/integration/gaia-central/rev/16e03106e123 Author: John Hu Desc: Bug 1164353 - migrate browser context menu to use smart-modal-dialog --- b2g/config/gaia.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/b2g/config/gaia.json b/b2g/config/gaia.json index 129c8450a07..7629ca1037b 100644 --- a/b2g/config/gaia.json +++ b/b2g/config/gaia.json @@ -1,9 +1,9 @@ { "git": { - "git_revision": "6fbb088da67e3efce11ab4d362e9bc972babe97e", + "git_revision": "14968bb2c34ca406a696d8281aa0b76cf87dbbff", "remote": "https://git.mozilla.org/releases/gaia.git", "branch": "" }, - "revision": "9985ff19b86496b1c6aa00ac08af21c5c52c6149", + "revision": "e09b00b0e18bcbe2a3648393e3271218859c1a7b", "repo_path": "integration/gaia-central" } From ca0acbed52aedebd99e1238494fbd9ca554a5109 Mon Sep 17 00:00:00 2001 From: B2G Bumper Bot Date: Tue, 19 May 2015 03:27:22 -0700 Subject: [PATCH 21/39] Bumping manifests a=b2g-bump --- b2g/config/aries/sources.xml | 2 +- b2g/config/dolphin/sources.xml | 2 +- b2g/config/emulator-ics/sources.xml | 2 +- b2g/config/emulator-jb/sources.xml | 2 +- b2g/config/emulator-kk/sources.xml | 2 +- b2g/config/emulator-l/sources.xml | 2 +- b2g/config/emulator/sources.xml | 2 +- b2g/config/flame-kk/sources.xml | 2 +- b2g/config/nexus-4/sources.xml | 2 +- b2g/config/nexus-5-l/sources.xml | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/b2g/config/aries/sources.xml b/b2g/config/aries/sources.xml index 37c74394ff7..ec8ed9cfae1 100644 --- a/b2g/config/aries/sources.xml +++ b/b2g/config/aries/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/dolphin/sources.xml b/b2g/config/dolphin/sources.xml index c04c56b97ee..0e809b832af 100644 --- a/b2g/config/dolphin/sources.xml +++ b/b2g/config/dolphin/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/emulator-ics/sources.xml b/b2g/config/emulator-ics/sources.xml index a99065c2460..0bc4dd2faff 100644 --- a/b2g/config/emulator-ics/sources.xml +++ b/b2g/config/emulator-ics/sources.xml @@ -19,7 +19,7 @@ - + diff --git a/b2g/config/emulator-jb/sources.xml b/b2g/config/emulator-jb/sources.xml index 628fde04dbe..538810099cc 100644 --- a/b2g/config/emulator-jb/sources.xml +++ b/b2g/config/emulator-jb/sources.xml @@ -17,7 +17,7 @@ - + diff --git a/b2g/config/emulator-kk/sources.xml b/b2g/config/emulator-kk/sources.xml index 3346a96467a..e79266f9107 100644 --- a/b2g/config/emulator-kk/sources.xml +++ b/b2g/config/emulator-kk/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/emulator-l/sources.xml b/b2g/config/emulator-l/sources.xml index a72b0235d3b..dc5bc0240d9 100644 --- a/b2g/config/emulator-l/sources.xml +++ b/b2g/config/emulator-l/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/emulator/sources.xml b/b2g/config/emulator/sources.xml index a99065c2460..0bc4dd2faff 100644 --- a/b2g/config/emulator/sources.xml +++ b/b2g/config/emulator/sources.xml @@ -19,7 +19,7 @@ - + diff --git a/b2g/config/flame-kk/sources.xml b/b2g/config/flame-kk/sources.xml index 4de4a3e2999..cc4fa111943 100644 --- a/b2g/config/flame-kk/sources.xml +++ b/b2g/config/flame-kk/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/nexus-4/sources.xml b/b2g/config/nexus-4/sources.xml index 6b1f40353cd..41faee2e750 100644 --- a/b2g/config/nexus-4/sources.xml +++ b/b2g/config/nexus-4/sources.xml @@ -17,7 +17,7 @@ - + diff --git a/b2g/config/nexus-5-l/sources.xml b/b2g/config/nexus-5-l/sources.xml index 68e80304e97..a5340bf8e67 100644 --- a/b2g/config/nexus-5-l/sources.xml +++ b/b2g/config/nexus-5-l/sources.xml @@ -15,7 +15,7 @@ - + From 3fa2e451657adb90933a40619caaa3a219eefe59 Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Tue, 19 May 2015 12:28:38 +0200 Subject: [PATCH 22/39] Bug 1164498: Cleanup Bluetooth utility functions for dispatching replies, r=btian This patch adds support for |DispatchReplySuccess| and |DispatchReplyError| to Bluetooth v1. --- dom/bluetooth/BluetoothUtils.cpp | 43 ++++++++++++++++---------------- dom/bluetooth/BluetoothUtils.h | 11 +++----- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/dom/bluetooth/BluetoothUtils.cpp b/dom/bluetooth/BluetoothUtils.cpp index b52356e5ec5..3298a0db811 100644 --- a/dom/bluetooth/BluetoothUtils.cpp +++ b/dom/bluetooth/BluetoothUtils.cpp @@ -270,7 +270,6 @@ BroadcastSystemMessage(const nsAString& aType, return true; } -#ifdef MOZ_B2G_BT_API_V2 void DispatchReplySuccess(BluetoothReplyRunnable* aRunnable) { @@ -297,8 +296,14 @@ DispatchReplyError(BluetoothReplyRunnable* aRunnable, MOZ_ASSERT(aRunnable); MOZ_ASSERT(!aErrorStr.IsEmpty()); + // Reply will be deleted by the runnable after running on main thread +#if MOZ_B2G_BT_API_V2 BluetoothReply* reply = new BluetoothReply(BluetoothReplyError(STATUS_FAIL, nsString(aErrorStr))); +#else + BluetoothReply* reply = + new BluetoothReply(BluetoothReplyError(nsString(aErrorStr))); +#endif aRunnable->SetReply(reply); // runnable will delete reply after Run() NS_WARN_IF(NS_FAILED(NS_DispatchToMainThread(aRunnable))); @@ -311,30 +316,23 @@ DispatchReplyError(BluetoothReplyRunnable* aRunnable, MOZ_ASSERT(aRunnable); MOZ_ASSERT(aStatus != STATUS_SUCCESS); + // Reply will be deleted by the runnable after running on main thread +#if MOZ_B2G_BT_API_V2 BluetoothReply* reply = new BluetoothReply(BluetoothReplyError(aStatus, EmptyString())); +#else + BluetoothReply* reply = + new BluetoothReply( + BluetoothReplyError(NS_LITERAL_STRING("Internal error"))); +#endif aRunnable->SetReply(reply); // runnable will delete reply after Run() NS_WARN_IF(NS_FAILED(NS_DispatchToMainThread(aRunnable))); } -void -DispatchStatusChangedEvent(const nsAString& aType, - const nsAString& aAddress, - bool aStatus) -{ - MOZ_ASSERT(NS_IsMainThread()); - - InfallibleTArray data; - BT_APPEND_NAMED_VALUE(data, "address", nsString(aAddress)); - BT_APPEND_NAMED_VALUE(data, "status", aStatus); - - BluetoothService* bs = BluetoothService::Get(); - NS_ENSURE_TRUE_VOID(bs); - bs->DistributeSignal(aType, NS_LITERAL_STRING(KEY_ADAPTER), data); -} -#else +#if MOZ_B2G_BT_API_V2 // TODO: remove with bluetooth1 +#else void DispatchBluetoothReply(BluetoothReplyRunnable* aRunnable, const BluetoothValue& aValue, @@ -355,8 +353,8 @@ DispatchBluetoothReply(BluetoothReplyRunnable* aRunnable, BT_WARNING("Failed to dispatch to main thread!"); } } +#endif -// TODO: remove with bluetooth1 void DispatchStatusChangedEvent(const nsAString& aType, const nsAString& aAddress, @@ -368,13 +366,16 @@ DispatchStatusChangedEvent(const nsAString& aType, BT_APPEND_NAMED_VALUE(data, "address", nsString(aAddress)); BT_APPEND_NAMED_VALUE(data, "status", aStatus); - BluetoothSignal signal(nsString(aType), NS_LITERAL_STRING(KEY_ADAPTER), data); - BluetoothService* bs = BluetoothService::Get(); NS_ENSURE_TRUE_VOID(bs); + +#ifdef MOZ_B2G_BT_API_V2 + bs->DistributeSignal(aType, NS_LITERAL_STRING(KEY_ADAPTER), data); +#else + BluetoothSignal signal(nsString(aType), NS_LITERAL_STRING(KEY_ADAPTER), data); bs->DistributeSignal(signal); -} #endif +} bool IsMainProcess() diff --git a/dom/bluetooth/BluetoothUtils.h b/dom/bluetooth/BluetoothUtils.h index 1b231376d49..6c528c6801d 100644 --- a/dom/bluetooth/BluetoothUtils.h +++ b/dom/bluetooth/BluetoothUtils.h @@ -127,7 +127,6 @@ BroadcastSystemMessage(const nsAString& aType, // Dispatch bluetooth reply to main thread // -#ifdef MOZ_B2G_BT_API_V2 /** * Dispatch successful bluetooth reply with NO value to reply request. * @@ -177,18 +176,14 @@ DispatchReplyError(BluetoothReplyRunnable* aRunnable, void DispatchReplyError(BluetoothReplyRunnable* aRunnable, const enum BluetoothStatus aStatus); -#else + +#if MOZ_B2G_BT_API_V2 // TODO: remove with bluetooth1 +#else void DispatchBluetoothReply(BluetoothReplyRunnable* aRunnable, const BluetoothValue& aValue, const nsAString& aErrorStr); - -// TODO: remove with bluetooth1 -void -DispatchStatusChangedEvent(const nsAString& aType, - const nsAString& aDeviceAddress, - bool aStatus); #endif void From d24e02cf389d36f1e1323c65d9c11e58accc94ee Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Tue, 19 May 2015 12:28:38 +0200 Subject: [PATCH 23/39] Bug 1164498: Remove |DispatchBluetoothReply| from |BluetoothServiceBluedroid|, r=btian This patch replaces |DispatchBluetoothReply| in |BluetoothServiceBluedroid| by corresponding calls to |DispatchReplySuccess| or |DispatchReplyError|. --- .../bluedroid/BluetoothServiceBluedroid.cpp | 153 +++--------------- 1 file changed, 22 insertions(+), 131 deletions(-) diff --git a/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp b/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp index c3f2eb41e3c..cd1f74b2ba9 100644 --- a/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp +++ b/dom/bluetooth/bluedroid/BluetoothServiceBluedroid.cpp @@ -45,8 +45,6 @@ #include "nsDataHashtable.h" #endif -#ifdef MOZ_B2G_BT_API_V2 - #define ENSURE_BLUETOOTH_IS_READY(runnable, result) \ do { \ if (!sBtInterface || !IsEnabled()) { \ @@ -65,6 +63,8 @@ } \ } while(0) +#ifdef MOZ_B2G_BT_API_V2 + #define ENSURE_GATT_MGR_IS_READY_VOID(gatt, runnable) \ do { \ if (!gatt) { \ @@ -594,24 +594,6 @@ BluetoothServiceBluedroid::GattClientWriteDescriptorValueInternal( } #else -#define ENSURE_BLUETOOTH_IS_READY(runnable, result) \ - do { \ - if (!sBtInterface || !IsEnabled()) { \ - NS_NAMED_LITERAL_STRING(errorStr, "Bluetooth is not ready"); \ - DispatchBluetoothReply(runnable, BluetoothValue(), errorStr); \ - return result; \ - } \ - } while(0) - -#define ENSURE_BLUETOOTH_IS_READY_VOID(runnable) \ - do { \ - if (!sBtInterface || !IsEnabled()) { \ - NS_NAMED_LITERAL_STRING(errorStr, "Bluetooth is not ready"); \ - DispatchBluetoothReply(runnable, BluetoothValue(), errorStr); \ - return; \ - } \ - } while(0) - // Audio: Major service class = 0x100 (Bit 21 is set) #define SET_AUDIO_BIT(cod) (cod |= 0x200000) // Rendering: Major service class = 0x20 (Bit 18 is set) @@ -936,8 +918,7 @@ ReplyStatusError(BluetoothReplyRunnable* aBluetoothReplyRunnable, replyError.AppendLiteral(":BT_STATUS_FAIL"); } - DispatchBluetoothReply(aBluetoothReplyRunnable, BluetoothValue(true), - replyError); + DispatchReplyError(aBluetoothReplyRunnable, replyError); } /** @@ -1057,7 +1038,7 @@ BluetoothServiceBluedroid::GetDefaultAdapterPathInternal( BT_APPEND_NAMED_VALUE(v.get_ArrayOfBluetoothNamedValue(), "Devices", sAdapterBondedAddressArray); - DispatchBluetoothReply(aRunnable, v, EmptyString()); + DispatchReplySuccess(aRunnable, v); return NS_OK; } @@ -1098,8 +1079,7 @@ public: /* dispatch result after final pending operation */ if (--sRequestedDeviceCountArray[0] == 0) { if (!sGetDeviceRunnableArray.IsEmpty()) { - DispatchBluetoothReply(sGetDeviceRunnableArray[0], - sRemoteDevicesPack, EmptyString()); + DispatchReplySuccess(sGetDeviceRunnableArray[0], sRemoteDevicesPack); sGetDeviceRunnableArray.RemoveElementAt(0); } @@ -1147,8 +1127,7 @@ BluetoothServiceBluedroid::GetConnectedDevicePropertiesInternal( BluetoothUuidHelper::GetBluetoothProfileManager(aServiceUuid); if (!profile) { InfallibleTArray emptyArr; - DispatchBluetoothReply(aRunnable, emptyArr, - NS_LITERAL_STRING(ERR_UNKNOWN_PROFILE)); + DispatchReplyError(aRunnable, NS_LITERAL_STRING(ERR_UNKNOWN_PROFILE)); return NS_OK; } @@ -1162,7 +1141,7 @@ BluetoothServiceBluedroid::GetConnectedDevicePropertiesInternal( int requestedDeviceCount = deviceAddresses.Length(); if (requestedDeviceCount == 0) { InfallibleTArray emptyArr; - DispatchBluetoothReply(aRunnable, emptyArr, EmptyString()); + DispatchReplySuccess(aRunnable, emptyArr); return NS_OK; } #endif @@ -1196,8 +1175,7 @@ BluetoothServiceBluedroid::GetPairedDevicePropertiesInternal( #else int requestedDeviceCount = aDeviceAddress.Length(); if (requestedDeviceCount == 0) { - InfallibleTArray emptyArr; - DispatchBluetoothReply(aRunnable, BluetoothValue(emptyArr), EmptyString()); + DispatchReplySuccess(aRunnable, InfallibleTArray()); return NS_OK; } @@ -1233,7 +1211,7 @@ public: void StartDiscovery() override { MOZ_ASSERT(NS_IsMainThread()); - DispatchBluetoothReply(mRunnable, true, EmptyString()); + DispatchReplySuccess(mRunnable); } void OnError(BluetoothStatus aStatus) override @@ -1282,7 +1260,7 @@ public: void CancelDiscovery() override { MOZ_ASSERT(NS_IsMainThread()); - DispatchBluetoothReply(mRunnable, true, EmptyString()); + DispatchReplySuccess(mRunnable); } void OnError(BluetoothStatus aStatus) override @@ -1552,7 +1530,7 @@ public: void PinReply() override { - DispatchBluetoothReply(mRunnable, BluetoothValue(true), EmptyString()); + DispatchReplySuccess(mRunnable); } void OnError(BluetoothStatus aStatus) override @@ -1652,7 +1630,7 @@ public: void SspReply() override { - DispatchBluetoothReply(mRunnable, BluetoothValue(true), EmptyString()); + DispatchReplySuccess(mRunnable); } void OnError(BluetoothStatus aStatus) override @@ -1785,10 +1763,10 @@ BluetoothServiceBluedroid::IsConnected(const uint16_t aServiceUuid, BluetoothProfileManagerBase* profile = BluetoothUuidHelper::GetBluetoothProfileManager(aServiceUuid); if (profile) { - DispatchBluetoothReply(aRunnable, profile->IsConnected(), EmptyString()); + DispatchReplySuccess(aRunnable, profile->IsConnected()); } else { BT_WARNING("Can't find profile manager with uuid: %x", aServiceUuid); - DispatchBluetoothReply(aRunnable, false, EmptyString()); + DispatchReplySuccess(aRunnable, false); } } #endif @@ -1806,7 +1784,6 @@ BluetoothServiceBluedroid::SendFile(const nsAString& aDeviceAddress, // has been determined when calling 'Connect()'. Nevertheless, keep // it for future use. -#ifdef MOZ_B2G_BT_API_V2 BluetoothOppManager* opp = BluetoothOppManager::Get(); if (!opp || !opp->SendFile(aDeviceAddress, aBlobParent)) { DispatchReplyError(aRunnable, NS_LITERAL_STRING("SendFile failed")); @@ -1814,15 +1791,6 @@ BluetoothServiceBluedroid::SendFile(const nsAString& aDeviceAddress, } DispatchReplySuccess(aRunnable); -#else - BluetoothOppManager* opp = BluetoothOppManager::Get(); - nsAutoString errorStr; - if (!opp || !opp->SendFile(aDeviceAddress, aBlobParent)) { - errorStr.AssignLiteral("Calling SendFile() failed"); - } - - DispatchBluetoothReply(aRunnable, BluetoothValue(true), errorStr); -#endif } void @@ -1837,7 +1805,6 @@ BluetoothServiceBluedroid::SendFile(const nsAString& aDeviceAddress, // has been determined when calling 'Connect()'. Nevertheless, keep // it for future use. -#ifdef MOZ_B2G_BT_API_V2 BluetoothOppManager* opp = BluetoothOppManager::Get(); if (!opp || !opp->SendFile(aDeviceAddress, aBlob)) { DispatchReplyError(aRunnable, NS_LITERAL_STRING("SendFile failed")); @@ -1845,15 +1812,6 @@ BluetoothServiceBluedroid::SendFile(const nsAString& aDeviceAddress, } DispatchReplySuccess(aRunnable); -#else - BluetoothOppManager* opp = BluetoothOppManager::Get(); - nsAutoString errorStr; - if (!opp || !opp->SendFile(aDeviceAddress, aBlob)) { - errorStr.AssignLiteral("Calling SendFile() failed"); - } - - DispatchBluetoothReply(aRunnable, BluetoothValue(true), errorStr); -#endif } void @@ -1867,7 +1825,6 @@ BluetoothServiceBluedroid::StopSendingFile(const nsAString& aDeviceAddress, // has been determined when calling 'Connect()'. Nevertheless, keep // it for future use. -#ifdef MOZ_B2G_BT_API_V2 BluetoothOppManager* opp = BluetoothOppManager::Get(); nsAutoString errorStr; if (!opp || !opp->StopSendingFile()) { @@ -1876,15 +1833,6 @@ BluetoothServiceBluedroid::StopSendingFile(const nsAString& aDeviceAddress, } DispatchReplySuccess(aRunnable); -#else - BluetoothOppManager* opp = BluetoothOppManager::Get(); - nsAutoString errorStr; - if (!opp || !opp->StopSendingFile()) { - errorStr.AssignLiteral("Calling StopSendingFile() failed"); - } - - DispatchBluetoothReply(aRunnable, BluetoothValue(true), errorStr); -#endif } void @@ -1899,7 +1847,6 @@ BluetoothServiceBluedroid::ConfirmReceivingFile( // has been determined when calling 'Connect()'. Nevertheless, keep // it for future use. -#ifdef MOZ_B2G_BT_API_V2 BluetoothOppManager* opp = BluetoothOppManager::Get(); nsAutoString errorStr; if (!opp || !opp->ConfirmReceivingFile(aConfirm)) { @@ -1909,15 +1856,6 @@ BluetoothServiceBluedroid::ConfirmReceivingFile( } DispatchReplySuccess(aRunnable); -#else - BluetoothOppManager* opp = BluetoothOppManager::Get(); - nsAutoString errorStr; - if (!opp || !opp->ConfirmReceivingFile(aConfirm)) { - errorStr.AssignLiteral("Calling ConfirmReceivingFile() failed"); - } - - DispatchBluetoothReply(aRunnable, BluetoothValue(true), errorStr); -#endif } void @@ -1925,7 +1863,6 @@ BluetoothServiceBluedroid::ConnectSco(BluetoothReplyRunnable* aRunnable) { MOZ_ASSERT(NS_IsMainThread()); -#ifdef MOZ_B2G_BT_API_V2 BluetoothHfpManager* hfp = BluetoothHfpManager::Get(); if (!hfp || !hfp->ConnectSco()) { DispatchReplyError(aRunnable, NS_LITERAL_STRING("ConnectSco failed")); @@ -1933,16 +1870,6 @@ BluetoothServiceBluedroid::ConnectSco(BluetoothReplyRunnable* aRunnable) } DispatchReplySuccess(aRunnable); -#else - BluetoothHfpManager* hfp = BluetoothHfpManager::Get(); - if (!hfp || !hfp->ConnectSco()) { - NS_NAMED_LITERAL_STRING(replyError, "Calling ConnectSco() failed"); - DispatchBluetoothReply(aRunnable, BluetoothValue(), replyError); - return; - } - - DispatchBluetoothReply(aRunnable, BluetoothValue(true), EmptyString()); -#endif } void @@ -1950,7 +1877,6 @@ BluetoothServiceBluedroid::DisconnectSco(BluetoothReplyRunnable* aRunnable) { MOZ_ASSERT(NS_IsMainThread()); -#ifdef MOZ_B2G_BT_API_V2 BluetoothHfpManager* hfp = BluetoothHfpManager::Get(); if (!hfp || !hfp->DisconnectSco()) { DispatchReplyError(aRunnable, NS_LITERAL_STRING("DisconnectSco failed")); @@ -1958,16 +1884,6 @@ BluetoothServiceBluedroid::DisconnectSco(BluetoothReplyRunnable* aRunnable) } DispatchReplySuccess(aRunnable); -#else - BluetoothHfpManager* hfp = BluetoothHfpManager::Get(); - if (!hfp || !hfp->DisconnectSco()) { - NS_NAMED_LITERAL_STRING(replyError, "Calling DisconnectSco() failed"); - DispatchBluetoothReply(aRunnable, BluetoothValue(), replyError); - return; - } - - DispatchBluetoothReply(aRunnable, BluetoothValue(true), EmptyString()); -#endif } void @@ -1975,7 +1891,6 @@ BluetoothServiceBluedroid::IsScoConnected(BluetoothReplyRunnable* aRunnable) { MOZ_ASSERT(NS_IsMainThread()); -#ifdef MOZ_B2G_BT_API_V2 BluetoothHfpManager* hfp = BluetoothHfpManager::Get(); if (!hfp) { DispatchReplyError(aRunnable, NS_LITERAL_STRING("IsScoConnected failed")); @@ -1983,16 +1898,6 @@ BluetoothServiceBluedroid::IsScoConnected(BluetoothReplyRunnable* aRunnable) } DispatchReplySuccess(aRunnable, BluetoothValue(hfp->IsScoConnected())); -#else - BluetoothHfpManager* hfp = BluetoothHfpManager::Get(); - if (!hfp) { - NS_NAMED_LITERAL_STRING(replyError, "Fail to get BluetoothHfpManager"); - DispatchBluetoothReply(aRunnable, BluetoothValue(), replyError); - return; - } - - DispatchBluetoothReply(aRunnable, hfp->IsScoConnected(), EmptyString()); -#endif } void @@ -2009,11 +1914,7 @@ BluetoothServiceBluedroid::SendMetaData(const nsAString& aTitle, a2dp->UpdateMetaData(aTitle, aArtist, aAlbum, aMediaNumber, aTotalMediaCount, aDuration); } -#ifdef MOZ_B2G_BT_API_V2 DispatchReplySuccess(aRunnable); -#else - DispatchBluetoothReply(aRunnable, BluetoothValue(true), EmptyString()); -#endif } void @@ -2028,11 +1929,7 @@ BluetoothServiceBluedroid::SendPlayStatus( PlayStatusStringToControlPlayStatus(aPlayStatus); a2dp->UpdatePlayStatus(aDuration, aPosition, playStatus); } -#ifdef MOZ_B2G_BT_API_V2 DispatchReplySuccess(aRunnable); -#else - DispatchBluetoothReply(aRunnable, BluetoothValue(true), EmptyString()); -#endif } void @@ -2491,8 +2388,7 @@ BluetoothServiceBluedroid::AdapterPropertiesNotification( // Send reply for SetProperty if (!sSetPropertyRunnableArray.IsEmpty()) { - DispatchBluetoothReply(sSetPropertyRunnableArray[0], - BluetoothValue(true), EmptyString()); + DispatchReplySuccess(sSetPropertyRunnableArray[0]); sSetPropertyRunnableArray.RemoveElementAt(0); } #endif @@ -2699,8 +2595,7 @@ BluetoothServiceBluedroid::RemoteDevicePropertiesNotification( if (--sRequestedDeviceCountArray[0] == 0) { if (!sGetDeviceRunnableArray.IsEmpty()) { - DispatchBluetoothReply(sGetDeviceRunnableArray[0], - sRemoteDevicesPack, EmptyString()); + DispatchReplySuccess(sGetDeviceRunnableArray[0], sRemoteDevicesPack); sGetDeviceRunnableArray.RemoveElementAt(0); } @@ -3066,13 +2961,11 @@ BluetoothServiceBluedroid::BondStateChangedNotification( BluetoothValue(propertiesChangeArray))); if (bonded && !sBondingRunnableArray.IsEmpty()) { - DispatchBluetoothReply(sBondingRunnableArray[0], - BluetoothValue(true), EmptyString()); + DispatchReplySuccess(sBondingRunnableArray[0]); sBondingRunnableArray.RemoveElementAt(0); } else if (!bonded && !sUnbondingRunnableArray.IsEmpty()) { - DispatchBluetoothReply(sUnbondingRunnableArray[0], - BluetoothValue(true), EmptyString()); + DispatchReplySuccess(sUnbondingRunnableArray[0]); sUnbondingRunnableArray.RemoveElementAt(0); } @@ -3098,9 +2991,8 @@ BluetoothServiceBluedroid::BondStateChangedNotification( BluetoothValue(propertiesArray))); if (!sBondingRunnableArray.IsEmpty()) { - DispatchBluetoothReply(sBondingRunnableArray[0], - BluetoothValue(true), - NS_LITERAL_STRING("Authentication failure")); + DispatchReplyError(sBondingRunnableArray[0], + NS_LITERAL_STRING("Authentication failure")); sBondingRunnableArray.RemoveElementAt(0); } break; @@ -3109,9 +3001,8 @@ BluetoothServiceBluedroid::BondStateChangedNotification( BT_WARNING("Got an unhandled status of BondStateChangedCallback!"); // Dispatch a reply to unblock the waiting status of pairing. if (!sBondingRunnableArray.IsEmpty()) { - DispatchBluetoothReply(sBondingRunnableArray[0], - BluetoothValue(true), - NS_LITERAL_STRING("Internal failure")); + DispatchReplyError(sBondingRunnableArray[0], + NS_LITERAL_STRING("Internal failure")); sBondingRunnableArray.RemoveElementAt(0); } break; From 9420568af4ee164993736ed048d3fd15a221e7fe Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Tue, 19 May 2015 12:28:38 +0200 Subject: [PATCH 24/39] Bug 1164498: Remove |DispatchBluetoothReply| from |BluetoothProfileController|, r=btian This patch replaces |DispatchBluetoothReply| in |BluetoothProfileController| with corresponding calls to |DispatchReplySuccess| or |DispatchReplyError|. --- .../bluetooth1/BluetoothProfileController.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/dom/bluetooth/bluetooth1/BluetoothProfileController.cpp b/dom/bluetooth/bluetooth1/BluetoothProfileController.cpp index b63b2ccd53c..bdf017a5b72 100644 --- a/dom/bluetooth/bluetooth1/BluetoothProfileController.cpp +++ b/dom/bluetooth/bluetooth1/BluetoothProfileController.cpp @@ -116,8 +116,7 @@ BluetoothProfileController::AddProfileWithServiceClass( profile = BluetoothHidManager::Get(); break; default: - DispatchBluetoothReply(mRunnable, BluetoothValue(), - NS_LITERAL_STRING(ERR_UNKNOWN_PROFILE)); + DispatchReplyError(mRunnable, NS_LITERAL_STRING(ERR_UNKNOWN_PROFILE)); mCallback(); return; } @@ -130,8 +129,8 @@ BluetoothProfileController::AddProfile(BluetoothProfileManagerBase* aProfile, bool aCheckConnected) { if (!aProfile) { - DispatchBluetoothReply(mRunnable, BluetoothValue(), - NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE)); + DispatchReplyError(mRunnable, + NS_LITERAL_STRING(ERR_NO_AVAILABLE_RESOURCE)); mCallback(); return; } @@ -266,13 +265,11 @@ BluetoothProfileController::EndSession() // The action has completed, so the DOM request should be replied then invoke // the callback. if (mSuccess) { - DispatchBluetoothReply(mRunnable, BluetoothValue(true), EmptyString()); + DispatchReplySuccess(mRunnable); } else if (mConnect) { - DispatchBluetoothReply(mRunnable, BluetoothValue(true), - NS_LITERAL_STRING(ERR_CONNECTION_FAILED)); + DispatchReplyError(mRunnable, NS_LITERAL_STRING(ERR_CONNECTION_FAILED)); } else { - DispatchBluetoothReply(mRunnable, BluetoothValue(true), - NS_LITERAL_STRING(ERR_DISCONNECTION_FAILED)); + DispatchReplyError(mRunnable, NS_LITERAL_STRING(ERR_DISCONNECTION_FAILED)); } mCallback(); From f62c2b2bcbede075dd1ed0a3c48374ecde765a52 Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Tue, 19 May 2015 12:28:38 +0200 Subject: [PATCH 25/39] Bug 1164498: Remove |DispatchBluetoothReply| from |BluetoothHfpManger|, r=btian This patch replaces |DispatchBluetoothReply| in |BluetoothHfpManager| with corresponding calls to |DispatchReplySuccess| or |DispatchReplyError|. --- dom/bluetooth/bluez/BluetoothHfpManager.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/dom/bluetooth/bluez/BluetoothHfpManager.cpp b/dom/bluetooth/bluez/BluetoothHfpManager.cpp index b6982807f7d..283a864ca99 100644 --- a/dom/bluetooth/bluez/BluetoothHfpManager.cpp +++ b/dom/bluetooth/bluez/BluetoothHfpManager.cpp @@ -1916,12 +1916,7 @@ BluetoothHfpManager::OnScoConnectSuccess() { // For active connection request, we need to reply the DOMRequest if (mScoRunnable) { -#ifdef MOZ_B2G_BT_API_V2 DispatchReplySuccess(mScoRunnable); -#else - DispatchBluetoothReply(mScoRunnable, - BluetoothValue(true), EmptyString()); -#endif mScoRunnable = nullptr; } @@ -1935,13 +1930,8 @@ void BluetoothHfpManager::OnScoConnectError() { if (mScoRunnable) { -#ifdef MOZ_B2G_BT_API_V2 DispatchReplyError(mScoRunnable, NS_LITERAL_STRING("Failed to create SCO socket!")); -#else - NS_NAMED_LITERAL_STRING(replyError, "Failed to create SCO socket!"); - DispatchBluetoothReply(mScoRunnable, BluetoothValue(), replyError); -#endif mScoRunnable = nullptr; } From b1655e9352aac293d9649de90f64c42ce9f1b682 Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Tue, 19 May 2015 12:28:38 +0200 Subject: [PATCH 26/39] Bug 1164498: Remove |DispatchBluetoothReply|, r=btian This patch removes |DispatchBluetoothReply|. The only remaining user is |BluetoothDBusService|, but it comes with its own implemenation of the function. --- dom/bluetooth/BluetoothUtils.cpp | 25 -------------------- dom/bluetooth/BluetoothUtils.h | 9 ------- dom/bluetooth/bluez/BluetoothDBusService.cpp | 8 ++----- 3 files changed, 2 insertions(+), 40 deletions(-) diff --git a/dom/bluetooth/BluetoothUtils.cpp b/dom/bluetooth/BluetoothUtils.cpp index 3298a0db811..a3f1a834e23 100644 --- a/dom/bluetooth/BluetoothUtils.cpp +++ b/dom/bluetooth/BluetoothUtils.cpp @@ -330,31 +330,6 @@ DispatchReplyError(BluetoothReplyRunnable* aRunnable, NS_WARN_IF(NS_FAILED(NS_DispatchToMainThread(aRunnable))); } -#if MOZ_B2G_BT_API_V2 -// TODO: remove with bluetooth1 -#else -void -DispatchBluetoothReply(BluetoothReplyRunnable* aRunnable, - const BluetoothValue& aValue, - const nsAString& aErrorStr) -{ - // Reply will be deleted by the runnable after running on main thread - BluetoothReply* reply; - if (!aErrorStr.IsEmpty()) { - nsString err(aErrorStr); - reply = new BluetoothReply(BluetoothReplyError(err)); - } else { - MOZ_ASSERT(aValue.type() != BluetoothValue::T__None); - reply = new BluetoothReply(BluetoothReplySuccess(aValue)); - } - - aRunnable->SetReply(reply); - if (NS_FAILED(NS_DispatchToMainThread(aRunnable))) { - BT_WARNING("Failed to dispatch to main thread!"); - } -} -#endif - void DispatchStatusChangedEvent(const nsAString& aType, const nsAString& aAddress, diff --git a/dom/bluetooth/BluetoothUtils.h b/dom/bluetooth/BluetoothUtils.h index 6c528c6801d..666a94094c3 100644 --- a/dom/bluetooth/BluetoothUtils.h +++ b/dom/bluetooth/BluetoothUtils.h @@ -177,15 +177,6 @@ void DispatchReplyError(BluetoothReplyRunnable* aRunnable, const enum BluetoothStatus aStatus); -#if MOZ_B2G_BT_API_V2 -// TODO: remove with bluetooth1 -#else -void -DispatchBluetoothReply(BluetoothReplyRunnable* aRunnable, - const BluetoothValue& aValue, - const nsAString& aErrorStr); -#endif - void DispatchStatusChangedEvent(const nsAString& aType, const nsAString& aDeviceAddress, diff --git a/dom/bluetooth/bluez/BluetoothDBusService.cpp b/dom/bluetooth/bluez/BluetoothDBusService.cpp index a43887267f4..7136d9f461b 100644 --- a/dom/bluetooth/bluez/BluetoothDBusService.cpp +++ b/dom/bluetooth/bluez/BluetoothDBusService.cpp @@ -420,7 +420,6 @@ DispatchToBtThread(nsIRunnable* aRunnable) return sBluetoothThread->Dispatch(aRunnable, NS_DISPATCH_NORMAL); } -#ifdef MOZ_B2G_BT_API_V2 static void DispatchBluetoothReply(BluetoothReplyRunnable* aRunnable, const BluetoothValue& aValue, @@ -432,9 +431,6 @@ DispatchBluetoothReply(BluetoothReplyRunnable* aRunnable, DispatchReplySuccess(aRunnable, aValue); } } -#else -// Missing in bluetooth1 -#endif BluetoothDBusService::BluetoothDBusService() { @@ -4698,14 +4694,14 @@ BluetoothDBusService::UpdateNotification(ControlEventId aEventId, void BluetoothDBusService::StartLeScanInternal( const nsTArray& aServiceUuids, - BluetoothReplyRunnable* aRunnable); + BluetoothReplyRunnable* aRunnable) { } void BluetoothDBusService::StopLeScanInternal( const nsAString& aAppUuid, - BluetoothReplyRunnable* aRunnable); + BluetoothReplyRunnable* aRunnable) { } From 7dc01cb0eb124f201de664864c79c390a9260865 Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Tue, 19 May 2015 13:28:46 +0200 Subject: [PATCH 27/39] Bug 1161020: Added clean interface to |UnixSocketConnector|, r=kmachulis The current interface of |UnixSocketConnector| doesn't follow any design and is not easily understandable. This patch adds a new interface to the class. The new interface provides a method for each of the following operations: * converting an address to a human-readable string, * creating a listening socket, * creating a stream socket, and * accepting a stream socket from a listening socket. All arguments are stored in the connector class, so that connect and listen methods of the socket classes don't require protocol-specific arguments. All socket parameters are set within the connector class, so each connector class can now select parameters individually. --- ipc/unixsocket/UnixSocketConnector.cpp | 37 +++++++++++++++ ipc/unixsocket/UnixSocketConnector.h | 64 +++++++++++++++++++++++++- 2 files changed, 100 insertions(+), 1 deletion(-) diff --git a/ipc/unixsocket/UnixSocketConnector.cpp b/ipc/unixsocket/UnixSocketConnector.cpp index ef958f062f8..6c23b237acc 100644 --- a/ipc/unixsocket/UnixSocketConnector.cpp +++ b/ipc/unixsocket/UnixSocketConnector.cpp @@ -9,8 +9,45 @@ namespace mozilla { namespace ipc { +UnixSocketConnector::UnixSocketConnector() +{ } + UnixSocketConnector::~UnixSocketConnector() { } +nsresult +UnixSocketConnector::ConvertAddressToString(const struct sockaddr& aAddress, + socklen_t aAddressLength, + nsACString& aAddressString) +{ + MOZ_CRASH("|UnixSocketConnector| does not convert addresses to strings."); + return NS_ERROR_ABORT; +} + +nsresult +UnixSocketConnector::CreateListenSocket(struct sockaddr* aAddress, + socklen_t* aAddressLength, + int& aListenFd) +{ + MOZ_CRASH("|UnixSocketConnector| does not support listening sockets."); +} + +nsresult +UnixSocketConnector::AcceptStreamSocket(int aListenFd, + struct sockaddr* aAddress, + socklen_t* aAddressLen, + int& aStreamFd) +{ + MOZ_CRASH("|UnixSocketConnector| does not support accepting stream sockets."); +} + +nsresult +UnixSocketConnector::CreateStreamSocket(struct sockaddr* aAddress, + socklen_t* aAddressLength, + int& aStreamFd) +{ + MOZ_CRASH("|UnixSocketConnector| does not support creating stream sockets."); +} + } } diff --git a/ipc/unixsocket/UnixSocketConnector.h b/ipc/unixsocket/UnixSocketConnector.h index dcfb1b83149..2573271a5cd 100644 --- a/ipc/unixsocket/UnixSocketConnector.h +++ b/ipc/unixsocket/UnixSocketConnector.h @@ -7,6 +7,7 @@ #ifndef mozilla_ipc_unixsocketconnector_h #define mozilla_ipc_unixsocketconnector_h +#include #include "mozilla/ipc/UnixSocketWatcher.h" #include "nsString.h" @@ -16,7 +17,7 @@ namespace ipc { /** * |UnixSocketConnector| defines the socket creation and connection/listening * functions for |UnixSocketConsumer|, et al. Due to the fact that socket setup - * can vary between protocols (unix sockets, tcp sockets, bluetooth sockets, etc), + * can vary between protocols (Unix sockets, TCP sockets, Bluetooth sockets, etc), * this allows the user to create whatever connection mechanism they need while * still depending on libevent for non-blocking communication handling. */ @@ -25,9 +26,61 @@ class UnixSocketConnector public: virtual ~UnixSocketConnector(); + /** + * Converts an address to a human-readable string. + * + * @param aAddress A socket address + * @param aAddressLength The number of valid bytes in |aAddress| + * @param[out] aAddressString The resulting string + * @return NS_OK on success, or an XPCOM error code otherwise. + */ + virtual nsresult ConvertAddressToString(const struct sockaddr& aAddress, + socklen_t aAddressLength, + nsACString& aAddressString); + + /** + * Creates a listening socket. I/O thread only. + * + * @param[out] aAddress The listening socket's address + * @param[out] aAddressLength The number of valid bytes in |aAddress| + * @param[out] aListenFd The socket's file descriptor + * @return NS_OK on success, or an XPCOM error code otherwise. + */ + virtual nsresult CreateListenSocket(struct sockaddr* aAddress, + socklen_t* aAddressLength, + int& aListenFd); + + /** + * Accepts a stream socket from a listening socket. I/O thread only. + * + * @param aListenFd The listening socket + * @param[out] aAddress Returns the stream socket's address + * @param[out] aAddressLength Returns the number of valid bytes in |aAddress| + * @param[out] aStreamFd The stream socket's file descriptor + * @return NS_OK on success, or an XPCOM error code otherwise. + */ + virtual nsresult AcceptStreamSocket(int aListenFd, + struct sockaddr* aAddress, + socklen_t* aAddressLen, + int& aStreamFd); + + /** + * Creates a stream socket. I/O thread only. + * + * @param[in|out] aAddress The stream socket's address + * @param[in|out] aAddressLength The number of valid bytes in |aAddress| + * @param[out] aStreamFd The socket's file descriptor + * @return NS_OK on success, or an XPCOM error code otherwise. + */ + virtual nsresult CreateStreamSocket(struct sockaddr* aAddress, + socklen_t* aAddressLength, + int& aStreamFd); + /** * Establishs a file descriptor for a socket. * + * @deprecated + * * @return File descriptor for socket */ virtual int Create() = 0; @@ -37,6 +90,8 @@ public: * sockaddr struct, this function is defined by subclasses and fills in the * structure as needed for whatever connection it is trying to build * + * @deprecated + * * @param aIsServer True is we are acting as a server socket * @param aAddrSize Size of the struct * @param aAddr Struct to fill @@ -62,6 +117,8 @@ public: /** * Perform socket setup for socket created by ListenSocket(), after listen(). * + * @deprecated + * * @param aFd File descriptor for opened socket * * @return true is successful, false otherwise @@ -72,11 +129,16 @@ public: * Get address of socket we're currently connected to. Return null string if * not connected. * + * @deprecated + * * @param aAddr Address struct * @param aAddrStr String to store address to */ virtual void GetSocketAddr(const sockaddr_any& aAddr, nsAString& aAddrStr) = 0; + +protected: + UnixSocketConnector(); }; } From 9c1ff726f4753367d06a5d1d156686a90dcdd154 Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Tue, 19 May 2015 13:28:46 +0200 Subject: [PATCH 28/39] Bug 1161020: Implement new socket-connector interface for NFC, r=allstars.chh This patch moves |NfcConnector| into its own file and implements the new socket-connector interface. --- dom/nfc/gonk/NfcService.cpp | 4 +- ipc/nfc/Nfc.cpp | 71 +--------- ipc/nfc/Nfc.h | 18 --- ipc/nfc/NfcConnector.cpp | 260 ++++++++++++++++++++++++++++++++++++ ipc/nfc/NfcConnector.h | 70 ++++++++++ ipc/nfc/moz.build | 2 + 6 files changed, 337 insertions(+), 88 deletions(-) create mode 100644 ipc/nfc/NfcConnector.cpp create mode 100644 ipc/nfc/NfcConnector.h diff --git a/dom/nfc/gonk/NfcService.cpp b/dom/nfc/gonk/NfcService.cpp index f0923b5331d..de1d6951181 100644 --- a/dom/nfc/gonk/NfcService.cpp +++ b/dom/nfc/gonk/NfcService.cpp @@ -12,6 +12,7 @@ #include "mozilla/dom/NfcOptionsBinding.h" #include "mozilla/dom/ToJSValue.h" #include "mozilla/dom/RootedDictionary.h" +#include "mozilla/ipc/NfcConnector.h" #include "mozilla/unused.h" #include "nsAutoPtr.h" #include "nsString.h" @@ -312,7 +313,8 @@ NfcService::Start(nsINfcGonkEventListener* aListener) mListenSocket = new NfcListenSocket(this); - bool success = mListenSocket->Listen(new NfcConnector(), mConsumer); + bool success = mListenSocket->Listen(new NfcConnector(mListenSocketName), + mConsumer); if (!success) { mConsumer = nullptr; return NS_ERROR_FAILURE; diff --git a/ipc/nfc/Nfc.cpp b/ipc/nfc/Nfc.cpp index 9ff5e49d600..15162149242 100644 --- a/ipc/nfc/Nfc.cpp +++ b/ipc/nfc/Nfc.cpp @@ -22,6 +22,7 @@ #include "jsfriendapi.h" #include "mozilla/ArrayUtils.h" +#include "mozilla/ipc/NfcConnector.h" #include "nsThreadUtils.h" // For NS_IsMainThread. using namespace mozilla::ipc; @@ -60,74 +61,6 @@ private: namespace mozilla { namespace ipc { -// -// NfcConnector -// - -int -NfcConnector::Create() -{ - MOZ_ASSERT(!NS_IsMainThread()); - - int fd = socket(AF_LOCAL, SOCK_STREAM, 0); - if (fd < 0) { - NS_WARNING("Could not open nfc socket!"); - return -1; - } - - if (!SetUp(fd)) { - NS_WARNING("Could not set up socket!"); - } - return fd; -} - -bool -NfcConnector::CreateAddr(bool aIsServer, - socklen_t& aAddrSize, - sockaddr_any& aAddr, - const char* aAddress) -{ - static const size_t sNameOffset = 1; - - nsDependentCString socketName("nfcd"); - - size_t namesiz = socketName.Length() + 1; /* include trailing '\0' */ - - if ((sNameOffset + namesiz) > sizeof(aAddr.un.sun_path)) { - NS_WARNING("Address too long for socket struct!"); - return false; - } - - memset(aAddr.un.sun_path, '\0', sNameOffset); // abstract socket - memcpy(aAddr.un.sun_path + sNameOffset, socketName.get(), namesiz); - aAddr.un.sun_family = AF_UNIX; - - aAddrSize = offsetof(struct sockaddr_un, sun_path) + sNameOffset + namesiz; - - return true; -} - -bool -NfcConnector::SetUp(int aFd) -{ - // Nothing to do here. - return true; -} - -bool -NfcConnector::SetUpListenSocket(int aFd) -{ - // Nothing to do here. - return true; -} - -void -NfcConnector::GetSocketAddr(const sockaddr_any& aAddr, - nsAString& aAddrStr) -{ - MOZ_CRASH("This should never be called!"); -} - // // NfcListenSocket // @@ -231,7 +164,7 @@ NfcConsumer::OnDisconnect() ConnectionOrientedSocketIO* NfcConsumer::GetIO() { - return PrepareAccept(new NfcConnector()); + return PrepareAccept(new NfcConnector(NS_LITERAL_CSTRING("nfcd"))); } } // namespace ipc diff --git a/ipc/nfc/Nfc.h b/ipc/nfc/Nfc.h index 583c4174df5..198f7d666fe 100644 --- a/ipc/nfc/Nfc.h +++ b/ipc/nfc/Nfc.h @@ -11,7 +11,6 @@ #include #include -#include namespace mozilla { namespace ipc { @@ -44,23 +43,6 @@ private: NfcSocketListener* mListener; }; -class NfcConnector final : public mozilla::ipc::UnixSocketConnector -{ -public: - NfcConnector() - { } - - int Create() override; - bool CreateAddr(bool aIsServer, - socklen_t& aAddrSize, - sockaddr_any& aAddr, - const char* aAddress) override; - bool SetUp(int aFd) override; - bool SetUpListenSocket(int aFd) override; - void GetSocketAddr(const sockaddr_any& aAddr, - nsAString& aAddrStr) override; -}; - class NfcConsumer final : public mozilla::ipc::StreamSocket { public: diff --git a/ipc/nfc/NfcConnector.cpp b/ipc/nfc/NfcConnector.cpp new file mode 100644 index 00000000000..05a092d7e20 --- /dev/null +++ b/ipc/nfc/NfcConnector.cpp @@ -0,0 +1,260 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* vim: set sw=2 ts=8 et ft=cpp: */ + +/* 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 "NfcConnector.h" +#include +#include +#include "nsThreadUtils.h" // For NS_IsMainThread. + +namespace mozilla { +namespace ipc { + +NfcConnector::NfcConnector(const nsACString& aAddressString) + : mAddressString(aAddressString) +{ } + +NfcConnector::~NfcConnector() +{ } + +nsresult +NfcConnector::CreateSocket(int& aFd) const +{ + aFd = socket(AF_LOCAL, SOCK_STREAM, 0); + if (aFd < 0) { + NS_WARNING("Could not open NFC socket!"); + return NS_ERROR_FAILURE; + } + + return NS_OK; +} + +nsresult +NfcConnector::SetSocketFlags(int aFd) const +{ + static const int sReuseAddress = 1; + + // Set close-on-exec bit. + int flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFD)); + if (flags < 0) { + return NS_ERROR_FAILURE; + } + flags |= FD_CLOEXEC; + int res = TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFD, flags)); + if (res < 0) { + return NS_ERROR_FAILURE; + } + + // Set non-blocking status flag. + flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFL)); + if (flags < 0) { + return NS_ERROR_FAILURE; + } + flags |= O_NONBLOCK; + res = TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFL, flags)); + if (res < 0) { + return NS_ERROR_FAILURE; + } + + // Set socket addr to be reused even if kernel is still waiting to close. + res = setsockopt(aFd, SOL_SOCKET, SO_REUSEADDR, &sReuseAddress, + sizeof(sReuseAddress)); + if (res < 0) { + return NS_ERROR_FAILURE; + } + + return NS_OK; +} + +nsresult +NfcConnector::CreateAddress(struct sockaddr& aAddress, + socklen_t& aAddressLength) const +{ + static const size_t sNameOffset = 1; + + struct sockaddr_un* address = + reinterpret_cast(&aAddress); + + size_t namesiz = mAddressString.Length() + 1; // include trailing '\0' + + if (NS_WARN_IF((sNameOffset + namesiz) > sizeof(address->sun_path))) { + return NS_ERROR_FAILURE; + } + + address->sun_family = AF_UNIX; + memset(address->sun_path, '\0', sNameOffset); // abstract socket + memcpy(address->sun_path + sNameOffset, mAddressString.get(), namesiz); + + aAddressLength = + offsetof(struct sockaddr_un, sun_path) + sNameOffset + namesiz; + + return NS_OK; +} + +// |UnixSocketConnector| +// + +nsresult +NfcConnector::ConvertAddressToString(const struct sockaddr& aAddress, + socklen_t aAddressLength, + nsACString& aAddressString) +{ + MOZ_ASSERT(aAddress.sa_family == AF_UNIX); + + const struct sockaddr_un* un = + reinterpret_cast(&aAddress); + + size_t len = aAddressLength - offsetof(struct sockaddr_un, sun_path); + + aAddressString.Assign(un->sun_path, len); + + return NS_OK; +} + +nsresult +NfcConnector::CreateListenSocket(struct sockaddr* aAddress, + socklen_t* aAddressLength, + int& aListenFd) +{ + ScopedClose fd; + + nsresult rv = CreateSocket(fd.rwget()); + if (NS_FAILED(rv)) { + return rv; + } + rv = SetSocketFlags(fd); + if (NS_FAILED(rv)) { + return rv; + } + if (aAddress && aAddressLength) { + rv = CreateAddress(*aAddress, *aAddressLength); + if (NS_FAILED(rv)) { + return rv; + } + } + + aListenFd = fd.forget(); + + return NS_OK; +} + +nsresult +NfcConnector::AcceptStreamSocket(int aListenFd, + struct sockaddr* aAddress, + socklen_t* aAddressLength, + int& aStreamFd) +{ + ScopedClose fd( + TEMP_FAILURE_RETRY(accept(aListenFd, aAddress, aAddressLength))); + if (fd < 0) { + NS_WARNING("Cannot accept file descriptor!"); + return NS_ERROR_FAILURE; + } + nsresult rv = SetSocketFlags(fd); + if (NS_FAILED(rv)) { + return rv; + } + + aStreamFd = fd.forget(); + + return NS_OK; +} + +nsresult +NfcConnector::CreateStreamSocket(struct sockaddr* aAddress, + socklen_t* aAddressLength, + int& aStreamFd) +{ + ScopedClose fd; + + nsresult rv = CreateSocket(fd.rwget()); + if (NS_FAILED(rv)) { + return rv; + } + rv = SetSocketFlags(fd); + if (NS_FAILED(rv)) { + return rv; + } + if (aAddress && aAddressLength) { + rv = CreateAddress(*aAddress, *aAddressLength); + if (NS_FAILED(rv)) { + return rv; + } + } + + aStreamFd = fd.forget(); + + return NS_OK; +} + +// Deprecated + +int +NfcConnector::Create() +{ + MOZ_ASSERT(!NS_IsMainThread()); + + int fd = socket(AF_LOCAL, SOCK_STREAM, 0); + if (fd < 0) { + NS_WARNING("Could not open nfc socket!"); + return -1; + } + + if (!SetUp(fd)) { + NS_WARNING("Could not set up socket!"); + } + return fd; +} + +bool +NfcConnector::CreateAddr(bool aIsServer, + socklen_t& aAddrSize, + sockaddr_any& aAddr, + const char* aAddress) +{ + static const size_t sNameOffset = 1; + + nsDependentCString socketName("nfcd"); + + size_t namesiz = socketName.Length() + 1; /* include trailing '\0' */ + + if ((sNameOffset + namesiz) > sizeof(aAddr.un.sun_path)) { + NS_WARNING("Address too long for socket struct!"); + return false; + } + + memset(aAddr.un.sun_path, '\0', sNameOffset); // abstract socket + memcpy(aAddr.un.sun_path + sNameOffset, socketName.get(), namesiz); + aAddr.un.sun_family = AF_UNIX; + + aAddrSize = offsetof(struct sockaddr_un, sun_path) + sNameOffset + namesiz; + + return true; +} + +bool +NfcConnector::SetUp(int aFd) +{ + // Nothing to do here. + return true; +} + +bool +NfcConnector::SetUpListenSocket(int aFd) +{ + // Nothing to do here. + return true; +} + +void +NfcConnector::GetSocketAddr(const sockaddr_any& aAddr, + nsAString& aAddrStr) +{ + MOZ_CRASH("This should never be called!"); +} + +} +} diff --git a/ipc/nfc/NfcConnector.h b/ipc/nfc/NfcConnector.h new file mode 100644 index 00000000000..6bf4427b8f1 --- /dev/null +++ b/ipc/nfc/NfcConnector.h @@ -0,0 +1,70 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* vim: set sw=2 ts=8 et ft=cpp: */ + +/* 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/. */ + +#ifndef mozilla_ipc_NfcConnector_h +#define mozilla_ipc_NfcConnector_h + +#include "mozilla/ipc/UnixSocketConnector.h" + +namespace mozilla { +namespace ipc { + +/** + * |NfcConnector| creates sockets for communicating with + * the NFC daemon. + */ +class NfcConnector final : public UnixSocketConnector +{ +public: + NfcConnector(const nsACString& aAddressString); + ~NfcConnector(); + + // Methods for |UnixSocketConnector| + // + + nsresult ConvertAddressToString(const struct sockaddr& aAddress, + socklen_t aAddressLength, + nsACString& aAddressString) override; + + nsresult CreateListenSocket(struct sockaddr* aAddress, + socklen_t* aAddressLength, + int& aListenFd) override; + + nsresult AcceptStreamSocket(int aListenFd, + struct sockaddr* aAddress, + socklen_t* aAddressLen, + int& aStreamFd) override; + + nsresult CreateStreamSocket(struct sockaddr* aAddress, + socklen_t* aAddressLength, + int& aStreamFd) override; + + // Deprecated + + int Create() override; + bool CreateAddr(bool aIsServer, + socklen_t& aAddrSize, + sockaddr_any& aAddr, + const char* aAddress) override; + bool SetUp(int aFd) override; + bool SetUpListenSocket(int aFd) override; + void GetSocketAddr(const sockaddr_any& aAddr, + nsAString& aAddrStr) override; + +private: + nsresult CreateSocket(int& aFd) const; + nsresult SetSocketFlags(int aFd) const; + nsresult CreateAddress(struct sockaddr& aAddress, + socklen_t& aAddressLength) const; + + nsCString mAddressString; +}; + +} +} + +#endif diff --git a/ipc/nfc/moz.build b/ipc/nfc/moz.build index 8443be5bedb..b824ae1c8ed 100644 --- a/ipc/nfc/moz.build +++ b/ipc/nfc/moz.build @@ -6,9 +6,11 @@ if CONFIG['MOZ_NFC']: EXPORTS.mozilla.ipc += [ 'Nfc.h', + 'NfcConnector.h', ] SOURCES += [ 'Nfc.cpp', + 'NfcConnector.cpp', ] include('/ipc/chromium/chromium-config.mozbuild') From 94673e3ad427103af82668656f81a8ea3851f024 Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Tue, 19 May 2015 13:28:46 +0200 Subject: [PATCH 29/39] Bug 1161020: Implement new socket-connector interface for RIL, r=htsai This patch moves |RilConnector| into its own file and implements the new socket-connector interface. --- ipc/ril/Ril.cpp | 115 +-------------- ipc/ril/RilConnector.cpp | 292 +++++++++++++++++++++++++++++++++++++++ ipc/ril/RilConnector.h | 72 ++++++++++ ipc/ril/moz.build | 1 + 4 files changed, 369 insertions(+), 111 deletions(-) create mode 100644 ipc/ril/RilConnector.cpp create mode 100644 ipc/ril/RilConnector.h diff --git a/ipc/ril/Ril.cpp b/ipc/ril/Ril.cpp index c7848bb9519..48264e1a91d 100644 --- a/ipc/ril/Ril.cpp +++ b/ipc/ril/Ril.cpp @@ -21,9 +21,9 @@ #include "jsfriendapi.h" #include "mozilla/ArrayUtils.h" -#include "mozilla/ipc/UnixSocketConnector.h" #include "nsTArray.h" #include "nsThreadUtils.h" // For NS_IsMainThread. +#include "RilConnector.h" USING_WORKERS_NAMESPACE using namespace mozilla::ipc; @@ -32,10 +32,6 @@ namespace { static const char RIL_SOCKET_NAME[] = "/dev/socket/rilproxy"; -// Network port to connect to for adb forwarded sockets when doing -// desktop development. -static const uint32_t RIL_TEST_PORT = 6200; - static nsTArray > sRilConsumers; class ConnectWorkerToRIL final : public WorkerTask @@ -199,109 +195,6 @@ DispatchRILEvent::RunTask(JSContext* aCx) return JS_CallFunctionName(aCx, obj, "onRILMessage", args, &rval); } -class RilConnector final : public mozilla::ipc::UnixSocketConnector -{ -public: - RilConnector(unsigned long aClientId) - : mClientId(aClientId) - { } - - int Create() override; - bool CreateAddr(bool aIsServer, - socklen_t& aAddrSize, - sockaddr_any& aAddr, - const char* aAddress) override; - bool SetUp(int aFd) override; - bool SetUpListenSocket(int aFd) override; - void GetSocketAddr(const sockaddr_any& aAddr, - nsAString& aAddrStr) override; - -private: - unsigned long mClientId; -}; - -int -RilConnector::Create() -{ - MOZ_ASSERT(!NS_IsMainThread()); - - int fd = -1; - -#if defined(MOZ_WIDGET_GONK) - fd = socket(AF_LOCAL, SOCK_STREAM, 0); -#else - // If we can't hit a local loopback, fail later in connect. - fd = socket(AF_INET, SOCK_STREAM, 0); -#endif - - if (fd < 0) { - NS_WARNING("Could not open ril socket!"); - return -1; - } - - if (!SetUp(fd)) { - NS_WARNING("Could not set up socket!"); - } - return fd; -} - -bool -RilConnector::CreateAddr(bool aIsServer, - socklen_t& aAddrSize, - sockaddr_any& aAddr, - const char* aAddress) -{ - // We never open ril socket as server. - MOZ_ASSERT(!aIsServer); - uint32_t af; -#if defined(MOZ_WIDGET_GONK) - af = AF_LOCAL; -#else - af = AF_INET; -#endif - switch (af) { - case AF_LOCAL: - aAddr.un.sun_family = af; - if(strlen(aAddress) > sizeof(aAddr.un.sun_path)) { - NS_WARNING("Address too long for socket struct!"); - return false; - } - strcpy((char*)&aAddr.un.sun_path, aAddress); - aAddrSize = strlen(aAddress) + offsetof(struct sockaddr_un, sun_path) + 1; - break; - case AF_INET: - aAddr.in.sin_family = af; - aAddr.in.sin_port = htons(RIL_TEST_PORT + mClientId); - aAddr.in.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - aAddrSize = sizeof(sockaddr_in); - break; - default: - NS_WARNING("Socket type not handled by connector!"); - return false; - } - return true; -} - -bool -RilConnector::SetUp(int aFd) -{ - // Nothing to do here. - return true; -} - -bool -RilConnector::SetUpListenSocket(int aFd) -{ - // Nothing to do here. - return true; -} - -void -RilConnector::GetSocketAddr(const sockaddr_any& aAddr, nsAString& aAddrStr) -{ - MOZ_CRASH("This should never be called!"); -} - } // anonymous namespace namespace mozilla { @@ -324,7 +217,7 @@ RilConsumer::RilConsumer(unsigned long aClientId, mAddress = addr_un.sun_path; } - Connect(new RilConnector(mClientId), mAddress.get()); + Connect(new RilConnector(mAddress, mClientId), mAddress.get()); } nsresult @@ -396,7 +289,7 @@ RilConsumer::OnDisconnect() { CHROMIUM_LOG("RIL[%lu]: %s\n", mClientId, __FUNCTION__); if (!mShutdown) { - Connect(new RilConnector(mClientId), mAddress.get(), + Connect(new RilConnector(mAddress, mClientId), mAddress.get(), GetSuggestedConnectDelayMs()); } } @@ -404,7 +297,7 @@ RilConsumer::OnDisconnect() ConnectionOrientedSocketIO* RilConsumer::GetIO() { - return PrepareAccept(new RilConnector(mClientId)); + return PrepareAccept(new RilConnector(mAddress, mClientId)); } } // namespace ipc diff --git a/ipc/ril/RilConnector.cpp b/ipc/ril/RilConnector.cpp new file mode 100644 index 00000000000..6fbcdb16eae --- /dev/null +++ b/ipc/ril/RilConnector.cpp @@ -0,0 +1,292 @@ +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ +/* vim: set ts=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 "RilConnector.h" +#include +#include +#include "nsThreadUtils.h" // For NS_IsMainThread. + +#ifdef AF_INET +#include +#include +#endif +#ifdef AF_UNIX +#include +#endif + +namespace mozilla { +namespace ipc { + +static const uint16_t RIL_TEST_PORT = 6200; + +RilConnector::RilConnector(const nsACString& aAddressString, + unsigned long aClientId) + : mAddressString(aAddressString) + , mClientId(aClientId) +{ } + +RilConnector::~RilConnector() +{ } + +nsresult +RilConnector::CreateSocket(int aDomain, int& aFd) const +{ + aFd = socket(aDomain, SOCK_STREAM, 0); + if (aFd < 0) { + NS_WARNING("Could not open RIL socket!"); + return NS_ERROR_FAILURE; + } + + return NS_OK; +} + +nsresult +RilConnector::SetSocketFlags(int aFd) const +{ + static const int sReuseAddress = 1; + + // Set close-on-exec bit. + int flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFD)); + if (flags < 0) { + return NS_ERROR_FAILURE; + } + flags |= FD_CLOEXEC; + int res = TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFD, flags)); + if (res < 0) { + return NS_ERROR_FAILURE; + } + + // Set non-blocking status flag. + flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFL)); + if (flags < 0) { + return NS_ERROR_FAILURE; + } + flags |= O_NONBLOCK; + res = TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFL, flags)); + if (res < 0) { + return NS_ERROR_FAILURE; + } + + // Set socket addr to be reused even if kernel is still waiting to close. + res = setsockopt(aFd, SOL_SOCKET, SO_REUSEADDR, &sReuseAddress, + sizeof(sReuseAddress)); + if (res < 0) { + return NS_ERROR_FAILURE; + } + + return NS_OK; +} + +nsresult +RilConnector::CreateAddress(int aDomain, + struct sockaddr& aAddress, + socklen_t& aAddressLength) const +{ + switch (aDomain) { +#ifdef AF_UNIX + case AF_UNIX: { + struct sockaddr_un* address = + reinterpret_cast(&aAddress); + address->sun_family = aDomain; + size_t siz = mAddressString.Length() + 1; + if (siz > sizeof(address->sun_path)) { + NS_WARNING("Address too long for socket struct!"); + return NS_ERROR_FAILURE; + } + memcpy(address->sun_path, mAddressString.get(), siz); + aAddressLength = offsetof(struct sockaddr_un, sun_path) + siz; + } + break; +#endif +#ifdef AF_INET + case AF_INET: { + struct sockaddr_in* address = + reinterpret_cast(&aAddress); + address->sin_family = aDomain; + address->sin_port = htons(RIL_TEST_PORT + mClientId); + address->sin_addr.s_addr = htonl(INADDR_LOOPBACK); + aAddressLength = sizeof(*address); + } + break; +#endif + default: + NS_WARNING("Address family not handled by connector!"); + return NS_ERROR_FAILURE; + } + + return NS_OK; +} + +// |UnixSocketConnector| + +nsresult +RilConnector::ConvertAddressToString(const struct sockaddr& aAddress, + socklen_t aAddressLength, + nsACString& aAddressString) +{ +#ifdef AF_UNIX + if (aAddress.sa_family == AF_UNIX) { + const struct sockaddr_un* un = + reinterpret_cast(&aAddress); + + size_t len = aAddressLength - offsetof(struct sockaddr_un, sun_path); + + aAddressString.Assign(un->sun_path, len); + } else +#endif +#ifdef AF_INET + if (aAddress.sa_family == AF_INET) { + const struct sockaddr_in* in = + reinterpret_cast(&aAddress); + + aAddressString.Assign(nsDependentCString(inet_ntoa(in->sin_addr))); + } else +#endif + { + NS_WARNING("Address family not handled by connector!"); + return NS_ERROR_FAILURE; + } + + return NS_OK; +} + +nsresult +RilConnector::CreateListenSocket(struct sockaddr* aAddress, + socklen_t* aAddressLength, + int& aListenFd) +{ + MOZ_CRASH("|RilConnector| does not support listening sockets."); +} + +nsresult +RilConnector::AcceptStreamSocket(int aListenFd, + struct sockaddr* aAddress, + socklen_t* aAddressLen, + int& aStreamFd) +{ + MOZ_CRASH("|RilConnector| does not support accepting sockets."); +} + +nsresult +RilConnector::CreateStreamSocket(struct sockaddr* aAddress, + socklen_t* aAddressLength, + int& aStreamFd) +{ +#ifdef MOZ_WIDGET_GONK + static const int sDomain = AF_UNIX; +#else + static const int sDomain = AF_INET; +#endif + + ScopedClose fd; + + nsresult rv = CreateSocket(sDomain, fd.rwget()); + if (NS_FAILED(rv)) { + return rv; + } + rv = SetSocketFlags(fd); + if (NS_FAILED(rv)) { + return rv; + } + if (aAddress && aAddressLength) { + rv = CreateAddress(sDomain, *aAddress, *aAddressLength); + if (NS_FAILED(rv)) { + return rv; + } + } + + aStreamFd = fd.forget(); + + return NS_OK; +} + +// Deprecated + +int +RilConnector::Create() +{ + MOZ_ASSERT(!NS_IsMainThread()); + + int fd = -1; + +#if defined(MOZ_WIDGET_GONK) + fd = socket(AF_LOCAL, SOCK_STREAM, 0); +#else + // If we can't hit a local loopback, fail later in connect. + fd = socket(AF_INET, SOCK_STREAM, 0); +#endif + + if (fd < 0) { + NS_WARNING("Could not open ril socket!"); + return -1; + } + + if (!SetUp(fd)) { + NS_WARNING("Could not set up socket!"); + } + return fd; +} + +bool +RilConnector::CreateAddr(bool aIsServer, + socklen_t& aAddrSize, + sockaddr_any& aAddr, + const char* aAddress) +{ + // We never open ril socket as server. + MOZ_ASSERT(!aIsServer); + uint32_t af; +#if defined(MOZ_WIDGET_GONK) + af = AF_LOCAL; +#else + af = AF_INET; +#endif + switch (af) { + case AF_LOCAL: + aAddr.un.sun_family = af; + if(strlen(aAddress) > sizeof(aAddr.un.sun_path)) { + NS_WARNING("Address too long for socket struct!"); + return false; + } + strcpy((char*)&aAddr.un.sun_path, aAddress); + aAddrSize = strlen(aAddress) + offsetof(struct sockaddr_un, sun_path) + 1; + break; + case AF_INET: + aAddr.in.sin_family = af; + aAddr.in.sin_port = htons(RIL_TEST_PORT + mClientId); + aAddr.in.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + aAddrSize = sizeof(sockaddr_in); + break; + default: + NS_WARNING("Socket type not handled by connector!"); + return false; + } + return true; +} + +bool +RilConnector::SetUp(int aFd) +{ + // Nothing to do here. + return true; +} + +bool +RilConnector::SetUpListenSocket(int aFd) +{ + // Nothing to do here. + return true; +} + +void +RilConnector::GetSocketAddr(const sockaddr_any& aAddr, nsAString& aAddrStr) +{ + MOZ_CRASH("This should never be called!"); +} + +} +} diff --git a/ipc/ril/RilConnector.h b/ipc/ril/RilConnector.h new file mode 100644 index 00000000000..a4decc49428 --- /dev/null +++ b/ipc/ril/RilConnector.h @@ -0,0 +1,72 @@ +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ +/* vim: set ts=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/. */ + +#ifndef mozilla_ipc_RilConnector_h +#define mozilla_ipc_RilConnector_h + +#include "mozilla/ipc/UnixSocketConnector.h" + +namespace mozilla { +namespace ipc { + +/** + * |RilConnector| creates sockets for connecting to rild. + */ +class RilConnector final : public UnixSocketConnector +{ +public: + RilConnector(const nsACString& aAddressString, + unsigned long aClientId); + ~RilConnector(); + + // Methods for |UnixSocketConnector| + // + + nsresult ConvertAddressToString(const struct sockaddr& aAddress, + socklen_t aAddressLength, + nsACString& aAddressString) override; + + nsresult CreateListenSocket(struct sockaddr* aAddress, + socklen_t* aAddressLength, + int& aListenFd) override; + + nsresult AcceptStreamSocket(int aListenFd, + struct sockaddr* aAddress, + socklen_t* aAddressLen, + int& aStreamFd) override; + + nsresult CreateStreamSocket(struct sockaddr* aAddress, + socklen_t* aAddressLength, + int& aStreamFd) override; + + // Deprecated + + int Create() override; + bool CreateAddr(bool aIsServer, + socklen_t& aAddrSize, + sockaddr_any& aAddr, + const char* aAddress) override; + bool SetUp(int aFd) override; + bool SetUpListenSocket(int aFd) override; + void GetSocketAddr(const sockaddr_any& aAddr, + nsAString& aAddrStr) override; + +private: + nsresult CreateSocket(int aDomain, int& aFd) const; + nsresult SetSocketFlags(int aFd) const; + nsresult CreateAddress(int aDomain, + struct sockaddr& aAddress, + socklen_t& aAddressLength) const; + + nsCString mAddressString; + unsigned long mClientId; +}; + +} +} + +#endif diff --git a/ipc/ril/moz.build b/ipc/ril/moz.build index 2ab5da59e8d..4e7018bcb6a 100644 --- a/ipc/ril/moz.build +++ b/ipc/ril/moz.build @@ -10,6 +10,7 @@ EXPORTS.mozilla.ipc += [ SOURCES += [ 'Ril.cpp', + 'RilConnector.cpp' ] include('/ipc/chromium/chromium-config.mozbuild') From 642c57904ce4ebc8b08e756981bfb27c26c21c68 Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Tue, 19 May 2015 13:28:46 +0200 Subject: [PATCH 30/39] Bug 1161020: Implement new socket-connector interface for key store, r=chucklee This patch moves |KeyStoreConnector| into its own file and implements the new socket-connector interface. --- ipc/keystore/KeyStore.cpp | 77 +------ ipc/keystore/KeyStore.h | 21 -- ipc/keystore/KeyStoreConnector.cpp | 316 +++++++++++++++++++++++++++++ ipc/keystore/KeyStoreConnector.h | 67 ++++++ ipc/keystore/moz.build | 3 +- 5 files changed, 389 insertions(+), 95 deletions(-) create mode 100644 ipc/keystore/KeyStoreConnector.cpp create mode 100644 ipc/keystore/KeyStoreConnector.h diff --git a/ipc/keystore/KeyStore.cpp b/ipc/keystore/KeyStore.cpp index 1bf568b8521..0a878e221d2 100644 --- a/ipc/keystore/KeyStore.cpp +++ b/ipc/keystore/KeyStore.cpp @@ -19,6 +19,7 @@ #include "KeyStore.h" #include "jsfriendapi.h" +#include "KeyStoreConnector.h" #include "MainThreadUtils.h" // For NS_IsMainThread. #include "nsICryptoHash.h" @@ -304,7 +305,6 @@ static const char *CA_BEGIN = "-----BEGIN ", namespace mozilla { namespace ipc { -static const char* KEYSTORE_SOCKET_PATH = "/dev/socket/keystore"; static const char* KEYSTORE_ALLOWED_USERS[] = { "root", "wifi", @@ -672,76 +672,6 @@ checkPermission(uid_t uid) return false; } -int -KeyStoreConnector::Create() -{ - MOZ_ASSERT(!NS_IsMainThread()); - - int fd; - - unlink(KEYSTORE_SOCKET_PATH); - - fd = socket(AF_LOCAL, SOCK_STREAM, 0); - - if (fd < 0) { - NS_WARNING("Could not open keystore socket!"); - return -1; - } - - return fd; -} - -bool -KeyStoreConnector::CreateAddr(bool aIsServer, - socklen_t& aAddrSize, - sockaddr_any& aAddr, - const char* aAddress) -{ - // Keystore socket must be server - MOZ_ASSERT(aIsServer); - - aAddr.un.sun_family = AF_LOCAL; - if(strlen(KEYSTORE_SOCKET_PATH) > sizeof(aAddr.un.sun_path)) { - NS_WARNING("Address too long for socket struct!"); - return false; - } - strcpy((char*)&aAddr.un.sun_path, KEYSTORE_SOCKET_PATH); - aAddrSize = strlen(KEYSTORE_SOCKET_PATH) + offsetof(struct sockaddr_un, sun_path) + 1; - - return true; -} - -bool -KeyStoreConnector::SetUp(int aFd) -{ - // Socket permission check. - struct ucred userCred; - socklen_t len = sizeof(struct ucred); - - if (getsockopt(aFd, SOL_SOCKET, SO_PEERCRED, &userCred, &len)) { - return false; - } - - return ::checkPermission(userCred.uid); -} - -bool -KeyStoreConnector::SetUpListenSocket(int aFd) -{ - // Allow access of wpa_supplicant(different user, differnt group) - chmod(KEYSTORE_SOCKET_PATH, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); - - return true; -} - -void -KeyStoreConnector::GetSocketAddr(const sockaddr_any& aAddr, - nsAString& aAddrStr) -{ - // Unused. - MOZ_CRASH("This should never be called!"); -} - // // KeyStore::ListenSocket // @@ -818,7 +748,7 @@ KeyStore::StreamSocket::ReceiveSocketData(nsAutoPtr& aBuffer) ConnectionOrientedSocketIO* KeyStore::StreamSocket::GetIO() { - return PrepareAccept(new KeyStoreConnector()); + return PrepareAccept(new KeyStoreConnector(KEYSTORE_ALLOWED_USERS)); } // @@ -877,7 +807,8 @@ KeyStore::Listen() if (!mListenSocket) { // We only ever allocate one |ListenSocket|... mListenSocket = new ListenSocket(this); - mListenSocket->Listen(new KeyStoreConnector(), mStreamSocket); + mListenSocket->Listen(new KeyStoreConnector(KEYSTORE_ALLOWED_USERS), + mStreamSocket); } else { // ... but keep it open. mListenSocket->Listen(mStreamSocket); diff --git a/ipc/keystore/KeyStore.h b/ipc/keystore/KeyStore.h index 797cd536937..18dcf3b56ea 100644 --- a/ipc/keystore/KeyStore.h +++ b/ipc/keystore/KeyStore.h @@ -12,7 +12,6 @@ #include "cert.h" #include "mozilla/ipc/ListenSocket.h" #include "mozilla/ipc/StreamSocket.h" -#include "mozilla/ipc/UnixSocketConnector.h" #include "nsNSSShutDown.h" namespace mozilla { @@ -79,26 +78,6 @@ typedef enum { STATE_PROCESSING } ProtocolHandlerState; -class KeyStoreConnector : public mozilla::ipc::UnixSocketConnector -{ -public: - KeyStoreConnector() - {} - - virtual ~KeyStoreConnector() - {} - - virtual int Create(); - virtual bool CreateAddr(bool aIsServer, - socklen_t& aAddrSize, - sockaddr_any& aAddr, - const char* aAddress); - virtual bool SetUp(int aFd); - virtual bool SetUpListenSocket(int aFd); - virtual void GetSocketAddr(const sockaddr_any& aAddr, - nsAString& aAddrStr); -}; - class KeyStore final : public nsNSSShutDownObject { public: diff --git a/ipc/keystore/KeyStoreConnector.cpp b/ipc/keystore/KeyStoreConnector.cpp new file mode 100644 index 00000000000..e089eaf88ef --- /dev/null +++ b/ipc/keystore/KeyStoreConnector.cpp @@ -0,0 +1,316 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set sw=2 ts=2 et ft=cpp: 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 "KeyStoreConnector.h" +#include +#include +#include +#include +#include "nsThreadUtils.h" // For NS_IsMainThread. + +#ifdef MOZ_WIDGET_GONK +#include +#define KEYSTORE_LOG(args...) __android_log_print(ANDROID_LOG_INFO, "Gonk", args) +#else +#define KEYSTORE_LOG(args...) printf(args); +#endif + +namespace mozilla { +namespace ipc { + +static const char KEYSTORE_SOCKET_PATH[] = "/dev/socket/keystore"; + +KeyStoreConnector::KeyStoreConnector(const char** const aAllowedUsers) + : mAllowedUsers(aAllowedUsers) +{ } + +KeyStoreConnector::~KeyStoreConnector() +{ } + +nsresult +KeyStoreConnector::CreateSocket(int& aFd) const +{ + unlink(KEYSTORE_SOCKET_PATH); + + aFd = socket(AF_LOCAL, SOCK_STREAM, 0); + if (aFd < 0) { + KEYSTORE_LOG("Could not open KeyStore socket!"); + return NS_ERROR_FAILURE; + } + + return NS_OK; +} + +nsresult +KeyStoreConnector::SetSocketFlags(int aFd) const +{ + static const int sReuseAddress = 1; + + // Set close-on-exec bit. + int flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFD)); + if (flags < 0) { + return NS_ERROR_FAILURE; + } + flags |= FD_CLOEXEC; + int res = TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFD, flags)); + if (res < 0) { + return NS_ERROR_FAILURE; + } + + // Set non-blocking status flag. + flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFL)); + if (flags < 0) { + return NS_ERROR_FAILURE; + } + flags |= O_NONBLOCK; + res = TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFL, flags)); + if (res < 0) { + return NS_ERROR_FAILURE; + } + + // Set socket addr to be reused even if kernel is still waiting to close. + res = setsockopt(aFd, SOL_SOCKET, SO_REUSEADDR, &sReuseAddress, + sizeof(sReuseAddress)); + if (res < 0) { + return NS_ERROR_FAILURE; + } + + return NS_OK; +} + +nsresult +KeyStoreConnector::CheckPermission(int aFd) const +{ + struct ucred userCred; + socklen_t len = sizeof(userCred); + + if (getsockopt(aFd, SOL_SOCKET, SO_PEERCRED, &userCred, &len)) { + return NS_ERROR_FAILURE; + } + + const struct passwd* userInfo = getpwuid(userCred.uid); + if (!userInfo) { + return NS_ERROR_FAILURE; + } + + if (!mAllowedUsers) { + return NS_ERROR_FAILURE; + } + + for (const char** user = mAllowedUsers; *user; ++user) { + if (!strcmp(*user, userInfo->pw_name)) { + return NS_OK; + } + } + + return NS_ERROR_FAILURE; +} + +nsresult +KeyStoreConnector::CreateAddress(struct sockaddr& aAddress, + socklen_t& aAddressLength) const +{ + struct sockaddr_un* address = + reinterpret_cast(&aAddress); + + size_t namesiz = strlen(KEYSTORE_SOCKET_PATH) + 1; // include trailing '\0' + + if (namesiz > sizeof(address->sun_path)) { + KEYSTORE_LOG("Address too long for socket struct!"); + return NS_ERROR_FAILURE; + } + + address->sun_family = AF_UNIX; + memcpy(address->sun_path, KEYSTORE_SOCKET_PATH, namesiz); + + aAddressLength = offsetof(struct sockaddr_un, sun_path) + namesiz; + + return NS_OK; +} + +// |UnixSocketConnector| + +nsresult +KeyStoreConnector::ConvertAddressToString(const struct sockaddr& aAddress, + socklen_t aAddressLength, + nsACString& aAddressString) +{ + MOZ_ASSERT(aAddress.sa_family == AF_UNIX); + + const struct sockaddr_un* un = + reinterpret_cast(&aAddress); + + size_t len = aAddressLength - offsetof(struct sockaddr_un, sun_path); + + aAddressString.Assign(un->sun_path, len); + + return NS_OK; +} + +nsresult +KeyStoreConnector::CreateListenSocket(struct sockaddr* aAddress, + socklen_t* aAddressLength, + int& aListenFd) +{ + ScopedClose fd; + + nsresult rv = CreateSocket(fd.rwget()); + if (NS_FAILED(rv)) { + return rv; + } + rv = SetSocketFlags(fd); + if (NS_FAILED(rv)) { + return rv; + } + if (aAddress && aAddressLength) { + rv = CreateAddress(*aAddress, *aAddressLength); + if (NS_FAILED(rv)) { + return rv; + } + } + + // Allow access for wpa_supplicant (different user, different group) + // + // TODO: Improve this by setting specific user/group for + // wpa_supplicant by calling |fchmod| and |fchown|. + // + chmod(KEYSTORE_SOCKET_PATH, S_IRUSR|S_IWUSR| + S_IRGRP|S_IWGRP| + S_IROTH|S_IWOTH); + + aListenFd = fd.forget(); + + return NS_OK; +} + +nsresult +KeyStoreConnector::AcceptStreamSocket(int aListenFd, + struct sockaddr* aAddress, + socklen_t* aAddressLength, + int& aStreamFd) +{ + ScopedClose fd( + TEMP_FAILURE_RETRY(accept(aListenFd, aAddress, aAddressLength))); + if (fd < 0) { + NS_WARNING("Cannot accept file descriptor!"); + return NS_ERROR_FAILURE; + } + nsresult rv = SetSocketFlags(fd); + if (NS_FAILED(rv)) { + return rv; + } + rv = CheckPermission(fd); + if (NS_FAILED(rv)) { + return rv; + } + + aStreamFd = fd.forget(); + + return NS_OK; +} + +nsresult +KeyStoreConnector::CreateStreamSocket(struct sockaddr* aAddress, + socklen_t* aAddressLength, + int& aStreamFd) +{ + MOZ_CRASH("|KeyStoreConnector| does not support creating stream sockets."); + return NS_ERROR_FAILURE; +} + +// Deprecated + +static const char* KEYSTORE_ALLOWED_USERS[] = { + "root", + "wifi", + NULL +}; + +static bool checkPermission(uid_t uid) +{ + struct passwd *userInfo = getpwuid(uid); + for (const char **user = KEYSTORE_ALLOWED_USERS; *user; user++ ) { + if (!strcmp(*user, userInfo->pw_name)) { + return true; + } + } + + return false; +} + +int +KeyStoreConnector::Create() +{ + MOZ_ASSERT(!NS_IsMainThread()); + + int fd; + + unlink(KEYSTORE_SOCKET_PATH); + + fd = socket(AF_LOCAL, SOCK_STREAM, 0); + + if (fd < 0) { + NS_WARNING("Could not open keystore socket!"); + return -1; + } + + return fd; +} + +bool +KeyStoreConnector::CreateAddr(bool aIsServer, + socklen_t& aAddrSize, + sockaddr_any& aAddr, + const char* aAddress) +{ + // Keystore socket must be server + MOZ_ASSERT(aIsServer); + + aAddr.un.sun_family = AF_LOCAL; + if(strlen(KEYSTORE_SOCKET_PATH) > sizeof(aAddr.un.sun_path)) { + NS_WARNING("Address too long for socket struct!"); + return false; + } + strcpy((char*)&aAddr.un.sun_path, KEYSTORE_SOCKET_PATH); + aAddrSize = strlen(KEYSTORE_SOCKET_PATH) + offsetof(struct sockaddr_un, sun_path) + 1; + + return true; +} + +bool +KeyStoreConnector::SetUp(int aFd) +{ + // Socket permission check. + struct ucred userCred; + socklen_t len = sizeof(struct ucred); + + if (getsockopt(aFd, SOL_SOCKET, SO_PEERCRED, &userCred, &len)) { + return false; + } + + return checkPermission(userCred.uid); +} + +bool +KeyStoreConnector::SetUpListenSocket(int aFd) +{ + // Allow access of wpa_supplicant(different user, differnt group) + chmod(KEYSTORE_SOCKET_PATH, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); + + return true; +} + +void +KeyStoreConnector::GetSocketAddr(const sockaddr_any& aAddr, + nsAString& aAddrStr) +{ + // Unused. + MOZ_CRASH("This should never be called!"); +} + +} +} diff --git a/ipc/keystore/KeyStoreConnector.h b/ipc/keystore/KeyStoreConnector.h new file mode 100644 index 00000000000..31c71986268 --- /dev/null +++ b/ipc/keystore/KeyStoreConnector.h @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set sw=2 ts=2 et ft=cpp: 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/. */ + +#ifndef mozilla_ipc_KeyStoreConnector_h +#define mozilla_ipc_KeyStoreConnector_h + +#include "mozilla/ipc/UnixSocketConnector.h" + +namespace mozilla { +namespace ipc { + +class KeyStoreConnector final : public UnixSocketConnector +{ +public: + KeyStoreConnector(const char** const aAllowedUsers); + ~KeyStoreConnector(); + + // Methods for |UnixSocketConnector| + // + + nsresult ConvertAddressToString(const struct sockaddr& aAddress, + socklen_t aAddressLength, + nsACString& aAddressString) override; + + nsresult CreateListenSocket(struct sockaddr* aAddress, + socklen_t* aAddressLength, + int& aListenFd) override; + + nsresult AcceptStreamSocket(int aListenFd, + struct sockaddr* aAddress, + socklen_t* aAddressLength, + int& aStreamFd) override; + + nsresult CreateStreamSocket(struct sockaddr* aAddress, + socklen_t* aAddressLength, + int& aStreamFd) override; + + // Deprecated + + int Create(); + bool CreateAddr(bool aIsServer, + socklen_t& aAddrSize, + sockaddr_any& aAddr, + const char* aAddress); + bool SetUp(int aFd); + bool SetUpListenSocket(int aFd); + void GetSocketAddr(const sockaddr_any& aAddr, + nsAString& aAddrStr); + +private: + nsresult CreateSocket(int& aFd) const; + nsresult SetSocketFlags(int aFd) const; + nsresult CheckPermission(int aFd) const; + nsresult CreateAddress(struct sockaddr& aAddress, + socklen_t& aAddressLength) const; + + const char** const mAllowedUsers; +}; + +} +} + +#endif diff --git a/ipc/keystore/moz.build b/ipc/keystore/moz.build index 78af00cb211..62005f33aa8 100644 --- a/ipc/keystore/moz.build +++ b/ipc/keystore/moz.build @@ -9,7 +9,8 @@ EXPORTS.mozilla.ipc += [ ] SOURCES += [ - 'KeyStore.cpp' + 'KeyStore.cpp', + 'KeyStoreConnector.cpp' ] FAIL_ON_WARNINGS = True From 22475e33487e5ed847ee5cbf4bae343e20b491c4 Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Tue, 19 May 2015 13:28:46 +0200 Subject: [PATCH 31/39] Bug 1161020: Implement new socket-connector interface for Bluetooth daemon socket, r=shuang This patch moves |BluetoothDaemonSocketConnector| into its own file, renames it to |BluetoothDaemonConnector| and implements the new socket- connector interface. --- .../bluedroid/BluetoothDaemonConnector.cpp | 237 ++++++++++++++++++ .../bluedroid/BluetoothDaemonConnector.h | 66 +++++ .../bluedroid/BluetoothDaemonInterface.cpp | 76 +----- dom/bluetooth/moz.build | 1 + 4 files changed, 306 insertions(+), 74 deletions(-) create mode 100644 dom/bluetooth/bluedroid/BluetoothDaemonConnector.cpp create mode 100644 dom/bluetooth/bluedroid/BluetoothDaemonConnector.h diff --git a/dom/bluetooth/bluedroid/BluetoothDaemonConnector.cpp b/dom/bluetooth/bluedroid/BluetoothDaemonConnector.cpp new file mode 100644 index 00000000000..6942e255b3d --- /dev/null +++ b/dom/bluetooth/bluedroid/BluetoothDaemonConnector.cpp @@ -0,0 +1,237 @@ +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ +/* vim: set ts=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 "BluetoothDaemonConnector.h" +#include +#include "nsThreadUtils.h" + +BEGIN_BLUETOOTH_NAMESPACE + +BluetoothDaemonConnector::BluetoothDaemonConnector( + const nsACString& aSocketName) + : mSocketName(aSocketName) +{ } + +BluetoothDaemonConnector::~BluetoothDaemonConnector() +{ } + +nsresult +BluetoothDaemonConnector::CreateSocket(int& aFd) const +{ + aFd = socket(AF_UNIX, SOCK_SEQPACKET, 0); + if (aFd < 0) { + BT_WARNING("Could not open Bluetooth daemon socket!"); + return NS_ERROR_FAILURE; + } + + return NS_OK; +} + +nsresult +BluetoothDaemonConnector::SetSocketFlags(int aFd) const +{ + static const int sReuseAddress = 1; + + // Set close-on-exec bit. + int flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFD)); + if (flags < 0) { + return NS_ERROR_FAILURE; + } + flags |= FD_CLOEXEC; + int res = TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFD, flags)); + if (res < 0) { + return NS_ERROR_FAILURE; + } + + // Set non-blocking status flag. + flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFL)); + if (flags < 0) { + return NS_ERROR_FAILURE; + } + flags |= O_NONBLOCK; + res = TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFL, flags)); + if (res < 0) { + return NS_ERROR_FAILURE; + } + + // Set socket addr to be reused even if kernel is still waiting to close. + res = setsockopt(aFd, SOL_SOCKET, SO_REUSEADDR, &sReuseAddress, + sizeof(sReuseAddress)); + if (res < 0) { + return NS_ERROR_FAILURE; + } + + return NS_OK; +} + +nsresult +BluetoothDaemonConnector::CreateAddress(struct sockaddr& aAddress, + socklen_t& aAddressLength) const +{ + static const size_t sNameOffset = 1; + + struct sockaddr_un* address = + reinterpret_cast(&aAddress); + + size_t namesiz = mSocketName.Length() + 1; // include trailing '\0' + + if (NS_WARN_IF((sNameOffset + namesiz) > sizeof(address->sun_path))) { + return NS_ERROR_FAILURE; + } + + address->sun_family = AF_UNIX; + memset(address->sun_path, '\0', sNameOffset); // abstract socket + memcpy(address->sun_path + sNameOffset, mSocketName.get(), namesiz); + + aAddressLength = + offsetof(struct sockaddr_un, sun_path) + sNameOffset + namesiz; + + return NS_OK; +} + +// |UnixSocketConnector| + +nsresult +BluetoothDaemonConnector::ConvertAddressToString( + const struct sockaddr& aAddress, socklen_t aAddressLength, + nsACString& aAddressString) +{ + MOZ_ASSERT(aAddress.sa_family == AF_UNIX); + + const struct sockaddr_un* un = + reinterpret_cast(&aAddress); + + size_t len = aAddressLength - offsetof(struct sockaddr_un, sun_path); + + aAddressString.Assign(un->sun_path, len); + + return NS_OK; +} + +nsresult +BluetoothDaemonConnector::CreateListenSocket(struct sockaddr* aAddress, + socklen_t* aAddressLength, + int& aListenFd) +{ + ScopedClose fd; + + nsresult rv = CreateSocket(fd.rwget()); + if (NS_FAILED(rv)) { + return rv; + } + rv = SetSocketFlags(fd); + if (NS_FAILED(rv)) { + return rv; + } + if (aAddress && aAddressLength) { + rv = CreateAddress(*aAddress, *aAddressLength); + if (NS_FAILED(rv)) { + return rv; + } + } + + aListenFd = fd.forget(); + + return NS_OK; +} + +nsresult +BluetoothDaemonConnector::AcceptStreamSocket(int aListenFd, + struct sockaddr* aAddress, + socklen_t* aAddressLength, + int& aStreamFd) +{ + ScopedClose fd( + TEMP_FAILURE_RETRY(accept(aListenFd, aAddress, aAddressLength))); + if (fd < 0) { + NS_WARNING("Cannot accept file descriptor!"); + return NS_ERROR_FAILURE; + } + nsresult rv = SetSocketFlags(fd); + if (NS_FAILED(rv)) { + return rv; + } + + aStreamFd = fd.forget(); + + return NS_OK; +} + +nsresult +BluetoothDaemonConnector::CreateStreamSocket(struct sockaddr* aAddress, + socklen_t* aAddressLength, + int& aStreamFd) +{ + MOZ_CRASH("|BluetoothDaemonConnector| does not support " + "creating stream sockets."); + return NS_ERROR_ABORT; +} + +// Deprecated + +int +BluetoothDaemonConnector::Create() +{ + MOZ_ASSERT(!NS_IsMainThread()); + + int fd = socket(AF_UNIX, SOCK_SEQPACKET, 0); + if (fd < 0) { + BT_WARNING("Could not open socket!"); + return -1; + } + return fd; +} + +bool +BluetoothDaemonConnector::CreateAddr(bool aIsServer, + socklen_t& aAddrSize, + mozilla::ipc::sockaddr_any& aAddr, + const char* aAddress) +{ + static const size_t sNameOffset = 1; + + size_t namesiz = mSocketName.Length() + 1; /* include trailing '\0' */ + + if ((sNameOffset + namesiz) > sizeof(aAddr.un.sun_path)) { + BT_WARNING("Address too long for socket struct!"); + return false; + } + + memset(aAddr.un.sun_path, '\0', sNameOffset); // abstract socket + memcpy(aAddr.un.sun_path + sNameOffset, mSocketName.get(), namesiz); + aAddr.un.sun_family = AF_UNIX; + + aAddrSize = offsetof(struct sockaddr_un, sun_path) + sNameOffset + namesiz; + + return true; +} + +bool +BluetoothDaemonConnector::SetUp(int aFd) +{ + if (TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFL, O_NONBLOCK)) < 0) { + BT_WARNING("Failed to set non-blocking I/O."); + return false; + } + return true; +} + +bool +BluetoothDaemonConnector::SetUpListenSocket(int aFd) +{ + return true; +} + +void +BluetoothDaemonConnector::GetSocketAddr( + const mozilla::ipc::sockaddr_any& aAddr, nsAString& aAddrStr) +{ + // Unused. + MOZ_CRASH("This should never be called!"); +} + +END_BLUETOOTH_NAMESPACE diff --git a/dom/bluetooth/bluedroid/BluetoothDaemonConnector.h b/dom/bluetooth/bluedroid/BluetoothDaemonConnector.h new file mode 100644 index 00000000000..c7105a5e9af --- /dev/null +++ b/dom/bluetooth/bluedroid/BluetoothDaemonConnector.h @@ -0,0 +1,66 @@ +/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ +/* vim: set ts=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/. */ + +#ifndef mozilla_dom_bluetooth_bluedroid_bluetoothdaemonconnector_h +#define mozilla_dom_bluetooth_bluedroid_bluetoothdaemonconnector_h + +#include "mozilla/dom/bluetooth/BluetoothCommon.h" +#include "mozilla/ipc/UnixSocketConnector.h" + +BEGIN_BLUETOOTH_NAMESPACE + +class BluetoothDaemonConnector final + : public mozilla::ipc::UnixSocketConnector +{ +public: + BluetoothDaemonConnector(const nsACString& aSocketName); + ~BluetoothDaemonConnector(); + + // Methods for |UnixSocketConnector| + // + + nsresult ConvertAddressToString(const struct sockaddr& aAddress, + socklen_t aAddressLength, + nsACString& aAddressString) override; + + nsresult CreateListenSocket(struct sockaddr* aAddress, + socklen_t* aAddressLength, + int& aListenFd) override; + + nsresult AcceptStreamSocket(int aListenFd, + struct sockaddr* aAddress, + socklen_t* aAddressLen, + int& aStreamFd) override; + + nsresult CreateStreamSocket(struct sockaddr* aAddress, + socklen_t* aAddressLength, + int& aStreamFd) override; + + // Deprecated + + int Create() override; + bool CreateAddr(bool aIsServer, + socklen_t& aAddrSize, + mozilla::ipc::sockaddr_any& aAddr, + const char* aAddress) override; + bool SetUp(int aFd) override; + bool SetUpListenSocket(int aFd) override; + void GetSocketAddr(const mozilla::ipc::sockaddr_any& aAddr, + nsAString& aAddrStr) override; + +private: + nsresult CreateSocket(int& aFd) const; + nsresult SetSocketFlags(int aFd) const; + nsresult CreateAddress(struct sockaddr& aAddress, + socklen_t& aAddressLength) const; + + nsCString mSocketName; +}; + +END_BLUETOOTH_NAMESPACE + +#endif diff --git a/dom/bluetooth/bluedroid/BluetoothDaemonInterface.cpp b/dom/bluetooth/bluedroid/BluetoothDaemonInterface.cpp index 91046bd744c..5b20efd8117 100644 --- a/dom/bluetooth/bluedroid/BluetoothDaemonInterface.cpp +++ b/dom/bluetooth/bluedroid/BluetoothDaemonInterface.cpp @@ -10,13 +10,13 @@ #include #include "BluetoothDaemonA2dpInterface.h" #include "BluetoothDaemonAvrcpInterface.h" +#include "BluetoothDaemonConnector.h" #include "BluetoothDaemonHandsfreeInterface.h" #include "BluetoothDaemonHelpers.h" #include "BluetoothDaemonSetupInterface.h" #include "BluetoothDaemonSocketInterface.h" #include "BluetoothInterfaceHelpers.h" #include "mozilla/ipc/ListenSocket.h" -#include "mozilla/ipc/UnixSocketConnector.h" #include "mozilla/unused.h" #include "prrng.h" @@ -2018,78 +2018,6 @@ BluetoothDaemonInterface::OnDisconnect(enum Channel aChannel) } } -class BluetoothDaemonSocketConnector final - : public mozilla::ipc::UnixSocketConnector -{ -public: - BluetoothDaemonSocketConnector(const nsACString& aSocketName) - : mSocketName(aSocketName) - { } - - int - Create() override - { - MOZ_ASSERT(!NS_IsMainThread()); - - int fd = socket(AF_UNIX, SOCK_SEQPACKET, 0); - if (fd < 0) { - BT_WARNING("Could not open socket!"); - return -1; - } - return fd; - } - - bool - CreateAddr(bool aIsServer, - socklen_t& aAddrSize, - sockaddr_any& aAddr, - const char* aAddress) override - { - static const size_t sNameOffset = 1; - - size_t namesiz = mSocketName.Length() + 1; /* include trailing '\0' */ - - if ((sNameOffset + namesiz) > sizeof(aAddr.un.sun_path)) { - BT_WARNING("Address too long for socket struct!"); - return false; - } - - memset(aAddr.un.sun_path, '\0', sNameOffset); // abstract socket - memcpy(aAddr.un.sun_path + sNameOffset, mSocketName.get(), namesiz); - aAddr.un.sun_family = AF_UNIX; - - aAddrSize = offsetof(struct sockaddr_un, sun_path) + sNameOffset + namesiz; - - return true; - } - - bool - SetUp(int aFd) override - { - if (TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFL, O_NONBLOCK)) < 0) { - BT_WARNING("Failed to set non-blocking I/O."); - return false; - } - return true; - } - - bool - SetUpListenSocket(int aFd) override - { - return true; - } - - void - GetSocketAddr(const sockaddr_any& aAddr, nsAString& aAddrStr) override - { - // Unused. - MOZ_CRASH("This should never be called!"); - } - -private: - nsCString mSocketName; -}; - nsresult BluetoothDaemonInterface::CreateRandomAddressString( const nsACString& aPrefix, unsigned long aPostfixLength, @@ -2209,7 +2137,7 @@ BluetoothDaemonInterface::Init( } bool success = mListenSocket->Listen( - new BluetoothDaemonSocketConnector(mListenSocketName), mCmdChannel); + new BluetoothDaemonConnector(mListenSocketName), mCmdChannel); if (!success) { OnConnectError(CMD_CHANNEL); return; diff --git a/dom/bluetooth/moz.build b/dom/bluetooth/moz.build index 78a84e766aa..538077133f0 100644 --- a/dom/bluetooth/moz.build +++ b/dom/bluetooth/moz.build @@ -94,6 +94,7 @@ if CONFIG['MOZ_B2G_BT']: 'bluedroid/BluetoothAvrcpHALInterface.cpp', 'bluedroid/BluetoothDaemonA2dpInterface.cpp', 'bluedroid/BluetoothDaemonAvrcpInterface.cpp', + 'bluedroid/BluetoothDaemonConnector.cpp', 'bluedroid/BluetoothDaemonHandsfreeInterface.cpp', 'bluedroid/BluetoothDaemonHelpers.cpp', 'bluedroid/BluetoothDaemonInterface.cpp', From 64ac4538b3fe09dbf9afdf1fda472cf3d311529a Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Tue, 19 May 2015 13:28:46 +0200 Subject: [PATCH 32/39] Bug 1161020: Implement new socket-connector interface for Bluetooth sockets, r=btian --- dom/bluetooth/bluez/BluetoothSocket.cpp | 6 +- .../bluez/BluetoothUnixSocketConnector.cpp | 395 +++++++++++++++++- .../bluez/BluetoothUnixSocketConnector.h | 45 +- 3 files changed, 418 insertions(+), 28 deletions(-) diff --git a/dom/bluetooth/bluez/BluetoothSocket.cpp b/dom/bluetooth/bluez/BluetoothSocket.cpp index 27b5d50d32f..2058c88195a 100644 --- a/dom/bluetooth/bluez/BluetoothSocket.cpp +++ b/dom/bluetooth/bluez/BluetoothSocket.cpp @@ -646,7 +646,8 @@ BluetoothSocket::Connect(const nsAString& aDeviceAddress, MOZ_ASSERT(!aDeviceAddress.IsEmpty()); nsAutoPtr c( - new BluetoothUnixSocketConnector(mType, aChannel, mAuth, mEncrypt)); + new BluetoothUnixSocketConnector(NS_ConvertUTF16toUTF8(aDeviceAddress), + mType, aChannel, mAuth, mEncrypt)); if (!ConnectSocket(c.forget(), NS_ConvertUTF16toUTF8(aDeviceAddress).BeginReading())) { @@ -668,7 +669,8 @@ BluetoothSocket::Listen(const nsAString& aServiceName, MOZ_ASSERT(NS_IsMainThread()); nsAutoPtr c( - new BluetoothUnixSocketConnector(mType, aChannel, mAuth, mEncrypt)); + new BluetoothUnixSocketConnector(NS_LITERAL_CSTRING(BLUETOOTH_ADDRESS_NONE), + mType, aChannel, mAuth, mEncrypt)); if (!ListenSocket(c.forget())) { nsAutoString addr; diff --git a/dom/bluetooth/bluez/BluetoothUnixSocketConnector.cpp b/dom/bluetooth/bluez/BluetoothUnixSocketConnector.cpp index bb980dec314..449d2c9dc0a 100644 --- a/dom/bluetooth/bluez/BluetoothUnixSocketConnector.cpp +++ b/dom/bluetooth/bluez/BluetoothUnixSocketConnector.cpp @@ -1,5 +1,6 @@ /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */ /* vim: set ts=2 et sw=2 tw=80: */ + /* * Copyright 2009, The Android Open Source Project * @@ -15,29 +16,26 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * NOTE: Due to being based on the dbus compatibility layer for - * android's bluetooth implementation, this file is licensed under the - * apache license instead of MPL. - * + * NOTE: Due to being based on the D-Bus compatibility layer for + * Android's Bluetooth implementation, this file is licensed under the + * Apache License instead of MPL. */ -#include -#include -#include -#include - -#include -#ifdef MOZ_B2G_BT_BLUEZ +#include "BluetoothUnixSocketConnector.h" #include #include #include #include -#endif -#include "BluetoothUnixSocketConnector.h" -#include "nsThreadUtils.h" +#include +#include +#include +#include +#include +#include "nsThreadUtils.h" // For NS_IsMainThread. using namespace mozilla::ipc; -USING_BLUETOOTH_NAMESPACE + +BEGIN_BLUETOOTH_NAMESPACE static const int RFCOMM_SO_SNDBUF = 70 * 1024; // 70 KB send buffer static const int L2CAP_SO_SNDBUF = 400 * 1024; // 400 KB send buffer @@ -67,16 +65,373 @@ void get_bdaddr_as_string(const bdaddr_t *ba, char *str) { #endif BluetoothUnixSocketConnector::BluetoothUnixSocketConnector( + const nsACString& aAddressString, BluetoothSocketType aType, int aChannel, bool aAuth, - bool aEncrypt) : mType(aType) - , mChannel(aChannel) - , mAuth(aAuth) - , mEncrypt(aEncrypt) + bool aEncrypt) + : mAddressString(aAddressString) + , mType(aType) + , mChannel(aChannel) + , mAuth(aAuth) + , mEncrypt(aEncrypt) +{ } + +BluetoothUnixSocketConnector::~BluetoothUnixSocketConnector() +{ } + +nsresult +BluetoothUnixSocketConnector::CreateSocket(int& aFd) const { + static const int sType[] = { + [0] = 0, + [BluetoothSocketType::RFCOMM] = SOCK_STREAM, + [BluetoothSocketType::SCO] = SOCK_SEQPACKET, + [BluetoothSocketType::L2CAP] = SOCK_SEQPACKET, + [BluetoothSocketType::EL2CAP] = SOCK_STREAM + }; + static const int sProtocol[] = { + [0] = 0, + [BluetoothSocketType::RFCOMM] = BTPROTO_RFCOMM, + [BluetoothSocketType::SCO] = BTPROTO_SCO, + [BluetoothSocketType::L2CAP] = BTPROTO_L2CAP, + [BluetoothSocketType::EL2CAP] = BTPROTO_L2CAP + }; + + MOZ_ASSERT(mType < MOZ_ARRAY_LENGTH(sType)); + MOZ_ASSERT(mType < MOZ_ARRAY_LENGTH(sProtocol)); + + aFd = socket(AF_BLUETOOTH, sType[mType], sProtocol[mType]); + if (aFd < 0) { + BT_LOGR("Could not open Bluetooth socket!"); + return NS_ERROR_FAILURE; + } + + return NS_OK; } +nsresult +BluetoothUnixSocketConnector::SetSocketFlags(int aFd) const +{ + static const int sReuseAddress = 1; + + // Set close-on-exec bit. + int flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFD)); + if (flags < 0) { + return NS_ERROR_FAILURE; + } + flags |= FD_CLOEXEC; + int res = TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFD, flags)); + if (res < 0) { + return NS_ERROR_FAILURE; + } + + // Set non-blocking status flag. + flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFL)); + if (flags < 0) { + return NS_ERROR_FAILURE; + } + flags |= O_NONBLOCK; + res = TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFL, flags)); + if (res < 0) { + return NS_ERROR_FAILURE; + } + + // Set socket addr to be reused even if kernel is still waiting to close. + res = setsockopt(aFd, SOL_SOCKET, SO_REUSEADDR, &sReuseAddress, + sizeof(sReuseAddress)); + if (res < 0) { + return NS_ERROR_FAILURE; + } + + int lm; + + switch (mType) { + case BluetoothSocketType::RFCOMM: + lm |= mAuth ? RFCOMM_LM_AUTH : 0; + lm |= mEncrypt ? RFCOMM_LM_ENCRYPT : 0; + break; + case BluetoothSocketType::L2CAP: + case BluetoothSocketType::EL2CAP: + lm |= mAuth ? L2CAP_LM_AUTH : 0; + lm |= mEncrypt ? L2CAP_LM_ENCRYPT : 0; + break; + default: + // kernel does not yet support LM for SCO + lm = 0; + break; + } + + if (lm) { + static const int sLevel[] = { + [0] = 0, + [BluetoothSocketType::RFCOMM] = SOL_RFCOMM, + [BluetoothSocketType::SCO] = 0, + [BluetoothSocketType::L2CAP] = SOL_L2CAP, + [BluetoothSocketType::EL2CAP] = SOL_L2CAP + }; + static const int sOptname[] = { + [0] = 0, + [BluetoothSocketType::RFCOMM] = RFCOMM_LM, + [BluetoothSocketType::SCO] = 0, + [BluetoothSocketType::L2CAP] = L2CAP_LM, + [BluetoothSocketType::EL2CAP] = L2CAP_LM + }; + + MOZ_ASSERT(mType < MOZ_ARRAY_LENGTH(sLevel)); + MOZ_ASSERT(mType < MOZ_ARRAY_LENGTH(sOptname)); + + if (setsockopt(aFd, sLevel[mType], sOptname[mType], &lm, sizeof(lm)) < 0) { + BT_LOGR("setsockopt(RFCOMM_LM) failed, throwing"); + return NS_ERROR_FAILURE; + } + } + + if (mType == BluetoothSocketType::RFCOMM) { + + /* Setting RFCOMM socket options */ + + int sndbuf = RFCOMM_SO_SNDBUF; + if (setsockopt(aFd, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof(sndbuf))) { + BT_WARNING("setsockopt(SO_SNDBUF) failed, throwing"); + return NS_ERROR_FAILURE; + } + } + + if (mType == BluetoothSocketType::L2CAP || + mType == BluetoothSocketType::EL2CAP) { + + /* Setting L2CAP/EL2CAP socket options */ + + struct l2cap_options opts; + socklen_t optlen = sizeof(opts); + int res = getsockopt(aFd, SOL_L2CAP, L2CAP_OPTIONS, &opts, &optlen); + if (!res) { + /* setting MTU for [E]L2CAP */ + opts.omtu = opts.imtu = L2CAP_MAX_MTU; + + /* Enable ERTM for [E]L2CAP */ + if (mType == BluetoothSocketType::EL2CAP) { + opts.flush_to = 0xffff; /* infinite */ + opts.mode = L2CAP_MODE_ERTM; + opts.fcs = 1; + opts.txwin_size = 64; + opts.max_tx = 10; + } + + setsockopt(aFd, SOL_L2CAP, L2CAP_OPTIONS, &opts, optlen); + } + + if (mType == BluetoothSocketType::EL2CAP) { + + /* Set larger SNDBUF and RCVBUF for EL2CAP connections */ + + int sndbuf = L2CAP_SO_SNDBUF; + if (setsockopt(aFd, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof(sndbuf)) < 0) { + BT_LOGR("setsockopt(SO_SNDBUF) failed, throwing"); + return NS_ERROR_FAILURE; + } + + int rcvbuf = L2CAP_SO_RCVBUF; + if (setsockopt(aFd, SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof(rcvbuf)) < 0) { + BT_LOGR("setsockopt(SO_RCVBUF) failed, throwing"); + return NS_ERROR_FAILURE; + } + } + } + + return NS_OK; +} + +nsresult +BluetoothUnixSocketConnector::CreateAddress(struct sockaddr& aAddress, + socklen_t& aAddressLength) const +{ + switch (mType) { + case BluetoothSocketType::RFCOMM: { + struct sockaddr_rc* rc = + reinterpret_cast(&aAddress); + rc->rc_family = AF_BLUETOOTH; + nsresult rv = ConvertAddressString(mAddressString.get(), + rc->rc_bdaddr); + if (NS_FAILED(rv)) { + return rv; + } + rc->rc_channel = mChannel; + aAddressLength = sizeof(*rc); + } + break; + case BluetoothSocketType::L2CAP: + case BluetoothSocketType::EL2CAP: { + struct sockaddr_l2* l2 = + reinterpret_cast(&aAddress); + l2->l2_family = AF_BLUETOOTH; + l2->l2_psm = mChannel; + nsresult rv = ConvertAddressString(mAddressString.get(), + l2->l2_bdaddr); + if (NS_FAILED(rv)) { + return rv; + } + l2->l2_cid = 0; + aAddressLength = sizeof(*l2); + } + break; + case BluetoothSocketType::SCO: { + struct sockaddr_sco* sco = + reinterpret_cast(&aAddress); + sco->sco_family = AF_BLUETOOTH; + nsresult rv = ConvertAddressString(mAddressString.get(), + sco->sco_bdaddr); + if (NS_FAILED(rv)) { + return rv; + } + sco->sco_pkt_type = 0; + aAddressLength = sizeof(*sco); + } + break; + default: + MOZ_CRASH("Socket type unknown!"); + return NS_ERROR_ABORT; + } + + return NS_OK; +} + +nsresult +BluetoothUnixSocketConnector::ConvertAddressString(const char* aAddressString, + bdaddr_t& aAddress) +{ + char* d = reinterpret_cast(aAddress.b) + 5; + + for (size_t i = 0; i < MOZ_ARRAY_LENGTH(aAddress.b); ++i) { + char* endp; + *d-- = strtoul(aAddressString, &endp, 16); + MOZ_ASSERT(!(*endp != ':' && i != 5)); + aAddressString = endp + 1; + } + return NS_OK; +} + +// |UnixSocketConnector| + +nsresult +BluetoothUnixSocketConnector::ConvertAddressToString( + const struct sockaddr& aAddress, socklen_t aAddressLength, + nsACString& aAddressString) +{ + MOZ_ASSERT(aAddress.sa_family == AF_BLUETOOTH); + + const uint8_t* b; + + switch (mType) { + case BluetoothSocketType::RFCOMM: { + const struct sockaddr_rc* rc = + reinterpret_cast(&aAddress); + b = rc->rc_bdaddr.b; + } + break; + case BluetoothSocketType::SCO: { + const struct sockaddr_sco* sco = + reinterpret_cast(&aAddress); + b = sco->sco_bdaddr.b; + } + break; + case BluetoothSocketType::L2CAP: + case BluetoothSocketType::EL2CAP: { + const struct sockaddr_l2* l2 = + reinterpret_cast(&aAddress); + b = l2->l2_bdaddr.b; + } + break; + } + + char str[32]; + snprintf(str, sizeof(str), "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", + b[5], b[4], b[3], b[2], b[1], b[0]); + + aAddressString.Assign(str); + + return NS_OK; +} + +nsresult +BluetoothUnixSocketConnector::CreateListenSocket(struct sockaddr* aAddress, + socklen_t* aAddressLength, + int& aListenFd) +{ + ScopedClose fd; + + nsresult rv = CreateSocket(fd.rwget()); + if (NS_FAILED(rv)) { + return rv; + } + rv = SetSocketFlags(fd); + if (NS_FAILED(rv)) { + return rv; + } + if (aAddress && aAddressLength) { + rv = CreateAddress(*aAddress, *aAddressLength); + if (NS_FAILED(rv)) { + return rv; + } + } + + aListenFd = fd.forget(); + + return NS_OK; +} + +nsresult +BluetoothUnixSocketConnector::AcceptStreamSocket(int aListenFd, + struct sockaddr* aAddress, + socklen_t* aAddressLength, + int& aStreamFd) +{ + ScopedClose fd( + TEMP_FAILURE_RETRY(accept(aListenFd, aAddress, aAddressLength))); + if (fd < 0) { + NS_WARNING("Cannot accept file descriptor!"); + return NS_ERROR_FAILURE; + } + nsresult rv = SetSocketFlags(fd); + if (NS_FAILED(rv)) { + return rv; + } + + aStreamFd = fd.forget(); + + return NS_OK; +} + +nsresult +BluetoothUnixSocketConnector::CreateStreamSocket(struct sockaddr* aAddress, + socklen_t* aAddressLength, + int& aStreamFd) +{ + ScopedClose fd; + + nsresult rv = CreateSocket(fd.rwget()); + if (NS_FAILED(rv)) { + return rv; + } + rv = SetSocketFlags(fd); + if (NS_FAILED(rv)) { + return rv; + } + if (aAddress && aAddressLength) { + rv = CreateAddress(*aAddress, *aAddressLength); + if (NS_FAILED(rv)) { + return rv; + } + } + + aStreamFd = fd.forget(); + + return NS_OK; +} + +// Deprecated + bool BluetoothUnixSocketConnector::SetUp(int aFd) { @@ -283,3 +638,5 @@ BluetoothUnixSocketConnector::GetSocketAddr(const sockaddr_any& aAddr, aAddrStr.AssignASCII(addr); #endif } + +END_BLUETOOTH_NAMESPACE diff --git a/dom/bluetooth/bluez/BluetoothUnixSocketConnector.h b/dom/bluetooth/bluez/BluetoothUnixSocketConnector.h index d793f470651..88b225ac554 100644 --- a/dom/bluetooth/bluez/BluetoothUnixSocketConnector.h +++ b/dom/bluetooth/bluez/BluetoothUnixSocketConnector.h @@ -8,18 +8,41 @@ #define mozilla_dom_bluetooth_BluetoothUnixSocketConnector_h #include "BluetoothCommon.h" -#include -#include +#include "mozilla/ipc/UnixSocketConnector.h" BEGIN_BLUETOOTH_NAMESPACE -class BluetoothUnixSocketConnector : public mozilla::ipc::UnixSocketConnector +class BluetoothUnixSocketConnector final + : public mozilla::ipc::UnixSocketConnector { public: - BluetoothUnixSocketConnector(BluetoothSocketType aType, int aChannel, - bool aAuth, bool aEncrypt); - virtual ~BluetoothUnixSocketConnector() - {} + BluetoothUnixSocketConnector(const nsACString& aAddressString, + BluetoothSocketType aType, + int aChannel, bool aAuth, bool aEncrypt); + ~BluetoothUnixSocketConnector(); + + // Methods for |UnixSocketConnector| + // + + nsresult ConvertAddressToString(const struct sockaddr& aAddress, + socklen_t aAddressLength, + nsACString& aAddressString) override; + + nsresult CreateListenSocket(struct sockaddr* aAddress, + socklen_t* aAddressLength, + int& aListenFd) override; + + nsresult AcceptStreamSocket(int aListenFd, + struct sockaddr* aAddress, + socklen_t* aAddressLen, + int& aStreamFd) override; + + nsresult CreateStreamSocket(struct sockaddr* aAddress, + socklen_t* aAddressLength, + int& aStreamFd) override; + + // Deprecated + virtual int Create() override; virtual bool CreateAddr(bool aIsServer, socklen_t& aAddrSize, @@ -31,6 +54,14 @@ public: nsAString& aAddrStr) override; private: + nsresult CreateSocket(int& aFd) const; + nsresult SetSocketFlags(int aFd) const; + nsresult CreateAddress(struct sockaddr& aAddress, + socklen_t& aAddressLength) const; + static nsresult ConvertAddressString(const char* aAddressString, + bdaddr_t& aAddress); + + nsCString mAddressString; BluetoothSocketType mType; int mChannel; bool mAuth; From 1097a756a32a83064adff3591dc12bb59b4bcafa Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Tue, 19 May 2015 13:28:46 +0200 Subject: [PATCH 33/39] Bug 1161020: Use new socket-connector interface in socket classes, r=kmachulis This patch converts the socket I/O classes to use the new interface of the socket-connector classes. All sockets are now created and set up by a socket connector. --- dom/bluetooth/bluez/BluetoothSocket.cpp | 157 ++++++++---------------- ipc/unixsocket/ListenSocket.cpp | 128 ++++++------------- ipc/unixsocket/StreamSocket.cpp | 134 ++++++-------------- 3 files changed, 124 insertions(+), 295 deletions(-) diff --git a/dom/bluetooth/bluez/BluetoothSocket.cpp b/dom/bluetooth/bluez/BluetoothSocket.cpp index 2058c88195a..02f573de6d9 100644 --- a/dom/bluetooth/bluez/BluetoothSocket.cpp +++ b/dom/bluetooth/bluez/BluetoothSocket.cpp @@ -30,11 +30,10 @@ class BluetoothSocket::BluetoothSocketIO final public: BluetoothSocketIO(MessageLoop* mIOLoop, BluetoothSocket* aConsumer, - UnixSocketConnector* aConnector, - const nsACString& aAddress); + UnixSocketConnector* aConnector); ~BluetoothSocketIO(); - void GetSocketAddr(nsAString& aAddrStr) const; + void GetSocketAddr(nsAString& aAddrStr) const; BluetoothSocket* GetBluetoothSocket(); DataSocket* GetDataSocket(); @@ -94,9 +93,6 @@ private: void FireSocketError(); - // Set up flags on file descriptor. - static bool SetSocketFlags(int aFd); - /** * Consumer pointer. Non-thread safe RefPtr, so should only be manipulated * directly from main thread. All non-main-thread accesses should happen with @@ -115,19 +111,14 @@ private: bool mShuttingDownOnIOThread; /** - * Address we are connecting to, assuming we are creating a client connection. + * Number of valid bytes in |mAddress| */ - nsCString mAddress; + socklen_t mAddressLength; /** - * Size of the socket address struct + * Address structure of the socket currently in use */ - socklen_t mAddrSize; - - /** - * Address struct of the socket currently in use - */ - sockaddr_any mAddr; + struct sockaddr_storage mAddress; /** * Task member for delayed connect task. Should only be access on main thread. @@ -143,13 +134,12 @@ private: BluetoothSocket::BluetoothSocketIO::BluetoothSocketIO( MessageLoop* mIOLoop, BluetoothSocket* aConsumer, - UnixSocketConnector* aConnector, - const nsACString& aAddress) + UnixSocketConnector* aConnector) : UnixSocketWatcher(mIOLoop) , mConsumer(aConsumer) , mConnector(aConnector) , mShuttingDownOnIOThread(false) - , mAddress(aAddress) + , mAddressLength(0) , mDelayedConnectTask(nullptr) { MOZ_ASSERT(mConsumer); @@ -170,7 +160,17 @@ BluetoothSocket::BluetoothSocketIO::GetSocketAddr(nsAString& aAddrStr) const aAddrStr.Truncate(); return; } - mConnector->GetSocketAddr(mAddr, aAddrStr); + + nsCString addressString; + nsresult rv = mConnector->ConvertAddressToString( + *reinterpret_cast(&mAddress), mAddressLength, + addressString); + if (NS_FAILED(rv)) { + aAddrStr.Truncate(); + return; + } + + aAddrStr.Assign(NS_ConvertUTF8toUTF16(addressString)); } BluetoothSocket* @@ -221,34 +221,20 @@ BluetoothSocket::BluetoothSocketIO::Listen() MOZ_ASSERT(mConnector); if (!IsOpen()) { - int fd = mConnector->Create(); - if (fd < 0) { - NS_WARNING("Cannot create socket fd!"); - FireSocketError(); - return; - } - if (!SetSocketFlags(fd)) { - NS_WARNING("Cannot set socket flags!"); - FireSocketError(); - return; - } - if (!mConnector->SetUpListenSocket(fd)) { - NS_WARNING("Could not set up listen socket!"); - FireSocketError(); - return; - } - // This will set things we don't particularly care about, but it will hand - // back the correct structure size which is what we do care about. - if (!mConnector->CreateAddr(true, mAddrSize, mAddr, nullptr)) { - NS_WARNING("Cannot create socket address!"); + mAddressLength = sizeof(mAddress); + + int fd; + nsresult rv = mConnector->CreateListenSocket( + reinterpret_cast(&mAddress), &mAddressLength, fd); + if (NS_WARN_IF(NS_FAILED(rv))) { FireSocketError(); return; } SetFd(fd); // calls OnListening on success, or OnError otherwise - nsresult rv = UnixSocketWatcher::Listen( - reinterpret_cast(&mAddr), mAddrSize); + rv = UnixSocketWatcher::Listen( + reinterpret_cast(&mAddress), mAddressLength); NS_WARN_IF(NS_FAILED(rv)); } } @@ -260,24 +246,12 @@ BluetoothSocket::BluetoothSocketIO::Connect() MOZ_ASSERT(mConnector); if (!IsOpen()) { - int fd = mConnector->Create(); - if (fd < 0) { - NS_WARNING("Cannot create socket fd!"); - FireSocketError(); - return; - } - if (!SetSocketFlags(fd)) { - NS_WARNING("Cannot set socket flags!"); - FireSocketError(); - return; - } - if (!mConnector->SetUp(fd)) { - NS_WARNING("Could not set up socket!"); - FireSocketError(); - return; - } - if (!mConnector->CreateAddr(false, mAddrSize, mAddr, mAddress.get())) { - NS_WARNING("Cannot create socket address!"); + mAddressLength = sizeof(mAddress); + + int fd; + nsresult rv = mConnector->CreateStreamSocket( + reinterpret_cast(&mAddress), &mAddressLength, fd); + if (NS_WARN_IF(NS_FAILED(rv))) { FireSocketError(); return; } @@ -286,7 +260,7 @@ BluetoothSocket::BluetoothSocketIO::Connect() // calls OnConnected() on success, or OnError() otherwise nsresult rv = UnixSocketWatcher::Connect( - reinterpret_cast(&mAddr), mAddrSize); + reinterpret_cast(&mAddress), mAddressLength); NS_WARN_IF(NS_FAILED(rv)); } @@ -338,18 +312,14 @@ BluetoothSocket::BluetoothSocketIO::OnSocketCanAcceptWithoutBlocking() RemoveWatchers(READ_WATCHER|WRITE_WATCHER); - socklen_t mAddrSize = sizeof(mAddr); - int fd = TEMP_FAILURE_RETRY(accept(GetFd(), - reinterpret_cast(&mAddr), &mAddrSize)); - if (fd < 0) { - OnError("accept", errno); - return; - } - if (!SetSocketFlags(fd)) { - return; - } - if (!mConnector->SetUp(fd)) { - NS_WARNING("Could not set up socket!"); + mAddressLength = sizeof(mAddress); + + int fd; + nsresult rv = mConnector->AcceptStreamSocket( + GetFd(), + reinterpret_cast(&mAddress), &mAddressLength, fd); + if (NS_WARN_IF(NS_FAILED(rv))) { + FireSocketError(); return; } @@ -411,38 +381,6 @@ BluetoothSocket::BluetoothSocketIO::FireSocketError() } -bool -BluetoothSocket::BluetoothSocketIO::SetSocketFlags(int aFd) -{ - // Set socket addr to be reused even if kernel is still waiting to close - int n = 1; - if (setsockopt(aFd, SOL_SOCKET, SO_REUSEADDR, &n, sizeof(n)) < 0) { - return false; - } - - // Set close-on-exec bit. - int flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFD)); - if (-1 == flags) { - return false; - } - flags |= FD_CLOEXEC; - if (-1 == TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFD, flags))) { - return false; - } - - // Set non-blocking status flag. - flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFL)); - if (-1 == flags) { - return false; - } - flags |= O_NONBLOCK; - if (-1 == TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFL, flags))) { - return false; - } - - return true; -} - // |DataSocketIO| nsresult @@ -730,9 +668,8 @@ BluetoothSocket::ConnectSocket(BluetoothUnixSocketConnector* aConnector, return false; } - nsCString addr(aAddress); MessageLoop* ioLoop = XRE_GetIOMessageLoop(); - mIO = new BluetoothSocketIO(ioLoop, this, connector.forget(), addr); + mIO = new BluetoothSocketIO(ioLoop, this, connector.forget()); SetConnectionStatus(SOCKET_CONNECTING); if (aDelayMs > 0) { DelayedConnectTask* connectTask = new DelayedConnectTask(mIO); @@ -757,10 +694,12 @@ BluetoothSocket::ListenSocket(BluetoothUnixSocketConnector* aConnector) return false; } - mIO = new BluetoothSocketIO( - XRE_GetIOMessageLoop(), this, connector.forget(), EmptyCString()); + MessageLoop* ioLoop = XRE_GetIOMessageLoop(); + + mIO = new BluetoothSocketIO(ioLoop, this, connector.forget()); SetConnectionStatus(SOCKET_LISTENING); - XRE_GetIOMessageLoop()->PostTask(FROM_HERE, new ListenTask(mIO)); + ioLoop->PostTask(FROM_HERE, new ListenTask(mIO)); + return true; } diff --git a/ipc/unixsocket/ListenSocket.cpp b/ipc/unixsocket/ListenSocket.cpp index fca2f896b2d..62cb76fba54 100644 --- a/ipc/unixsocket/ListenSocket.cpp +++ b/ipc/unixsocket/ListenSocket.cpp @@ -28,8 +28,7 @@ public: ListenSocketIO(MessageLoop* mIOLoop, ListenSocket* aListenSocket, - UnixSocketConnector* aConnector, - const nsACString& aAddress); + UnixSocketConnector* aConnector); ~ListenSocketIO(); void GetSocketAddr(nsAString& aAddrStr) const; @@ -64,9 +63,6 @@ public: private: void FireSocketError(); - // Set up flags on file descriptor. - static bool SetSocketFlags(int aFd); - /** * Consumer pointer. Non-thread safe RefPtr, so should only be manipulated * directly from main thread. All non-main-thread accesses should happen with @@ -85,33 +81,27 @@ private: bool mShuttingDownOnIOThread; /** - * Address we are connecting to, assuming we are creating a client connection. + * Number of valid bytes in |mAddress| */ - nsCString mAddress; + socklen_t mAddressLength; /** - * Size of the socket address struct + * Address structure of the socket currently in use */ - socklen_t mAddrSize; - - /** - * Address struct of the socket currently in use - */ - sockaddr_any mAddr; + struct sockaddr_storage mAddress; ConnectionOrientedSocketIO* mCOSocketIO; }; ListenSocketIO::ListenSocketIO(MessageLoop* mIOLoop, ListenSocket* aListenSocket, - UnixSocketConnector* aConnector, - const nsACString& aAddress) + UnixSocketConnector* aConnector) : UnixSocketWatcher(mIOLoop) , SocketIOBase() , mListenSocket(aListenSocket) , mConnector(aConnector) , mShuttingDownOnIOThread(false) - , mAddress(aAddress) + , mAddressLength(0) , mCOSocketIO(nullptr) { MOZ_ASSERT(mListenSocket); @@ -132,7 +122,16 @@ ListenSocketIO::GetSocketAddr(nsAString& aAddrStr) const aAddrStr.Truncate(); return; } - mConnector->GetSocketAddr(mAddr, aAddrStr); + + nsCString addressString; + nsresult rv = mConnector->ConvertAddressToString( + *reinterpret_cast(&mAddress), mAddressLength, + addressString); + if (NS_FAILED(rv)) { + return; + } + + aAddrStr.Assign(NS_ConvertUTF8toUTF16(addressString)); } void @@ -142,28 +141,14 @@ ListenSocketIO::Listen(ConnectionOrientedSocketIO* aCOSocketIO) MOZ_ASSERT(mConnector); MOZ_ASSERT(aCOSocketIO); + struct sockaddr* address = reinterpret_cast(&mAddress); + mAddressLength = sizeof(mAddress); + if (!IsOpen()) { - int fd = mConnector->Create(); - if (fd < 0) { - NS_WARNING("Cannot create socket fd!"); - FireSocketError(); - return; - } - if (!SetSocketFlags(fd)) { - NS_WARNING("Cannot set socket flags!"); - FireSocketError(); - return; - } - if (!mConnector->SetUpListenSocket(GetFd())) { - NS_WARNING("Could not set up listen socket!"); - FireSocketError(); - return; - } - // This will set things we don't particularly care about, but - // it will hand back the correct structure size which is what - // we do care about. - if (!mConnector->CreateAddr(true, mAddrSize, mAddr, nullptr)) { - NS_WARNING("Cannot create socket address!"); + int fd; + nsresult rv = mConnector->CreateListenSocket(address, &mAddressLength, + fd); + if (NS_FAILED(rv)) { FireSocketError(); return; } @@ -173,8 +158,7 @@ ListenSocketIO::Listen(ConnectionOrientedSocketIO* aCOSocketIO) mCOSocketIO = aCOSocketIO; // calls OnListening on success, or OnError otherwise - nsresult rv = UnixSocketWatcher::Listen( - reinterpret_cast(&mAddr), mAddrSize); + nsresult rv = UnixSocketWatcher::Listen(address, mAddressLength); NS_WARN_IF(NS_FAILED(rv)); } @@ -221,41 +205,6 @@ ListenSocketIO::FireSocketError() new SocketIOEventRunnable(this, SocketIOEventRunnable::CONNECT_ERROR)); } -bool -ListenSocketIO::SetSocketFlags(int aFd) -{ - static const int reuseaddr = 1; - - // Set socket addr to be reused even if kernel is still waiting to close - int res = setsockopt(aFd, SOL_SOCKET, SO_REUSEADDR, - &reuseaddr, sizeof(reuseaddr)); - if (res < 0) { - return false; - } - - // Set close-on-exec bit. - int flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFD)); - if (-1 == flags) { - return false; - } - flags |= FD_CLOEXEC; - if (-1 == TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFD, flags))) { - return false; - } - - // Set non-blocking status flag. - flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFL)); - if (-1 == flags) { - return false; - } - flags |= O_NONBLOCK; - if (-1 == TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFL, flags))) { - return false; - } - - return true; -} - void ListenSocketIO::OnSocketCanAcceptWithoutBlocking() { @@ -263,20 +212,24 @@ ListenSocketIO::OnSocketCanAcceptWithoutBlocking() MOZ_ASSERT(GetConnectionStatus() == SOCKET_IS_LISTENING); MOZ_ASSERT(mCOSocketIO); - struct sockaddr_storage addr; - socklen_t addrLen = sizeof(addr); - int fd = TEMP_FAILURE_RETRY(accept(GetFd(), - reinterpret_cast(&addr), &addrLen)); - if (fd < 0) { - OnError("accept", errno); + RemoveWatchers(READ_WATCHER|WRITE_WATCHER); + + struct sockaddr_storage storage; + socklen_t addressLength = sizeof(storage); + + int fd; + nsresult rv = mConnector->AcceptStreamSocket( + GetFd(), + reinterpret_cast(&storage), &addressLength, + fd); + if (NS_FAILED(rv)) { + FireSocketError(); return; } - RemoveWatchers(READ_WATCHER|WRITE_WATCHER); - mCOSocketIO->Accept(fd, - reinterpret_cast(&addr), - addrLen); + reinterpret_cast(&storage), + addressLength); } // |SocketIOBase| @@ -397,8 +350,7 @@ ListenSocket::Listen(UnixSocketConnector* aConnector, return false; } - mIO = new ListenSocketIO( - XRE_GetIOMessageLoop(), this, connector.forget(), EmptyCString()); + mIO = new ListenSocketIO(XRE_GetIOMessageLoop(), this, connector.forget()); // Prepared I/O object, now start listening. return Listen(aCOSocket); diff --git a/ipc/unixsocket/StreamSocket.cpp b/ipc/unixsocket/StreamSocket.cpp index d6e423ba593..79b8471efc6 100644 --- a/ipc/unixsocket/StreamSocket.cpp +++ b/ipc/unixsocket/StreamSocket.cpp @@ -30,13 +30,11 @@ public: StreamSocketIO(MessageLoop* mIOLoop, StreamSocket* aStreamSocket, - UnixSocketConnector* aConnector, - const nsACString& aAddress); + UnixSocketConnector* aConnector); StreamSocketIO(MessageLoop* mIOLoop, int aFd, ConnectionStatus aConnectionStatus, StreamSocket* aStreamSocket, - UnixSocketConnector* aConnector, - const nsACString& aAddress); + UnixSocketConnector* aConnector); ~StreamSocketIO(); void GetSocketAddr(nsAString& aAddrStr) const; @@ -98,9 +96,6 @@ public: private: void FireSocketError(); - // Set up flags on file descriptor. - static bool SetSocketFlags(int aFd); - /** * Consumer pointer. Non-thread safe RefPtr, so should only be manipulated * directly from main thread. All non-main-thread accesses should happen with @@ -119,19 +114,14 @@ private: bool mShuttingDownOnIOThread; /** - * Address we are connecting to, assuming we are creating a client connection. + * Number of valid bytes in |mAddress| */ - nsCString mAddress; + socklen_t mAddressLength; /** - * Size of the socket address struct + * Address structure of the socket currently in use */ - socklen_t mAddrSize; - - /** - * Address struct of the socket currently in use - */ - sockaddr_any mAddr; + struct sockaddr_storage mAddress; /** * Task member for delayed connect task. Should only be access on main thread. @@ -146,13 +136,12 @@ private: StreamSocketIO::StreamSocketIO(MessageLoop* mIOLoop, StreamSocket* aStreamSocket, - UnixSocketConnector* aConnector, - const nsACString& aAddress) + UnixSocketConnector* aConnector) : UnixSocketWatcher(mIOLoop) , mStreamSocket(aStreamSocket) , mConnector(aConnector) , mShuttingDownOnIOThread(false) - , mAddress(aAddress) + , mAddressLength(0) , mDelayedConnectTask(nullptr) { MOZ_ASSERT(mStreamSocket); @@ -162,13 +151,12 @@ StreamSocketIO::StreamSocketIO(MessageLoop* mIOLoop, StreamSocketIO::StreamSocketIO(MessageLoop* mIOLoop, int aFd, ConnectionStatus aConnectionStatus, StreamSocket* aStreamSocket, - UnixSocketConnector* aConnector, - const nsACString& aAddress) + UnixSocketConnector* aConnector) : UnixSocketWatcher(mIOLoop, aFd, aConnectionStatus) , mStreamSocket(aStreamSocket) , mConnector(aConnector) , mShuttingDownOnIOThread(false) - , mAddress(aAddress) + , mAddressLength(0) , mDelayedConnectTask(nullptr) { MOZ_ASSERT(mStreamSocket); @@ -189,7 +177,16 @@ StreamSocketIO::GetSocketAddr(nsAString& aAddrStr) const aAddrStr.Truncate(); return; } - mConnector->GetSocketAddr(mAddr, aAddrStr); + + nsCString addressString; + nsresult rv = mConnector->ConvertAddressToString( + *reinterpret_cast(&mAddress), mAddressLength, + addressString); + if (NS_FAILED(rv)) { + return; + } + + aAddrStr.Assign(NS_ConvertUTF8toUTF16(addressString)); } StreamSocket* @@ -239,34 +236,21 @@ StreamSocketIO::Connect() MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop()); MOZ_ASSERT(mConnector); - if (!IsOpen()) { - int fd = mConnector->Create(); - if (fd < 0) { - NS_WARNING("Cannot create socket fd!"); - FireSocketError(); - return; - } - if (!SetSocketFlags(fd)) { - NS_WARNING("Cannot set socket flags!"); - FireSocketError(); - return; - } - if (!mConnector->SetUp(GetFd())) { - NS_WARNING("Could not set up socket!"); - FireSocketError(); - return; - } - if (!mConnector->CreateAddr(false, mAddrSize, mAddr, mAddress.get())) { - NS_WARNING("Cannot create socket address!"); - FireSocketError(); - return; - } - SetFd(fd); + MOZ_ASSERT(!IsOpen()); + + struct sockaddr* address = reinterpret_cast(&mAddress); + mAddressLength = sizeof(mAddress); + + int fd; + nsresult rv = mConnector->CreateStreamSocket(address, &mAddressLength, fd); + if (NS_FAILED(rv)) { + FireSocketError(); + return; } + SetFd(fd); // calls OnConnected() on success, or OnError() otherwise - nsresult rv = UnixSocketWatcher::Connect( - reinterpret_cast(&mAddr), mAddrSize); + rv = UnixSocketWatcher::Connect(address, mAddressLength); NS_WARN_IF(NS_FAILED(rv)); } @@ -354,41 +338,6 @@ StreamSocketIO::FireSocketError() new SocketIOEventRunnable(this, SocketIOEventRunnable::CONNECT_ERROR)); } -bool -StreamSocketIO::SetSocketFlags(int aFd) -{ - static const int reuseaddr = 1; - - // Set socket addr to be reused even if kernel is still waiting to close - int res = setsockopt(aFd, SOL_SOCKET, SO_REUSEADDR, - &reuseaddr, sizeof(reuseaddr)); - if (res < 0) { - return false; - } - - // Set close-on-exec bit. - int flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFD)); - if (-1 == flags) { - return false; - } - flags |= FD_CLOEXEC; - if (-1 == TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFD, flags))) { - return false; - } - - // Set non-blocking status flag. - flags = TEMP_FAILURE_RETRY(fcntl(aFd, F_GETFL)); - if (-1 == flags) { - return false; - } - flags |= O_NONBLOCK; - if (-1 == TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFL, flags))) { - return false; - } - - return true; -} - // |ConnectionOrientedSocketIO| nsresult @@ -398,21 +347,11 @@ StreamSocketIO::Accept(int aFd, MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop()); MOZ_ASSERT(GetConnectionStatus() == SOCKET_IS_CONNECTING); - // File-descriptor setup - - if (!SetSocketFlags(aFd)) { - return NS_ERROR_FAILURE; - } - if (!mConnector->SetUp(aFd)) { - NS_WARNING("Could not set up socket!"); - return NS_ERROR_FAILURE; - } - SetSocket(aFd, SOCKET_IS_CONNECTED); // Address setup - memcpy(&mAddr, aAddr, aAddrLen); - mAddrSize = aAddrLen; + mAddressLength = aAddrLen; + memcpy(&mAddress, aAddr, mAddressLength); // Signal success NS_DispatchToMainThread( @@ -652,9 +591,8 @@ StreamSocket::Connect(UnixSocketConnector* aConnector, return false; } - nsCString addr(aAddress); MessageLoop* ioLoop = XRE_GetIOMessageLoop(); - mIO = new StreamSocketIO(ioLoop, this, connector.forget(), addr); + mIO = new StreamSocketIO(ioLoop, this, connector.forget()); SetConnectionStatus(SOCKET_CONNECTING); if (aDelayMs > 0) { StreamSocketIO::DelayedConnectTask* connectTask = @@ -681,7 +619,7 @@ StreamSocket::PrepareAccept(UnixSocketConnector* aConnector) mIO = new StreamSocketIO(XRE_GetIOMessageLoop(), -1, UnixSocketWatcher::SOCKET_IS_CONNECTING, - this, connector.forget(), EmptyCString()); + this, connector.forget()); return mIO; } From 86db93eaf29a29a3b6d96ea1b28894d1200a286e Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Tue, 19 May 2015 13:28:46 +0200 Subject: [PATCH 34/39] Bug 1161020: Remove old interface and implementation from socket-connector classes, r=kmachulis --- .../bluedroid/BluetoothDaemonConnector.cpp | 63 ----- .../bluedroid/BluetoothDaemonConnector.h | 12 - .../bluez/BluetoothUnixSocketConnector.cpp | 231 ------------------ .../bluez/BluetoothUnixSocketConnector.h | 12 - ipc/keystore/KeyStoreConnector.cpp | 90 ------- ipc/keystore/KeyStoreConnector.h | 12 - ipc/nfc/NfcConnector.cpp | 66 ----- ipc/nfc/NfcConnector.h | 12 - ipc/ril/RilConnector.cpp | 84 ------- ipc/ril/RilConnector.h | 12 - ipc/unixsocket/UnixSocketConnector.cpp | 34 --- ipc/unixsocket/UnixSocketConnector.h | 69 +----- 12 files changed, 4 insertions(+), 693 deletions(-) diff --git a/dom/bluetooth/bluedroid/BluetoothDaemonConnector.cpp b/dom/bluetooth/bluedroid/BluetoothDaemonConnector.cpp index 6942e255b3d..a526fca396e 100644 --- a/dom/bluetooth/bluedroid/BluetoothDaemonConnector.cpp +++ b/dom/bluetooth/bluedroid/BluetoothDaemonConnector.cpp @@ -171,67 +171,4 @@ BluetoothDaemonConnector::CreateStreamSocket(struct sockaddr* aAddress, return NS_ERROR_ABORT; } -// Deprecated - -int -BluetoothDaemonConnector::Create() -{ - MOZ_ASSERT(!NS_IsMainThread()); - - int fd = socket(AF_UNIX, SOCK_SEQPACKET, 0); - if (fd < 0) { - BT_WARNING("Could not open socket!"); - return -1; - } - return fd; -} - -bool -BluetoothDaemonConnector::CreateAddr(bool aIsServer, - socklen_t& aAddrSize, - mozilla::ipc::sockaddr_any& aAddr, - const char* aAddress) -{ - static const size_t sNameOffset = 1; - - size_t namesiz = mSocketName.Length() + 1; /* include trailing '\0' */ - - if ((sNameOffset + namesiz) > sizeof(aAddr.un.sun_path)) { - BT_WARNING("Address too long for socket struct!"); - return false; - } - - memset(aAddr.un.sun_path, '\0', sNameOffset); // abstract socket - memcpy(aAddr.un.sun_path + sNameOffset, mSocketName.get(), namesiz); - aAddr.un.sun_family = AF_UNIX; - - aAddrSize = offsetof(struct sockaddr_un, sun_path) + sNameOffset + namesiz; - - return true; -} - -bool -BluetoothDaemonConnector::SetUp(int aFd) -{ - if (TEMP_FAILURE_RETRY(fcntl(aFd, F_SETFL, O_NONBLOCK)) < 0) { - BT_WARNING("Failed to set non-blocking I/O."); - return false; - } - return true; -} - -bool -BluetoothDaemonConnector::SetUpListenSocket(int aFd) -{ - return true; -} - -void -BluetoothDaemonConnector::GetSocketAddr( - const mozilla::ipc::sockaddr_any& aAddr, nsAString& aAddrStr) -{ - // Unused. - MOZ_CRASH("This should never be called!"); -} - END_BLUETOOTH_NAMESPACE diff --git a/dom/bluetooth/bluedroid/BluetoothDaemonConnector.h b/dom/bluetooth/bluedroid/BluetoothDaemonConnector.h index c7105a5e9af..c3f014294f4 100644 --- a/dom/bluetooth/bluedroid/BluetoothDaemonConnector.h +++ b/dom/bluetooth/bluedroid/BluetoothDaemonConnector.h @@ -40,18 +40,6 @@ public: socklen_t* aAddressLength, int& aStreamFd) override; - // Deprecated - - int Create() override; - bool CreateAddr(bool aIsServer, - socklen_t& aAddrSize, - mozilla::ipc::sockaddr_any& aAddr, - const char* aAddress) override; - bool SetUp(int aFd) override; - bool SetUpListenSocket(int aFd) override; - void GetSocketAddr(const mozilla::ipc::sockaddr_any& aAddr, - nsAString& aAddrStr) override; - private: nsresult CreateSocket(int& aFd) const; nsresult SetSocketFlags(int aFd) const; diff --git a/dom/bluetooth/bluez/BluetoothUnixSocketConnector.cpp b/dom/bluetooth/bluez/BluetoothUnixSocketConnector.cpp index 449d2c9dc0a..f9fbfbdf8de 100644 --- a/dom/bluetooth/bluez/BluetoothUnixSocketConnector.cpp +++ b/dom/bluetooth/bluez/BluetoothUnixSocketConnector.cpp @@ -42,28 +42,6 @@ static const int L2CAP_SO_SNDBUF = 400 * 1024; // 400 KB send buffer static const int L2CAP_SO_RCVBUF = 400 * 1024; // 400 KB receive buffer static const int L2CAP_MAX_MTU = 65000; -#ifdef MOZ_B2G_BT_BLUEZ -static -int get_bdaddr(const char *str, bdaddr_t *ba) -{ - char *d = ((char*)ba) + 5, *endp; - for (int i = 0; i < 6; i++) { - *d-- = strtol(str, &endp, 16); - MOZ_ASSERT(!(*endp != ':' && i != 5)); - str = endp + 1; - } - return 0; -} - -static -void get_bdaddr_as_string(const bdaddr_t *ba, char *str) { - const uint8_t *b = (const uint8_t *)ba; - sprintf(str, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X", - b[5], b[4], b[3], b[2], b[1], b[0]); -} - -#endif - BluetoothUnixSocketConnector::BluetoothUnixSocketConnector( const nsACString& aAddressString, BluetoothSocketType aType, @@ -430,213 +408,4 @@ BluetoothUnixSocketConnector::CreateStreamSocket(struct sockaddr* aAddress, return NS_OK; } -// Deprecated - -bool -BluetoothUnixSocketConnector::SetUp(int aFd) -{ -#ifdef MOZ_B2G_BT_BLUEZ - int lm = 0; - int sndbuf, rcvbuf; - - /* kernel does not yet support LM for SCO */ - switch (mType) { - case BluetoothSocketType::RFCOMM: - lm |= mAuth ? RFCOMM_LM_AUTH : 0; - lm |= mEncrypt ? RFCOMM_LM_ENCRYPT : 0; - break; - case BluetoothSocketType::L2CAP: - case BluetoothSocketType::EL2CAP: - lm |= mAuth ? L2CAP_LM_AUTH : 0; - lm |= mEncrypt ? L2CAP_LM_ENCRYPT : 0; - break; - case BluetoothSocketType::SCO: - break; - default: - MOZ_CRASH("Unknown socket type!"); - } - - if (lm) { - if (mType == BluetoothSocketType::RFCOMM) { - if (setsockopt(aFd, SOL_RFCOMM, RFCOMM_LM, &lm, sizeof(lm))) { - BT_WARNING("setsockopt(RFCOMM_LM) failed, throwing"); - return false; - } - } else if (mType == BluetoothSocketType::L2CAP || - mType == BluetoothSocketType::EL2CAP) { - if (setsockopt(aFd, SOL_L2CAP, L2CAP_LM, &lm, sizeof(lm))) { - BT_WARNING("setsockopt(L2CAP_LM) failed, throwing"); - return false; - } - } - } - - if (mType == BluetoothSocketType::RFCOMM) { - sndbuf = RFCOMM_SO_SNDBUF; - if (setsockopt(aFd, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof(sndbuf))) { - BT_WARNING("setsockopt(SO_SNDBUF) failed, throwing"); - return false; - } - } - - /* Setting L2CAP socket options */ - if (mType == BluetoothSocketType::L2CAP || - mType == BluetoothSocketType::EL2CAP) { - struct l2cap_options opts; - socklen_t optlen = sizeof(opts); - int err; - err = getsockopt(aFd, SOL_L2CAP, L2CAP_OPTIONS, &opts, &optlen); - if (!err) { - /* setting MTU for [E]L2CAP */ - opts.omtu = opts.imtu = L2CAP_MAX_MTU; - - /* Enable ERTM for [E]L2CAP */ - if (mType == BluetoothSocketType::EL2CAP) { - opts.flush_to = 0xffff; /* infinite */ - opts.mode = L2CAP_MODE_ERTM; - opts.fcs = 1; - opts.txwin_size = 64; - opts.max_tx = 10; - } - - err = setsockopt(aFd, SOL_L2CAP, L2CAP_OPTIONS, &opts, optlen); - } - - /* Set larger SNDBUF & RCVBUF for EL2CAP connections */ - if (mType == BluetoothSocketType::EL2CAP) { - sndbuf = L2CAP_SO_SNDBUF; - if (setsockopt(aFd, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof(sndbuf))) { - BT_WARNING("setsockopt(SO_SNDBUF) failed, throwing"); - return false; - } - - rcvbuf = L2CAP_SO_RCVBUF; - if (setsockopt(aFd, SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof(rcvbuf))) { - BT_WARNING("setsockopt(SO_RCVBUF) failed, throwing"); - return false; - } - } - } -#endif - return true; -} - -bool -BluetoothUnixSocketConnector::SetUpListenSocket(int aFd) -{ - // Nothing to do here. - return true; -} - -int -BluetoothUnixSocketConnector::Create() -{ - MOZ_ASSERT(!NS_IsMainThread()); - int fd = -1; - -#ifdef MOZ_B2G_BT_BLUEZ - switch (mType) { - case BluetoothSocketType::RFCOMM: - fd = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); - break; - case BluetoothSocketType::SCO: - fd = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_SCO); - break; - case BluetoothSocketType::L2CAP: - fd = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP); - break; - case BluetoothSocketType::EL2CAP: - fd = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_L2CAP); - break; - default: - MOZ_CRASH(); - } - - if (fd < 0) { - BT_WARNING("Could not open bluetooth socket!"); - return -1; - } - - if (!SetUp(fd)) { - BT_WARNING("Could not set up socket!"); - return -1; - } -#endif - return fd; -} - -bool -BluetoothUnixSocketConnector::CreateAddr(bool aIsServer, - socklen_t& aAddrSize, - sockaddr_any& aAddr, - const char* aAddress) -{ -#ifdef MOZ_B2G_BT_BLUEZ - // Set to BDADDR_ANY, if it's not a server, we'll reset. - bdaddr_t bd_address_obj = {{0, 0, 0, 0, 0, 0}}; - - if (!aIsServer && aAddress && strlen(aAddress) > 0) { - if (get_bdaddr(aAddress, &bd_address_obj)) { - BT_WARNING("Can't get bluetooth address!"); - return false; - } - } - - // Initialize - memset(&aAddr, 0, sizeof(aAddr)); - - switch (mType) { - case BluetoothSocketType::RFCOMM: - struct sockaddr_rc addr_rc; - aAddrSize = sizeof(addr_rc); - aAddr.rc.rc_family = AF_BLUETOOTH; - aAddr.rc.rc_channel = mChannel; - memcpy(&aAddr.rc.rc_bdaddr, &bd_address_obj, sizeof(bd_address_obj)); - break; - case BluetoothSocketType::L2CAP: - case BluetoothSocketType::EL2CAP: - struct sockaddr_l2 addr_l2; - aAddrSize = sizeof(addr_l2); - aAddr.l2.l2_family = AF_BLUETOOTH; - aAddr.l2.l2_psm = mChannel; - memcpy(&aAddr.l2.l2_bdaddr, &bd_address_obj, sizeof(bdaddr_t)); - break; - case BluetoothSocketType::SCO: - struct sockaddr_sco addr_sco; - aAddrSize = sizeof(addr_sco); - aAddr.sco.sco_family = AF_BLUETOOTH; - memcpy(&aAddr.sco.sco_bdaddr, &bd_address_obj, sizeof(bd_address_obj)); - break; - default: - BT_WARNING("Socket type unknown!"); - return false; - } -#endif - return true; -} - -void -BluetoothUnixSocketConnector::GetSocketAddr(const sockaddr_any& aAddr, - nsAString& aAddrStr) -{ -#ifdef MOZ_B2G_BT_BLUEZ - char addr[18]; - switch (mType) { - case BluetoothSocketType::RFCOMM: - get_bdaddr_as_string((bdaddr_t*)(&aAddr.rc.rc_bdaddr), addr); - break; - case BluetoothSocketType::SCO: - get_bdaddr_as_string((bdaddr_t*)(&aAddr.sco.sco_bdaddr), addr); - break; - case BluetoothSocketType::L2CAP: - case BluetoothSocketType::EL2CAP: - get_bdaddr_as_string((bdaddr_t*)(&aAddr.l2.l2_bdaddr), addr); - break; - default: - MOZ_CRASH("Socket should be either RFCOMM or SCO!"); - } - aAddrStr.AssignASCII(addr); -#endif -} - END_BLUETOOTH_NAMESPACE diff --git a/dom/bluetooth/bluez/BluetoothUnixSocketConnector.h b/dom/bluetooth/bluez/BluetoothUnixSocketConnector.h index 88b225ac554..852a5e69389 100644 --- a/dom/bluetooth/bluez/BluetoothUnixSocketConnector.h +++ b/dom/bluetooth/bluez/BluetoothUnixSocketConnector.h @@ -41,18 +41,6 @@ public: socklen_t* aAddressLength, int& aStreamFd) override; - // Deprecated - - virtual int Create() override; - virtual bool CreateAddr(bool aIsServer, - socklen_t& aAddrSize, - mozilla::ipc::sockaddr_any& aAddr, - const char* aAddress) override; - virtual bool SetUp(int aFd) override; - virtual bool SetUpListenSocket(int aFd) override; - virtual void GetSocketAddr(const mozilla::ipc::sockaddr_any& aAddr, - nsAString& aAddrStr) override; - private: nsresult CreateSocket(int& aFd) const; nsresult SetSocketFlags(int aFd) const; diff --git a/ipc/keystore/KeyStoreConnector.cpp b/ipc/keystore/KeyStoreConnector.cpp index e089eaf88ef..a40fef8665b 100644 --- a/ipc/keystore/KeyStoreConnector.cpp +++ b/ipc/keystore/KeyStoreConnector.cpp @@ -222,95 +222,5 @@ KeyStoreConnector::CreateStreamSocket(struct sockaddr* aAddress, return NS_ERROR_FAILURE; } -// Deprecated - -static const char* KEYSTORE_ALLOWED_USERS[] = { - "root", - "wifi", - NULL -}; - -static bool checkPermission(uid_t uid) -{ - struct passwd *userInfo = getpwuid(uid); - for (const char **user = KEYSTORE_ALLOWED_USERS; *user; user++ ) { - if (!strcmp(*user, userInfo->pw_name)) { - return true; - } - } - - return false; -} - -int -KeyStoreConnector::Create() -{ - MOZ_ASSERT(!NS_IsMainThread()); - - int fd; - - unlink(KEYSTORE_SOCKET_PATH); - - fd = socket(AF_LOCAL, SOCK_STREAM, 0); - - if (fd < 0) { - NS_WARNING("Could not open keystore socket!"); - return -1; - } - - return fd; -} - -bool -KeyStoreConnector::CreateAddr(bool aIsServer, - socklen_t& aAddrSize, - sockaddr_any& aAddr, - const char* aAddress) -{ - // Keystore socket must be server - MOZ_ASSERT(aIsServer); - - aAddr.un.sun_family = AF_LOCAL; - if(strlen(KEYSTORE_SOCKET_PATH) > sizeof(aAddr.un.sun_path)) { - NS_WARNING("Address too long for socket struct!"); - return false; - } - strcpy((char*)&aAddr.un.sun_path, KEYSTORE_SOCKET_PATH); - aAddrSize = strlen(KEYSTORE_SOCKET_PATH) + offsetof(struct sockaddr_un, sun_path) + 1; - - return true; -} - -bool -KeyStoreConnector::SetUp(int aFd) -{ - // Socket permission check. - struct ucred userCred; - socklen_t len = sizeof(struct ucred); - - if (getsockopt(aFd, SOL_SOCKET, SO_PEERCRED, &userCred, &len)) { - return false; - } - - return checkPermission(userCred.uid); -} - -bool -KeyStoreConnector::SetUpListenSocket(int aFd) -{ - // Allow access of wpa_supplicant(different user, differnt group) - chmod(KEYSTORE_SOCKET_PATH, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); - - return true; -} - -void -KeyStoreConnector::GetSocketAddr(const sockaddr_any& aAddr, - nsAString& aAddrStr) -{ - // Unused. - MOZ_CRASH("This should never be called!"); -} - } } diff --git a/ipc/keystore/KeyStoreConnector.h b/ipc/keystore/KeyStoreConnector.h index 31c71986268..5387b5290ff 100644 --- a/ipc/keystore/KeyStoreConnector.h +++ b/ipc/keystore/KeyStoreConnector.h @@ -39,18 +39,6 @@ public: socklen_t* aAddressLength, int& aStreamFd) override; - // Deprecated - - int Create(); - bool CreateAddr(bool aIsServer, - socklen_t& aAddrSize, - sockaddr_any& aAddr, - const char* aAddress); - bool SetUp(int aFd); - bool SetUpListenSocket(int aFd); - void GetSocketAddr(const sockaddr_any& aAddr, - nsAString& aAddrStr); - private: nsresult CreateSocket(int& aFd) const; nsresult SetSocketFlags(int aFd) const; diff --git a/ipc/nfc/NfcConnector.cpp b/ipc/nfc/NfcConnector.cpp index 05a092d7e20..5c36d7450aa 100644 --- a/ipc/nfc/NfcConnector.cpp +++ b/ipc/nfc/NfcConnector.cpp @@ -190,71 +190,5 @@ NfcConnector::CreateStreamSocket(struct sockaddr* aAddress, return NS_OK; } -// Deprecated - -int -NfcConnector::Create() -{ - MOZ_ASSERT(!NS_IsMainThread()); - - int fd = socket(AF_LOCAL, SOCK_STREAM, 0); - if (fd < 0) { - NS_WARNING("Could not open nfc socket!"); - return -1; - } - - if (!SetUp(fd)) { - NS_WARNING("Could not set up socket!"); - } - return fd; -} - -bool -NfcConnector::CreateAddr(bool aIsServer, - socklen_t& aAddrSize, - sockaddr_any& aAddr, - const char* aAddress) -{ - static const size_t sNameOffset = 1; - - nsDependentCString socketName("nfcd"); - - size_t namesiz = socketName.Length() + 1; /* include trailing '\0' */ - - if ((sNameOffset + namesiz) > sizeof(aAddr.un.sun_path)) { - NS_WARNING("Address too long for socket struct!"); - return false; - } - - memset(aAddr.un.sun_path, '\0', sNameOffset); // abstract socket - memcpy(aAddr.un.sun_path + sNameOffset, socketName.get(), namesiz); - aAddr.un.sun_family = AF_UNIX; - - aAddrSize = offsetof(struct sockaddr_un, sun_path) + sNameOffset + namesiz; - - return true; -} - -bool -NfcConnector::SetUp(int aFd) -{ - // Nothing to do here. - return true; -} - -bool -NfcConnector::SetUpListenSocket(int aFd) -{ - // Nothing to do here. - return true; -} - -void -NfcConnector::GetSocketAddr(const sockaddr_any& aAddr, - nsAString& aAddrStr) -{ - MOZ_CRASH("This should never be called!"); -} - } } diff --git a/ipc/nfc/NfcConnector.h b/ipc/nfc/NfcConnector.h index 6bf4427b8f1..b4ef85ef60f 100644 --- a/ipc/nfc/NfcConnector.h +++ b/ipc/nfc/NfcConnector.h @@ -43,18 +43,6 @@ public: socklen_t* aAddressLength, int& aStreamFd) override; - // Deprecated - - int Create() override; - bool CreateAddr(bool aIsServer, - socklen_t& aAddrSize, - sockaddr_any& aAddr, - const char* aAddress) override; - bool SetUp(int aFd) override; - bool SetUpListenSocket(int aFd) override; - void GetSocketAddr(const sockaddr_any& aAddr, - nsAString& aAddrStr) override; - private: nsresult CreateSocket(int& aFd) const; nsresult SetSocketFlags(int aFd) const; diff --git a/ipc/ril/RilConnector.cpp b/ipc/ril/RilConnector.cpp index 6fbcdb16eae..35bcd48b68d 100644 --- a/ipc/ril/RilConnector.cpp +++ b/ipc/ril/RilConnector.cpp @@ -204,89 +204,5 @@ RilConnector::CreateStreamSocket(struct sockaddr* aAddress, return NS_OK; } -// Deprecated - -int -RilConnector::Create() -{ - MOZ_ASSERT(!NS_IsMainThread()); - - int fd = -1; - -#if defined(MOZ_WIDGET_GONK) - fd = socket(AF_LOCAL, SOCK_STREAM, 0); -#else - // If we can't hit a local loopback, fail later in connect. - fd = socket(AF_INET, SOCK_STREAM, 0); -#endif - - if (fd < 0) { - NS_WARNING("Could not open ril socket!"); - return -1; - } - - if (!SetUp(fd)) { - NS_WARNING("Could not set up socket!"); - } - return fd; -} - -bool -RilConnector::CreateAddr(bool aIsServer, - socklen_t& aAddrSize, - sockaddr_any& aAddr, - const char* aAddress) -{ - // We never open ril socket as server. - MOZ_ASSERT(!aIsServer); - uint32_t af; -#if defined(MOZ_WIDGET_GONK) - af = AF_LOCAL; -#else - af = AF_INET; -#endif - switch (af) { - case AF_LOCAL: - aAddr.un.sun_family = af; - if(strlen(aAddress) > sizeof(aAddr.un.sun_path)) { - NS_WARNING("Address too long for socket struct!"); - return false; - } - strcpy((char*)&aAddr.un.sun_path, aAddress); - aAddrSize = strlen(aAddress) + offsetof(struct sockaddr_un, sun_path) + 1; - break; - case AF_INET: - aAddr.in.sin_family = af; - aAddr.in.sin_port = htons(RIL_TEST_PORT + mClientId); - aAddr.in.sin_addr.s_addr = htonl(INADDR_LOOPBACK); - aAddrSize = sizeof(sockaddr_in); - break; - default: - NS_WARNING("Socket type not handled by connector!"); - return false; - } - return true; -} - -bool -RilConnector::SetUp(int aFd) -{ - // Nothing to do here. - return true; -} - -bool -RilConnector::SetUpListenSocket(int aFd) -{ - // Nothing to do here. - return true; -} - -void -RilConnector::GetSocketAddr(const sockaddr_any& aAddr, nsAString& aAddrStr) -{ - MOZ_CRASH("This should never be called!"); -} - } } diff --git a/ipc/ril/RilConnector.h b/ipc/ril/RilConnector.h index a4decc49428..49c1cf051cb 100644 --- a/ipc/ril/RilConnector.h +++ b/ipc/ril/RilConnector.h @@ -43,18 +43,6 @@ public: socklen_t* aAddressLength, int& aStreamFd) override; - // Deprecated - - int Create() override; - bool CreateAddr(bool aIsServer, - socklen_t& aAddrSize, - sockaddr_any& aAddr, - const char* aAddress) override; - bool SetUp(int aFd) override; - bool SetUpListenSocket(int aFd) override; - void GetSocketAddr(const sockaddr_any& aAddr, - nsAString& aAddrStr) override; - private: nsresult CreateSocket(int aDomain, int& aFd) const; nsresult SetSocketFlags(int aFd) const; diff --git a/ipc/unixsocket/UnixSocketConnector.cpp b/ipc/unixsocket/UnixSocketConnector.cpp index 6c23b237acc..37ddd0fb1b0 100644 --- a/ipc/unixsocket/UnixSocketConnector.cpp +++ b/ipc/unixsocket/UnixSocketConnector.cpp @@ -15,39 +15,5 @@ UnixSocketConnector::UnixSocketConnector() UnixSocketConnector::~UnixSocketConnector() { } -nsresult -UnixSocketConnector::ConvertAddressToString(const struct sockaddr& aAddress, - socklen_t aAddressLength, - nsACString& aAddressString) -{ - MOZ_CRASH("|UnixSocketConnector| does not convert addresses to strings."); - return NS_ERROR_ABORT; -} - -nsresult -UnixSocketConnector::CreateListenSocket(struct sockaddr* aAddress, - socklen_t* aAddressLength, - int& aListenFd) -{ - MOZ_CRASH("|UnixSocketConnector| does not support listening sockets."); -} - -nsresult -UnixSocketConnector::AcceptStreamSocket(int aListenFd, - struct sockaddr* aAddress, - socklen_t* aAddressLen, - int& aStreamFd) -{ - MOZ_CRASH("|UnixSocketConnector| does not support accepting stream sockets."); -} - -nsresult -UnixSocketConnector::CreateStreamSocket(struct sockaddr* aAddress, - socklen_t* aAddressLength, - int& aStreamFd) -{ - MOZ_CRASH("|UnixSocketConnector| does not support creating stream sockets."); -} - } } diff --git a/ipc/unixsocket/UnixSocketConnector.h b/ipc/unixsocket/UnixSocketConnector.h index 2573271a5cd..39f76501c70 100644 --- a/ipc/unixsocket/UnixSocketConnector.h +++ b/ipc/unixsocket/UnixSocketConnector.h @@ -36,7 +36,7 @@ public: */ virtual nsresult ConvertAddressToString(const struct sockaddr& aAddress, socklen_t aAddressLength, - nsACString& aAddressString); + nsACString& aAddressString) = 0; /** * Creates a listening socket. I/O thread only. @@ -48,7 +48,7 @@ public: */ virtual nsresult CreateListenSocket(struct sockaddr* aAddress, socklen_t* aAddressLength, - int& aListenFd); + int& aListenFd) = 0; /** * Accepts a stream socket from a listening socket. I/O thread only. @@ -62,7 +62,7 @@ public: virtual nsresult AcceptStreamSocket(int aListenFd, struct sockaddr* aAddress, socklen_t* aAddressLen, - int& aStreamFd); + int& aStreamFd) = 0; /** * Creates a stream socket. I/O thread only. @@ -74,68 +74,7 @@ public: */ virtual nsresult CreateStreamSocket(struct sockaddr* aAddress, socklen_t* aAddressLength, - int& aStreamFd); - - /** - * Establishs a file descriptor for a socket. - * - * @deprecated - * - * @return File descriptor for socket - */ - virtual int Create() = 0; - - /** - * Since most socket specifics are related to address formation into a - * sockaddr struct, this function is defined by subclasses and fills in the - * structure as needed for whatever connection it is trying to build - * - * @deprecated - * - * @param aIsServer True is we are acting as a server socket - * @param aAddrSize Size of the struct - * @param aAddr Struct to fill - * @param aAddress If aIsServer is false, Address to connect to. nullptr otherwise. - * - * @return True if address is filled correctly, false otherwise - */ - virtual bool CreateAddr(bool aIsServer, - socklen_t& aAddrSize, - sockaddr_any& aAddr, - const char* aAddress) = 0; - - /** - * Does any socket type specific setup that may be needed, only for socket - * created by ConnectSocket() - * - * @param aFd File descriptor for opened socket - * - * @return true is successful, false otherwise - */ - virtual bool SetUp(int aFd) = 0; - - /** - * Perform socket setup for socket created by ListenSocket(), after listen(). - * - * @deprecated - * - * @param aFd File descriptor for opened socket - * - * @return true is successful, false otherwise - */ - virtual bool SetUpListenSocket(int aFd) = 0; - - /** - * Get address of socket we're currently connected to. Return null string if - * not connected. - * - * @deprecated - * - * @param aAddr Address struct - * @param aAddrStr String to store address to - */ - virtual void GetSocketAddr(const sockaddr_any& aAddr, - nsAString& aAddrStr) = 0; + int& aStreamFd) = 0; protected: UnixSocketConnector(); From c3fc304ef36ea68489f868a06e7e26c07b6782c4 Mon Sep 17 00:00:00 2001 From: B2G Bumper Bot Date: Tue, 19 May 2015 04:35:36 -0700 Subject: [PATCH 35/39] Bumping gaia.json for 2 gaia revision(s) a=gaia-bump ======== https://hg.mozilla.org/integration/gaia-central/rev/9d2910149892 Author: autolander Desc: Bug 1161750 - merge pull request #30091 from yuwen41200:master to mozilla-b2g:master ======== https://hg.mozilla.org/integration/gaia-central/rev/6ed7e8b11bcc Author: yuwen41200 Desc: Bug 1161750 - [Settings][Date&Time] Toggling Automatic and Manual setting pushes/indents 'Region' and 'City' text up r=arthur --- b2g/config/gaia.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/b2g/config/gaia.json b/b2g/config/gaia.json index 7629ca1037b..f383875397c 100644 --- a/b2g/config/gaia.json +++ b/b2g/config/gaia.json @@ -1,9 +1,9 @@ { "git": { - "git_revision": "14968bb2c34ca406a696d8281aa0b76cf87dbbff", + "git_revision": "d88c2f98ebdc75f8eb4d54de0ef267f32414618f", "remote": "https://git.mozilla.org/releases/gaia.git", "branch": "" }, - "revision": "e09b00b0e18bcbe2a3648393e3271218859c1a7b", + "revision": "9d29101498928027976cd4ddec16c8ca6ee35d15", "repo_path": "integration/gaia-central" } From 42658efab97e3b1a6180f31cd9c35aad748bf93a Mon Sep 17 00:00:00 2001 From: B2G Bumper Bot Date: Tue, 19 May 2015 04:37:32 -0700 Subject: [PATCH 36/39] Bumping manifests a=b2g-bump --- b2g/config/aries/sources.xml | 2 +- b2g/config/dolphin/sources.xml | 2 +- b2g/config/emulator-ics/sources.xml | 2 +- b2g/config/emulator-jb/sources.xml | 2 +- b2g/config/emulator-kk/sources.xml | 2 +- b2g/config/emulator-l/sources.xml | 2 +- b2g/config/emulator/sources.xml | 2 +- b2g/config/flame-kk/sources.xml | 2 +- b2g/config/nexus-4/sources.xml | 2 +- b2g/config/nexus-5-l/sources.xml | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/b2g/config/aries/sources.xml b/b2g/config/aries/sources.xml index ec8ed9cfae1..88e94438bbc 100644 --- a/b2g/config/aries/sources.xml +++ b/b2g/config/aries/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/dolphin/sources.xml b/b2g/config/dolphin/sources.xml index 0e809b832af..822e82bbe44 100644 --- a/b2g/config/dolphin/sources.xml +++ b/b2g/config/dolphin/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/emulator-ics/sources.xml b/b2g/config/emulator-ics/sources.xml index 0bc4dd2faff..adddda6f38d 100644 --- a/b2g/config/emulator-ics/sources.xml +++ b/b2g/config/emulator-ics/sources.xml @@ -19,7 +19,7 @@ - + diff --git a/b2g/config/emulator-jb/sources.xml b/b2g/config/emulator-jb/sources.xml index 538810099cc..6b4934f5369 100644 --- a/b2g/config/emulator-jb/sources.xml +++ b/b2g/config/emulator-jb/sources.xml @@ -17,7 +17,7 @@ - + diff --git a/b2g/config/emulator-kk/sources.xml b/b2g/config/emulator-kk/sources.xml index e79266f9107..13f501853e4 100644 --- a/b2g/config/emulator-kk/sources.xml +++ b/b2g/config/emulator-kk/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/emulator-l/sources.xml b/b2g/config/emulator-l/sources.xml index dc5bc0240d9..e98eaaad87e 100644 --- a/b2g/config/emulator-l/sources.xml +++ b/b2g/config/emulator-l/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/emulator/sources.xml b/b2g/config/emulator/sources.xml index 0bc4dd2faff..adddda6f38d 100644 --- a/b2g/config/emulator/sources.xml +++ b/b2g/config/emulator/sources.xml @@ -19,7 +19,7 @@ - + diff --git a/b2g/config/flame-kk/sources.xml b/b2g/config/flame-kk/sources.xml index cc4fa111943..4ef56e81f8a 100644 --- a/b2g/config/flame-kk/sources.xml +++ b/b2g/config/flame-kk/sources.xml @@ -15,7 +15,7 @@ - + diff --git a/b2g/config/nexus-4/sources.xml b/b2g/config/nexus-4/sources.xml index 41faee2e750..a073d7a64eb 100644 --- a/b2g/config/nexus-4/sources.xml +++ b/b2g/config/nexus-4/sources.xml @@ -17,7 +17,7 @@ - + diff --git a/b2g/config/nexus-5-l/sources.xml b/b2g/config/nexus-5-l/sources.xml index a5340bf8e67..f067a838a50 100644 --- a/b2g/config/nexus-5-l/sources.xml +++ b/b2g/config/nexus-5-l/sources.xml @@ -15,7 +15,7 @@ - + From f809ef40c254e00ee789f45459a90295ad88ac17 Mon Sep 17 00:00:00 2001 From: B2G Bumper Bot Date: Tue, 19 May 2015 07:33:16 -0700 Subject: [PATCH 37/39] Bumping manifests a=b2g-bump --- b2g/config/aries/sources.xml | 2 +- b2g/config/dolphin/sources.xml | 2 +- b2g/config/emulator-ics/sources.xml | 2 +- b2g/config/emulator-jb/sources.xml | 2 +- b2g/config/emulator-kk/sources.xml | 2 +- b2g/config/emulator-l/sources.xml | 2 +- b2g/config/emulator/sources.xml | 2 +- b2g/config/flame-kk/sources.xml | 2 +- b2g/config/nexus-4/sources.xml | 2 +- b2g/config/nexus-5-l/sources.xml | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/b2g/config/aries/sources.xml b/b2g/config/aries/sources.xml index 88e94438bbc..8dccac33ddf 100644 --- a/b2g/config/aries/sources.xml +++ b/b2g/config/aries/sources.xml @@ -17,7 +17,7 @@ - + diff --git a/b2g/config/dolphin/sources.xml b/b2g/config/dolphin/sources.xml index 822e82bbe44..238ba932e2d 100644 --- a/b2g/config/dolphin/sources.xml +++ b/b2g/config/dolphin/sources.xml @@ -17,7 +17,7 @@ - + diff --git a/b2g/config/emulator-ics/sources.xml b/b2g/config/emulator-ics/sources.xml index adddda6f38d..0a506461bbd 100644 --- a/b2g/config/emulator-ics/sources.xml +++ b/b2g/config/emulator-ics/sources.xml @@ -20,7 +20,7 @@ - + diff --git a/b2g/config/emulator-jb/sources.xml b/b2g/config/emulator-jb/sources.xml index 6b4934f5369..8d84621adec 100644 --- a/b2g/config/emulator-jb/sources.xml +++ b/b2g/config/emulator-jb/sources.xml @@ -18,7 +18,7 @@ - + diff --git a/b2g/config/emulator-kk/sources.xml b/b2g/config/emulator-kk/sources.xml index 13f501853e4..89914cb3882 100644 --- a/b2g/config/emulator-kk/sources.xml +++ b/b2g/config/emulator-kk/sources.xml @@ -17,7 +17,7 @@ - + diff --git a/b2g/config/emulator-l/sources.xml b/b2g/config/emulator-l/sources.xml index e98eaaad87e..3ea4aa87c68 100644 --- a/b2g/config/emulator-l/sources.xml +++ b/b2g/config/emulator-l/sources.xml @@ -17,7 +17,7 @@ - + diff --git a/b2g/config/emulator/sources.xml b/b2g/config/emulator/sources.xml index adddda6f38d..0a506461bbd 100644 --- a/b2g/config/emulator/sources.xml +++ b/b2g/config/emulator/sources.xml @@ -20,7 +20,7 @@ - + diff --git a/b2g/config/flame-kk/sources.xml b/b2g/config/flame-kk/sources.xml index 4ef56e81f8a..2ef1a9f6a1d 100644 --- a/b2g/config/flame-kk/sources.xml +++ b/b2g/config/flame-kk/sources.xml @@ -17,7 +17,7 @@ - + diff --git a/b2g/config/nexus-4/sources.xml b/b2g/config/nexus-4/sources.xml index a073d7a64eb..f4c3db458ae 100644 --- a/b2g/config/nexus-4/sources.xml +++ b/b2g/config/nexus-4/sources.xml @@ -18,7 +18,7 @@ - + diff --git a/b2g/config/nexus-5-l/sources.xml b/b2g/config/nexus-5-l/sources.xml index f067a838a50..bf76e4d229e 100644 --- a/b2g/config/nexus-5-l/sources.xml +++ b/b2g/config/nexus-5-l/sources.xml @@ -17,7 +17,7 @@ - + From 16fe09461efac801fff8406d75764f86b258c8eb Mon Sep 17 00:00:00 2001 From: B2G Bumper Bot Date: Tue, 19 May 2015 08:10:32 -0700 Subject: [PATCH 38/39] Bumping gaia.json for 2 gaia revision(s) a=gaia-bump ======== https://hg.mozilla.org/integration/gaia-central/rev/c2b9d5ec2383 Author: autolander Desc: Bug 1105285 - merge pull request #30101 from dwi2:bug1105285 to mozilla-b2g:master ======== https://hg.mozilla.org/integration/gaia-central/rev/6ef65007e88a Author: Tzu-Lin Huang Desc: Bug 1105285 - Prevent default behavior of hardware home button pressing when software home button is enabled --- b2g/config/gaia.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/b2g/config/gaia.json b/b2g/config/gaia.json index f383875397c..79c7e328a48 100644 --- a/b2g/config/gaia.json +++ b/b2g/config/gaia.json @@ -1,9 +1,9 @@ { "git": { - "git_revision": "d88c2f98ebdc75f8eb4d54de0ef267f32414618f", + "git_revision": "600fd8249960b8256af9de67d9171025bb9a3ff3", "remote": "https://git.mozilla.org/releases/gaia.git", "branch": "" }, - "revision": "9d29101498928027976cd4ddec16c8ca6ee35d15", + "revision": "c2b9d5ec23830d9e360ca665ffe4d60195f60c91", "repo_path": "integration/gaia-central" } From cfae2cbbb94e39bdeb02c69d2b842b92a13ebcfd Mon Sep 17 00:00:00 2001 From: B2G Bumper Bot Date: Tue, 19 May 2015 08:12:55 -0700 Subject: [PATCH 39/39] Bumping manifests a=b2g-bump --- b2g/config/aries/sources.xml | 4 ++-- b2g/config/dolphin/sources.xml | 4 ++-- b2g/config/emulator-ics/sources.xml | 2 +- b2g/config/emulator-jb/sources.xml | 4 ++-- b2g/config/emulator-kk/sources.xml | 4 ++-- b2g/config/emulator-l/sources.xml | 4 ++-- b2g/config/emulator/sources.xml | 2 +- b2g/config/flame-kk/sources.xml | 4 ++-- b2g/config/nexus-4/sources.xml | 4 ++-- b2g/config/nexus-5-l/sources.xml | 4 ++-- 10 files changed, 18 insertions(+), 18 deletions(-) diff --git a/b2g/config/aries/sources.xml b/b2g/config/aries/sources.xml index 8dccac33ddf..528e121b45e 100644 --- a/b2g/config/aries/sources.xml +++ b/b2g/config/aries/sources.xml @@ -15,7 +15,7 @@ - + @@ -23,7 +23,7 @@ - + diff --git a/b2g/config/dolphin/sources.xml b/b2g/config/dolphin/sources.xml index 238ba932e2d..c6b682a2e91 100644 --- a/b2g/config/dolphin/sources.xml +++ b/b2g/config/dolphin/sources.xml @@ -15,7 +15,7 @@ - + @@ -23,7 +23,7 @@ - + diff --git a/b2g/config/emulator-ics/sources.xml b/b2g/config/emulator-ics/sources.xml index 0a506461bbd..734631a7c94 100644 --- a/b2g/config/emulator-ics/sources.xml +++ b/b2g/config/emulator-ics/sources.xml @@ -19,7 +19,7 @@ - + diff --git a/b2g/config/emulator-jb/sources.xml b/b2g/config/emulator-jb/sources.xml index 8d84621adec..2070ced2909 100644 --- a/b2g/config/emulator-jb/sources.xml +++ b/b2g/config/emulator-jb/sources.xml @@ -17,10 +17,10 @@ - + - + diff --git a/b2g/config/emulator-kk/sources.xml b/b2g/config/emulator-kk/sources.xml index 89914cb3882..73c497efdba 100644 --- a/b2g/config/emulator-kk/sources.xml +++ b/b2g/config/emulator-kk/sources.xml @@ -15,7 +15,7 @@ - + @@ -23,7 +23,7 @@ - + diff --git a/b2g/config/emulator-l/sources.xml b/b2g/config/emulator-l/sources.xml index 3ea4aa87c68..b7ad9ace7bb 100644 --- a/b2g/config/emulator-l/sources.xml +++ b/b2g/config/emulator-l/sources.xml @@ -15,7 +15,7 @@ - + @@ -23,7 +23,7 @@ - + diff --git a/b2g/config/emulator/sources.xml b/b2g/config/emulator/sources.xml index 0a506461bbd..734631a7c94 100644 --- a/b2g/config/emulator/sources.xml +++ b/b2g/config/emulator/sources.xml @@ -19,7 +19,7 @@ - + diff --git a/b2g/config/flame-kk/sources.xml b/b2g/config/flame-kk/sources.xml index 2ef1a9f6a1d..1b9e7974971 100644 --- a/b2g/config/flame-kk/sources.xml +++ b/b2g/config/flame-kk/sources.xml @@ -15,7 +15,7 @@ - + @@ -23,7 +23,7 @@ - + diff --git a/b2g/config/nexus-4/sources.xml b/b2g/config/nexus-4/sources.xml index f4c3db458ae..c4c1cbe75ce 100644 --- a/b2g/config/nexus-4/sources.xml +++ b/b2g/config/nexus-4/sources.xml @@ -17,10 +17,10 @@ - + - + diff --git a/b2g/config/nexus-5-l/sources.xml b/b2g/config/nexus-5-l/sources.xml index bf76e4d229e..8dbab3baccf 100644 --- a/b2g/config/nexus-5-l/sources.xml +++ b/b2g/config/nexus-5-l/sources.xml @@ -15,7 +15,7 @@ - + @@ -23,7 +23,7 @@ - +