Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: chrome/installer/util/registry_entry.h

Issue 623903002: Move shell_util's RegistryEntry class into a separate file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shell_util-generic-associations
Patch Set: Do-over and rebase. Most of the changes have been taken care of in precursor CLs. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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.
4
5 #ifndef CHROME_INSTALLER_UTIL_REGISTRY_ENTRY_H_
6 #define CHROME_INSTALLER_UTIL_REGISTRY_ENTRY_H_
7
8 #include <windows.h>
9
10 #include "base/macros.h"
11 #include "base/strings/string16.h"
12
13 class WorkItemList;
14
15 // This class represents a single registry entry (a key and its value). A
16 // collection of registry entries should be collected into a list and written
17 // transactionally using a WorkItemList. This is preferred to writing to the
18 // registry directly, because if anything goes wrong, they can be rolled back.
19 class RegistryEntry {
20 public:
21 // A bit-field enum of places to look for this key in the Windows registry.
22 enum LookForIn {
23 LOOK_IN_HKCU = 1 << 0,
24 LOOK_IN_HKLM = 1 << 1,
25 LOOK_IN_HKCU_THEN_HKLM = LOOK_IN_HKCU | LOOK_IN_HKLM,
26 };
27
28 // Identifies the type of removal this RegistryEntry is flagged for, if any.
29 enum class RemovalFlag {
30 // Default case: install the key/value.
31 NONE,
32 // Registry value under |key_path_|\|name_| is flagged for deletion.
33 VALUE,
34 // Registry key under |key_path_| is flag for deletion.
35 KEY,
36 };
37
38 // Create an object that represent default value of a key.
39 RegistryEntry(const base::string16& key_path, const base::string16& value);
40
41 // Create an object that represent a key of type REG_SZ.
42 RegistryEntry(const base::string16& key_path,
43 const base::string16& name,
44 const base::string16& value);
45
46 // Create an object that represent a key of integer type.
47 RegistryEntry(const base::string16& key_path,
48 const base::string16& name,
49 DWORD value);
50
51 // Flags this RegistryKey with |removal_flag|, indicating that it should be
52 // removed rather than created. Note that this will not result in cleaning up
53 // the entire registry hierarchy below RegistryEntry even if it is left empty
54 // by this operation (this should thus not be used for uninstall, but only to
55 // unregister keys that should explicitly no longer be active in the current
56 // configuration).
57 void set_removal_flag(RemovalFlag removal_flag) {
58 removal_flag_ = removal_flag;
59 }
60
61 // Generates work_item tasks required to create (or potentially delete based
62 // on |removal_flag_|) the current RegistryEntry and add them to the given
63 // work item list.
64 void AddToWorkItemList(HKEY root, WorkItemList* items) const;
65
66 // Returns true if this key is flagged for removal.
67 bool IsFlaggedForRemoval() const {
68 return removal_flag_ != RemovalFlag::NONE;
69 }
70
71 // Checks if the current registry entry exists in HKCU\|key_path_|\|name_|
72 // and value is |value_|. If the key does NOT exist in HKCU, checks for
73 // the correct name and value in HKLM.
74 // |look_for_in| specifies roots (HKCU and/or HKLM) in which to look for the
75 // key, unspecified roots are not looked into (i.e. the the key is assumed not
76 // to exist in them).
77 // |look_for_in| must at least specify one root to look into.
78 // If |look_for_in| is LOOK_IN_HKCU_THEN_HKLM, this method mimics Windows'
79 // behavior when searching in HKCR (HKCU takes precedence over HKLM). For
80 // registrations outside of HKCR on versions of Windows prior to Win8,
81 // Chrome's values go in HKLM. This function will make unnecessary (but
82 // harmless) queries into HKCU in that case.
83 bool ExistsInRegistry(uint32 look_for_in) const;
84
85 // Checks if the current registry entry exists in \|key_path_|\|name_|,
86 // regardless of value. Same lookup rules as ExistsInRegistry.
87 // Unlike ExistsInRegistry, this returns true if some other value is present
88 // with the same key.
89 bool KeyExistsInRegistry(uint32 look_for_in) const;
90
91 private:
92 // States this RegistryKey can be in compared to the registry.
93 enum RegistryStatus {
94 // |name_| does not exist in the registry
95 DOES_NOT_EXIST,
96 // |name_| exists, but its value != |value_|
97 DIFFERENT_VALUE,
98 // |name_| exists and its value is |value_|
99 SAME_VALUE,
100 };
101
102 base::string16 key_path_; // key path for the registry entry
103 base::string16 name_; // name of the registry entry
104 bool is_string_; // true if current registry entry is of type REG_SZ
105 base::string16 value_; // string value (useful if is_string_ = true)
106 DWORD int_value_; // integer value (useful if is_string_ = false)
107
108 // Identifies whether this RegistryEntry is flagged for removal (i.e. no
109 // longer relevant on the configuration it was created under).
110 RemovalFlag removal_flag_;
111
112 // Helper function for ExistsInRegistry().
113 // Returns the RegistryStatus of the current registry entry in
114 // |root|\|key_path_|\|name_|.
115 RegistryStatus StatusInRegistryUnderRoot(HKEY root) const;
116
117 DISALLOW_COPY_AND_ASSIGN(RegistryEntry);
118 };
119
120 #endif // CHROME_INSTALLER_UTIL_REGISTRY_ENTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698