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 kEdgeFavoritesOrderKey[] = | |
19 L"MicrosoftEdge\\FavOrder\\Favorites"; | |
20 | |
21 const base::char16 kEdgeSettingsMainKey[] = L"MicrosoftEdge\\Main"; | |
22 | |
23 const base::char16 kEdgePackageName[] = | |
24 L"microsoft.microsoftedge_8wekyb3d8bbwe"; | |
25 | |
26 // We assume at the moment that the package name never changes for Edge. | |
27 base::string16 GetEdgePackageName() { | |
28 return kEdgePackageName; | |
29 } | |
30 | |
31 base::string16 GetEdgeRegistryKey(const base::string16& key_name) { | |
32 base::string16 base_key = | |
33 L"Software\\Classes\\Local " | |
34 L"Settings\\Software\\Microsoft\\Windows\\CurrentVersion\\AppContainer\\S" | |
35 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
| |
36 base_key += GetEdgePackageName(); | |
37 base_key += L"\\"; | |
38 base_key += key_name; | |
39 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.
| |
40 } | |
41 | |
42 base::string16 GetPotentiallyOverridenIEKey( | |
Ilya Sherman
2015/11/26 02:04:43
nit: s/IE/Edge?
| |
43 const base::string16& desired_key_path) { | |
44 base::string16 test_reg_override( | |
Ilya Sherman
2015/11/26 02:04:44
nit: s/reg/registry
| |
45 IEImporterTestRegistryOverrider::GetTestRegistryOverride()); | |
46 return test_reg_override.empty() ? GetEdgeRegistryKey(desired_key_path) | |
47 : test_reg_override; | |
48 } | |
49 | |
50 } // namespace | |
51 | |
52 namespace importer { | |
53 | |
54 base::string16 GetEdgeFavoritesOrderKey() { | |
55 return GetPotentiallyOverridenIEKey(kEdgeFavoritesOrderKey); | |
56 } | |
57 | |
58 base::string16 GetEdgeSettingsKey() { | |
59 return GetPotentiallyOverridenIEKey(kEdgeSettingsMainKey); | |
60 } | |
61 | |
62 base::FilePath GetEdgeDataFilePath() { | |
63 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
| |
64 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
| |
65 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
| |
66 return base::FilePath(); | |
67 | |
68 base::FilePath base_path(buffer); | |
69 base::string16 rel_path = L"Packages\\"; | |
70 rel_path += GetEdgePackageName(); | |
71 rel_path += L"\\AC\\MicrosoftEdge\\User\\Default"; | |
72 return base_path.Append(rel_path); | |
73 } | |
74 | |
75 bool IsEdgeFavoritesLegacyMode() { | |
76 base::win::RegKey key(HKEY_CURRENT_USER, GetEdgeSettingsKey().c_str(), | |
77 KEY_READ); | |
78 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.
| |
79 if (key.ReadValueDW(L"FavoritesESEEnabled", &ese_enabled) == ERROR_SUCCESS) | |
80 return !ese_enabled; | |
81 return true; | |
82 } | |
83 | |
84 bool EdgeImporterCanImport() { | |
85 base::File::Info file_info; | |
86 if (base::win::GetVersion() < base::win::VERSION_WIN10) | |
87 return false; | |
88 return base::GetFileInfo(GetEdgeDataFilePath(), &file_info) && | |
89 file_info.is_directory; | |
90 } | |
91 | |
92 } // namespace importer | |
OLD | NEW |