Bug 1112989 - Part 2. Forward device-storage volumes info to ContentChild before app startup. r=dhylands
authorKan-Ru Chen (陳侃如) <kanru@kanru.info>
Wed, 28 Jan 2015 13:54:10 +0800
changeset 226664 e76c017e5b571df6b0739bb61a9d96b9cd05452d
parent 226663 3680606bad2c7fae111b932dadd150bca8f5f8e8
child 226665 e539715710f65372563acd79fbfb2f9629a9c277
push id28203
push userryanvm@gmail.com
push dateFri, 30 Jan 2015 16:59:54 +0000
treeherdermozilla-central@cdd62a8caf30 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdhylands
bugs1112989
milestone38.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1112989 - Part 2. Forward device-storage volumes info to ContentChild before app startup. r=dhylands
dom/ipc/ContentChild.cpp
dom/ipc/ContentChild.h
dom/ipc/ContentParent.cpp
dom/ipc/PContent.ipdl
dom/system/gonk/nsVolumeService.cpp
dom/system/gonk/nsVolumeService.h
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -2132,16 +2132,28 @@ bool
 ContentChild::RecvLastPrivateDocShellDestroyed()
 {
     nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
     obs->NotifyObservers(nullptr, "last-pb-context-exited", nullptr);
     return true;
 }
 
 bool
