summaryrefslogtreecommitdiffstats
path: root/dom/system/gonk/nsVolumeService.h
blob: 9bddc0b8fe20eb2d27ba7188bb26d445bcd1faba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* 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/. */

#ifndef mozilla_system_nsvolumeservice_h__
#define mozilla_system_nsvolumeservice_h__

#include "mozilla/Monitor.h"
#include "mozilla/RefPtr.h"
#include "mozilla/StaticPtr.h"
#include "nsCOMPtr.h"
#include "nsIDOMWakeLockListener.h"
#include "nsIVolume.h"
#include "nsIVolumeService.h"
#include "nsVolume.h"

namespace mozilla {

namespace dom {
class VolumeInfo;
} // dom

namespace system {

class Volume;

/***************************************************************************
* The nsVolumeData class encapsulates the data that is updated/maintained
* on the main thread in order to support the nsIVolume and nsIVolumeService
* classes.
*/

class nsVolumeService final : public nsIVolumeService,
                              public nsIDOMMozWakeLockListener
{
public:
  NS_DECL_THREADSAFE_ISUPPORTS
  NS_DECL_NSIVOLUMESERVICE
  NS_DECL_NSIDOMMOZWAKELOCKLISTENER

  nsVolumeService();

  static already_AddRefed<nsVolumeService> GetSingleton();
  //static nsVolumeService* GetSingleton();
  static void Shutdown();

  void DumpNoLock(const char* aLabel);

  // To use this function, you have to create a new volume and pass it in.
  void UpdateVolume(nsVolume* aVolume, bool aNotifyObservers = true);
  void UpdateVolumeIOThread(const Volume* aVolume);

  void RecvVolumesFromParent(const nsTArray<dom::VolumeInfo>& aVolumes);
  void GetVolumesForIPC(nsTArray<dom::VolumeInfo>* aResult);

  void RemoveVolumeByName(const nsAString& aName);

private:
  ~nsVolumeService();

  void CheckMountLock(const nsAString& aMountLockName,
                      const nsAString& aMountLockState);
  already_AddRefed<nsVolume> FindVolumeByMountLockName(const nsAString& aMountLockName);

  already_AddRefed<nsVolume> FindVolumeByName(const nsAString& aName,
                                              nsVolume::Array::index_type* aIndex = nullptr);

  Monitor mArrayMonitor;
  nsVolume::Array mVolumeArray;

  static StaticRefPtr<nsVolumeService> sSingleton;
  bool mGotVolumesFromParent;
};

} // system
} // mozilla

#endif  // mozilla_system_nsvolumeservice_h__