Bug 1299500 - Get rid of DeviceStorage API - part 3 - DeviceStorageAreaListener, r=ehsan, a=lizzard
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 08 Mar 2017 20:15:44 +0100
changeset 379241 c51eb9dcfded22debfaea75a848de2d5759ee232
parent 379240 71d55c22894809ad6f7efddea305dcfe38cd357d
child 379242 0a2cc0c61dcbfea00ad628130f5313d893ea70bd
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan, lizzard
bugs1299500
milestone53.0
Bug 1299500 - Get rid of DeviceStorage API - part 3 - DeviceStorageAreaListener, r=ehsan, a=lizzard
dom/base/Navigator.cpp
dom/base/Navigator.h
dom/devicestorage/DeviceStorageAreaListener.cpp
dom/devicestorage/DeviceStorageAreaListener.h
dom/devicestorage/moz.build
dom/devicestorage/nsDeviceStorage.cpp
dom/webidl/DeviceStorageAreaListener.webidl
dom/webidl/Navigator.webidl
dom/webidl/moz.build
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -26,17 +26,16 @@
 #include "nsICookiePermission.h"
 #include "nsIScriptSecurityManager.h"
 #include "nsCharSeparatedTokenizer.h"
 #include "nsContentUtils.h"
 #include "nsUnicharUtils.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Telemetry.h"
 #include "BatteryManager.h"
-#include "mozilla/dom/DeviceStorageAreaListener.h"
 #include "mozilla/dom/GamepadServiceTest.h"
 #include "mozilla/dom/PowerManager.h"
 #include "mozilla/dom/WakeLock.h"
 #include "mozilla/dom/power/PowerManagerService.h"
 #include "mozilla/dom/FlyWebPublishedServer.h"
 #include "mozilla/dom/FlyWebService.h"
 #include "mozilla/dom/Permissions.h"
 #include "mozilla/dom/Presentation.h"
@@ -210,17 +209,16 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mAudioChannelManager)
 #endif
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaDevices)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTimeManager)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mServiceWorkerContainer)
 
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWindow)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaKeySystemAccessManager)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDeviceStorageAreaListener)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPresentation)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGamepadServiceTest)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVRGetDisplaysPromises)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(Navigator)
 
 void
@@ -295,20 +293,16 @@ Navigator::Invalidate()
 
   mServiceWorkerContainer = nullptr;
 
   if (mMediaKeySystemAccessManager) {
     mMediaKeySystemAccessManager->Shutdown();
     mMediaKeySystemAccessManager = nullptr;
   }
 
-  if (mDeviceStorageAreaListener) {
-    mDeviceStorageAreaListener = nullptr;
-  }
-
   if (mGamepadServiceTest) {
     mGamepadServiceTest->Shutdown();
     mGamepadServiceTest = nullptr;
   }
 
   mVRGetDisplaysPromises.Clear();
 }
 
@@ -1023,30 +1017,16 @@ Navigator::RegisterProtocolHandler(const
   if (!registrar) {
     return;
   }
 
   aRv = registrar->RegisterProtocolHandler(aProtocol, aURI, aTitle,
                                            mWindow->GetOuterWindow());
 }
 
