1*6777b538SAndroid Build Coastguard Worker // Copyright 2012 The Chromium Authors
2*6777b538SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*6777b538SAndroid Build Coastguard Worker // found in the LICENSE file.
4*6777b538SAndroid Build Coastguard Worker
5*6777b538SAndroid Build Coastguard Worker // =============================================================================
6*6777b538SAndroid Build Coastguard Worker // PLEASE READ
7*6777b538SAndroid Build Coastguard Worker //
8*6777b538SAndroid Build Coastguard Worker // In general, you should not be adding stuff to this file.
9*6777b538SAndroid Build Coastguard Worker //
10*6777b538SAndroid Build Coastguard Worker // - If your thing is only used in one place, just put it in a reasonable
11*6777b538SAndroid Build Coastguard Worker // location in or near that one place. It's nice you want people to be able
12*6777b538SAndroid Build Coastguard Worker // to re-use your function, but realistically, if it hasn't been necessary
13*6777b538SAndroid Build Coastguard Worker // before after so many years of development, it's probably not going to be
14*6777b538SAndroid Build Coastguard Worker // used in other places in the future unless you know of them now.
15*6777b538SAndroid Build Coastguard Worker //
16*6777b538SAndroid Build Coastguard Worker // - If your thing is used by multiple callers and is UI-related, it should
17*6777b538SAndroid Build Coastguard Worker // probably be in app/win/ instead. Try to put it in the most specific file
18*6777b538SAndroid Build Coastguard Worker // possible (avoiding the *_util files when practical).
19*6777b538SAndroid Build Coastguard Worker //
20*6777b538SAndroid Build Coastguard Worker // =============================================================================
21*6777b538SAndroid Build Coastguard Worker
22*6777b538SAndroid Build Coastguard Worker #ifndef BASE_WIN_WIN_UTIL_H_
23*6777b538SAndroid Build Coastguard Worker #define BASE_WIN_WIN_UTIL_H_
24*6777b538SAndroid Build Coastguard Worker
25*6777b538SAndroid Build Coastguard Worker #include <stdint.h>
26*6777b538SAndroid Build Coastguard Worker
27*6777b538SAndroid Build Coastguard Worker #include <optional>
28*6777b538SAndroid Build Coastguard Worker #include <string>
29*6777b538SAndroid Build Coastguard Worker #include <string_view>
30*6777b538SAndroid Build Coastguard Worker #include <vector>
31*6777b538SAndroid Build Coastguard Worker
32*6777b538SAndroid Build Coastguard Worker #include "base/base_export.h"
33*6777b538SAndroid Build Coastguard Worker #include "base/win/windows_types.h"
34*6777b538SAndroid Build Coastguard Worker
35*6777b538SAndroid Build Coastguard Worker struct IPropertyStore;
36*6777b538SAndroid Build Coastguard Worker struct _tagpropertykey;
37*6777b538SAndroid Build Coastguard Worker using PROPERTYKEY = _tagpropertykey;
38*6777b538SAndroid Build Coastguard Worker struct tagPOINTER_DEVICE_INFO;
39*6777b538SAndroid Build Coastguard Worker using POINTER_DEVICE_INFO = tagPOINTER_DEVICE_INFO;
40*6777b538SAndroid Build Coastguard Worker
41*6777b538SAndroid Build Coastguard Worker namespace base {
42*6777b538SAndroid Build Coastguard Worker
43*6777b538SAndroid Build Coastguard Worker struct NativeLibraryLoadError;
44*6777b538SAndroid Build Coastguard Worker
45*6777b538SAndroid Build Coastguard Worker namespace win {
46*6777b538SAndroid Build Coastguard Worker
HandleToUint32(HANDLE h)47*6777b538SAndroid Build Coastguard Worker inline uint32_t HandleToUint32(HANDLE h) {
48*6777b538SAndroid Build Coastguard Worker // Cast through uintptr_t and then unsigned int to make the truncation to
49*6777b538SAndroid Build Coastguard Worker // 32 bits explicit. Handles are size of-pointer but are always 32-bit values.
50*6777b538SAndroid Build Coastguard Worker // https://msdn.microsoft.com/en-us/library/aa384203(VS.85).aspx says:
51*6777b538SAndroid Build Coastguard Worker // 64-bit versions of Windows use 32-bit handles for interoperability.
52*6777b538SAndroid Build Coastguard Worker return static_cast<uint32_t>(reinterpret_cast<uintptr_t>(h));
53*6777b538SAndroid Build Coastguard Worker }
54*6777b538SAndroid Build Coastguard Worker
Uint32ToHandle(uint32_t h)55*6777b538SAndroid Build Coastguard Worker inline HANDLE Uint32ToHandle(uint32_t h) {
56*6777b538SAndroid Build Coastguard Worker return reinterpret_cast<HANDLE>(
57*6777b538SAndroid Build Coastguard Worker static_cast<uintptr_t>(static_cast<int32_t>(h)));
58*6777b538SAndroid Build Coastguard Worker }
59*6777b538SAndroid Build Coastguard Worker
60*6777b538SAndroid Build Coastguard Worker // Returns the string representing the current user sid. Does not modify
61*6777b538SAndroid Build Coastguard Worker // |user_sid| on failure.
62*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool GetUserSidString(std::wstring* user_sid);
63*6777b538SAndroid Build Coastguard Worker
64*6777b538SAndroid Build Coastguard Worker // Returns false if user account control (UAC) has been disabled with the
65*6777b538SAndroid Build Coastguard Worker // EnableLUA registry flag. Returns true if user account control is enabled.
66*6777b538SAndroid Build Coastguard Worker // NOTE: The EnableLUA registry flag, which is ignored on Windows XP
67*6777b538SAndroid Build Coastguard Worker // machines, might still exist and be set to 0 (UAC disabled), in which case
68*6777b538SAndroid Build Coastguard Worker // this function will return false. You should therefore check this flag only
69*6777b538SAndroid Build Coastguard Worker // if the OS is Vista or later.
70*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool UserAccountControlIsEnabled();
71*6777b538SAndroid Build Coastguard Worker
72*6777b538SAndroid Build Coastguard Worker // Sets the boolean value for a given key in given IPropertyStore.
73*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool SetBooleanValueForPropertyStore(
74*6777b538SAndroid Build Coastguard Worker IPropertyStore* property_store,
75*6777b538SAndroid Build Coastguard Worker const PROPERTYKEY& property_key,
76*6777b538SAndroid Build Coastguard Worker bool property_bool_value);
77*6777b538SAndroid Build Coastguard Worker
78*6777b538SAndroid Build Coastguard Worker // Sets the string value for a given key in given IPropertyStore.
79*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool SetStringValueForPropertyStore(
80*6777b538SAndroid Build Coastguard Worker IPropertyStore* property_store,
81*6777b538SAndroid Build Coastguard Worker const PROPERTYKEY& property_key,
82*6777b538SAndroid Build Coastguard Worker const wchar_t* property_string_value);
83*6777b538SAndroid Build Coastguard Worker
84*6777b538SAndroid Build Coastguard Worker // Sets the CLSID value for a given key in a given IPropertyStore.
85*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool SetClsidForPropertyStore(IPropertyStore* property_store,
86*6777b538SAndroid Build Coastguard Worker const PROPERTYKEY& property_key,
87*6777b538SAndroid Build Coastguard Worker const CLSID& property_clsid_value);
88*6777b538SAndroid Build Coastguard Worker
89*6777b538SAndroid Build Coastguard Worker // Sets the application id in given IPropertyStore. The function is used to tag
90*6777b538SAndroid Build Coastguard Worker // application/Chrome shortcuts, and set app details for Chrome windows.
91*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool SetAppIdForPropertyStore(IPropertyStore* property_store,
92*6777b538SAndroid Build Coastguard Worker const wchar_t* app_id);
93*6777b538SAndroid Build Coastguard Worker
94*6777b538SAndroid Build Coastguard Worker // Adds the specified |command| using the specified |name| to the AutoRun key.
95*6777b538SAndroid Build Coastguard Worker // |root_key| could be HKCU or HKLM or the root of any user hive.
96*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool AddCommandToAutoRun(HKEY root_key,
97*6777b538SAndroid Build Coastguard Worker const std::wstring& name,
98*6777b538SAndroid Build Coastguard Worker const std::wstring& command);
99*6777b538SAndroid Build Coastguard Worker // Removes the command specified by |name| from the AutoRun key. |root_key|
100*6777b538SAndroid Build Coastguard Worker // could be HKCU or HKLM or the root of any user hive.
101*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool RemoveCommandFromAutoRun(HKEY root_key,
102*6777b538SAndroid Build Coastguard Worker const std::wstring& name);
103*6777b538SAndroid Build Coastguard Worker
104*6777b538SAndroid Build Coastguard Worker // Reads the command specified by |name| from the AutoRun key. |root_key|
105*6777b538SAndroid Build Coastguard Worker // could be HKCU or HKLM or the root of any user hive. Used for unit-tests.
106*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool ReadCommandFromAutoRun(HKEY root_key,
107*6777b538SAndroid Build Coastguard Worker const std::wstring& name,
108*6777b538SAndroid Build Coastguard Worker std::wstring* command);
109*6777b538SAndroid Build Coastguard Worker
110*6777b538SAndroid Build Coastguard Worker // Sets whether to crash the process during exit. This is inspected by DLLMain
111*6777b538SAndroid Build Coastguard Worker // and used to intercept unexpected terminations of the process (via calls to
112*6777b538SAndroid Build Coastguard Worker // exit(), abort(), _exit(), ExitProcess()) and convert them into crashes.
113*6777b538SAndroid Build Coastguard Worker // Note that not all mechanisms for terminating the process are covered by
114*6777b538SAndroid Build Coastguard Worker // this. In particular, TerminateProcess() is not caught.
115*6777b538SAndroid Build Coastguard Worker BASE_EXPORT void SetShouldCrashOnProcessDetach(bool crash);
116*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool ShouldCrashOnProcessDetach();
117*6777b538SAndroid Build Coastguard Worker
118*6777b538SAndroid Build Coastguard Worker // Adjusts the abort behavior so that crash reports can be generated when the
119*6777b538SAndroid Build Coastguard Worker // process is aborted.
120*6777b538SAndroid Build Coastguard Worker BASE_EXPORT void SetAbortBehaviorForCrashReporting();
121*6777b538SAndroid Build Coastguard Worker
122*6777b538SAndroid Build Coastguard Worker // Checks whether the supplied |hwnd| is in Windows 10 tablet mode. Will return
123*6777b538SAndroid Build Coastguard Worker // false on versions below 10.
124*6777b538SAndroid Build Coastguard Worker // While tablet mode isn't officially supported in Windows 11, the function will
125*6777b538SAndroid Build Coastguard Worker // make an attempt to inspect other signals for tablet mode.
126*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool IsWindows10OrGreaterTabletMode(HWND hwnd);
127*6777b538SAndroid Build Coastguard Worker
128*6777b538SAndroid Build Coastguard Worker // A tablet is a device that is touch enabled and also is being used
129*6777b538SAndroid Build Coastguard Worker // "like a tablet". This is used by the following:
130*6777b538SAndroid Build Coastguard Worker // 1. Metrics: To gain insight into how users use Chrome.
131*6777b538SAndroid Build Coastguard Worker // 2. Physical keyboard presence: If a device is in tablet mode, it means
132*6777b538SAndroid Build Coastguard Worker // that there is no physical keyboard attached.
133*6777b538SAndroid Build Coastguard Worker // This function optionally sets the |reason| parameter to determine as to why
134*6777b538SAndroid Build Coastguard Worker // or why not a device was deemed to be a tablet.
135*6777b538SAndroid Build Coastguard Worker // Returns true if the user has set Windows 10 in tablet mode.
136*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool IsTabletDevice(std::string* reason, HWND hwnd);
137*6777b538SAndroid Build Coastguard Worker
138*6777b538SAndroid Build Coastguard Worker // Return true if the device is physically used as a tablet independently of
139*6777b538SAndroid Build Coastguard Worker // Windows tablet mode. It checks if the device:
140*6777b538SAndroid Build Coastguard Worker // - Is running Windows 8 or newer,
141*6777b538SAndroid Build Coastguard Worker // - Has a touch digitizer,
142*6777b538SAndroid Build Coastguard Worker // - Is not docked,
143*6777b538SAndroid Build Coastguard Worker // - Has a supported rotation sensor,
144*6777b538SAndroid Build Coastguard Worker // - Is not in laptop mode,
145*6777b538SAndroid Build Coastguard Worker // - prefers the mobile or slate power management profile (per OEM choice), and
146*6777b538SAndroid Build Coastguard Worker // - Is in slate mode.
147*6777b538SAndroid Build Coastguard Worker // This function optionally sets the |reason| parameter to determine as to why
148*6777b538SAndroid Build Coastguard Worker // or why not a device was deemed to be a tablet.
149*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool IsDeviceUsedAsATablet(std::string* reason);
150*6777b538SAndroid Build Coastguard Worker
151*6777b538SAndroid Build Coastguard Worker // A slate is a touch device that may have a keyboard attached. This function
152*6777b538SAndroid Build Coastguard Worker // returns true if a keyboard is attached and optionally will set the |reason|
153*6777b538SAndroid Build Coastguard Worker // parameter to the detection method that was used to detect the keyboard.
154*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool IsKeyboardPresentOnSlate(HWND hwnd, std::string* reason);
155*6777b538SAndroid Build Coastguard Worker
156*6777b538SAndroid Build Coastguard Worker // Get the size of a struct up to and including the specified member.
157*6777b538SAndroid Build Coastguard Worker // This is necessary to set compatible struct sizes for different versions
158*6777b538SAndroid Build Coastguard Worker // of certain Windows APIs (e.g. SystemParametersInfo).
159*6777b538SAndroid Build Coastguard Worker #define SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(struct_name, member) \
160*6777b538SAndroid Build Coastguard Worker offsetof(struct_name, member) + \
161*6777b538SAndroid Build Coastguard Worker (sizeof static_cast<struct_name*>(NULL)->member)
162*6777b538SAndroid Build Coastguard Worker
163*6777b538SAndroid Build Coastguard Worker // Returns true if the machine is enrolled to a domain.
164*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool IsEnrolledToDomain();
165*6777b538SAndroid Build Coastguard Worker
166*6777b538SAndroid Build Coastguard Worker // Returns true if either the device is joined to Azure Active Directory (AD) or
167*6777b538SAndroid Build Coastguard Worker // one or more Azure AD work accounts have been added on the device. This call
168*6777b538SAndroid Build Coastguard Worker // trigger some I/O when loading netapi32.dll to determine the management state.
169*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool IsJoinedToAzureAD();
170*6777b538SAndroid Build Coastguard Worker
171*6777b538SAndroid Build Coastguard Worker // Returns true if the machine is being managed by an MDM system.
172*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool IsDeviceRegisteredWithManagement();
173*6777b538SAndroid Build Coastguard Worker
174*6777b538SAndroid Build Coastguard Worker // Returns true if the current process can make USER32 or GDI32 calls such as
175*6777b538SAndroid Build Coastguard Worker // CreateWindow and CreateDC. Windows 8 and above allow the kernel component
176*6777b538SAndroid Build Coastguard Worker // of these calls to be disabled (also known as win32k lockdown) which can
177*6777b538SAndroid Build Coastguard Worker // cause undefined behaviour such as crashes. This function can be used to
178*6777b538SAndroid Build Coastguard Worker // guard areas of code using these calls and provide a fallback path if
179*6777b538SAndroid Build Coastguard Worker // necessary.
180*6777b538SAndroid Build Coastguard Worker // Because they are not always needed (and not needed at all in processes that
181*6777b538SAndroid Build Coastguard Worker // have the win32k lockdown), USER32 and GDI32 are delayloaded. Attempts to
182*6777b538SAndroid Build Coastguard Worker // load them in those processes will cause a crash. Any code which uses USER32
183*6777b538SAndroid Build Coastguard Worker // or GDI32 and may run in a locked-down process MUST be guarded using this
184*6777b538SAndroid Build Coastguard Worker // method. Before the dlls were delayloaded, method calls into USER32 and GDI32
185*6777b538SAndroid Build Coastguard Worker // did not work, so adding calls to this method to guard them simply avoids
186*6777b538SAndroid Build Coastguard Worker // unnecessary method calls.
187*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool IsUser32AndGdi32Available();
188*6777b538SAndroid Build Coastguard Worker
189*6777b538SAndroid Build Coastguard Worker // Takes a snapshot of the modules loaded in the |process|. The returned
190*6777b538SAndroid Build Coastguard Worker // HMODULEs are not add-ref'd, so they should not be closed and may be
191*6777b538SAndroid Build Coastguard Worker // invalidated at any time (should a module be unloaded). |process| requires
192*6777b538SAndroid Build Coastguard Worker // the PROCESS_QUERY_INFORMATION and PROCESS_VM_READ permissions.
193*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool GetLoadedModulesSnapshot(HANDLE process,
194*6777b538SAndroid Build Coastguard Worker std::vector<HMODULE>* snapshot);
195*6777b538SAndroid Build Coastguard Worker
196*6777b538SAndroid Build Coastguard Worker // Adds or removes the MICROSOFT_TABLETPENSERVICE_PROPERTY property with the
197*6777b538SAndroid Build Coastguard Worker // TABLET_DISABLE_FLICKS & TABLET_DISABLE_FLICKFALLBACKKEYS flags in order to
198*6777b538SAndroid Build Coastguard Worker // disable pen flick gestures for the given HWND.
199*6777b538SAndroid Build Coastguard Worker BASE_EXPORT void EnableFlicks(HWND hwnd);
200*6777b538SAndroid Build Coastguard Worker BASE_EXPORT void DisableFlicks(HWND hwnd);
201*6777b538SAndroid Build Coastguard Worker
202*6777b538SAndroid Build Coastguard Worker // Enable high-DPI support for the current process.
203*6777b538SAndroid Build Coastguard Worker BASE_EXPORT void EnableHighDPISupport();
204*6777b538SAndroid Build Coastguard Worker
205*6777b538SAndroid Build Coastguard Worker // Returns a string representation of |rguid|.
206*6777b538SAndroid Build Coastguard Worker BASE_EXPORT std::wstring WStringFromGUID(const ::GUID& rguid);
207*6777b538SAndroid Build Coastguard Worker
208*6777b538SAndroid Build Coastguard Worker // Attempts to pin user32.dll to ensure it remains loaded. If it isn't loaded
209*6777b538SAndroid Build Coastguard Worker // yet, the module will first be loaded and then the pin will be attempted. If
210*6777b538SAndroid Build Coastguard Worker // pinning is successful, returns true. If the module cannot be loaded and/or
211*6777b538SAndroid Build Coastguard Worker // pinned, |error| is set and the method returns false.
212*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool PinUser32(NativeLibraryLoadError* error = nullptr);
213*6777b538SAndroid Build Coastguard Worker
214*6777b538SAndroid Build Coastguard Worker // Gets a pointer to a function within user32.dll, if available. If user32.dll
215*6777b538SAndroid Build Coastguard Worker // cannot be loaded or the function cannot be found, this function returns
216*6777b538SAndroid Build Coastguard Worker // nullptr and sets |error|. Once loaded, user32.dll is pinned, and therefore
217*6777b538SAndroid Build Coastguard Worker // the function pointer returned by this function will never change and can be
218*6777b538SAndroid Build Coastguard Worker // cached.
219*6777b538SAndroid Build Coastguard Worker BASE_EXPORT void* GetUser32FunctionPointer(
220*6777b538SAndroid Build Coastguard Worker const char* function_name,
221*6777b538SAndroid Build Coastguard Worker NativeLibraryLoadError* error = nullptr);
222*6777b538SAndroid Build Coastguard Worker
223*6777b538SAndroid Build Coastguard Worker // Returns the name of a desktop or a window station.
224*6777b538SAndroid Build Coastguard Worker BASE_EXPORT std::wstring GetWindowObjectName(HANDLE handle);
225*6777b538SAndroid Build Coastguard Worker
226*6777b538SAndroid Build Coastguard Worker // Gets information about the pointer device. When successful, updates `result`
227*6777b538SAndroid Build Coastguard Worker // and returns true, otherwise returns false without modifying `result`.
228*6777b538SAndroid Build Coastguard Worker // https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getpointerdevice
229*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool GetPointerDevice(HANDLE device, POINTER_DEVICE_INFO& result);
230*6777b538SAndroid Build Coastguard Worker
231*6777b538SAndroid Build Coastguard Worker // Gets information about the pointer devices attached to the system.
232*6777b538SAndroid Build Coastguard Worker // https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getpointerdevices
233*6777b538SAndroid Build Coastguard Worker BASE_EXPORT std::optional<std::vector<POINTER_DEVICE_INFO>> GetPointerDevices();
234*6777b538SAndroid Build Coastguard Worker
235*6777b538SAndroid Build Coastguard Worker // Registers a window to process the WM_POINTERDEVICECHANGE event, and
236*6777b538SAndroid Build Coastguard Worker // optionally WM_POINTERDEVICEINRANGE and WM_POINTERDEVICEOUTOFRANGE events when
237*6777b538SAndroid Build Coastguard Worker // `notify_proximity_changes` is set.
238*6777b538SAndroid Build Coastguard Worker // https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-registerpointerdevicenotifications
239*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool RegisterPointerDeviceNotifications(
240*6777b538SAndroid Build Coastguard Worker HWND hwnd,
241*6777b538SAndroid Build Coastguard Worker bool notify_proximity_changes = false);
242*6777b538SAndroid Build Coastguard Worker
243*6777b538SAndroid Build Coastguard Worker // Checks if the calling thread is running under a desktop with the name
244*6777b538SAndroid Build Coastguard Worker // given by |desktop_name|. |desktop_name| is ASCII case insensitive (non-ASCII
245*6777b538SAndroid Build Coastguard Worker // characters will be compared with exact matches).
246*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool IsRunningUnderDesktopName(std::wstring_view desktop_name);
247*6777b538SAndroid Build Coastguard Worker
248*6777b538SAndroid Build Coastguard Worker // Returns true if current session is a remote session.
249*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool IsCurrentSessionRemote();
250*6777b538SAndroid Build Coastguard Worker
251*6777b538SAndroid Build Coastguard Worker // IsAppVerifierLoaded() indicates whether Application Verifier is *already*
252*6777b538SAndroid Build Coastguard Worker // loaded into the current process.
253*6777b538SAndroid Build Coastguard Worker BASE_EXPORT bool IsAppVerifierLoaded();
254*6777b538SAndroid Build Coastguard Worker
255*6777b538SAndroid Build Coastguard Worker // Allows changing the domain enrolled state for the life time of the object.
256*6777b538SAndroid Build Coastguard Worker // The original state is restored upon destruction.
257*6777b538SAndroid Build Coastguard Worker class BASE_EXPORT ScopedDomainStateForTesting {
258*6777b538SAndroid Build Coastguard Worker public:
259*6777b538SAndroid Build Coastguard Worker explicit ScopedDomainStateForTesting(bool state);
260*6777b538SAndroid Build Coastguard Worker
261*6777b538SAndroid Build Coastguard Worker ScopedDomainStateForTesting(const ScopedDomainStateForTesting&) = delete;
262*6777b538SAndroid Build Coastguard Worker ScopedDomainStateForTesting& operator=(const ScopedDomainStateForTesting&) =
263*6777b538SAndroid Build Coastguard Worker delete;
264*6777b538SAndroid Build Coastguard Worker
265*6777b538SAndroid Build Coastguard Worker ~ScopedDomainStateForTesting();
266*6777b538SAndroid Build Coastguard Worker
267*6777b538SAndroid Build Coastguard Worker private:
268*6777b538SAndroid Build Coastguard Worker bool initial_state_;
269*6777b538SAndroid Build Coastguard Worker };
270*6777b538SAndroid Build Coastguard Worker
271*6777b538SAndroid Build Coastguard Worker // Allows changing the management registration state for the life time of the
272*6777b538SAndroid Build Coastguard Worker // object. The original state is restored upon destruction.
273*6777b538SAndroid Build Coastguard Worker class BASE_EXPORT ScopedDeviceRegisteredWithManagementForTesting {
274*6777b538SAndroid Build Coastguard Worker public:
275*6777b538SAndroid Build Coastguard Worker explicit ScopedDeviceRegisteredWithManagementForTesting(bool state);
276*6777b538SAndroid Build Coastguard Worker
277*6777b538SAndroid Build Coastguard Worker ScopedDeviceRegisteredWithManagementForTesting(
278*6777b538SAndroid Build Coastguard Worker const ScopedDeviceRegisteredWithManagementForTesting&) = delete;
279*6777b538SAndroid Build Coastguard Worker ScopedDeviceRegisteredWithManagementForTesting& operator=(
280*6777b538SAndroid Build Coastguard Worker const ScopedDeviceRegisteredWithManagementForTesting&) = delete;
281*6777b538SAndroid Build Coastguard Worker
282*6777b538SAndroid Build Coastguard Worker ~ScopedDeviceRegisteredWithManagementForTesting();
283*6777b538SAndroid Build Coastguard Worker
284*6777b538SAndroid Build Coastguard Worker private:
285*6777b538SAndroid Build Coastguard Worker bool initial_state_;
286*6777b538SAndroid Build Coastguard Worker };
287*6777b538SAndroid Build Coastguard Worker
288*6777b538SAndroid Build Coastguard Worker // Allows changing the Azure Active Directory join state for the lifetime of the
289*6777b538SAndroid Build Coastguard Worker // object. The original state is restored upon destruction.
290*6777b538SAndroid Build Coastguard Worker class BASE_EXPORT ScopedAzureADJoinStateForTesting {
291*6777b538SAndroid Build Coastguard Worker public:
292*6777b538SAndroid Build Coastguard Worker explicit ScopedAzureADJoinStateForTesting(bool state);
293*6777b538SAndroid Build Coastguard Worker ScopedAzureADJoinStateForTesting(const ScopedAzureADJoinStateForTesting&) =
294*6777b538SAndroid Build Coastguard Worker delete;
295*6777b538SAndroid Build Coastguard Worker ScopedAzureADJoinStateForTesting& operator=(
296*6777b538SAndroid Build Coastguard Worker const ScopedAzureADJoinStateForTesting&) = delete;
297*6777b538SAndroid Build Coastguard Worker ~ScopedAzureADJoinStateForTesting();
298*6777b538SAndroid Build Coastguard Worker
299*6777b538SAndroid Build Coastguard Worker private:
300*6777b538SAndroid Build Coastguard Worker const bool initial_state_;
301*6777b538SAndroid Build Coastguard Worker };
302*6777b538SAndroid Build Coastguard Worker
303*6777b538SAndroid Build Coastguard Worker } // namespace win
304*6777b538SAndroid Build Coastguard Worker } // namespace base
305*6777b538SAndroid Build Coastguard Worker
306*6777b538SAndroid Build Coastguard Worker #endif // BASE_WIN_WIN_UTIL_H_
307