Bug 1050720 - [DeviceStorage] Avoid to send the same status in two continuous storage-state-change event. r=dhylands
authorAlphan Chen <alchen@mozilla.com>
Mon, 11 Aug 2014 23:31:00 -0400
changeset 198999 112307bd6632315900f569dc9c85e12c3f71ed8e
parent 198998 40dbead999f087dc0cb476c359c7590fd5e18ec7
child 199000 48746ed94cb895837b69de4c7fdf96eb3558d2cc
push id9654
push userryanvm@gmail.com
push dateTue, 12 Aug 2014 15:03:23 +0000
treeherderb2g-inbound@112307bd6632 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdhylands
bugs1050720
milestone34.0a1
Bug 1050720 - [DeviceStorage] Avoid to send the same status in two continuous storage-state-change event. r=dhylands
dom/devicestorage/DeviceStorage.h
dom/devicestorage/nsDeviceStorage.cpp
--- a/dom/devicestorage/DeviceStorage.h
+++ b/dom/devicestorage/DeviceStorage.h
@@ -337,18 +337,19 @@ private:
 
   friend class WatchFileEvent;
   friend class DeviceStorageRequest;
 
   static mozilla::StaticAutoPtr<nsTArray<nsString>> sVolumeNameCache;
 
 #ifdef MOZ_WIDGET_GONK
   nsString mLastStatus;
+  nsString mLastStorageStatus;
   void DispatchStatusChangeEvent(nsAString& aStatus);
-  void DispatchStorageStatusChangeEvent(nsAString& aVolumeStatus);
+  void DispatchStorageStatusChangeEvent(nsAString& aStorageStatus);
 #endif
 
   // nsIDOMDeviceStorage.type
   enum {
       DEVICE_STORAGE_TYPE_DEFAULT = 0,
       DEVICE_STORAGE_TYPE_SHARED,
       DEVICE_STORAGE_TYPE_EXTERNAL
   };
--- a/dom/devicestorage/nsDeviceStorage.cpp
+++ b/dom/devicestorage/nsDeviceStorage.cpp
@@ -4156,23 +4156,29 @@ nsDOMDeviceStorage::DispatchStatusChange
                                           init);
   event->SetTrusted(true);
 
   bool ignore;
   DispatchEvent(event, &ignore);
 }
 
 void
-nsDOMDeviceStorage::DispatchStorageStatusChangeEvent(nsAString& aVolumeStatus)
+nsDOMDeviceStorage::DispatchStorageStatusChangeEvent(nsAString& aStorageStatus)
 {
+  if (aStorageStatus == mLastStorageStatus) {
+     // We've already sent this status, don't bother sending it again.
+    return;
+  }
+  mLastStorageStatus = aStorageStatus;
+
   DeviceStorageChangeEventInit init;
   init.mBubbles = true;
   init.mCancelable = false;
   init.mPath = mStorageName;
-  init.mReason = aVolumeStatus;
+  init.mReason = aStorageStatus;
 
   nsRefPtr<DeviceStorageChangeEvent> event =
     DeviceStorageChangeEvent::Constructor(this, NS_LITERAL_STRING("storage-state-change"),
                                           init);
   event->SetTrusted(true);
 
   bool ignore;
   DispatchEvent(event, &ignore);