Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "VolumeServiceIOThread.h" |
michael@0 | 6 | #include "base/message_loop.h" |
michael@0 | 7 | #include "nsVolumeService.h" |
michael@0 | 8 | #include "nsXULAppAPI.h" |
michael@0 | 9 | #include "Volume.h" |
michael@0 | 10 | #include "VolumeManager.h" |
michael@0 | 11 | |
michael@0 | 12 | namespace mozilla { |
michael@0 | 13 | namespace system { |
michael@0 | 14 | |
michael@0 | 15 | VolumeServiceIOThread::VolumeServiceIOThread(nsVolumeService* aVolumeService) |
michael@0 | 16 | : mVolumeService(aVolumeService) |
michael@0 | 17 | { |
michael@0 | 18 | MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop()); |
michael@0 | 19 | |
michael@0 | 20 | VolumeManager::RegisterStateObserver(this); |
michael@0 | 21 | Volume::RegisterObserver(this); |
michael@0 | 22 | UpdateAllVolumes(); |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | VolumeServiceIOThread::~VolumeServiceIOThread() |
michael@0 | 26 | { |
michael@0 | 27 | MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop()); |
michael@0 | 28 | Volume::UnregisterObserver(this); |
michael@0 | 29 | VolumeManager::UnregisterStateObserver(this); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | void |
michael@0 | 33 | VolumeServiceIOThread::Notify(Volume* const & aVolume) |
michael@0 | 34 | { |
michael@0 | 35 | MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop()); |
michael@0 | 36 | if (VolumeManager::State() != VolumeManager::VOLUMES_READY) { |
michael@0 | 37 | return; |
michael@0 | 38 | } |
michael@0 | 39 | mVolumeService->UpdateVolumeIOThread(aVolume); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | void |
michael@0 | 43 | VolumeServiceIOThread::Notify(const VolumeManager::StateChangedEvent& aEvent) |
michael@0 | 44 | { |
michael@0 | 45 | MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop()); |
michael@0 | 46 | UpdateAllVolumes(); |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | void |
michael@0 | 50 | VolumeServiceIOThread::UpdateAllVolumes() |
michael@0 | 51 | { |
michael@0 | 52 | MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop()); |
michael@0 | 53 | if (VolumeManager::State() != VolumeManager::VOLUMES_READY) { |
michael@0 | 54 | return; |
michael@0 | 55 | } |
michael@0 | 56 | VolumeManager::VolumeArray::size_type numVolumes = VolumeManager::NumVolumes(); |
michael@0 | 57 | VolumeManager::VolumeArray::index_type volIndex; |
michael@0 | 58 | |
michael@0 | 59 | for (volIndex = 0; volIndex < numVolumes; volIndex++) { |
michael@0 | 60 | RefPtr<Volume> vol = VolumeManager::GetVolume(volIndex); |
michael@0 | 61 | mVolumeService->UpdateVolumeIOThread(vol); |
michael@0 | 62 | } |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | static StaticRefPtr<VolumeServiceIOThread> sVolumeServiceIOThread; |
michael@0 | 66 | |
michael@0 | 67 | void |
michael@0 | 68 | InitVolumeServiceIOThread(nsVolumeService* const & aVolumeService) |
michael@0 | 69 | { |
michael@0 | 70 | MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop()); |
michael@0 | 71 | sVolumeServiceIOThread = new VolumeServiceIOThread(aVolumeService); |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | void |
michael@0 | 75 | ShutdownVolumeServiceIOThread() |
michael@0 | 76 | { |
michael@0 | 77 | MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop()); |
michael@0 | 78 | sVolumeServiceIOThread = nullptr; |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | } // system |
michael@0 | 82 | } // mozilla |