OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/common/importer/edge_importer_utils_win.h" |
| 6 |
| 7 #include <Shlobj.h> |
| 8 |
| 9 #include "base/files/file.h" |
| 10 #include "base/files/file_path.h" |
| 11 #include "base/files/file_util.h" |
| 12 #include "base/win/registry.h" |
| 13 #include "base/win/windows_version.h" |
| 14 #include "chrome/common/importer/ie_importer_test_registry_overrider_win.h" |
| 15 |
| 16 namespace { |
| 17 |
| 18 const base::char16 kEdgeSettingsMainKey[] = L"MicrosoftEdge\\Main"; |
| 19 |
| 20 const base::char16 kEdgePackageName[] = |
| 21 L"microsoft.microsoftedge_8wekyb3d8bbwe"; |
| 22 |
| 23 // We assume at the moment that the package name never changes for Edge. |
| 24 base::string16 GetEdgePackageName() { |
| 25 return kEdgePackageName; |
| 26 } |
| 27 |
| 28 base::string16 GetEdgeRegistryKey(const base::string16& key_name) { |
| 29 base::string16 registry_key = |
| 30 L"Software\\Classes\\Local Settings\\" |
| 31 L"Software\\Microsoft\\Windows\\CurrentVersion\\AppContainer\\" |
| 32 L"Storage\\"; |
| 33 registry_key += GetEdgePackageName(); |
| 34 registry_key += L"\\"; |
| 35 registry_key += key_name; |
| 36 return registry_key; |
| 37 } |
| 38 |
| 39 base::string16 GetPotentiallyOverridenEdgeKey( |
| 40 const base::string16& desired_key_path) { |
| 41 base::string16 test_registry_override( |
| 42 IEImporterTestRegistryOverrider::GetTestRegistryOverride()); |
| 43 return test_registry_override.empty() ? GetEdgeRegistryKey(desired_key_path) |
| 44 : test_registry_override; |
| 45 } |
| 46 |
| 47 } // namespace |
| 48 |
| 49 namespace importer { |
| 50 |
| 51 base::string16 GetEdgeSettingsKey() { |
| 52 return GetPotentiallyOverridenEdgeKey(kEdgeSettingsMainKey); |
| 53 } |
| 54 |
| 55 base::FilePath GetEdgeDataFilePath() { |
| 56 wchar_t buffer[MAX_PATH]; |
| 57 if (::SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, |
| 58 buffer) != S_OK) |
| 59 return base::FilePath(); |
| 60 |
| 61 base::FilePath base_path(buffer); |
| 62 base::string16 rel_path = L"Packages\\"; |
| 63 rel_path += GetEdgePackageName(); |
| 64 rel_path += L"\\AC\\MicrosoftEdge\\User\\Default"; |
| 65 return base_path.Append(rel_path); |
| 66 } |
| 67 |
| 68 bool IsEdgeFavoritesLegacyMode() { |
| 69 base::win::RegKey key(HKEY_CURRENT_USER, GetEdgeSettingsKey().c_str(), |
| 70 KEY_READ); |
| 71 DWORD ese_enabled = 0; |
| 72 // Check whether Edge is using the new Extensible Store Engine (ESE) format |
| 73 // for its favorites. |
| 74 if (key.ReadValueDW(L"FavoritesESEEnabled", &ese_enabled) == ERROR_SUCCESS) |
| 75 return !ese_enabled; |
| 76 return true; |
| 77 } |
| 78 |
| 79 bool EdgeImporterCanImport() { |
| 80 base::File::Info file_info; |
| 81 if (base::win::GetVersion() < base::win::VERSION_WIN10) |
| 82 return false; |
| 83 return base::GetFileInfo(GetEdgeDataFilePath(), &file_info) && |
| 84 file_info.is_directory; |
| 85 } |
| 86 |
| 87 } // namespace importer |
OLD | NEW |