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"
10 #include "VolumeManager.h"
15 VolumeServiceIOThread::VolumeServiceIOThread(nsVolumeService
* aVolumeService
)
16 : mVolumeService(aVolumeService
)
18 MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
20 VolumeManager::RegisterStateObserver(this);
21 Volume::RegisterObserver(this);
25 VolumeServiceIOThread::~VolumeServiceIOThread()
27 MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
28 Volume::UnregisterObserver(this);
29 VolumeManager::UnregisterStateObserver(this);
33 VolumeServiceIOThread::Notify(Volume
* const & aVolume
)
35 MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
36 if (VolumeManager::State() != VolumeManager::VOLUMES_READY
) {
39 mVolumeService
->UpdateVolumeIOThread(aVolume
);
43 VolumeServiceIOThread::Notify(const VolumeManager::StateChangedEvent
& aEvent
)
45 MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
50 VolumeServiceIOThread::UpdateAllVolumes()
52 MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
53 if (VolumeManager::State() != VolumeManager::VOLUMES_READY
) {
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
;
68 InitVolumeServiceIOThread(nsVolumeService
* const & aVolumeService
)
70 MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
71 sVolumeServiceIOThread
= new VolumeServiceIOThread(aVolumeService
);
75 ShutdownVolumeServiceIOThread()
77 MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());
78 sVolumeServiceIOThread
= nullptr;