Enable password generation only if sync for passwords is enabled.
[chromium-blink-merge.git] / base / win / win_util.h
blob733f2092ce54cd29283a419381b2ac0130e66095
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // =============================================================================
6 // PLEASE READ
7 //
8 // In general, you should not be adding stuff to this file.
9 //
10 // - If your thing is only used in one place, just put it in a reasonable
11 // location in or near that one place. It's nice you want people to be able
12 // to re-use your function, but realistically, if it hasn't been necessary
13 // before after so many years of development, it's probably not going to be
14 // used in other places in the future unless you know of them now.
16 // - If your thing is used by multiple callers and is UI-related, it should
17 // probably be in app/win/ instead. Try to put it in the most specific file
18 // possible (avoiding the *_util files when practical).
20 // =============================================================================
22 #ifndef BASE_WIN_WIN_UTIL_H_
23 #define BASE_WIN_WIN_UTIL_H_
24 #pragma once
26 #include <windows.h>
28 #include <string>
30 #include "base/base_export.h"
31 #include "base/string16.h"
33 struct IPropertyStore;
34 struct _tagpropertykey;
35 typedef _tagpropertykey PROPERTYKEY;
37 namespace base {
38 namespace win {
40 // A Windows message reflected from other windows. This message is sent
41 // with the following arguments:
42 // hWnd - Target window
43 // uMsg - kReflectedMessage
44 // wParam - Should be 0
45 // lParam - Pointer to MSG struct containing the original message.
46 const int kReflectedMessage = WM_APP + 3;
48 BASE_EXPORT void GetNonClientMetrics(NONCLIENTMETRICS* metrics);
50 // Returns the string representing the current user sid.
51 BASE_EXPORT bool GetUserSidString(std::wstring* user_sid);
53 // Returns true if the shift key is currently pressed.
54 BASE_EXPORT bool IsShiftPressed();
56 // Returns true if the ctrl key is currently pressed.
57 BASE_EXPORT bool IsCtrlPressed();
59 // Returns true if the alt key is currently pressed.
60 BASE_EXPORT bool IsAltPressed();
62 // Returns false if user account control (UAC) has been disabled with the
63 // EnableLUA registry flag. Returns true if user account control is enabled.
64 // NOTE: The EnableLUA registry flag, which is ignored on Windows XP
65 // machines, might still exist and be set to 0 (UAC disabled), in which case
66 // this function will return false. You should therefore check this flag only
67 // if the OS is Vista or later.
68 BASE_EXPORT bool UserAccountControlIsEnabled();
70 // Sets the string value for given key in given IPropertyStore.
71 BASE_EXPORT bool SetStringValueForPropertyStore(
72 IPropertyStore* property_store,
73 const PROPERTYKEY& property_key,
74 const wchar_t* property_string_value);
76 // Sets the application id in given IPropertyStore. The function is intended
77 // for tagging application/chromium shortcut, browser window and jump list for
78 // Win7.
79 BASE_EXPORT bool SetAppIdForPropertyStore(IPropertyStore* property_store,
80 const wchar_t* app_id);
82 // Adds the specified |command| using the specified |name| to the AutoRun key.
83 // |root_key| could be HKCU or HKLM or the root of any user hive.
84 BASE_EXPORT bool AddCommandToAutoRun(HKEY root_key, const string16& name,
85 const string16& command);
86 // Removes the command specified by |name| from the AutoRun key. |root_key|
87 // could be HKCU or HKLM or the root of any user hive.
88 BASE_EXPORT bool RemoveCommandFromAutoRun(HKEY root_key, const string16& name);
90 // Reads the command specified by |name| from the AutoRun key. |root_key|
91 // could be HKCU or HKLM or the root of any user hive. Used for unit-tests.
92 BASE_EXPORT bool ReadCommandFromAutoRun(HKEY root_key,
93 const string16& name,
94 string16* command);
96 // Sets whether to crash the process during exit. This is inspected by DLLMain
97 // and used to intercept unexpected terminations of the process (via calls to
98 // exit(), abort(), _exit(), ExitProcess()) and convert them into crashes.
99 // Note that not all mechanisms for terminating the process are covered by
100 // this. In particular, TerminateProcess() is not caught.
101 BASE_EXPORT void SetShouldCrashOnProcessDetach(bool crash);
102 BASE_EXPORT bool ShouldCrashOnProcessDetach();
104 // Get the size of a struct up to and including the specified member.
105 // This is necessary to set compatible struct sizes for different versions
106 // of certain Windows APIs (e.g. SystemParametersInfo).
107 #define SIZEOF_STRUCT_WITH_SPECIFIED_LAST_MEMBER(struct_name, member) \
108 offsetof(struct_name, member) + \
109 (sizeof static_cast<struct_name*>(NULL)->member)
111 } // namespace win
112 } // namespace base
114 #endif // BASE_WIN_WIN_UTIL_H_