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

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: Created 6 years, 2 months 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 2014 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/basictypes.h"
11 #include "base/macros.h"
12 #include "base/strings/string16.h"
13
14 class WorkItemList;
15
16 // This class represents a single registry entry (a key and its value). A
17 // collection of registry entries should be collected into a list and written
18 // atomically using a WorkItemList. This is preferred to writing to the registry
19 // directly, because if anything goes wrong, they can be rolled back atomically.
20 class RegistryEntry {
21 public:
22 // A bit-field enum of places to look for this key in the Windows registry.
23 enum LookForIn {
24 LOOK_IN_HKCU = 1 << 0,
25 LOOK_IN_HKLM = 1 << 1,
26 LOOK_IN_HKCU_THEN_HKLM = LOOK_IN_HKCU | LOOK_IN_HKLM,
27 };
28
29 // Create a object that represent default value of a key
30 RegistryEntry(const base::string16& key_path, const base::string16& value);
31
32 // Create a object that represent a key of type REG_SZ
33 RegistryEntry(const base::string16& key_path,
34 const base::string16& name,
35 const base::string16& value);
36
37 // Create a object that represent a key of integer type
38 RegistryEntry(const base::string16& key_path,
39 const base::string16& name,
40 DWORD value);
41
42 // Generate work_item tasks required to create current registry entry and
43 // add them to the given work item list.
44 void AddToWorkItemList(HKEY root, WorkItemList* items) const;
45
46 // Checks if the current registry entry exists in HKCU\|key_path_|\|name_|
47 // and value is |value_|. If the key does NOT exist in HKCU, checks for
48 // the correct name and value in HKLM.
49 // |look_for_in| specifies roots (HKCU and/or HKLM) in which to look for the
50 // key, unspecified roots are not looked into (i.e. the the key is assumed not
51 // to exist in them).
52 // |look_for_in| must at least specify one root to look into.
53 // If |look_for_in| is LOOK_IN_HKCU_THEN_HKLM, this method mimics Windows'
54 // behavior when searching in HKCR (HKCU takes precedence over HKLM). For
55 // registrations outside of HKCR on versions of Windows prior to Win8,
56 // Chrome's values go in HKLM. This function will make unnecessary (but
57 // harmless) queries into HKCU in that case.
58 bool ExistsInRegistry(uint32 look_for_in) const;
59
60 // Checks if the current registry entry exists in \|key_path_|\|name_|,
61 // regardless of value. Same lookup rules as ExistsInRegistry.
62 // Unlike ExistsInRegistry, this returns true if some other value is present
63 // with the same key.
64 bool KeyExistsInRegistry(uint32 look_for_in) const;
65
66 private:
67 // States this RegistryKey can be in compared to the registry.
68 enum RegistryStatus {
69 // |name_| does not exist in the registry
70 DOES_NOT_EXIST,
71 // |name_| exists, but its value != |value_|
72 DIFFERENT_VALUE,
73 // |name_| exists and its value is |value_|
74 SAME_VALUE,
75 };
76
77 base::string16 key_path_; // key path for the registry entry
78 base::string16 name_; // name of the registry entry
79 bool is_string_; // true if current registry entry is of type REG_SZ
80 base::string16 value_; // string value (useful if is_string_ = true)
grt (UTC plus 2) 2014/10/03 14:31:07 this class would be more flexible if is_string_, v
Matt Giuca 2015/01/20 02:41:17 OK, I totally agree that this is better, but it is
grt (UTC plus 2) 2015/01/20 20:05:31 Not to nitpick, but I proposed an implementation c
Matt Giuca 2015/01/20 23:16:35 semantics != interface. I meant a semantic change
grt (UTC plus 2) 2015/01/20 23:30:56 I don't think my proposal changed the meaning or b
81 DWORD int_value_; // integer value (useful if is_string_ = false)
82
83 // Helper function for ExistsInRegistry().
84 // Returns the RegistryStatus of the current registry entry in
85 // |root|\|key_path_|\|name_|.
86 RegistryStatus StatusInRegistryUnderRoot(HKEY root) const;
87
88 DISALLOW_COPY_AND_ASSIGN(RegistryEntry);
89 };
90
91 #endif // CHROME_INSTALLER_UTIL_REGISTRY_ENTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698