Index: chrome/common/importer/edge_importer_utils_win.cc |
diff --git a/chrome/common/importer/edge_importer_utils_win.cc b/chrome/common/importer/edge_importer_utils_win.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4e0ec1f4049119622d8321bdec06b2648d9b336e |
--- /dev/null |
+++ b/chrome/common/importer/edge_importer_utils_win.cc |
@@ -0,0 +1,92 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/common/importer/edge_importer_utils_win.h" |
+ |
+#include <Shlobj.h> |
+ |
+#include "base/files/file.h" |
+#include "base/files/file_path.h" |
+#include "base/files/file_util.h" |
+#include "base/win/registry.h" |
+#include "base/win/windows_version.h" |
+#include "chrome/common/importer/ie_importer_test_registry_overrider_win.h" |
+ |
+namespace { |
+ |
+const base::char16 kEdgeFavoritesOrderKey[] = |
+ L"MicrosoftEdge\\FavOrder\\Favorites"; |
+ |
+const base::char16 kEdgeSettingsMainKey[] = L"MicrosoftEdge\\Main"; |
+ |
+const base::char16 kEdgePackageName[] = |
+ L"microsoft.microsoftedge_8wekyb3d8bbwe"; |
+ |
+// We assume at the moment that the package name never changes for Edge. |
+base::string16 GetEdgePackageName() { |
+ return kEdgePackageName; |
+} |
+ |
+base::string16 GetEdgeRegistryKey(const base::string16& key_name) { |
+ base::string16 base_key = |
+ L"Software\\Classes\\Local " |
+ L"Settings\\Software\\Microsoft\\Windows\\CurrentVersion\\AppContainer\\S" |
+ L"torage\\"; |
Ilya Sherman
2015/11/26 02:04:44
nit: This string is pretty oddly wrapped. Could y
forshaw
2015/11/30 12:57:58
Will fix, clearly cl format doesn't understand the
|
+ base_key += GetEdgePackageName(); |
+ base_key += L"\\"; |
+ base_key += key_name; |
+ return base_key; |
Ilya Sherman
2015/11/26 02:04:43
nit: What does the "base" in "base_key" mean?
forshaw
2015/11/30 12:57:58
Will rename.
|
+} |
+ |
+base::string16 GetPotentiallyOverridenIEKey( |
Ilya Sherman
2015/11/26 02:04:43
nit: s/IE/Edge?
|
+ const base::string16& desired_key_path) { |
+ base::string16 test_reg_override( |
Ilya Sherman
2015/11/26 02:04:44
nit: s/reg/registry
|
+ IEImporterTestRegistryOverrider::GetTestRegistryOverride()); |
+ return test_reg_override.empty() ? GetEdgeRegistryKey(desired_key_path) |
+ : test_reg_override; |
+} |
+ |
+} // namespace |
+ |
+namespace importer { |
+ |
+base::string16 GetEdgeFavoritesOrderKey() { |
+ return GetPotentiallyOverridenIEKey(kEdgeFavoritesOrderKey); |
+} |
+ |
+base::string16 GetEdgeSettingsKey() { |
+ return GetPotentiallyOverridenIEKey(kEdgeSettingsMainKey); |
+} |
+ |
+base::FilePath GetEdgeDataFilePath() { |
+ wchar_t buffer[MAX_PATH]; |
Ilya Sherman
2015/11/26 02:04:43
I noticed that a lot -- but not all -- of our othe
forshaw
2015/11/30 12:57:58
This is a Windows coding idiom to initialize array
|
+ if (::SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, |
Ilya Sherman
2015/11/26 02:04:43
Why do you need the leading "::"?
forshaw
2015/11/30 12:57:58
Again a common Windows idiom to ensure you access
|
+ buffer) != S_OK) |
Ilya Sherman
2015/11/26 02:04:43
nit: I noticed that other code uses FAILED rather
forshaw
2015/11/30 12:57:58
I think the other code is technically wrong, but w
|
+ return base::FilePath(); |
+ |
+ base::FilePath base_path(buffer); |
+ base::string16 rel_path = L"Packages\\"; |
+ rel_path += GetEdgePackageName(); |
+ rel_path += L"\\AC\\MicrosoftEdge\\User\\Default"; |
+ return base_path.Append(rel_path); |
+} |
+ |
+bool IsEdgeFavoritesLegacyMode() { |
+ base::win::RegKey key(HKEY_CURRENT_USER, GetEdgeSettingsKey().c_str(), |
+ KEY_READ); |
+ DWORD ese_enabled = 0; |
Ilya Sherman
2015/11/26 02:04:44
nit: I don't know what "ese" is. Please either ex
forshaw
2015/11/30 12:57:58
Acknowledged.
|
+ if (key.ReadValueDW(L"FavoritesESEEnabled", &ese_enabled) == ERROR_SUCCESS) |
+ return !ese_enabled; |
+ return true; |
+} |
+ |
+bool EdgeImporterCanImport() { |
+ base::File::Info file_info; |
+ if (base::win::GetVersion() < base::win::VERSION_WIN10) |
+ return false; |
+ return base::GetFileInfo(GetEdgeDataFilePath(), &file_info) && |
+ file_info.is_directory; |
+} |
+ |
+} // namespace importer |