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

Side by Side Diff: base/win/registry.cc

Issue 616173003: Allow Registry Iterator functions to use a specified WOW64 mode when iterating. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: code review comments 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/win/registry.h" 5 #include "base/win/registry.h"
6 6
7 #include <shlwapi.h> 7 #include <shlwapi.h>
8 #include <algorithm> 8 #include <algorithm>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 480
481 // Try again to delete the key. 481 // Try again to delete the key.
482 result = RegDeleteKeyExWrapper(root_key, name.c_str(), access, 0); 482 result = RegDeleteKeyExWrapper(root_key, name.c_str(), access, 0);
483 483
484 return result; 484 return result;
485 } 485 }
486 486
487 // RegistryValueIterator ------------------------------------------------------ 487 // RegistryValueIterator ------------------------------------------------------
488 488
489 RegistryValueIterator::RegistryValueIterator(HKEY root_key, 489 RegistryValueIterator::RegistryValueIterator(HKEY root_key,
490 const wchar_t* folder_key,
491 REGSAM wow64access)
492 : name_(MAX_PATH, L'\0'),
493 value_(MAX_PATH, L'\0') {
494 Initialize(root_key, folder_key, wow64access);
495 }
496
497 RegistryValueIterator::RegistryValueIterator(HKEY root_key,
490 const wchar_t* folder_key) 498 const wchar_t* folder_key)
491 : name_(MAX_PATH, L'\0'), 499 : name_(MAX_PATH, L'\0'),
492 value_(MAX_PATH, L'\0') { 500 value_(MAX_PATH, L'\0') {
493 LONG result = RegOpenKeyEx(root_key, folder_key, 0, KEY_READ, &key_); 501 Initialize(root_key, folder_key, 0);
502 }
503
504 void RegistryValueIterator::Initialize(HKEY root_key,
505 const wchar_t* folder_key,
506 REGSAM wow64access) {
507 DCHECK_EQ(wow64access & ~kWow64AccessMask, static_cast<REGSAM>(0));
508 LONG result =
509 RegOpenKeyEx(root_key, folder_key, 0, KEY_READ | wow64access, &key_);
494 if (result != ERROR_SUCCESS) { 510 if (result != ERROR_SUCCESS) {
495 key_ = NULL; 511 key_ = NULL;
496 } else { 512 } else {
497 DWORD count = 0; 513 DWORD count = 0;
498 result = ::RegQueryInfoKey(key_, NULL, 0, NULL, NULL, NULL, NULL, &count, 514 result = ::RegQueryInfoKey(key_, NULL, 0, NULL, NULL, NULL, NULL, &count,
499 NULL, NULL, NULL, NULL); 515 NULL, NULL, NULL, NULL);
500 516
501 if (result != ERROR_SUCCESS) { 517 if (result != ERROR_SUCCESS) {
502 ::RegCloseKey(key_); 518 ::RegCloseKey(key_);
503 key_ = NULL; 519 key_ = NULL;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 name_[0] = L'\0'; 586 name_[0] = L'\0';
571 value_[0] = L'\0'; 587 value_[0] = L'\0';
572 value_size_ = 0; 588 value_size_ = 0;
573 return false; 589 return false;
574 } 590 }
575 591
576 // RegistryKeyIterator -------------------------------------------------------- 592 // RegistryKeyIterator --------------------------------------------------------
577 593
578 RegistryKeyIterator::RegistryKeyIterator(HKEY root_key, 594 RegistryKeyIterator::RegistryKeyIterator(HKEY root_key,
579 const wchar_t* folder_key) { 595 const wchar_t* folder_key) {
580 LONG result = RegOpenKeyEx(root_key, folder_key, 0, KEY_READ, &key_); 596 Initialize(root_key, folder_key, 0);
581 if (result != ERROR_SUCCESS) { 597 }
582 key_ = NULL;
583 } else {
584 DWORD count = 0;
585 LONG result = ::RegQueryInfoKey(key_, NULL, 0, NULL, &count, NULL, NULL,
586 NULL, NULL, NULL, NULL, NULL);
587 598
588 if (result != ERROR_SUCCESS) { 599 RegistryKeyIterator::RegistryKeyIterator(HKEY root_key,
589 ::RegCloseKey(key_); 600 const wchar_t* folder_key,
590 key_ = NULL; 601 REGSAM wow64access) {
591 } else { 602 Initialize(root_key, folder_key, wow64access);
592 index_ = count - 1;
593 }
594 }
595
596 Read();
597 } 603 }
598 604
599 RegistryKeyIterator::~RegistryKeyIterator() { 605 RegistryKeyIterator::~RegistryKeyIterator() {
600 if (key_) 606 if (key_)
601 ::RegCloseKey(key_); 607 ::RegCloseKey(key_);
602 } 608 }
603 609
604 DWORD RegistryKeyIterator::SubkeyCount() const { 610 DWORD RegistryKeyIterator::SubkeyCount() const {
605 DWORD count = 0; 611 DWORD count = 0;
606 LONG result = ::RegQueryInfoKey(key_, NULL, 0, NULL, &count, NULL, NULL, 612 LONG result = ::RegQueryInfoKey(key_, NULL, 0, NULL, &count, NULL, NULL,
(...skipping 20 matching lines...) Expand all
627 LONG r = ::RegEnumKeyEx(key_, index_, name_, &ncount, NULL, NULL, 633 LONG r = ::RegEnumKeyEx(key_, index_, name_, &ncount, NULL, NULL,
628 NULL, &written); 634 NULL, &written);
629 if (ERROR_SUCCESS == r) 635 if (ERROR_SUCCESS == r)
630 return true; 636 return true;
631 } 637 }
632 638
633 name_[0] = '\0'; 639 name_[0] = '\0';
634 return false; 640 return false;
635 } 641 }
636 642
643 void RegistryKeyIterator::Initialize(HKEY root_key,
644 const wchar_t* folder_key,
645 REGSAM wow64access) {
646 DCHECK_EQ(wow64access & ~kWow64AccessMask, static_cast<REGSAM>(0));
647 LONG result =
648 RegOpenKeyEx(root_key, folder_key, 0, KEY_READ | wow64access, &key_);
649 if (result != ERROR_SUCCESS) {
650 key_ = NULL;
651 } else {
652 DWORD count = 0;
653 LONG result = ::RegQueryInfoKey(key_, NULL, 0, NULL, &count, NULL, NULL,
654 NULL, NULL, NULL, NULL, NULL);
655
656 if (result != ERROR_SUCCESS) {
657 ::RegCloseKey(key_);
658 key_ = NULL;
659 } else {
660 index_ = count - 1;
661 }
662 }
663
664 Read();
665 }
666
637 } // namespace win 667 } // namespace win
638 } // namespace base 668 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698