Bug 1299500 - Get rid of DeviceStorage API - part 3 - DeviceStorageAreaListener, r=ehsan
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 08 Mar 2017 20:15:44 +0100
changeset 346577 07ed303b1e3ee01e9c1850ff2d1a2c11f1ba1e21
parent 346576 41cbf92cfad2d34768272a5a4dedf9758d92a5a4
child 346578 a35a754a55d89566aa9c0e3cf4646e6782c4ab78
push id87844
push useramarchesini@mozilla.com
push dateWed, 08 Mar 2017 19:31:23 +0000
treeherdermozilla-inbound@c539b2e9f9c9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1299500
milestone55.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 1299500 - Get rid of DeviceStorage API - part 3 - DeviceStorageAreaListener, r=ehsan
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
@@ -28,17 +28,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"
@@ -214,17 +213,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(mVRServiceTest)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(Navigator)
 
@@ -300,20 +298,16 @@ Navigator::Invalidate()
 
   mServiceWorkerContainer = nullptr;
 
   if (mMediaKeySystemAccessManager) {
     mMediaKeySystemAccessManager->Shutdown();
     mMediaKeySystemAccessManager = nullptr;
   }
 
-  if (mDeviceStorageAreaListener) {
-    mDeviceStorageAreaListener = nullptr;
-  }
-
   if (mGamepadServiceTest) {
     mGamepadServiceTest->Shutdown();
     mGamepadServiceTest = nullptr;
   }
 
   mVRGetDisplaysPromises.Clear();
 
   if (mVRServiceTest) {
@@ -1033,30 +1027,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
@@ -70,17 +70,16 @@ class NavigatorUserMediaSuccessCallback;
 class NavigatorUserMediaErrorCallback;
 class MozGetUserMediaDevicesSuccessCallback;
 
 namespace network {
 class Connection;
 } // namespace network
 
 class PowerManager;
-class DeviceStorageAreaListener;
 class Presentation;
 class LegacyMozTCPSocket;
 class VRDisplay;
 class VRServiceTest;
 class StorageManager;
 
 namespace time {
 class TimeManager;
@@ -191,17 +190,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);
 
@@ -322,17 +320,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;
   RefPtr<VRServiceTest> mVRServiceTest;
   nsTArray<uint32_t> mRequestedVibrationPattern;
   RefPtr<StorageManager> mStorageManager;
 };
 
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
@@ -9,28 +9,23 @@ with Files("**"):
 
 
 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
@@ -2775,19 +2775,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
@@ -480,17 +480,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',