Bug 1888033 - [Menu Redesign] Add a secret setting and feature flag for the menu...
[gecko.git] / toolkit / xre / LauncherRegistryInfo.h
blobc89ed66a695fa86d2d5964e1fd2590a96d1a200e
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_LauncherRegistryInfo_h
8 #define mozilla_LauncherRegistryInfo_h
10 #include "mozilla/Maybe.h"
11 #include "mozilla/WinHeaderOnlyUtils.h"
12 #include "nsWindowsHelpers.h"
14 #include <string>
16 /**
17 * We use std::wstring here because this code must be usable within both the
18 * launcher process and Gecko itself.
21 namespace mozilla {
23 class LauncherRegistryInfo final {
24 public:
25 enum class ProcessType { Launcher, Browser };
27 enum class EnabledState {
28 Enabled,
29 FailDisabled,
30 ForceDisabled,
33 enum class CheckOption {
34 Default,
35 Force,
38 LauncherRegistryInfo() : mBinPath(GetFullBinaryPath().get()) {}
39 ~LauncherRegistryInfo() { Abort(); }
41 LauncherVoidResult ReflectPrefToRegistry(const bool aEnable);
42 LauncherResult<EnabledState> IsEnabled();
43 LauncherResult<bool> IsTelemetryEnabled();
44 LauncherVoidResult ReflectTelemetryPrefToRegistry(const bool aEnable);
45 LauncherResult<ProcessType> Check(
46 const ProcessType aDesiredType,
47 const CheckOption aOption = CheckOption::Default);
48 LauncherVoidResult DisableDueToFailure();
49 LauncherVoidResult Commit();
50 void Abort();
51 LauncherResult<std::wstring> GetBlocklistFileName();
53 private:
54 enum class Disposition { CreatedNew, OpenedExisting };
56 private:
57 // This flag is to prevent the disabled state from being accidentally
58 // re-enabled by another instance.
59 static bool sAllowCommit;
61 static EnabledState GetEnabledState(const Maybe<uint64_t>& aLauncherTs,
62 const Maybe<uint64_t>& aBrowserTs);
64 LauncherResult<Disposition> Open();
65 LauncherVoidResult WriteLauncherStartTimestamp(uint64_t aValue);
66 LauncherVoidResult WriteBrowserStartTimestamp(uint64_t aValue);
67 LauncherVoidResult WriteImageTimestamp(DWORD aTimestamp);
68 LauncherResult<bool> ClearLauncherStartTimestamp();
69 LauncherResult<bool> ClearBrowserStartTimestamp();
70 LauncherVoidResult ClearStartTimestamps();
71 LauncherResult<Maybe<DWORD>> GetSavedImageTimestamp();
72 LauncherResult<Maybe<uint64_t>> GetLauncherStartTimestamp();
73 LauncherResult<Maybe<uint64_t>> GetBrowserStartTimestamp();
74 LauncherResult<std::wstring> BuildDefaultBlocklistFilename();
76 const std::wstring& ResolveLauncherValueName();
77 const std::wstring& ResolveBrowserValueName();
78 const std::wstring& ResolveImageTimestampValueName();
79 const std::wstring& ResolveTelemetryValueName();
80 const std::wstring& ResolveBlocklistValueName();
82 private:
83 Maybe<uint64_t> mLauncherTimestampToWrite;
84 Maybe<uint64_t> mBrowserTimestampToWrite;
86 nsAutoRegKey mRegKey;
87 std::wstring mBinPath;
88 std::wstring mImageValueName;
89 std::wstring mBrowserValueName;
90 std::wstring mLauncherValueName;
91 std::wstring mTelemetryValueName;
92 std::wstring mBlocklistValueName;
94 static const wchar_t kLauncherSubKeyPath[];
95 static const wchar_t kLauncherSuffix[];
96 static const wchar_t kBrowserSuffix[];
97 static const wchar_t kImageTimestampSuffix[];
98 static const wchar_t kTelemetrySuffix[];
99 static const wchar_t kBlocklistSuffix[];
102 } // namespace mozilla
104 #endif // mozilla_LauncherRegistryInfo_h