+ContentChild::RecvVolumes(nsTArray<VolumeInfo>&& aVolumes)
+{
+#ifdef MOZ_WIDGET_GONK
+    nsRefPtr<nsVolumeService> vs = nsVolumeService::GetSingleton();
+    if (vs) {
+        vs->RecvVolumesFromParent(aVolumes);
+    }
+#endif
+    return true;
+}
+
+bool
 ContentChild::RecvFilePathUpdate(const nsString& aStorageType,
                                  const nsString& aStorageName,
                                  const nsString& aPath,
                                  const nsCString& aReason)
 {
     nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(aStorageType, aStorageName, aPath);
 
     nsString reason;
--- a/dom/ipc/ContentChild.h
+++ b/dom/ipc/ContentChild.h
@@ -327,16 +327,17 @@ public:
     virtual bool RecvCycleCollect() MOZ_OVERRIDE;
 
     virtual bool RecvAppInfo(const nsCString& version, const nsCString& buildID,
                              const nsCString& name, const nsCString& UAName,
                              const nsCString& ID, const nsCString& vendor) MOZ_OVERRIDE;
 
     virtual bool RecvLastPrivateDocShellDestroyed() MOZ_OVERRIDE;
 
+    virtual bool RecvVolumes(InfallibleTArray<VolumeInfo>&& aVolumes) MOZ_OVERRIDE;
     virtual bool RecvFilePathUpdate(const nsString& aStorageType,
                                     const nsString& aStorageName,
                                     const nsString& aPath,
                                     const nsCString& aReason) MOZ_OVERRIDE;
     virtual bool RecvFileSystemUpdate(const nsString& aFsName,
                                       const nsString& aVolumeName,
                                       const int32_t& aState,
                                       const int32_t& aMountGeneration,
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -1314,16 +1314,24 @@ ContentParent::Init()
 
 void
 ContentParent::ForwardKnownInfo()
 {
     MOZ_ASSERT(mMetamorphosed);
     if (!mMetamorphosed) {
         return;
     }
+#ifdef MOZ_WIDGET_GONK
+    InfallibleTArray<VolumeInfo> volumeInfo;
+    nsRefPtr<nsVolumeService> vs = nsVolumeService::GetSingleton();
+    if (vs) {
+        vs->GetVolumesForIPC(&volumeInfo);
+        unused << SendVolumes(volumeInfo);
+    }
+#endif /* MOZ_WIDGET_GONK */
 }
 
 namespace {
 
 class SystemMessageHandledListener MOZ_FINAL
     : public nsITimerCallback
     , public LinkedListElement<SystemMessageHandledListener>
 {
--- a/dom/ipc/PContent.ipdl
+++ b/dom/ipc/PContent.ipdl
@@ -466,16 +466,18 @@ child:
 
     UpdateDictionaryList(nsString[] dictionaries);
 
     // nsIPermissionManager messages
     AddPermission(Permission permission);
 
     ScreenSizeChanged(gfxIntSize size);
 
+    Volumes(VolumeInfo[] volumes);
+
     FlushMemory(nsString reason);
 
     GarbageCollect();
     CycleCollect();
 
     /**
      * Start accessibility engine in content process.
      */
--- a/dom/system/gonk/nsVolumeService.cpp
+++ b/dom/system/gonk/nsVolumeService.cpp
@@ -275,47 +275,62 @@ nsVolumeService::GetVolumesForIPC(nsTArr
     volInfo->isFake()           = vol->mIsFake;
     volInfo->isUnmounting()     = vol->mIsUnmounting;
     volInfo->isRemovable()      = vol->mIsRemovable;
     volInfo->isHotSwappable()   = vol->mIsHotSwappable;
   }
 }
 
 void
-nsVolumeService::GetVolumesFromParent()
+nsVolumeService::RecvVolumesFromParent(const nsTArray<VolumeInfo>& aVolumes)
 {
   if (XRE_GetProcessType() == GeckoProcessType_Default) {
     // We are the parent. Therefore our volumes are already correct.
     return;
   }
   if (mGotVolumesFromParent) {
     // We've already done this, no need to do it again.
     return;
   }
-  mGotVolumesFromParent = true;
-
-  nsTArray<VolumeInfo> result;
-  ContentChild::GetSingleton()->SendGetVolumes(&result);
-  for (uint32_t i = 0; i < result.Length(); i++) {
-    const VolumeInfo& volInfo(result[i]);
+  for (uint32_t i = 0; i < aVolumes.Length(); i++) {
+    const VolumeInfo& volInfo(aVolumes[i]);
     nsRefPtr<nsVolume> vol = new nsVolume(volInfo.name(),
                                           volInfo.mountPoint(),
                                           volInfo.volState(),
                                           volInfo.mountGeneration(),
                                           volInfo.isMediaPresent(),
                                           volInfo.isSharing(),
                                           volInfo.isFormatting(),
                                           volInfo.isFake(),
                                           volInfo.isUnmounting(),
                                           volInfo.isRemovable(),
                                           volInfo.isHotSwappable());
     UpdateVolume(vol, false);
   }
 }
 
+void
+nsVolumeService::GetVolumesFromParent()
+{
+  if (XRE_GetProcessType() == GeckoProcessType_Default) {
+    // We are the parent. Therefore our volumes are already correct.
+    return;
+  }
+  if (mGotVolumesFromParent) {
+    // We've already done this, no need to do it again.
+    return;
+  }
+
+  nsTArray<VolumeInfo> result;
+  ContentChild::GetSingleton()->SendGetVolumes(&result);
+  RecvVolumesFromParent(result);
+
+  mGotVolumesFromParent = true;
+}
+
 NS_IMETHODIMP
 nsVolumeService::CreateMountLock(const nsAString& aVolumeName, nsIVolumeMountLock **aResult)
 {
   nsCOMPtr<nsIVolumeMountLock> mountLock = nsVolumeMountLock::Create(aVolumeName);
   if (!mountLock) {
     return NS_ERROR_NOT_AVAILABLE;
   }
   mountLock.forget(aResult);
--- a/dom/system/gonk/nsVolumeService.h
+++ b/dom/system/gonk/nsVolumeService.h
@@ -43,16 +43,17 @@ public:
 
   static already_AddRefed<nsVolumeService> GetSingleton();
   //static nsVolumeService* GetSingleton();
   static void Shutdown();
 
   void UpdateVolume(nsIVolume* aVolume, bool aNotifyObservers = true);
   void UpdateVolumeIOThread(const Volume* aVolume);
 
+  void RecvVolumesFromParent(const nsTArray<dom::VolumeInfo>& aVolumes);
   void GetVolumesForIPC(nsTArray<dom::VolumeInfo>* aResult);
 
 private:
   ~nsVolumeService();
 
   void CheckMountLock(const nsAString& aMountLockName,
                       const nsAString& aMountLockState);
   already_AddRefed<nsVolume> FindVolumeByMountLockName(const nsAString& aMountLockName);