diff options
-rw-r--r-- | chrome/installer/util/copy_reg_key_work_item.cc | 5 | ||||
-rw-r--r-- | chrome/installer/util/copy_reg_key_work_item.h | 3 | ||||
-rw-r--r-- | chrome/installer/util/registry_key_backup.cc | 37 | ||||
-rw-r--r-- | chrome/installer/util/registry_key_backup.h | 1 |
4 files changed, 42 insertions, 4 deletions
diff --git a/chrome/installer/util/copy_reg_key_work_item.cc b/chrome/installer/util/copy_reg_key_work_item.cc index 71f6fd0..9fbac76 100644 --- a/chrome/installer/util/copy_reg_key_work_item.cc +++ b/chrome/installer/util/copy_reg_key_work_item.cc @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// Implementation of a work item that replaces the contents of one registry key +// with that of another (i.e., the destination is erased prior to the copy). + #include "chrome/installer/util/copy_reg_key_work_item.h" #include <shlwapi.h> @@ -80,7 +83,7 @@ bool CopyRegKeyWorkItem::Do() { SHDeleteKey(predefined_root_, dest_key_path_.c_str()); // Handle like a success. result = ERROR_SUCCESS; - // -- FALL THROUGH TO SUCCESS CASE -- + // -- Fall through to success case. -- case ERROR_SUCCESS: break; default: diff --git a/chrome/installer/util/copy_reg_key_work_item.h b/chrome/installer/util/copy_reg_key_work_item.h index cba85fe..cb43b2c 100644 --- a/chrome/installer/util/copy_reg_key_work_item.h +++ b/chrome/installer/util/copy_reg_key_work_item.h @@ -25,6 +25,8 @@ class CopyRegKeyWorkItem : public WorkItem { virtual void Rollback() OVERRIDE; private: + // Grant WorkItem access to the ctor (required by the existing WorkItem + // design). friend class WorkItem; // Neither |source_key_path| nor |dest_key_path| may be empty. @@ -44,6 +46,7 @@ class CopyRegKeyWorkItem : public WorkItem { // Path of the destination key. std::wstring dest_key_path_; + // WorkItem::ALWAYS or WorkItem::IF_NOT_PRESENT. CopyOverWriteOption overwrite_option_; // Backup of the destination key. diff --git a/chrome/installer/util/registry_key_backup.cc b/chrome/installer/util/registry_key_backup.cc index 93734b3..e3494614 100644 --- a/chrome/installer/util/registry_key_backup.cc +++ b/chrome/installer/util/registry_key_backup.cc @@ -22,16 +22,32 @@ class RegistryKeyBackup::KeyData { public: KeyData(); ~KeyData(); + + // Initializes this object by reading the values and subkeys of |key|. + // Security descriptors are not backed up. Returns true if the operation was + // successful; false otherwise, in which case the state of this object is not + // modified. bool Initialize(const RegKey& key); + + // Writes the contents of this object to |key|, which must have been opened + // with at least REG_SET_VALUE and KEY_CREATE_SUB_KEY access rights. Returns + // true if the operation was successful; false otherwise, in which case the + // contents of |key| may have been modified. bool WriteTo(RegKey* key) const; private: class ValueData; + // The values of this key. scoped_array<ValueData> values_; + // The names of this key's sub-keys (the data for subkey_names_[i] is in + // subkeys_[i]). scoped_array<std::wstring> subkey_names_; + // The key data of this key's sub-keys. scoped_array<KeyData> subkeys_; + // The number of values for this key. DWORD num_values_; + // The number of subkeys for this key. DWORD num_subkeys_; DISALLOW_COPY_AND_ASSIGN(KeyData); @@ -42,17 +58,35 @@ class RegistryKeyBackup::KeyData::ValueData { public: ValueData(); ~ValueData(); + + // Initializes this object with a name (the first |name_size| characters in + // |name_buffer|, |type|, and data (the first |data_size| bytes in |data|). void Initialize(const wchar_t* name_buffer, DWORD name_size, DWORD type, const uint8* data, DWORD data_size); + + // The possibly empty name of this value. const std::wstring& name_str() const { return name_; } + + // The name of this value, or NULL for the default (unnamed) value. const wchar_t* name() const { return name_.empty() ? NULL : name_.c_str(); } + + // The type of this value. DWORD type() const { return type_; } + + // A pointer to a buffer of |data_len()| bytes containing the value's data, + // or NULL if the value has no data. const uint8* data() const { return data_.empty() ? NULL : &data_[0]; } + + // The size, in bytes, of the value's data. DWORD data_len() const { return static_cast<DWORD>(data_.size()); } private: + // This value's name, or the empty string if this is the default (unnamed) + // value. std::wstring name_; + // This value's data. std::vector<uint8> data_; + // This value's type (e.g., REG_DWORD, REG_SZ, REG_QWORD, etc). DWORD type_; DISALLOW_COPY_AND_ASSIGN(ValueData); @@ -86,8 +120,6 @@ RegistryKeyBackup::KeyData::~KeyData() { } -// Initializes this object by reading the values and subkeys of |key|. -// Security descriptors are not backed up. bool RegistryKeyBackup::KeyData::Initialize(const RegKey& key) { scoped_array<ValueData> values; scoped_array<std::wstring> subkey_names; @@ -229,7 +261,6 @@ bool RegistryKeyBackup::KeyData::Initialize(const RegKey& key) { return true; } -// Writes the values and subkeys of this object into |key|. bool RegistryKeyBackup::KeyData::WriteTo(RegKey* key) const { DCHECK(key); diff --git a/chrome/installer/util/registry_key_backup.h b/chrome/installer/util/registry_key_backup.h index 41221bd..0d65b2f 100644 --- a/chrome/installer/util/registry_key_backup.h +++ b/chrome/installer/util/registry_key_backup.h @@ -49,6 +49,7 @@ class RegistryKeyBackup { private: class KeyData; + // The values and subkeys of the backed-up key. scoped_ptr<KeyData> key_data_; DISALLOW_COPY_AND_ASSIGN(RegistryKeyBackup); |