-DeviceStorageAreaListener*
-Navigator::GetDeviceStorageAreaListener(ErrorResult& aRv)
-{
-  if (!mDeviceStorageAreaListener) {
-    if (!mWindow || !mWindow->GetOuterWindow() || !mWindow->GetDocShell()) {
-      aRv.Throw(NS_ERROR_FAILURE);
-      return nullptr;
-    }
-    mDeviceStorageAreaListener = new DeviceStorageAreaListener(mWindow);
-  }
-
-  return mDeviceStorageAreaListener;
-}
-
 already_AddRefed<nsDOMDeviceStorage>
 Navigator::FindDeviceStorage(const nsAString& aName, const nsAString& aType)
 {
   auto i = mDeviceStorageStores.Length();
   while (i > 0) {
     --i;
     RefPtr<nsDOMDeviceStorage> storage =
       do_QueryReferent(mDeviceStorageStores[i]);
--- a/dom/base/Navigator.h
+++ b/dom/base/Navigator.h
@@ -68,17 +68,16 @@ class NavigatorUserMediaSuccessCallback;
 class NavigatorUserMediaErrorCallback;
 class MozGetUserMediaDevicesSuccessCallback;
 
 namespace network {
 class Connection;
 } // namespace network
 
 class PowerManager;
-class DeviceStorageAreaListener;
 class Presentation;
 class LegacyMozTCPSocket;
 class VRDisplay;
 class StorageManager;
 
 namespace time {
 class TimeManager;
 } // namespace time
@@ -188,17 +187,16 @@ public:
   bool TaintEnabled()
   {
     return false;
   }
   void AddIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv);
   void RemoveIdleObserver(MozIdleObserver& aObserver, ErrorResult& aRv);
   already_AddRefed<WakeLock> RequestWakeLock(const nsAString &aTopic,
                                              ErrorResult& aRv);
-  DeviceStorageAreaListener* GetDeviceStorageAreaListener(ErrorResult& aRv);
 
   already_AddRefed<nsDOMDeviceStorage> GetDeviceStorage(const nsAString& aType,
                                                         ErrorResult& aRv);
 
   void GetDeviceStorages(const nsAString& aType,
                          nsTArray<RefPtr<nsDOMDeviceStorage> >& aStores,
                          ErrorResult& aRv);
 
@@ -304,17 +302,16 @@ private:
 #ifdef MOZ_AUDIO_CHANNEL_MANAGER
   RefPtr<system::AudioChannelManager> mAudioChannelManager;
 #endif
   RefPtr<MediaDevices> mMediaDevices;
   nsTArray<nsWeakPtr> mDeviceStorageStores;
   RefPtr<time::TimeManager> mTimeManager;
   RefPtr<ServiceWorkerContainer> mServiceWorkerContainer;
   nsCOMPtr<nsPIDOMWindowInner> mWindow;
-  RefPtr<DeviceStorageAreaListener> mDeviceStorageAreaListener;
   RefPtr<Presentation> mPresentation;
   RefPtr<GamepadServiceTest> mGamepadServiceTest;
   nsTArray<RefPtr<Promise> > mVRGetDisplaysPromises;
   nsTArray<uint32_t> mRequestedVibrationPattern;
   RefPtr<StorageManager> mStorageManager;
 };
 
 } // namespace dom
