Bug 1465898 - Remove unused code for managing physical audio devices; r=agaynor
authorGabriele Svelto <gsvelto@mozilla.com>
Mon, 04 Jun 2018 22:28:09 +0200
changeset 421376 f2fa6b2a4eadc37d5c54fd64302bb63e596acee2
parent 421275 a358755643e92f8fc55a23e3ab1fbf88695b8bf3
child 421377 00c3d250decafbe23ce789dba82e19b9014143de
push id34093
push useraiakab@mozilla.com
push dateTue, 05 Jun 2018 21:58:58 +0000
treeherdermozilla-central@da28b92efe6f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersagaynor
bugs1465898
milestone62.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 1465898 - Remove unused code for managing physical audio devices; r=agaynor MozReview-Commit-ID: 7NsUfzJCUOB
hal/Hal.cpp
hal/Hal.h
hal/HalInternal.h
hal/HalTypes.h
hal/fallback/FallbackSwitch.cpp
hal/moz.build
hal/sandbox/PHal.ipdl
hal/sandbox/SandboxHal.cpp
--- a/hal/Hal.cpp
+++ b/hal/Hal.cpp
@@ -582,94 +582,16 @@ LockScreenOrientation(const dom::ScreenO
 
 void
 UnlockScreenOrientation()
 {
   AssertMainThread();
   PROXY_IF_SANDBOXED(UnlockScreenOrientation());
 }
 
-void
-EnableSwitchNotifications(SwitchDevice aDevice) {
-  AssertMainThread();
-  PROXY_IF_SANDBOXED(EnableSwitchNotifications(aDevice));
-}
-
-void
-DisableSwitchNotifications(SwitchDevice aDevice) {
-  AssertMainThread();
-  PROXY_IF_SANDBOXED(DisableSwitchNotifications(aDevice));
-}
-
-typedef mozilla::ObserverList<SwitchEvent> SwitchObserverList;
-
-static SwitchObserverList *sSwitchObserverLists = nullptr;
-
-static SwitchObserverList&
-GetSwitchObserverList(SwitchDevice aDevice) {
-  MOZ_ASSERT(0 <= aDevice && aDevice < NUM_SWITCH_DEVICE);
-  if (sSwitchObserverLists == nullptr) {
-    sSwitchObserverLists = new SwitchObserverList[NUM_SWITCH_DEVICE];
-  }
-  return sSwitchObserverLists[aDevice];
-}
-
-static void
-ReleaseObserversIfNeeded() {
-  for (int i = 0; i < NUM_SWITCH_DEVICE; i++) {
-    if (sSwitchObserverLists[i].Length() != 0)
-      return;
-  }
-
-  //The length of every list is 0, no observer in the list.
-  delete [] sSwitchObserverLists;
-  sSwitchObserverLists = nullptr;
-}
-
-void
-RegisterSwitchObserver(SwitchDevice aDevice, SwitchObserver *aObserver)
-{
-  AssertMainThread();
-  SwitchObserverList& observer = GetSwitchObserverList(aDevice);
-  observer.AddObserver(aObserver);
-  if (observer.Length() == 1) {
-    EnableSwitchNotifications(aDevice);
-  }
-}
-
-void
-UnregisterSwitchObserver(SwitchDevice aDevice, SwitchObserver *aObserver)
-{
-  AssertMainThread();
-
-  if (!sSwitchObserverLists) {
-    return;
-  }
-
-  SwitchObserverList& observer = GetSwitchObserverList(aDevice);
-  if (!observer.RemoveObserver(aObserver) || observer.Length() > 0) {
-    return;
-  }
-
-  DisableSwitchNotifications(aDevice);
-  ReleaseObserversIfNeeded();
-}
-
-void
-NotifySwitchChange(const SwitchEvent& aEvent)
-{
-  // When callback this notification, main thread may call unregister function
-  // first. We should check if this pointer is valid.
-  if (!sSwitchObserverLists)
-    return;
-
-  SwitchObserverList& observer = GetSwitchObserverList(aEvent.device());
-  observer.Broadcast(aEvent);
-}
-
 bool
 SetProcessPrioritySupported()
 {
   RETURN_PROXY_IF_SANDBOXED(SetProcessPrioritySupported(), false);
 }
 
 void
 SetProcessPriority(int aPid, ProcessPriority aPriority)
--- a/hal/Hal.h
+++ b/hal/Hal.h
@@ -257,36 +257,16 @@ void NotifyScreenConfigurationChange(con
 MOZ_MUST_USE bool LockScreenOrientation(const dom::ScreenOrientationInternal& aOrientation);
 
 /**
  * Unlock the screen orientation.
  */
 void UnlockScreenOrientation();
 
 /**
- * Register an observer for the switch of given SwitchDevice.
- *
- * The observer will receive data whenever the data generated by the
- * given switch.
- */
-void RegisterSwitchObserver(hal::SwitchDevice aDevice, hal::SwitchObserver *aSwitchObserver);
-
-/**
- * Unregister an observer for the switch of given SwitchDevice.
- */
-void UnregisterSwitchObserver(hal::SwitchDevice aDevice, hal::SwitchObserver *aSwitchObserver);
-
-/**
- * Notify the state of the switch.
- *
- * This API is internal to hal; clients shouldn't call it directly.
- */
-void NotifySwitchChange(const hal::SwitchEvent& aEvent);
-
-/**
  * Return true if the current platform supports the setting of process
  * priority.
  */
 bool SetProcessPrioritySupported();
 
 /**
  * Set the priority of the given process.
  *
--- a/hal/HalInternal.h
+++ b/hal/HalInternal.h
@@ -50,26 +50,16 @@ void DisableNetworkNotifications();
 void EnableScreenConfigurationNotifications();
 
 /**
  * Disables screen orientation notifications from the backend.
  */
 void DisableScreenConfigurationNotifications();
 
 /**
- * Enable switch notifications from the backend
- */
-void EnableSwitchNotifications(hal::SwitchDevice aDevice);
-
-/**
- * Disable switch notifications from the backend
- */
-void DisableSwitchNotifications(hal::SwitchDevice aDevice);
-
-/**
  * Has the child-side HAL IPC object been destroyed?  If so, you shouldn't send
  * messages to hal_sandbox.
  */
 bool HalChildDestroyed();
 } // namespace MOZ_HAL_NAMESPACE
 } // namespace mozilla
 
 #endif  // mozilla_HalInternal_h
