Line data Source code
1 : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : * This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #include "MediaPrefs.h"
7 :
8 : #include "mozilla/ClearOnShutdown.h"
9 : #include "mozilla/Preferences.h"
10 : #include "mozilla/StaticPtr.h"
11 : #include "MainThreadUtils.h"
12 :
13 : namespace mozilla {
14 :
15 3 : StaticAutoPtr<MediaPrefs> MediaPrefs::sInstance;
16 :
17 : MediaPrefs&
18 11 : MediaPrefs::GetSingleton()
19 : {
20 11 : if (!sInstance) {
21 3 : sInstance = new MediaPrefs;
22 3 : ClearOnShutdown(&sInstance);
23 : }
24 11 : MOZ_ASSERT(SingletonExists());
25 11 : return *sInstance;
26 : }
27 :
28 : bool
29 13 : MediaPrefs::SingletonExists()
30 : {
31 13 : return sInstance != nullptr;
32 : }
33 :
34 3 : MediaPrefs::MediaPrefs()
35 : {
36 3 : MediaPrefs::AssertMainThread();
37 3 : }
38 :
39 165 : void MediaPrefs::AssertMainThread()
40 : {
41 165 : MOZ_ASSERT(NS_IsMainThread(), "this code must be run on the main thread");
42 165 : }
43 :
44 114 : void MediaPrefs::PrefAddVarCache(bool* aVariable,
45 : const char* aPref,
46 : bool aDefault)
47 : {
48 114 : Preferences::AddBoolVarCache(aVariable, aPref, aDefault);
49 114 : }
50 :
51 6 : void MediaPrefs::PrefAddVarCache(int32_t* aVariable,
52 : const char* aPref,
53 : int32_t aDefault)
54 : {
55 6 : Preferences::AddIntVarCache(aVariable, aPref, aDefault);
56 6 : }
57 :
58 39 : void MediaPrefs::PrefAddVarCache(uint32_t* aVariable,
59 : const char* aPref,
60 : uint32_t aDefault)
61 : {
62 39 : Preferences::AddUintVarCache(aVariable, aPref, aDefault);
63 39 : }
64 :
65 0 : void MediaPrefs::PrefAddVarCache(float* aVariable,
66 : const char* aPref,
67 : float aDefault)
68 : {
69 0 : Preferences::AddFloatVarCache(aVariable, aPref, aDefault);
70 0 : }
71 :
72 3 : void MediaPrefs::PrefAddVarCache(AtomicUint32* aVariable,
73 : const char* aPref,
74 : uint32_t aDefault)
75 : {
76 3 : Preferences::AddAtomicUintVarCache(aVariable, aPref, aDefault);
77 3 : }
78 :
79 9 : } // namespace mozilla
|