Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 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_KEY_BACKUP_H_ | |
| 6 #define CHROME_INSTALLER_UTIL_REGISTRY_KEY_BACKUP_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <windows.h> | |
| 10 | |
| 11 #include <algorithm> | |
| 12 #include <string> | |
| 13 | |
| 14 #include "base/basictypes.h" | |
| 15 #include "base/memory/scoped_ptr.h" | |
| 16 | |
| 17 namespace base { | |
| 18 namespace win { | |
| 19 class RegKey; | |
| 20 } // namespace win | |
| 21 } // namespace base | |
| 22 | |
| 23 // A container for a registry key, its values, and its subkeys. We don't use | |
| 24 // more obvious methods for various reasons: | |
| 25 // - RegCopyTree isn't supported pre-Vista, so we'd have to do something | |
| 26 // different for XP anyway. | |
| 27 // - SHCopyKey can't copy subkeys into a volatile destination, so we'd have to | |
| 28 // worry about polluting the registry. | |
| 29 // We don't persist security attributes since we only delete keys that we own, | |
| 30 // and we don't set custom attributes on them anyway. | |
| 31 class RegistryKeyBackup { | |
| 32 public: | |
| 33 RegistryKeyBackup(); | |
| 34 ~RegistryKeyBackup(); | |
| 35 | |
| 36 // Recursively reads |key_path| into this instance. Backing up a non-existent | |
| 37 // key is valid. Returns true if the backup was successful; false otherwise, | |
| 38 // in which case the state of this instance is not modified. | |
| 39 bool Initialize(HKEY root, const wchar_t* key_path); | |
| 40 | |
| 41 // Writes the contents of this instance into |key|. The contents of | |
| 42 // |key_path| are not modified If this instance is uninitialized or was | |
| 43 // initialized from a non-existent key. | |
| 44 bool WriteTo(HKEY root, const wchar_t* key_path) const; | |
| 45 | |
| 46 void swap(RegistryKeyBackup& other) { | |
| 47 key_data_.swap(other.key_data_); | |
| 48 } | |
| 49 | |
| 50 private: | |
| 51 class KeyData; | |
| 52 | |
| 53 scoped_ptr<KeyData> key_data_; | |
| 54 | |
| 55 DISALLOW_COPY_AND_ASSIGN(RegistryKeyBackup); | |
| 56 }; | |
| 57 | |
| 58 namespace std { | |
|
erikwright (departed)
2011/09/16 18:41:45
This technically (at least) violates the coding gu
grt (UTC plus 2)
2011/09/16 20:44:46
The style guide's guidance is overreaching in this
| |
| 59 | |
| 60 template<> | |
| 61 inline void swap<RegistryKeyBackup>(RegistryKeyBackup& a, | |
| 62 RegistryKeyBackup& b) { | |
| 63 a.swap(b); | |
| 64 } | |
| 65 | |
| 66 } // namespace std | |
| 67 | |
| 68 #endif // CHROME_INSTALLER_UTIL_REGISTRY_KEY_BACKUP_H_ | |
| OLD | NEW |