--- a/hal/HalTypes.h
+++ b/hal/HalTypes.h
@@ -15,36 +15,16 @@ namespace hal {
 /**
  * These constants specify special values for content process IDs.  You can get
  * a content process ID by calling ContentChild::GetID() or
  * ContentParent::GetChildID().
  */
 const uint64_t CONTENT_PROCESS_ID_UNKNOWN = uint64_t(-1);
 const uint64_t CONTENT_PROCESS_ID_MAIN = 0;
 
-class SwitchEvent;
-
-enum SwitchDevice {
-  SWITCH_DEVICE_UNKNOWN = -1,
-  SWITCH_HEADPHONES,
-  SWITCH_USB,
-  NUM_SWITCH_DEVICE
-};
-
-enum SwitchState {
-  SWITCH_STATE_UNKNOWN = -1,
-  SWITCH_STATE_ON,
-  SWITCH_STATE_OFF,
-  SWITCH_STATE_HEADSET,          // Headphone with microphone
-  SWITCH_STATE_HEADPHONE,        // without microphone
-  NUM_SWITCH_STATE
-};
-
-typedef Observer<SwitchEvent> SwitchObserver;
-
 // Note that we rely on the order of this enum's entries.  Higher priorities
 // should have larger int values.
 enum ProcessPriority {
   PROCESS_PRIORITY_UNKNOWN = -1,
   PROCESS_PRIORITY_BACKGROUND,
   PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE,
   PROCESS_PRIORITY_FOREGROUND_KEYBOARD,
   // The special class for the preallocated process, high memory priority but
@@ -90,38 +70,16 @@ namespace IPC {
 template <>
 struct ParamTraits<mozilla::hal::WakeLockControl>
   : public ContiguousEnumSerializer<
              mozilla::hal::WakeLockControl,
              mozilla::hal::WAKE_LOCK_REMOVE_ONE,
              mozilla::hal::NUM_WAKE_LOCK>
 {};
 
-/**
- * Serializer for SwitchState
- */
-template <>
-struct ParamTraits<mozilla::hal::SwitchState>:
-  public ContiguousEnumSerializer<
-           mozilla::hal::SwitchState,
-           mozilla::hal::SWITCH_STATE_UNKNOWN,
-           mozilla::hal::NUM_SWITCH_STATE> {
-};
-
-/**
- * Serializer for SwitchDevice
- */
-template <>
-struct ParamTraits<mozilla::hal::SwitchDevice>:
-  public ContiguousEnumSerializer<
-           mozilla::hal::SwitchDevice,
-           mozilla::hal::SWITCH_DEVICE_UNKNOWN,
-           mozilla::hal::NUM_SWITCH_DEVICE> {
-};
-
 template <>
 struct ParamTraits<mozilla::hal::ProcessPriority>:
   public ContiguousEnumSerializer<
            mozilla::hal::ProcessPriority,
            mozilla::hal::PROCESS_PRIORITY_UNKNOWN,
            mozilla::hal::NUM_PROCESS_PRIORITY> {
 };
 
deleted file mode 100644
--- a/hal/fallback/FallbackSwitch.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-/* -*- Mode: C++; 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/. */
-
-#include "mozilla/Hal.h"
-
-using namespace mozilla::hal;
-
-namespace mozilla {
-namespace hal_impl {
-
-void
-EnableSwitchNotifications(SwitchDevice aDevice)
-{
-}
-
-void
-DisableSwitchNotifications(SwitchDevice aDevice)
-{
-}
-
-} // namespace hal_impl
-} // namespace mozilla
--- a/hal/moz.build
+++ b/hal/moz.build
@@ -94,17 +94,16 @@ else:
         'fallback/FallbackSensor.cpp',
         'fallback/FallbackVibration.cpp',
     ]
 
 # Fallbacks for backends no longer implemented.
 UNIFIED_SOURCES += [
     'fallback/FallbackDiskSpaceWatcher.cpp',
     'fallback/FallbackProcessPriority.cpp',
-    'fallback/FallbackSwitch.cpp',
 ]
 
 # Fallbacks for backends implemented on Android only.
 if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'android':
     UNIFIED_SOURCES += [
         'fallback/FallbackNetwork.cpp',
     ]
 
--- a/hal/sandbox/PHal.ipdl
+++ b/hal/sandbox/PHal.ipdl
@@ -8,18 +8,16 @@ include protocol PContent;
 include protocol PBrowser;
 
 include "mozilla/GfxMessageUtils.h";
 
 using mozilla::dom::ScreenOrientationInternal from "mozilla/dom/ScreenOrientation.h";
 using mozilla::hal::SensorType from "mozilla/HalSensor.h";
 using mozilla::hal::SensorAccuracyType from "mozilla/HalSensor.h";
 using mozilla::hal::WakeLockControl from "mozilla/HalTypes.h";
-using mozilla::hal::SwitchState from "mozilla/HalTypes.h";
-using mozilla::hal::SwitchDevice from "mozilla/HalTypes.h";
 using mozilla::hal::ProcessPriority from "mozilla/HalTypes.h";
 using nsIntRect from "nsRect.h";
 using PRTime from "prtime.h";
 
 namespace mozilla {
 
 namespace hal {
 struct BatteryInformation {
@@ -36,21 +34,16 @@ struct SensorData {
 };
 
 struct NetworkInformation {
   uint32_t type;
   bool   isWifi;
   uint32_t dhcpGateway;
 };
 
-struct SwitchEvent {
-  SwitchDevice device;
-  SwitchState status;
-};
-
 struct WakeLockInformation {
   nsString topic;
   uint32_t numLocks;
   uint32_t numHidden;
   uint64_t[] lockingProcesses;
 };
 
 struct ScreenConfiguration {
@@ -68,17 +61,16 @@ namespace hal_sandbox {
 nested(upto inside_cpow) sync protocol PHal {
     manager PContent;
 
 child:
     async NotifyBatteryChange(BatteryInformation aBatteryInfo);
     async NotifyNetworkChange(NetworkInformation aNetworkInfo);
     async NotifyWakeLockChange(WakeLockInformation aWakeLockInfo);
     async NotifyScreenConfigurationChange(ScreenConfiguration aScreenOrientation);
-    async NotifySwitchChange(SwitchEvent aEvent);
 
 parent:
     async Vibrate(uint32_t[] pattern, uint64_t[] id, PBrowser browser);
     async CancelVibrate(uint64_t[] id, PBrowser browser);
 
     async EnableBatteryNotifications();
     async DisableBatteryNotifications();
     sync GetCurrentBatteryInformation()
@@ -98,19 +90,16 @@ parent:
     sync GetWakeLockInfo(nsString aTopic)
       returns (WakeLockInformation aWakeLockInfo);
 
     async EnableScreenConfigurationNotifications();
     async DisableScreenConfigurationNotifications();
     sync LockScreenOrientation(ScreenOrientationInternal aOrientation)
       returns (bool allowed);
     async UnlockScreenOrientation();
- 
-    async EnableSwitchNotifications(SwitchDevice aDevice);
-    async DisableSwitchNotifications(SwitchDevice aDevice);
 
 child:
     async NotifySensorChange(SensorData aSensorData);
 
 parent:
     async EnableSensorNotifications(SensorType aSensor);
     async DisableSensorNotifications(SensorType aSensor);
 
--- a/hal/sandbox/SandboxHal.cpp
+++ b/hal/sandbox/SandboxHal.cpp
@@ -169,28 +169,16 @@ ModifyWakeLock(const nsAString &aTopic,
 }
 
 void
 GetWakeLockInfo(const nsAString &aTopic, WakeLockInformation *aWakeLockInfo)
 {
   Hal()->SendGetWakeLockInfo(nsString(aTopic), aWakeLockInfo);
 }
 
-void
-EnableSwitchNotifications(SwitchDevice aDevice)
-{
-  Hal()->SendEnableSwitchNotifications(aDevice);
-}
-
-void
-DisableSwitchNotifications(SwitchDevice aDevice)
-{
-  Hal()->SendDisableSwitchNotifications(aDevice);
-}
-
 bool
 EnableAlarm()
 {
   MOZ_CRASH("Alarms can't be programmed from sandboxed contexts.  Yet.");
 }
 
 void
 DisableAlarm()
@@ -229,36 +217,31 @@ StopDiskSpaceWatcher()
 }
 
 class HalParent : public PHalParent
                 , public BatteryObserver
                 , public NetworkObserver
                 , public ISensorObserver
                 , public WakeLockObserver
                 , public ScreenConfigurationObserver
-                , public SwitchObserver
 {
 public:
   virtual void
   ActorDestroy(ActorDestroyReason aWhy) override
   {
     // NB: you *must* unconditionally unregister your observer here,
     // if it *may* be registered below.
     hal::UnregisterBatteryObserver(this);
     hal::UnregisterNetworkObserver(this);
     hal::UnregisterScreenConfigurationObserver(this);
     for (int32_t sensor = SENSOR_UNKNOWN + 1;
          sensor < NUM_SENSOR_TYPE; ++sensor) {
       hal::UnregisterSensorObserver(SensorType(sensor), this);
     }
     hal::UnregisterWakeLockObserver(this);
-    for (int32_t switchDevice = SWITCH_DEVICE_UNKNOWN + 1;
-         switchDevice < NUM_SWITCH_DEVICE; ++switchDevice) {
-      hal::UnregisterSwitchObserver(SwitchDevice(switchDevice), this);
-    }
   }
 
   virtual mozilla::ipc::IPCResult
   RecvVibrate(InfallibleTArray<unsigned int>&& pattern,
               InfallibleTArray<uint64_t>&& id,
               PBrowserParent *browserParent) override
   {
     // We give all content vibration permission.
@@ -421,36 +404,16 @@ public:
     hal::GetWakeLockInfo(aTopic, aWakeLockInfo);
     return IPC_OK();
   }
 
   void Notify(const WakeLockInformation& aWakeLockInfo) override
   {
     Unused << SendNotifyWakeLockChange(aWakeLockInfo);
   }
-
-  virtual mozilla::ipc::IPCResult
-  RecvEnableSwitchNotifications(const SwitchDevice& aDevice) override
-  {
-    // Content has no reason to listen to switch events currently.
-    hal::RegisterSwitchObserver(aDevice, this);
-    return IPC_OK();
-  }
-
-  virtual mozilla::ipc::IPCResult
-  RecvDisableSwitchNotifications(const SwitchDevice& aDevice) override
-  {
-    hal::UnregisterSwitchObserver(aDevice, this);
-    return IPC_OK();
-  }
-
-  void Notify(const SwitchEvent& aSwitchEvent) override
-  {
-    Unused << SendNotifySwitchChange(aSwitchEvent);
-  }
 };
 
 class HalChild : public PHalChild {
 public:
   virtual void
   ActorDestroy(ActorDestroyReason aWhy) override
   {
     sHalChildDestroyed = true;
@@ -477,22 +440,16 @@ public:
     return IPC_OK();
   }
 
   virtual mozilla::ipc::IPCResult
   RecvNotifyScreenConfigurationChange(const ScreenConfiguration& aScreenConfiguration) override {
     hal::NotifyScreenConfigurationChange(aScreenConfiguration);
     return IPC_OK();
   }
-
-  virtual mozilla::ipc::IPCResult
-  RecvNotifySwitchChange(const mozilla::hal::SwitchEvent& aEvent) override {
-    hal::NotifySwitchChange(aEvent);
-    return IPC_OK();
-  }
 };
 
 mozilla::ipc::IPCResult
 HalChild::RecvNotifySensorChange(const hal::SensorData &aSensorData) {
   hal::NotifySensorChange(aSensorData);
 
   return IPC_OK();
 }