diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-31 01:08:10 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-31 01:08:10 +0000 |
commit | 2a72bb972a684f6e3ad7469d6a47288ba8154f3e (patch) | |
tree | bf023505abae9a6f0c5177ad4d5dd43f191a3ed6 | |
parent | ed3c0adca2c3d2f95ebb9b81fcd9c786f0541998 (diff) | |
download | chromium_src-2a72bb972a684f6e3ad7469d6a47288ba8154f3e.zip chromium_src-2a72bb972a684f6e3ad7469d6a47288ba8154f3e.tar.gz chromium_src-2a72bb972a684f6e3ad7469d6a47288ba8154f3e.tar.bz2 |
Remove deprecated versions of Registry functions.
BUG=None
TEST=trybots
Review URL: http://codereview.chromium.org/2403001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48581 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/registry.h | 138 | ||||
-rw-r--r-- | chrome/browser/importer/firefox_importer_utils_win.cc | 21 | ||||
-rw-r--r-- | chrome/browser/importer/ie_importer.cc | 12 |
3 files changed, 63 insertions, 108 deletions
diff --git a/base/registry.h b/base/registry.h index 757e409..0babbc8 100644 --- a/base/registry.h +++ b/base/registry.h @@ -1,10 +1,10 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // All Rights Reserved. -#ifndef BASE_REGISTRY_H__ -#define BASE_REGISTRY_H__ +#ifndef BASE_REGISTRY_H_ +#define BASE_REGISTRY_H_ #include <windows.h> #include <tchar.h> @@ -27,9 +27,8 @@ class RegKey { public: RegKey(HKEY rootkey = NULL, CTP subkey = NULL, REGSAM access = KEY_READ); - // start there - ~RegKey() { this->Close(); } + ~RegKey() { Close(); } bool Create(HKEY rootkey, CTP subkey, REGSAM access = KEY_READ); @@ -38,7 +37,7 @@ class RegKey { bool Open(HKEY rootkey, CTP subkey, REGSAM access = KEY_READ); - // Create a subkey (or open if exists) + // Create a subkey (or open if exists). bool CreateKey(CTP name, REGSAM access); // Open a subkey @@ -47,44 +46,43 @@ class RegKey { // all done, eh? void Close(); - DWORD ValueCount(); // Count of the number of value extant + // Count of the number of value extant. + DWORD ValueCount(); - bool ReadName(int index, tstr* name); // Determine the Nth value's name + // Determine the Nth value's name. + bool ReadName(int index, tstr* name); - // True while the key is valid - bool Valid() const { return NULL != key_; } + // True while the key is valid. + bool Valid() const { return key_ != NULL; } - // Kill key and everything that liveth below it; please be careful out there + // Kill key and everything that liveth below it; please be careful out there. bool DeleteKey(CTP name); - // Delete a single value within the key + // Delete a single value within the key. bool DeleteValue(CTP name); bool ValueExists(CTP name); - bool ReadValue(CTP name, void * data, DWORD * dsize, DWORD * dtype = NULL); - bool ReadValue(CTP name, tstr * value); - bool ReadValueDW(CTP name, DWORD * value); // Named to differ from tstr* + bool ReadValue(CTP name, void* data, DWORD* dsize, DWORD* dtype = NULL); + bool ReadValue(CTP name, tstr* value); + bool ReadValueDW(CTP name, DWORD* value); // Named to differ from tstr* - bool WriteValue(CTP name, const void * data, DWORD dsize, + bool WriteValue(CTP name, const void* data, DWORD dsize, DWORD dtype = REG_BINARY); bool WriteValue(CTP name, CTP value); bool WriteValue(CTP name, DWORD value); - // StartWatching() - // Start watching the key to see if any of its values have changed. - // The key must have been opened with the KEY_NOTIFY access - // privelege. + // Start watching the key to see if any of its values have changed. + // The key must have been opened with the KEY_NOTIFY access + // privelege. bool StartWatching(); - // HasChanged() - // If StartWatching hasn't been called, always returns false. - // Otherwise, returns true if anything under the key has changed. - // This can't be const because the watch_event_ may be refreshed. + // If StartWatching hasn't been called, always returns false. + // Otherwise, returns true if anything under the key has changed. + // This can't be const because the |watch_event_| may be refreshed. bool HasChanged(); - // StopWatching() - // Will automatically be called by destructor if not manually called - // beforehand. Returns true if it was watching, false otherwise. + // Will automatically be called by destructor if not manually called + // beforehand. Returns true if it was watching, false otherwise. bool StopWatching(); inline bool IsWatching() const { return watch_event_ != 0; } @@ -92,75 +90,29 @@ class RegKey { HKEY Handle() const { return key_; } private: - HKEY key_; // the registry key being iterated + HKEY key_; // The registry key being iterated. HANDLE watch_event_; }; - -// Standalone registry functions -- sorta deprecated, they now map to -// using RegKey - - -// Add a raw data to the registry -- you can pass NULL for the data if -// you just want to create a key -inline bool AddToRegistry(HKEY root_key, CTP key, CTP value_name, - void const * data, DWORD dsize, - DWORD dtype = REG_BINARY) { - return RegKey(root_key, key, KEY_WRITE).WriteValue(value_name, data, dsize, - dtype); -} - -// Convenience routine to add a string value to the registry -inline bool AddToRegistry(HKEY root_key, CTP key, CTP value_name, CTP value) { - return AddToRegistry(root_key, key, value_name, value, - sizeof(*value) * (lstrlen(value) + 1), REG_SZ); -} - -// Read raw data from the registry -- pass something as the dtype -// parameter if you care to learn what type the value was stored as -inline bool ReadFromRegistry(HKEY root_key, CTP key, CTP value_name, - void* data, DWORD* dsize, DWORD* dtype = NULL) { - return RegKey(root_key, key).ReadValue(value_name, data, dsize, dtype); -} - - -// Delete a value or a key from the registry -inline bool DeleteFromRegistry(HKEY root_key, CTP subkey, CTP value_name) { - if (value_name) - return ERROR_SUCCESS == ::SHDeleteValue(root_key, subkey, value_name); - else - return ERROR_SUCCESS == ::SHDeleteKey(root_key, subkey); -} - - - -// delete a key and all subkeys from the registry -inline bool DeleteKeyFromRegistry(HKEY root_key, CTP key_path, CTP key_name) { - RegKey key; - return key.Open(root_key, key_path, KEY_WRITE) - && key.DeleteKey(key_name); -} - - // Iterates the entries found in a particular folder on the registry. // For this application I happen to know I wont need data size larger // than MAX_PATH, but in real life this wouldn't neccessarily be // adequate. class RegistryValueIterator { public: - // Specify a key in construction + // Specify a key in construction. RegistryValueIterator(HKEY root_key, LPCTSTR folder_key); ~RegistryValueIterator(); - DWORD ValueCount() const; // count of the number of subkeys extant + DWORD ValueCount() const; // Count of the number of subkeys extant. - bool Valid() const; // true while the iterator is valid + bool Valid() const; // True while the iterator is valid. - void operator++(); // advance to the next entry in the folder + void operator++(); // Advance to the next entry in the folder. // The pointers returned by these functions are statics owned by the - // Name and Value functions + // Name and Value functions. CTP Name() const { return name_; } CTP Value() const { return value_; } DWORD ValueSize() const { return value_size_; } @@ -169,12 +121,12 @@ class RegistryValueIterator { int Index() const { return index_; } private: - bool Read(); // read in the current values + bool Read(); // Read in the current values. - HKEY key_; // the registry key being iterated - int index_; // current index of the iteration + HKEY key_; // The registry key being iterated. + int index_; // Current index of the iteration. - // Current values + // Current values. TCHAR name_[MAX_PATH]; TCHAR value_[MAX_PATH]; DWORD value_size_; @@ -184,29 +136,29 @@ class RegistryValueIterator { class RegistryKeyIterator { public: - // Specify a parent key in construction + // Specify a parent key in construction. RegistryKeyIterator(HKEY root_key, LPCTSTR folder_key); ~RegistryKeyIterator(); - DWORD SubkeyCount() const; // count of the number of subkeys extant + DWORD SubkeyCount() const; // Count of the number of subkeys extant. - bool Valid() const; // true while the iterator is valid + bool Valid() const; // True while the iterator is valid. - void operator++(); // advance to the next entry in the folder + void operator++(); // Advance to the next entry in the folder. - // The pointer returned by Name() is a static owned by the function + // The pointer returned by Name() is a static owned by the function. CTP Name() const { return name_; } int Index() const { return index_; } private: - bool Read(); // read in the current values + bool Read(); // Read in the current values. - HKEY key_; // the registry key being iterated - int index_; // current index of the iteration + HKEY key_; // The registry key being iterated. + int index_; // Current index of the iteration. - // Current values + // Current values. TCHAR name_[MAX_PATH]; }; @@ -222,4 +174,4 @@ bool UnregisterCOMServer(const tchar* guid); #undef CTP #undef tstr -#endif // BASE_REGISTRY_H__ +#endif // BASE_REGISTRY_H_ diff --git a/chrome/browser/importer/firefox_importer_utils_win.cc b/chrome/browser/importer/firefox_importer_utils_win.cc index 370ec68..548ecd1 100644 --- a/chrome/browser/importer/firefox_importer_utils_win.cc +++ b/chrome/browser/importer/firefox_importer_utils_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -28,9 +28,11 @@ int GetCurrentFirefoxMajorVersionFromRegistry() { // written under HKLM\Mozilla. Otherwise it the keys will be written under // HKCU\Mozilla. for (int i = 0; i < arraysize(kFireFoxRegistryPaths); ++i) { - bool result = ReadFromRegistry(kFireFoxRegistryPaths[i], - L"Software\\Mozilla\\Mozilla Firefox", - L"CurrentVersion", ver_buffer, &ver_buffer_length); + RegKey reg_key(kFireFoxRegistryPaths[i], + L"Software\\Mozilla\\Mozilla Firefox"); + + bool result = reg_key.ReadValue(L"CurrentVersion", ver_buffer, + &ver_buffer_length, NULL); if (!result) continue; highest_version = std::max(highest_version, _wtoi(ver_buffer)); @@ -43,15 +45,16 @@ std::wstring GetFirefoxInstallPathFromRegistry() { std::wstring registry_path = L"Software\\Mozilla\\Mozilla Firefox"; TCHAR buffer[MAX_PATH]; DWORD buffer_length = sizeof(buffer); - bool result; - result = ReadFromRegistry(HKEY_LOCAL_MACHINE, registry_path.c_str(), - L"CurrentVersion", buffer, &buffer_length); + RegKey reg_key(HKEY_LOCAL_MACHINE, registry_path.c_str()); + bool result = reg_key.ReadValue(L"CurrentVersion", buffer, + &buffer_length, NULL); if (!result) return std::wstring(); registry_path += L"\\" + std::wstring(buffer) + L"\\Main"; buffer_length = sizeof(buffer); - result = ReadFromRegistry(HKEY_LOCAL_MACHINE, registry_path.c_str(), - L"Install Directory", buffer, &buffer_length); + reg_key = RegKey(HKEY_LOCAL_MACHINE, registry_path.c_str()); + result = reg_key.ReadValue(L"Install Directory", buffer, + &buffer_length, NULL); if (!result) return std::wstring(); return buffer; diff --git a/chrome/browser/importer/ie_importer.cc b/chrome/browser/importer/ie_importer.cc index cae26ba..52a5803 100644 --- a/chrome/browser/importer/ie_importer.cc +++ b/chrome/browser/importer/ie_importer.cc @@ -459,9 +459,9 @@ bool IEImporter::GetFavoritesInfo(IEImporter::FavoritesInfo *info) { if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) { // The Link folder name is stored in the registry. DWORD buffer_length = sizeof(buffer); - if (!ReadFromRegistry(HKEY_CURRENT_USER, - L"Software\\Microsoft\\Internet Explorer\\Toolbar", - L"LinksFolderName", buffer, &buffer_length)) + RegKey reg_key(HKEY_CURRENT_USER, + L"Software\\Microsoft\\Internet Explorer\\Toolbar"); + if (reg_key.ReadValue(L"LinksFolderName", buffer, &buffer_length, NULL)) return false; info->links_folder = buffer; } else { @@ -568,9 +568,9 @@ int IEImporter::CurrentIEVersion() const { if (version < 0) { wchar_t buffer[128]; DWORD buffer_length = sizeof(buffer); - bool result = ReadFromRegistry(HKEY_LOCAL_MACHINE, - L"Software\\Microsoft\\Internet Explorer", - L"Version", buffer, &buffer_length); + RegKey reg_key(HKEY_LOCAL_MACHINE, + L"Software\\Microsoft\\Internet Explorer"); + bool result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); version = (result ? _wtoi(buffer) : 0); } return version; |