Bumping gaia.json for 2 gaia revision(s) a=gaia-bump
[gecko.git] / dom / system / gonk / VolumeServiceIOThread.cpp
blobbfaa1adc94284bf88f55aa60347c7ca17e189970
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "VolumeServiceIOThread.h"
6 #include "base/message_loop.h"
7 #include "nsVolumeService.h"
8 #include "nsXULAppAPI.h"
9 #include "Volume.h"
10 #include "VolumeManager.h"
12 namespace mozilla {
13 namespace system {
15 VolumeServiceIOThread::VolumeServiceIOThread(nsVolumeService* aVolumeService)
16 : mVolumeService(aVolumeService)
18 MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
20 VolumeManager::RegisterStateObserver(this);
21 Volume::RegisterObserver(this);
22 UpdateAllVolumes();
25 VolumeServiceIOThread::~VolumeServiceIOThread()
27 MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
28 Volume::UnregisterObserver(this);
29 VolumeManager::UnregisterStateObserver(this);
32 void
33 VolumeServiceIOThread::Notify(Volume* const & aVolume)
35 MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
36 if (VolumeManager::State() != VolumeManager::VOLUMES_READY) {
37 return;
39 mVolumeService->UpdateVolumeIOThread(aVolume);
42 void
43 VolumeServiceIOThread::Notify(const VolumeManager::StateChangedEvent& aEvent)
45 MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
46 UpdateAllVolumes();
49 void
50 VolumeServiceIOThread::UpdateAllVolumes()
52 MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
53 if (VolumeManager::State() != VolumeManager::VOLUMES_READY) {
54 return;
56 VolumeManager::VolumeArray::size_type numVolumes = VolumeManager::NumVolumes();
57 VolumeManager::VolumeArray::index_type volIndex;
59 for (volIndex = 0; volIndex < numVolumes; volIndex++) {
60 RefPtr<Volume> vol = VolumeManager::GetVolume(volIndex);
61 mVolumeService->UpdateVolumeIOThread(vol);
65 static StaticRefPtr<VolumeServiceIOThread> sVolumeServiceIOThread;
67 void
68 InitVolumeServiceIOThread(nsVolumeService* const & aVolumeService)
70 MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
71 sVolumeServiceIOThread = new VolumeServiceIOThread(aVolumeService);
74 void
75 ShutdownVolumeServiceIOThread()
77 MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
78 sVolumeServiceIOThread = nullptr;
81 } // system
82 } // mozilla