deleted file mode 100755
--- a/dom/devicestorage/DeviceStorageAreaListener.cpp
+++ /dev/null
@@ -1,141 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim:set ts=2 sw=2 sts=2 et cindent: */
-/* 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 "mozilla/dom/DeviceStorageAreaListener.h"
-#include "mozilla/dom/DeviceStorageAreaListenerBinding.h"
-#include "mozilla/Attributes.h"
-#include "mozilla/Services.h"
-#include "DeviceStorage.h"
-#include "nsIObserverService.h"
-#ifdef MOZ_WIDGET_GONK
-#include "nsIVolume.h"
-#include "nsIVolumeService.h"
-#endif
-
-namespace mozilla {
-namespace dom {
-
-class VolumeStateObserver final : public nsIObserver
-{
-public:
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIOBSERVER
-
-  explicit VolumeStateObserver(DeviceStorageAreaListener* aListener)
-    : mDeviceStorageAreaListener(aListener) {}
-  void ForgetListener() { mDeviceStorageAreaListener = nullptr; }
-
-private:
-  ~VolumeStateObserver() {};
-
-  // This reference is non-owning and it's cleared by
-  // DeviceStorageAreaListener's destructor.
-  DeviceStorageAreaListener* MOZ_NON_OWNING_REF mDeviceStorageAreaListener;
-};
-
-NS_IMPL_ISUPPORTS(VolumeStateObserver, nsIObserver)
-
-NS_IMETHODIMP
-VolumeStateObserver::Observe(nsISupports *aSubject,
-                             const char *aTopic,
-                             const char16_t *aData)
-{
-  if (!mDeviceStorageAreaListener) {
-    return NS_OK;
-  }
-
-#ifdef MOZ_WIDGET_GONK
-  if (!strcmp(aTopic, NS_VOLUME_STATE_CHANGED)) {
-    nsCOMPtr<nsIVolume> vol = do_QueryInterface(aSubject);
-    MOZ_ASSERT(vol);
-
-    int32_t state;
-    nsresult rv = vol->GetState(&state);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    nsString volName;
-    vol->GetName(volName);
-
-    switch (state) {
-      case nsIVolume::STATE_MOUNTED:
-        mDeviceStorageAreaListener->DispatchStorageAreaChangedEvent(
-          volName,
-          DeviceStorageAreaChangedEventOperation::Added);
-        break;
-      default:
-        mDeviceStorageAreaListener->DispatchStorageAreaChangedEvent(
-          volName,
-          DeviceStorageAreaChangedEventOperation::Removed);
-        break;
-    }
-  }
-#endif
-  return NS_OK;
-}
-
-NS_IMPL_ADDREF_INHERITED(DeviceStorageAreaListener, DOMEventTargetHelper)
-NS_IMPL_RELEASE_INHERITED(DeviceStorageAreaListener, DOMEventTargetHelper)
-
-NS_INTERFACE_MAP_BEGIN(DeviceStorageAreaListener)
-NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
-
-DeviceStorageAreaListener::DeviceStorageAreaListener(nsPIDOMWindowInner* aWindow)
-  : DOMEventTargetHelper(aWindow)
-{
-  MOZ_ASSERT(aWindow);
-
-  MOZ_ASSERT(NS_IsMainThread());
-
-  mVolumeStateObserver = new VolumeStateObserver(this);
-#ifdef MOZ_WIDGET_GONK
-  nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
-  if (obs) {
-    obs->AddObserver(mVolumeStateObserver, NS_VOLUME_STATE_CHANGED, false);
-  }
-#endif
-}
-
-DeviceStorageAreaListener::~DeviceStorageAreaListener()
-{
-#ifdef MOZ_WIDGET_GONK
-  nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
-  if (obs) {
-    obs->RemoveObserver(mVolumeStateObserver, NS_VOLUME_STATE_CHANGED);
-  }
-#endif
-  mVolumeStateObserver->ForgetListener();
-}
-
-JSObject*
-DeviceStorageAreaListener::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
-{
-  return DeviceStorageAreaListenerBinding::Wrap(aCx, this, aGivenProto);
-}
-
-void
-DeviceStorageAreaListener::DispatchStorageAreaChangedEvent(
-  const nsString& aStorageName,
-  DeviceStorageAreaChangedEventOperation aOperation)
-{
-  StateMapType::const_iterator iter = mStorageAreaStateMap.find(aStorageName);
-  if (iter == mStorageAreaStateMap.end() &&
-      aOperation != DeviceStorageAreaChangedEventOperation::Added) {
-    // The operation of the first event to dispatch should be "Added".
-    return;
-  }
-  if (iter != mStorageAreaStateMap.end() &&
-      iter->second == aOperation) {
-    // No need to disptach the event if the state is unchanged.
-    return;
-  }
-
-  mStorageAreaStateMap[aStorageName] = aOperation;
-
-  nsDOMDeviceStorage::InvalidateVolumeCaches();
-}
-
-} // namespace dom
-} // namespace mozilla
deleted file mode 100755
--- a/dom/devicestorage/DeviceStorageAreaListener.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim:set ts=2 sw=2 sts=2 et cindent: */
-/* 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_DeviceStorageAreaListener_h
-#define mozilla_dom_DeviceStorageAreaListener_h
-
-#include <map>
-#include "mozilla/DOMEventTargetHelper.h"
-#include "mozilla/dom/DeviceStorageAreaChangedEvent.h"
-
-namespace mozilla {
-namespace dom {
-
-class VolumeStateObserver;
-
-class DeviceStorageAreaListener final : public DOMEventTargetHelper
-{
-public:
-  NS_DECL_ISUPPORTS_INHERITED
-  IMPL_EVENT_HANDLER(storageareachanged)
-
-  explicit DeviceStorageAreaListener(nsPIDOMWindowInner* aWindow);
-
-  virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
-
-private:
-  friend class VolumeStateObserver;
-
-  typedef std::map<nsString, DeviceStorageAreaChangedEventOperation> StateMapType;
-  StateMapType mStorageAreaStateMap;
-
-  RefPtr<VolumeStateObserver> mVolumeStateObserver;
-
-  ~DeviceStorageAreaListener();
-
-  void DispatchStorageAreaChangedEvent(
-    const nsString& aStorageName,
-    DeviceStorageAreaChangedEventOperation aOperation);
-};
-
-} // namespace dom
-} // namespace mozilla
-
-#endif // mozilla_dom_DeviceStorageAreaListener_h
--- a/dom/devicestorage/moz.build
+++ b/dom/devicestorage/moz.build
@@ -5,28 +5,23 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 EXPORTS += [
     'DeviceStorage.h',
     'DeviceStorageFileDescriptor.h',
     'nsDeviceStorage.h',
 ]
 
-EXPORTS.mozilla.dom += [
-    'DeviceStorageAreaListener.h',
-]
-
 EXPORTS.mozilla.dom.devicestorage += [
     'DeviceStorageRequestChild.h',
     'DeviceStorageRequestParent.h',
     'DeviceStorageStatics.h',
 ]
 
 UNIFIED_SOURCES += [
-    'DeviceStorageAreaListener.cpp',
     'DeviceStorageRequestChild.cpp',
     'DeviceStorageRequestParent.cpp',
     'DeviceStorageStatics.cpp',
     'nsDeviceStorage.cpp',
 ]
 
 IPDL_SOURCES += [
     'PDeviceStorageRequest.ipdl',
--- a/dom/devicestorage/nsDeviceStorage.cpp
+++ b/dom/devicestorage/nsDeviceStorage.cpp
@@ -2773,19 +2773,16 @@ nsDOMDeviceStorage::Shutdown()
 
 StaticAutoPtr<nsTArray<nsString>> nsDOMDeviceStorage::sVolumeNameCache;
 
 // static
 void nsDOMDeviceStorage::InvalidateVolumeCaches()
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  // Currently there is only the one volume cache. DeviceStorageAreaListener
-  // calls this function any time it detects a volume was added or removed.
-
   sVolumeNameCache = nullptr;
 }
 
 // static
 void
 nsDOMDeviceStorage::GetOrderedVolumeNames(
   const nsAString& aType,
   nsDOMDeviceStorage::VolumeNameArray& aVolumeNames)
deleted file mode 100644
--- a/dom/webidl/DeviceStorageAreaListener.webidl
+++ /dev/null
@@ -1,10 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* 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/. */
-
-[Pref="device.storage.enabled"]
-interface DeviceStorageAreaListener : EventTarget {
-  // Fired when a storage area is added or removed.
-  attribute EventHandler onstorageareachanged;
-};
--- a/dom/webidl/Navigator.webidl
+++ b/dom/webidl/Navigator.webidl
@@ -240,21 +240,16 @@ partial interface Navigator {
 
   /**
    * Make CPU instruction subset information available for UpdateUtils.
    */
   [ChromeOnly]
   readonly attribute boolean cpuHasSSE2;
 };
 
