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"
17 * We use std::wstring here because this code must be usable within both the
18 * launcher process and Gecko itself.
23 class LauncherRegistryInfo final
{
25 enum class ProcessType
{ Launcher
, Browser
};
27 enum class EnabledState
{
33 enum class CheckOption
{
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();
51 LauncherResult
<std::wstring
> GetBlocklistFileName();
54 enum class Disposition
{ CreatedNew
, OpenedExisting
};
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();
83 Maybe
<uint64_t> mLauncherTimestampToWrite
;
84 Maybe
<uint64_t> mBrowserTimestampToWrite
;
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