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

Unified Diff: chrome/utility/importer/ie_importer_win.cc

Issue 1548153002: Switch to standard integer types in chrome/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/utility/importer/ie_importer_win.h ('k') | chrome/utility/importer/importer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/utility/importer/ie_importer_win.cc
diff --git a/chrome/utility/importer/ie_importer_win.cc b/chrome/utility/importer/ie_importer_win.cc
index f2fceb0d621a531d088f3ba13ffe62c8c6bb2c76..2ef4b470fe42970b914536ac962eb419f4c23284 100644
--- a/chrome/utility/importer/ie_importer_win.cc
+++ b/chrome/utility/importer/ie_importer_win.cc
@@ -7,6 +7,7 @@
#include <ole2.h>
#include <intshcut.h>
#include <shlobj.h>
+#include <stddef.h>
#include <urlhist.h>
#include <wininet.h>
@@ -18,6 +19,7 @@
#include "base/files/file_enumerator.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
+#include "base/macros.h"
#include "base/strings/string16.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
@@ -80,8 +82,8 @@ base::Time GetFileCreationTime(const base::string16& file) {
}
// Safely read an object of type T from a raw sequence of bytes.
-template<typename T>
-bool BinaryRead(T* data, size_t offset, const std::vector<uint8>& blob) {
+template <typename T>
+bool BinaryRead(T* data, size_t offset, const std::vector<uint8_t>& blob) {
if (offset + sizeof(T) > blob.size())
return false;
memcpy(data, &blob[offset], sizeof(T));
@@ -94,8 +96,9 @@ bool BinaryRead(T* data, size_t offset, const std::vector<uint8>& blob) {
// .cb = 0. Here, before simply casting &blob[offset] to LPITEMIDLIST,
// we verify that the list structure is not overrunning the boundary of
// the binary blob.
-LPCITEMIDLIST BinaryReadItemIDList(size_t offset, size_t idlist_size,
- const std::vector<uint8>& blob) {
+LPCITEMIDLIST BinaryReadItemIDList(size_t offset,
+ size_t idlist_size,
+ const std::vector<uint8_t>& blob) {
size_t head = 0;
while (true) {
// Use a USHORT instead of SHITEMID to avoid buffer over read.
@@ -114,7 +117,7 @@ LPCITEMIDLIST BinaryReadItemIDList(size_t offset, size_t idlist_size,
struct IEOrderBookmarkComparator {
bool operator()(const ImportedBookmarkEntry& lhs,
const ImportedBookmarkEntry& rhs) const {
- static const uint32 kNotSorted = 0xfffffffb; // IE uses this magic value.
+ static const uint32_t kNotSorted = 0xfffffffb; // IE uses this magic value.
base::FilePath lhs_prefix;
base::FilePath rhs_prefix;
for (size_t i = 0; i <= lhs.path.size() && i <= rhs.path.size(); ++i) {
@@ -127,14 +130,14 @@ struct IEOrderBookmarkComparator {
if (lhs_i == rhs_i)
continue;
// The first path element that differs between the two.
- std::map<base::FilePath, uint32>::const_iterator lhs_iter =
- sort_index_->find(lhs_prefix);
- std::map<base::FilePath, uint32>::const_iterator rhs_iter =
- sort_index_->find(rhs_prefix);
- uint32 lhs_sort_index = (lhs_iter == sort_index_->end() ? kNotSorted
- : lhs_iter->second);
- uint32 rhs_sort_index = (rhs_iter == sort_index_->end() ? kNotSorted
- : rhs_iter->second);
+ std::map<base::FilePath, uint32_t>::const_iterator lhs_iter =
+ sort_index_->find(lhs_prefix);
+ std::map<base::FilePath, uint32_t>::const_iterator rhs_iter =
+ sort_index_->find(rhs_prefix);
+ uint32_t lhs_sort_index =
+ (lhs_iter == sort_index_->end() ? kNotSorted : lhs_iter->second);
+ uint32_t rhs_sort_index =
+ (rhs_iter == sort_index_->end() ? kNotSorted : rhs_iter->second);
if (lhs_sort_index != rhs_sort_index)
return lhs_sort_index < rhs_sort_index;
// If they have the same sort order, sort alphabetically.
@@ -142,7 +145,7 @@ struct IEOrderBookmarkComparator {
}
return lhs.path.size() < rhs.path.size();
}
- const std::map<base::FilePath, uint32>* sort_index_;
+ const std::map<base::FilePath, uint32_t>* sort_index_;
};
// IE stores the order of the Favorites menu in registry under:
@@ -155,8 +158,9 @@ struct IEOrderBookmarkComparator {
// The content of the "Order" value is a raw binary dump of an array of the
// following data structure
// struct {
-// uint32 size; // Note that ITEMIDLIST is variably-sized.
-// uint32 sort_index; // 0 means this is the first item, 1 the second, ...
+// uint32_t size; // Note that ITEMIDLIST is variably-sized.
+// uint32_t sort_index; // 0 means this is the first item, 1 the second,
+// ...
// ITEMIDLIST item_id;
// };
// where each item_id should correspond to a favorites link file (*.url) in
@@ -167,38 +171,38 @@ struct IEOrderBookmarkComparator {
// build on Windows, declare some prototypes anyway to satisfy Clang's gcc
// compatibility warnings.
bool ParseFavoritesOrderBlob(const Importer* importer,
- const std::vector<uint8>& blob,
+ const std::vector<uint8_t>& blob,
const base::FilePath& path,
- std::map<base::FilePath, uint32>* sort_index)
+ std::map<base::FilePath, uint32_t>* sort_index)
WARN_UNUSED_RESULT;
bool ParseFavoritesOrderBlob(const Importer* importer,
- const std::vector<uint8>& blob,
+ const std::vector<uint8_t>& blob,
const base::FilePath& path,
- std::map<base::FilePath, uint32>* sort_index) {
+ std::map<base::FilePath, uint32_t>* sort_index) {
static const int kItemCountOffset = 16;
static const int kItemListStartOffset = 20;
// Read the number of items.
- uint32 item_count = 0;
+ uint32_t item_count = 0;
if (!BinaryRead(&item_count, kItemCountOffset, blob))
return false;
// Traverse over the items.
size_t base_offset = kItemListStartOffset;
- for (uint32 i = 0; i < item_count && !importer->cancelled(); ++i) {
+ for (uint32_t i = 0; i < item_count && !importer->cancelled(); ++i) {
static const int kSizeOffset = 0;
static const int kSortIndexOffset = 4;
static const int kItemIDListOffset = 8;
// Read the size (number of bytes) of the current item.
- uint32 item_size = 0;
+ uint32_t item_size = 0;
if (!BinaryRead(&item_size, base_offset + kSizeOffset, blob) ||
base_offset + item_size <= base_offset || // checking overflow
base_offset + item_size > blob.size())
return false;
// Read the sort index of the current item.
- uint32 item_sort_index = 0;
+ uint32_t item_sort_index = 0;
if (!BinaryRead(&item_sort_index, base_offset + kSortIndexOffset, blob))
return false;
@@ -222,16 +226,16 @@ bool ParseFavoritesOrderRegistryTree(
const Importer* importer,
const base::win::RegKey& key,
const base::FilePath& path,
- std::map<base::FilePath, uint32>* sort_index) WARN_UNUSED_RESULT;
+ std::map<base::FilePath, uint32_t>* sort_index) WARN_UNUSED_RESULT;
bool ParseFavoritesOrderRegistryTree(
const Importer* importer,
const base::win::RegKey& key,
const base::FilePath& path,
- std::map<base::FilePath, uint32>* sort_index) {
+ std::map<base::FilePath, uint32_t>* sort_index) {
// Parse the order information of the current folder.
DWORD blob_length = 0;
if (key.ReadValue(L"Order", NULL, &blob_length, NULL) == ERROR_SUCCESS) {
- std::vector<uint8> blob(blob_length);
+ std::vector<uint8_t> blob(blob_length);
if (blob_length > 0 &&
key.ReadValue(L"Order", reinterpret_cast<DWORD*>(&blob[0]),
&blob_length, NULL) == ERROR_SUCCESS) {
@@ -257,10 +261,10 @@ bool ParseFavoritesOrderRegistryTree(
}
bool ParseFavoritesOrderInfo(const Importer* importer,
- std::map<base::FilePath, uint32>* sort_index)
+ std::map<base::FilePath, uint32_t>* sort_index)
WARN_UNUSED_RESULT;
bool ParseFavoritesOrderInfo(const Importer* importer,
- std::map<base::FilePath, uint32>* sort_index) {
+ std::map<base::FilePath, uint32_t>* sort_index) {
base::string16 key_path(importer::GetIEFavoritesOrderKey());
base::win::RegKey key(HKEY_CURRENT_USER, key_path.c_str(), KEY_READ);
if (!key.Valid())
@@ -274,7 +278,7 @@ bool ParseFavoritesOrderInfo(const Importer* importer,
void SortBookmarksInIEOrder(
const Importer* importer,
std::vector<ImportedBookmarkEntry>* bookmarks) {
- std::map<base::FilePath, uint32> sort_index;
+ std::map<base::FilePath, uint32_t> sort_index;
if (!ParseFavoritesOrderInfo(importer, &sort_index))
return;
IEOrderBookmarkComparator compare = {&sort_index};
@@ -424,7 +428,7 @@ const GUID IEImporter::kUnittestGUID = {
IEImporter::IEImporter() : edge_import_mode_(false) {}
void IEImporter::StartImport(const importer::SourceProfile& source_profile,
- uint16 items,
+ uint16_t items,
ImporterBridge* bridge) {
edge_import_mode_ = source_profile.importer_type == importer::TYPE_EDGE;
bridge_ = bridge;
« no previous file with comments | « chrome/utility/importer/ie_importer_win.h ('k') | chrome/utility/importer/importer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698