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

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

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 #include "chrome/installer/util/registry_entry.h"
6
7 #include "base/strings/string_util.h"
8 #include "base/win/registry.h"
9 #include "chrome/installer/util/work_item.h"
10 #include "chrome/installer/util/work_item_list.h"
11
12 RegistryEntry::RegistryEntry(const base::string16& key_path,
13 const base::string16& value)
14 : key_path_(key_path),
15 name_(),
16 is_string_(true),
grt (UTC plus 2) 2014/10/03 14:31:07 type_(REG_SZ), value_(reinterpret_cast<const
Matt Giuca 2015/01/20 02:41:17 Acknowledged.
17 value_(value),
18 int_value_(0) {
19 }
20
21 RegistryEntry::RegistryEntry(const base::string16& key_path,
22 const base::string16& name,
23 const base::string16& value)
24 : key_path_(key_path),
25 name_(name),
26 is_string_(true),
grt (UTC plus 2) 2014/10/03 14:31:07 as above
Matt Giuca 2015/01/20 02:41:17 Acknowledged.
27 value_(value),
28 int_value_(0) {
29 }
30
31 RegistryEntry::RegistryEntry(const base::string16& key_path,
32 const base::string16& name,
33 DWORD value)
34 : key_path_(key_path),
35 name_(name),
36 is_string_(false),
grt (UTC plus 2) 2014/10/03 14:31:07 type_(REG_DWORD), value_(reinterpret_cast<co
Matt Giuca 2015/01/20 02:41:17 Acknowledged.
37 value_(),
38 int_value_(value) {
39 }
40
41 void RegistryEntry::AddToWorkItemList(HKEY root, WorkItemList* items) const {
42 items->AddCreateRegKeyWorkItem(root, key_path_, WorkItem::kWow64Default);
Will Harris 2014/10/03 05:13:45 Will this class ever be used to access 64-bit or 3
Matt Giuca 2014/10/03 10:09:39 No idea --- note that I'm just moving this code he
grt (UTC plus 2) 2015/01/20 20:05:31 This CL takes a private class and makes it public.
Matt Giuca 2015/01/20 23:16:35 OK, if you really feel strongly about this, then I
grt (UTC plus 2) 2015/01/20 23:30:55 I think it's a waste of both of our time to do it
43 if (is_string_) {
grt (UTC plus 2) 2014/10/03 14:31:07 items->AddSetRegValueWorkItem(root_, key_path_, Wo
Matt Giuca 2015/01/20 02:41:17 Again, should not be changed here.
44 items->AddSetRegValueWorkItem(
45 root, key_path_, WorkItem::kWow64Default, name_, value_, true);
46 } else {
47 items->AddSetRegValueWorkItem(
48 root, key_path_, WorkItem::kWow64Default, name_, int_value_, true);
49 }
50 }
51
52 bool RegistryEntry::ExistsInRegistry(uint32 look_for_in) const {
53 DCHECK(look_for_in);
54
55 RegistryStatus status = DOES_NOT_EXIST;
56 if (look_for_in & LOOK_IN_HKCU)
57 status = StatusInRegistryUnderRoot(HKEY_CURRENT_USER);
58 if (status == DOES_NOT_EXIST && (look_for_in & LOOK_IN_HKLM))
59 status = StatusInRegistryUnderRoot(HKEY_LOCAL_MACHINE);
60 return status == SAME_VALUE;
61 }
62
63 bool RegistryEntry::KeyExistsInRegistry(uint32 look_for_in) const {
64 DCHECK(look_for_in);
65
66 RegistryStatus status = DOES_NOT_EXIST;
67 if (look_for_in & LOOK_IN_HKCU)
68 status = StatusInRegistryUnderRoot(HKEY_CURRENT_USER);
69 if (status == DOES_NOT_EXIST && (look_for_in & LOOK_IN_HKLM))
70 status = StatusInRegistryUnderRoot(HKEY_LOCAL_MACHINE);
71 return status != DOES_NOT_EXIST;
72 }
73
74 RegistryEntry::RegistryStatus RegistryEntry::StatusInRegistryUnderRoot(
75 HKEY root) const {
76 base::win::RegKey key(root, key_path_.c_str(), KEY_QUERY_VALUE);
77 bool found = false;
78 bool correct_value = false;
79 if (is_string_) {
grt (UTC plus 2) 2014/10/03 14:31:07 since this has string-specific handling, you could
Matt Giuca 2015/01/20 02:41:17 Again, not here.
80 base::string16 read_value;
81 found = key.ReadValue(name_.c_str(), &read_value) == ERROR_SUCCESS;
82 if (found) {
83 correct_value = read_value.size() == value_.size() &&
84 std::equal(value_.begin(),
85 value_.end(),
86 read_value.begin(),
87 base::CaseInsensitiveCompare<wchar_t>());
88 }
89 } else {
90 DWORD read_value;
91 found = key.ReadValueDW(name_.c_str(), &read_value) == ERROR_SUCCESS;
92 if (found)
93 correct_value = read_value == int_value_;
94 }
95 return found ? (correct_value ? SAME_VALUE : DIFFERENT_VALUE)
96 : DOES_NOT_EXIST;
97 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698