| OLD | NEW |
| 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 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 } | 562 } |
| 563 | 563 |
| 564 bool RegistryValueIterator::Read() { | 564 bool RegistryValueIterator::Read() { |
| 565 if (Valid()) { | 565 if (Valid()) { |
| 566 DWORD capacity = static_cast<DWORD>(name_.capacity()); | 566 DWORD capacity = static_cast<DWORD>(name_.capacity()); |
| 567 DWORD name_size = capacity; | 567 DWORD name_size = capacity; |
| 568 // |value_size_| is in bytes. Reserve the last character for a NUL. | 568 // |value_size_| is in bytes. Reserve the last character for a NUL. |
| 569 value_size_ = static_cast<DWORD>((value_.size() - 1) * sizeof(wchar_t)); | 569 value_size_ = static_cast<DWORD>((value_.size() - 1) * sizeof(wchar_t)); |
| 570 LONG result = ::RegEnumValue( | 570 LONG result = ::RegEnumValue( |
| 571 key_, index_, WriteInto(&name_, name_size), &name_size, NULL, &type_, | 571 key_, index_, WriteInto(&name_, name_size), &name_size, NULL, &type_, |
| 572 reinterpret_cast<BYTE*>(vector_as_array(&value_)), &value_size_); | 572 reinterpret_cast<BYTE*>(value_.data()), &value_size_); |
| 573 | 573 |
| 574 if (result == ERROR_MORE_DATA) { | 574 if (result == ERROR_MORE_DATA) { |
| 575 // Registry key names are limited to 255 characters and fit within | 575 // Registry key names are limited to 255 characters and fit within |
| 576 // MAX_PATH (which is 260) but registry value names can use up to 16,383 | 576 // MAX_PATH (which is 260) but registry value names can use up to 16,383 |
| 577 // characters and the value itself is not limited | 577 // characters and the value itself is not limited |
| 578 // (from http://msdn.microsoft.com/en-us/library/windows/desktop/ | 578 // (from http://msdn.microsoft.com/en-us/library/windows/desktop/ |
| 579 // ms724872(v=vs.85).aspx). | 579 // ms724872(v=vs.85).aspx). |
| 580 // Resize the buffers and retry if their size caused the failure. | 580 // Resize the buffers and retry if their size caused the failure. |
| 581 DWORD value_size_in_wchars = to_wchar_size(value_size_); | 581 DWORD value_size_in_wchars = to_wchar_size(value_size_); |
| 582 if (value_size_in_wchars + 1 > value_.size()) | 582 if (value_size_in_wchars + 1 > value_.size()) |
| 583 value_.resize(value_size_in_wchars + 1, L'\0'); | 583 value_.resize(value_size_in_wchars + 1, L'\0'); |
| 584 value_size_ = static_cast<DWORD>((value_.size() - 1) * sizeof(wchar_t)); | 584 value_size_ = static_cast<DWORD>((value_.size() - 1) * sizeof(wchar_t)); |
| 585 name_size = name_size == capacity ? MAX_REGISTRY_NAME_SIZE : capacity; | 585 name_size = name_size == capacity ? MAX_REGISTRY_NAME_SIZE : capacity; |
| 586 result = ::RegEnumValue( | 586 result = ::RegEnumValue( |
| 587 key_, index_, WriteInto(&name_, name_size), &name_size, NULL, &type_, | 587 key_, index_, WriteInto(&name_, name_size), &name_size, NULL, &type_, |
| 588 reinterpret_cast<BYTE*>(vector_as_array(&value_)), &value_size_); | 588 reinterpret_cast<BYTE*>(value_.data()), &value_size_); |
| 589 } | 589 } |
| 590 | 590 |
| 591 if (result == ERROR_SUCCESS) { | 591 if (result == ERROR_SUCCESS) { |
| 592 DCHECK_LT(to_wchar_size(value_size_), value_.size()); | 592 DCHECK_LT(to_wchar_size(value_size_), value_.size()); |
| 593 value_[to_wchar_size(value_size_)] = L'\0'; | 593 value_[to_wchar_size(value_size_)] = L'\0'; |
| 594 return true; | 594 return true; |
| 595 } | 595 } |
| 596 } | 596 } |
| 597 | 597 |
| 598 name_[0] = L'\0'; | 598 name_[0] = L'\0'; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 } else { | 671 } else { |
| 672 index_ = count - 1; | 672 index_ = count - 1; |
| 673 } | 673 } |
| 674 } | 674 } |
| 675 | 675 |
| 676 Read(); | 676 Read(); |
| 677 } | 677 } |
| 678 | 678 |
| 679 } // namespace win | 679 } // namespace win |
| 680 } // namespace base | 680 } // namespace base |
| OLD | NEW |