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 "chrome/utility/importer/ie_importer_win.h" | 5 #include "chrome/utility/importer/ie_importer_win.h" |
6 | 6 |
7 #include <ole2.h> | 7 #include <ole2.h> |
8 #include <intshcut.h> | 8 #include <intshcut.h> |
9 #include <shlobj.h> | 9 #include <shlobj.h> |
10 #include <urlhist.h> | 10 #include <urlhist.h> |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 // recorded in the REG_BINARY value named "Order" of the corresponding key. | 153 // recorded in the REG_BINARY value named "Order" of the corresponding key. |
154 // The content of the "Order" value is a raw binary dump of an array of the | 154 // The content of the "Order" value is a raw binary dump of an array of the |
155 // following data structure | 155 // following data structure |
156 // struct { | 156 // struct { |
157 // uint32 size; // Note that ITEMIDLIST is variably-sized. | 157 // uint32 size; // Note that ITEMIDLIST is variably-sized. |
158 // uint32 sort_index; // 0 means this is the first item, 1 the second, ... | 158 // uint32 sort_index; // 0 means this is the first item, 1 the second, ... |
159 // ITEMIDLIST item_id; | 159 // ITEMIDLIST item_id; |
160 // }; | 160 // }; |
161 // where each item_id should correspond to a favorites link file (*.url) in | 161 // where each item_id should correspond to a favorites link file (*.url) in |
162 // the current folder. | 162 // the current folder. |
163 bool ParseFavoritesOrderBlob( | 163 // GCC, in its infinite wisdom, does not allow WARN_UNUSED_RESULT to be used in |
Lei Zhang
2015/10/07 16:28:09
What is GCC doing touching a _win.cc file? Did you
dcheng
2015/10/07 16:41:34
GCC only allows function attributes on prototypes.
Lei Zhang
2015/10/07 20:33:11
Can you mention the clang / gcc compatibility issu
dcheng
2015/10/08 03:48:07
Done.
| |
164 const Importer* importer, | 164 // a definition. |
165 const std::vector<uint8>& blob, | 165 bool ParseFavoritesOrderBlob(const Importer* importer, |
166 const base::FilePath& path, | 166 const std::vector<uint8>& blob, |
167 std::map<base::FilePath, uint32>* sort_index) WARN_UNUSED_RESULT { | 167 const base::FilePath& path, |
168 std::map<base::FilePath, uint32>* sort_index) | |
169 WARN_UNUSED_RESULT; | |
170 bool ParseFavoritesOrderBlob(const Importer* importer, | |
171 const std::vector<uint8>& blob, | |
172 const base::FilePath& path, | |
173 std::map<base::FilePath, uint32>* sort_index) { | |
168 static const int kItemCountOffset = 16; | 174 static const int kItemCountOffset = 16; |
169 static const int kItemListStartOffset = 20; | 175 static const int kItemListStartOffset = 20; |
170 | 176 |
171 // Read the number of items. | 177 // Read the number of items. |
172 uint32 item_count = 0; | 178 uint32 item_count = 0; |
173 if (!BinaryRead(&item_count, kItemCountOffset, blob)) | 179 if (!BinaryRead(&item_count, kItemCountOffset, blob)) |
174 return false; | 180 return false; |
175 | 181 |
176 // Traverse over the items. | 182 // Traverse over the items. |
177 size_t base_offset = kItemListStartOffset; | 183 size_t base_offset = kItemListStartOffset; |
(...skipping 27 matching lines...) Expand all Loading... | |
205 sort_index->insert(std::make_pair(item_relative_path, item_sort_index)); | 211 sort_index->insert(std::make_pair(item_relative_path, item_sort_index)); |
206 base_offset += item_size; | 212 base_offset += item_size; |
207 } | 213 } |
208 return true; | 214 return true; |
209 } | 215 } |
210 | 216 |
211 bool ParseFavoritesOrderRegistryTree( | 217 bool ParseFavoritesOrderRegistryTree( |
212 const Importer* importer, | 218 const Importer* importer, |
213 const base::win::RegKey& key, | 219 const base::win::RegKey& key, |
214 const base::FilePath& path, | 220 const base::FilePath& path, |
215 std::map<base::FilePath, uint32>* sort_index) WARN_UNUSED_RESULT { | 221 std::map<base::FilePath, uint32>* sort_index) WARN_UNUSED_RESULT; |
222 bool ParseFavoritesOrderRegistryTree( | |
223 const Importer* importer, | |
224 const base::win::RegKey& key, | |
225 const base::FilePath& path, | |
226 std::map<base::FilePath, uint32>* sort_index) { | |
216 // Parse the order information of the current folder. | 227 // Parse the order information of the current folder. |
217 DWORD blob_length = 0; | 228 DWORD blob_length = 0; |
218 if (key.ReadValue(L"Order", NULL, &blob_length, NULL) == ERROR_SUCCESS) { | 229 if (key.ReadValue(L"Order", NULL, &blob_length, NULL) == ERROR_SUCCESS) { |
219 std::vector<uint8> blob(blob_length); | 230 std::vector<uint8> blob(blob_length); |
220 if (blob_length > 0 && | 231 if (blob_length > 0 && |
221 key.ReadValue(L"Order", reinterpret_cast<DWORD*>(&blob[0]), | 232 key.ReadValue(L"Order", reinterpret_cast<DWORD*>(&blob[0]), |
222 &blob_length, NULL) == ERROR_SUCCESS) { | 233 &blob_length, NULL) == ERROR_SUCCESS) { |
223 if (!ParseFavoritesOrderBlob(importer, blob, path, sort_index)) | 234 if (!ParseFavoritesOrderBlob(importer, blob, path, sort_index)) |
224 return false; | 235 return false; |
225 } | 236 } |
226 } | 237 } |
227 | 238 |
228 // Recursively parse subfolders. | 239 // Recursively parse subfolders. |
229 for (base::win::RegistryKeyIterator child(key.Handle(), L""); | 240 for (base::win::RegistryKeyIterator child(key.Handle(), L""); |
230 child.Valid() && !importer->cancelled(); | 241 child.Valid() && !importer->cancelled(); |
231 ++child) { | 242 ++child) { |
232 base::win::RegKey subkey(key.Handle(), child.Name(), KEY_READ); | 243 base::win::RegKey subkey(key.Handle(), child.Name(), KEY_READ); |
233 if (subkey.Valid()) { | 244 if (subkey.Valid()) { |
234 base::FilePath subpath(path.Append(child.Name())); | 245 base::FilePath subpath(path.Append(child.Name())); |
235 if (!ParseFavoritesOrderRegistryTree(importer, subkey, subpath, | 246 if (!ParseFavoritesOrderRegistryTree(importer, subkey, subpath, |
236 sort_index)) { | 247 sort_index)) { |
237 return false; | 248 return false; |
238 } | 249 } |
239 } | 250 } |
240 } | 251 } |
241 return true; | 252 return true; |
242 } | 253 } |
243 | 254 |
244 bool ParseFavoritesOrderInfo( | 255 bool ParseFavoritesOrderInfo(const Importer* importer, |
245 const Importer* importer, | 256 std::map<base::FilePath, uint32>* sort_index) |
246 std::map<base::FilePath, uint32>* sort_index) WARN_UNUSED_RESULT { | 257 WARN_UNUSED_RESULT; |
258 bool ParseFavoritesOrderInfo(const Importer* importer, | |
259 std::map<base::FilePath, uint32>* sort_index) { | |
247 base::string16 key_path(importer::GetIEFavoritesOrderKey()); | 260 base::string16 key_path(importer::GetIEFavoritesOrderKey()); |
248 base::win::RegKey key(HKEY_CURRENT_USER, key_path.c_str(), KEY_READ); | 261 base::win::RegKey key(HKEY_CURRENT_USER, key_path.c_str(), KEY_READ); |
249 if (!key.Valid()) | 262 if (!key.Valid()) |
250 return false; | 263 return false; |
251 return ParseFavoritesOrderRegistryTree(importer, key, base::FilePath(), | 264 return ParseFavoritesOrderRegistryTree(importer, key, base::FilePath(), |
252 sort_index); | 265 sort_index); |
253 } | 266 } |
254 | 267 |
255 // Reads the sort order from registry. If failed, we don't touch the list | 268 // Reads the sort order from registry. If failed, we don't touch the list |
256 // and use the default (alphabetical) order. | 269 // and use the default (alphabetical) order. |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
885 static int version = -1; | 898 static int version = -1; |
886 if (version < 0) { | 899 if (version < 0) { |
887 wchar_t buffer[128]; | 900 wchar_t buffer[128]; |
888 DWORD buffer_length = sizeof(buffer); | 901 DWORD buffer_length = sizeof(buffer); |
889 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, kIEVersionKey, KEY_READ); | 902 base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, kIEVersionKey, KEY_READ); |
890 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); | 903 LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); |
891 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); | 904 version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); |
892 } | 905 } |
893 return version; | 906 return version; |
894 } | 907 } |
OLD | NEW |