dom/system/gonk/VolumeServiceIOThread.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/system/gonk/VolumeServiceIOThread.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,82 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#include "VolumeServiceIOThread.h"
     1.9 +#include "base/message_loop.h"
    1.10 +#include "nsVolumeService.h"
    1.11 +#include "nsXULAppAPI.h"
    1.12 +#include "Volume.h"
    1.13 +#include "VolumeManager.h"
    1.14 +
    1.15 +namespace mozilla {
    1.16 +namespace system {
    1.17 +
    1.18 +VolumeServiceIOThread::VolumeServiceIOThread(nsVolumeService* aVolumeService)
    1.19 +  : mVolumeService(aVolumeService)
    1.20 +{
    1.21 +  MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
    1.22 +
    1.23 +  VolumeManager::RegisterStateObserver(this);
    1.24 +  Volume::RegisterObserver(this);
    1.25 +  UpdateAllVolumes();
    1.26 +}
    1.27 +
    1.28 +VolumeServiceIOThread::~VolumeServiceIOThread()
    1.29 +{
    1.30 +  MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
    1.31 +  Volume::UnregisterObserver(this);
    1.32 +  VolumeManager::UnregisterStateObserver(this);
    1.33 +}
    1.34 +
    1.35 +void
    1.36 +VolumeServiceIOThread::Notify(Volume* const & aVolume)
    1.37 +{
    1.38 +  MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
    1.39 +  if (VolumeManager::State() != VolumeManager::VOLUMES_READY) {
    1.40 +    return;
    1.41 +  }
    1.42 +  mVolumeService->UpdateVolumeIOThread(aVolume);
    1.43 +}
    1.44 +
    1.45 +void
    1.46 +VolumeServiceIOThread::Notify(const VolumeManager::StateChangedEvent& aEvent)
    1.47 +{
    1.48 +  MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
    1.49 +  UpdateAllVolumes();
    1.50 +}
    1.51 +
    1.52 +void
    1.53 +VolumeServiceIOThread::UpdateAllVolumes()
    1.54 +{
    1.55 +  MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
    1.56 +  if (VolumeManager::State() != VolumeManager::VOLUMES_READY) {
    1.57 +    return;
    1.58 +  }
    1.59 +  VolumeManager::VolumeArray::size_type numVolumes = VolumeManager::NumVolumes();
    1.60 +  VolumeManager::VolumeArray::index_type volIndex;
    1.61 +
    1.62 +  for (volIndex = 0; volIndex < numVolumes; volIndex++) {
    1.63 +    RefPtr<Volume>  vol = VolumeManager::GetVolume(volIndex);
    1.64 +    mVolumeService->UpdateVolumeIOThread(vol);
    1.65 +  }
    1.66 +}
    1.67 +
    1.68 +static StaticRefPtr<VolumeServiceIOThread> sVolumeServiceIOThread;
    1.69 +
    1.70 +void
    1.71 +InitVolumeServiceIOThread(nsVolumeService* const & aVolumeService)
    1.72 +{
    1.73 +  MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
    1.74 +  sVolumeServiceIOThread = new VolumeServiceIOThread(aVolumeService);
    1.75 +}
    1.76 +
    1.77 +void
    1.78 +ShutdownVolumeServiceIOThread()
    1.79 +{
    1.80 +  MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
    1.81 +  sVolumeServiceIOThread = nullptr;
    1.82 +}
    1.83 +
    1.84 +} // system
    1.85 +} // mozilla

mercurial