Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 #include "chrome/installer/util/registry_entry.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/strings/string_util.h" | |
| 9 #include "base/win/registry.h" | |
| 10 #include "chrome/installer/util/work_item.h" | |
| 11 #include "chrome/installer/util/work_item_list.h" | |
| 12 | |
| 13 RegistryEntry::RegistryEntry(const base::string16& key_path, | |
| 14 const base::string16& value) | |
| 15 : key_path_(key_path), | |
| 16 name_(), | |
| 17 is_string_(true), | |
| 18 value_(value), | |
| 19 int_value_(0), | |
| 20 removal_flag_(RemovalFlag::NONE) {} | |
| 21 | |
| 22 RegistryEntry::RegistryEntry(const base::string16& key_path, | |
| 23 const base::string16& name, | |
| 24 const base::string16& value) | |
| 25 : key_path_(key_path), | |
| 26 name_(name), | |
| 27 is_string_(true), | |
| 28 value_(value), | |
| 29 int_value_(0), | |
| 30 removal_flag_(RemovalFlag::NONE) {} | |
| 31 | |
| 32 RegistryEntry::RegistryEntry(const base::string16& key_path, | |
| 33 const base::string16& name, | |
| 34 DWORD value) | |
| 35 : key_path_(key_path), | |
| 36 name_(name), | |
| 37 is_string_(false), | |
| 38 value_(), | |
| 39 int_value_(value), | |
| 40 removal_flag_(RemovalFlag::NONE) {} | |
| 41 | |
| 42 void RegistryEntry::AddToWorkItemList(HKEY root, WorkItemList* items) const { | |
| 43 if (removal_flag_ == RemovalFlag::VALUE) { | |
| 44 items->AddDeleteRegValueWorkItem(root, key_path_, WorkItem::kWow64Default, | |
| 45 name_); | |
| 46 } else if (removal_flag_ == RemovalFlag::KEY) { | |
| 47 items->AddDeleteRegKeyWorkItem(root, key_path_, WorkItem::kWow64Default); | |
| 48 } else { | |
| 49 DCHECK(removal_flag_ == RemovalFlag::NONE); | |
| 50 items->AddCreateRegKeyWorkItem(root, key_path_, WorkItem::kWow64Default); | |
| 51 if (is_string_) { | |
| 52 items->AddSetRegValueWorkItem(root, key_path_, WorkItem::kWow64Default, | |
| 53 name_, value_, true); | |
| 54 } else { | |
| 55 items->AddSetRegValueWorkItem(root, key_path_, WorkItem::kWow64Default, | |
| 56 name_, int_value_, true); | |
| 57 } | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 bool RegistryEntry::ExistsInRegistry(uint32 look_for_in) const { | |
| 62 DCHECK(look_for_in); | |
| 63 | |
| 64 RegistryStatus status = DOES_NOT_EXIST; | |
| 65 if (look_for_in & LOOK_IN_HKCU) | |
| 66 status = StatusInRegistryUnderRoot(HKEY_CURRENT_USER); | |
| 67 if (status == DOES_NOT_EXIST && (look_for_in & LOOK_IN_HKLM)) | |
| 68 status = StatusInRegistryUnderRoot(HKEY_LOCAL_MACHINE); | |
| 69 return status == SAME_VALUE; | |
| 70 } | |
| 71 | |
| 72 bool RegistryEntry::KeyExistsInRegistry(uint32 look_for_in) const { | |
| 73 DCHECK(look_for_in); | |
| 74 | |
| 75 RegistryStatus status = DOES_NOT_EXIST; | |
| 76 if (look_for_in & LOOK_IN_HKCU) | |
| 77 status = StatusInRegistryUnderRoot(HKEY_CURRENT_USER); | |
| 78 if (status == DOES_NOT_EXIST && (look_for_in & LOOK_IN_HKLM)) | |
| 79 status = StatusInRegistryUnderRoot(HKEY_LOCAL_MACHINE); | |
| 80 return status != DOES_NOT_EXIST; | |
| 81 } | |
| 82 | |
| 83 RegistryEntry::RegistryStatus RegistryEntry::StatusInRegistryUnderRoot( | |
| 84 HKEY root) const { | |
| 85 base::win::RegKey key(root, key_path_.c_str(), KEY_QUERY_VALUE); | |
|
Matt Giuca
2015/12/02 02:54:41
Note: This was the only line that changed during t
| |
| 86 bool found = false; | |
| 87 bool correct_value = false; | |
| 88 if (is_string_) { | |
| 89 base::string16 read_value; | |
| 90 found = key.ReadValue(name_.c_str(), &read_value) == ERROR_SUCCESS; | |
| 91 if (found) { | |
| 92 correct_value = | |
| 93 read_value.size() == value_.size() && | |
| 94 ::CompareString( | |
| 95 LOCALE_USER_DEFAULT, NORM_IGNORECASE, read_value.data(), | |
| 96 base::saturated_cast<int>(read_value.size()), value_.data(), | |
| 97 base::saturated_cast<int>(value_.size())) == CSTR_EQUAL; | |
| 98 } | |
| 99 } else { | |
| 100 DWORD read_value; | |
| 101 found = key.ReadValueDW(name_.c_str(), &read_value) == ERROR_SUCCESS; | |
| 102 if (found) | |
| 103 correct_value = read_value == int_value_; | |
| 104 } | |
| 105 return found ? (correct_value ? SAME_VALUE : DIFFERENT_VALUE) | |
| 106 : DOES_NOT_EXIST; | |
| 107 } | |
| OLD | NEW |