-partial interface Navigator {
-  [Throws, Pref="device.storage.enabled"]
-  readonly attribute DeviceStorageAreaListener deviceStorageAreaListener;
-};
-
 // nsIDOMNavigatorDeviceStorage
 partial interface Navigator {
   [Throws, Pref="device.storage.enabled"]
   DeviceStorage? getDeviceStorage(DOMString type);
   [Throws, Pref="device.storage.enabled"]
   sequence<DeviceStorage> getDeviceStorages(DOMString type);
   [Throws, Pref="device.storage.enabled"]
   DeviceStorage? getDeviceStorageByNameAndType(DOMString name, DOMString type);
--- a/dom/webidl/moz.build
+++ b/dom/webidl/moz.build
@@ -119,17 +119,16 @@ WEBIDL_FILES = [
     'DataTransferItem.webidl',
     'DataTransferItemList.webidl',
     'DecoderDoctorNotification.webidl',
     'DedicatedWorkerGlobalScope.webidl',
     'DelayNode.webidl',
     'DesktopNotification.webidl',
     'DeviceMotionEvent.webidl',
     'DeviceStorage.webidl',
-    'DeviceStorageAreaListener.webidl',
     'Directory.webidl',
     'Document.webidl',
     'DocumentFragment.webidl',
     'DocumentTimeline.webidl',
     'DocumentType.webidl',
     'DOMCursor.webidl',
     'DOMError.webidl',
     'DOMException.webidl',