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 // This file defines functions that integrate Chrome in Windows shell. These | 5 // This file defines functions that integrate Chrome in Windows shell. These |
6 // functions can be used by Chrome as well as Chrome installer. All of the | 6 // functions can be used by Chrome as well as Chrome installer. All of the |
7 // work is done by the local functions defined in anonymous namespace in | 7 // work is done by the local functions defined in anonymous namespace in |
8 // this class. | 8 // this class. |
9 | 9 |
10 #include "chrome/installer/util/shell_util.h" | 10 #include "chrome/installer/util/shell_util.h" |
11 | 11 |
12 #include <windows.h> | 12 #include <windows.h> |
13 #include <shlobj.h> | 13 #include <shlobj.h> |
14 | 14 |
15 #include <limits> | 15 #include <limits> |
16 #include <string> | 16 #include <string> |
17 | 17 |
18 #include "base/bind.h" | |
18 #include "base/command_line.h" | 19 #include "base/command_line.h" |
19 #include "base/file_util.h" | 20 #include "base/file_util.h" |
20 #include "base/files/file_path.h" | 21 #include "base/files/file_path.h" |
21 #include "base/lazy_instance.h" | 22 #include "base/lazy_instance.h" |
22 #include "base/logging.h" | 23 #include "base/logging.h" |
23 #include "base/md5.h" | 24 #include "base/md5.h" |
24 #include "base/memory/scoped_ptr.h" | 25 #include "base/memory/scoped_ptr.h" |
25 #include "base/memory/scoped_vector.h" | 26 #include "base/memory/scoped_vector.h" |
26 #include "base/path_service.h" | 27 #include "base/path_service.h" |
27 #include "base/string16.h" | 28 #include "base/string16.h" |
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1152 const base::win::Version windows_version = base::win::GetVersion(); | 1153 const base::win::Version windows_version = base::win::GetVersion(); |
1153 | 1154 |
1154 if (windows_version >= base::win::VERSION_WIN8) | 1155 if (windows_version >= base::win::VERSION_WIN8) |
1155 return ProbeCurrentDefaultHandlers(protocols, num_protocols); | 1156 return ProbeCurrentDefaultHandlers(protocols, num_protocols); |
1156 else if (windows_version >= base::win::VERSION_VISTA) | 1157 else if (windows_version >= base::win::VERSION_VISTA) |
1157 return ProbeAppIsDefaultHandlers(protocols, num_protocols); | 1158 return ProbeAppIsDefaultHandlers(protocols, num_protocols); |
1158 | 1159 |
1159 return ProbeOpenCommandHandlers(protocols, num_protocols); | 1160 return ProbeOpenCommandHandlers(protocols, num_protocols); |
1160 } | 1161 } |
1161 | 1162 |
1162 // Removes shortcut at |shortcut_path| if it is a shortcut that points to | 1163 // (Windows 8+) Finds the folder for app shortcuts, store it in *|path|. |
gab
2013/04/30 19:20:33
s/store/stores
huangs
2013/04/30 20:52:10
Rephrased.
| |
1163 // |target_exe|. If |delete_folder| is true, deletes the parent folder of | 1164 // Returns true on success. |
1164 // the shortcut completely. Returns true if either the shortcut was deleted | 1165 bool GetAppShortcutsFolder(BrowserDistribution* dist, |
1165 // successfully or if the shortcut did not point to |target_exe|. | 1166 ShellUtil::ShellChange level, |
1166 bool MaybeRemoveShortcutAtPath(const base::FilePath& shortcut_path, | 1167 base::FilePath *path) { |
1167 const base::FilePath& target_exe, | 1168 DCHECK(path); |
1168 bool delete_folder) { | 1169 if (base::win::GetVersion() < base::win::VERSION_WIN8) |
1169 base::FilePath target_path; | |
1170 if (!base::win::ResolveShortcut(shortcut_path, &target_path, NULL)) | |
1171 return false; | 1170 return false; |
1172 | 1171 |
1173 if (InstallUtil::ProgramCompare(target_exe).EvaluatePath(target_path)) { | 1172 base::FilePath folder; |
1174 // Unpin the shortcut if it was ever pinned by the user or the installer. | 1173 if (!PathService::Get(base::DIR_APP_SHORTCUTS, &folder) || folder.empty()) { |
1175 VLOG(1) << "Trying to unpin " << shortcut_path.value(); | 1174 LOG(ERROR) << "Could not get application shortcuts location."; |
1176 if (!base::win::TaskbarUnpinShortcutLink(shortcut_path.value().c_str())) { | 1175 return false; |
1177 VLOG(1) << shortcut_path.value() | |
1178 << " wasn't pinned (or the unpin failed)."; | |
1179 } | |
1180 if (delete_folder) | |
1181 return file_util::Delete(shortcut_path.DirName(), true); | |
1182 else | |
1183 return file_util::Delete(shortcut_path, false); | |
1184 } | 1176 } |
1185 | 1177 |
1186 // The shortcut at |shortcut_path| doesn't point to |target_exe|, act as if | 1178 folder = folder.Append(ShellUtil::GetBrowserModelId( |
1187 // our shortcut had been deleted. | 1179 dist, level == ShellUtil::CURRENT_USER)); |
1180 if (!file_util::DirectoryExists(folder)) { | |
1181 VLOG(1) << "No start screen shortcuts."; | |
1182 return false; | |
1183 } | |
1184 | |
1185 *path = folder; | |
1188 return true; | 1186 return true; |
1189 } | 1187 } |
1190 | 1188 |
1189 const wchar_t kAllShortcuts[] = L"*.lnk"; | |
1190 | |
1191 typedef base::Callback<bool(const base::FilePath&)> FileOperationCallback; | |
1192 | |
1193 // Shortcut operations for BatchShortcutAction(). | |
1194 | |
1195 bool ShortcutOpUnpin(const base::FilePath& shortcut_path) { | |
1196 VLOG(1) << "Trying to unpin " << shortcut_path.value(); | |
1197 if (!base::win::TaskbarUnpinShortcutLink(shortcut_path.value().c_str())) { | |
1198 VLOG(1) << shortcut_path.value() << " wasn't pinned (or the unpin failed)."; | |
1199 // No error, since shortcut might not be pinned. | |
1200 } | |
1201 return true; | |
1202 } | |
1203 | |
1204 bool ShortcutOpDelete(const base::FilePath& shortcut_path) { | |
1205 bool ret = file_util::Delete(shortcut_path, false); | |
1206 LOG_IF(ERROR, !ret) << "Failed to remove " << shortcut_path.value(); | |
1207 return ret; | |
1208 } | |
1209 | |
1210 bool ShortcutOpUnpinAndDelete(const base::FilePath& shortcut_path) { | |
1211 // Want to try both, without short-circuiting. | |
1212 bool ret1 = ShortcutOpUnpin(shortcut_path); | |
1213 bool ret2 = ShortcutOpDelete(shortcut_path); | |
1214 return ret1 && ret2; | |
1215 } | |
1216 | |
1217 bool ShortcutOpSetTarget(const base::FilePath& target_path, | |
1218 const base::FilePath& shortcut_path) { | |
1219 base::win::ShortcutProperties shortcut_properties; | |
1220 shortcut_properties.set_target(target_path); | |
1221 shortcut_properties.set_working_dir(target_path.DirName()); | |
1222 bool ret = base::win::CreateOrUpdateShortcutLink( | |
1223 shortcut_path, shortcut_properties, base::win::SHORTCUT_REPLACE_EXISTING); | |
1224 LOG_IF(ERROR, !ret) << "Failed to retarget " << shortcut_path.value(); | |
1225 return ret; | |
1226 } | |
1227 | |
1228 // {|location|, |dist|, |level|} determine |shortcut_folder|. | |
1229 // In |shortcut_folder|, applies |shortcut_operation| to each shortcut that | |
gab
2013/04/30 19:20:33
I find this wording weird, I'd prefer:
Applies |s
huangs
2013/04/30 20:52:10
Much better. Done.
| |
1230 // point to |target_exe|, | |
gab
2013/04/30 19:20:33
dot, not comma, at end of sentence.
huangs
2013/04/30 20:52:10
Done.
| |
1231 // Returns true if all operations are successful. All intended operations are | |
1232 // performed even if failures occur. | |
1233 bool BatchShortcutAction(const FileOperationCallback& shortcut_operation, | |
1234 ShellUtil::ShortcutLocation location, | |
1235 BrowserDistribution* dist, | |
1236 ShellUtil::ShellChange level, | |
1237 const base::FilePath& target_exe) { | |
1238 DCHECK(!shortcut_operation.is_null()); | |
1239 base::FilePath shortcut_folder; | |
1240 if (!ShellUtil::GetShortcutPath(location, dist, level, &shortcut_folder)) { | |
1241 LOG(WARNING) << "Cannot find path at location " << location; | |
1242 return false; | |
1243 } | |
1244 | |
1245 bool success = true; | |
1246 InstallUtil::ProgramCompare target_compare(target_exe); | |
1247 file_util::FileEnumerator enumerator( | |
1248 shortcut_folder, false, file_util::FileEnumerator::FILES, | |
1249 kAllShortcuts); | |
gab
2013/04/30 19:20:33
I think it's fine to hardcode ("*" + installer::kL
grt (UTC plus 2)
2013/04/30 19:59:53
+1
huangs
2013/04/30 20:52:10
Done.
huangs
2013/04/30 20:52:10
Done.
| |
1250 for (base::FilePath shortcut_path = enumerator.Next(); | |
1251 !shortcut_path.empty(); | |
1252 shortcut_path = enumerator.Next()) { | |
1253 base::FilePath target_path; | |
grt (UTC plus 2)
2013/04/30 19:59:53
nit: move this out of the loop so it isn't created
huangs
2013/04/30 20:52:10
Done.
| |
1254 if (base::win::ResolveShortcut(shortcut_path, &target_path, NULL)) { | |
1255 if (target_compare.EvaluatePath(target_path) && | |
1256 !shortcut_operation.Run(shortcut_path)) { | |
1257 success = false; | |
1258 } | |
1259 } else { | |
1260 LOG(ERROR) << "Cannot resolve shortcut at " << shortcut_path.value(); | |
1261 success = false; | |
1262 } | |
1263 } | |
1264 return success; | |
1265 } | |
1266 | |
1267 // Removes folder spsecified by {|location|, |dist|, |level|}. | |
1268 bool RemoveShortcutFolder(ShellUtil::ShortcutLocation location, | |
1269 BrowserDistribution* dist, | |
1270 ShellUtil::ShellChange level) { | |
1271 base::FilePath shortcut_folder; | |
1272 if (!ShellUtil::GetShortcutPath(location, dist, level, &shortcut_folder)) { | |
1273 LOG(WARNING) << "Cannot find path at location " << location; | |
gab
2013/04/30 19:20:33
See other other comment on "why did you remove the
grt (UTC plus 2)
2013/04/30 19:59:53
Looks like this isn't always the case -- on Win8 f
huangs
2013/04/30 20:52:10
The NOTREACHED() case is only for cases where fold
huangs
2013/04/30 20:52:10
Acknowledged.
gab
2013/04/30 22:30:22
Ok so lets keep LOG(WARNING), but also check !Path
| |
1274 return false; | |
1275 } | |
1276 if (!file_util::Delete(shortcut_folder, true)) { | |
1277 LOG(ERROR) << "Cannot remove folder " << shortcut_folder.value(); | |
1278 return false; | |
1279 } | |
1280 return true; | |
1281 } | |
1282 | |
1191 } // namespace | 1283 } // namespace |
1192 | 1284 |
1193 const wchar_t* ShellUtil::kRegDefaultIcon = L"\\DefaultIcon"; | 1285 const wchar_t* ShellUtil::kRegDefaultIcon = L"\\DefaultIcon"; |
1194 const wchar_t* ShellUtil::kRegShellPath = L"\\shell"; | 1286 const wchar_t* ShellUtil::kRegShellPath = L"\\shell"; |
1195 const wchar_t* ShellUtil::kRegShellOpen = L"\\shell\\open\\command"; | 1287 const wchar_t* ShellUtil::kRegShellOpen = L"\\shell\\open\\command"; |
1196 const wchar_t* ShellUtil::kRegStartMenuInternet = | 1288 const wchar_t* ShellUtil::kRegStartMenuInternet = |
1197 L"Software\\Clients\\StartMenuInternet"; | 1289 L"Software\\Clients\\StartMenuInternet"; |
1198 const wchar_t* ShellUtil::kRegClasses = L"Software\\Classes"; | 1290 const wchar_t* ShellUtil::kRegClasses = L"Software\\Classes"; |
1199 const wchar_t* ShellUtil::kRegRegisteredApplications = | 1291 const wchar_t* ShellUtil::kRegRegisteredApplications = |
1200 L"Software\\RegisteredApplications"; | 1292 L"Software\\RegisteredApplications"; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1247 const string16& chrome_exe, | 1339 const string16& chrome_exe, |
1248 const string16& suffix) { | 1340 const string16& suffix) { |
1249 return QuickIsChromeRegistered(dist, chrome_exe, suffix, | 1341 return QuickIsChromeRegistered(dist, chrome_exe, suffix, |
1250 CONFIRM_SHELL_REGISTRATION_IN_HKLM); | 1342 CONFIRM_SHELL_REGISTRATION_IN_HKLM); |
1251 } | 1343 } |
1252 | 1344 |
1253 bool ShellUtil::GetShortcutPath(ShellUtil::ShortcutLocation location, | 1345 bool ShellUtil::GetShortcutPath(ShellUtil::ShortcutLocation location, |
1254 BrowserDistribution* dist, | 1346 BrowserDistribution* dist, |
1255 ShellChange level, | 1347 ShellChange level, |
1256 base::FilePath* path) { | 1348 base::FilePath* path) { |
1349 DCHECK(path); | |
1257 int dir_key = -1; | 1350 int dir_key = -1; |
1258 bool add_folder_for_dist = false; | 1351 bool add_folder_for_dist = false; |
1259 switch (location) { | 1352 switch (location) { |
1260 case SHORTCUT_LOCATION_DESKTOP: | 1353 case SHORTCUT_LOCATION_DESKTOP: |
1261 dir_key = (level == CURRENT_USER) ? base::DIR_USER_DESKTOP : | 1354 dir_key = (level == CURRENT_USER) ? base::DIR_USER_DESKTOP : |
1262 base::DIR_COMMON_DESKTOP; | 1355 base::DIR_COMMON_DESKTOP; |
1263 break; | 1356 break; |
1264 case SHORTCUT_LOCATION_QUICK_LAUNCH: | 1357 case SHORTCUT_LOCATION_QUICK_LAUNCH: |
1265 dir_key = (level == CURRENT_USER) ? base::DIR_USER_QUICK_LAUNCH : | 1358 dir_key = (level == CURRENT_USER) ? base::DIR_USER_QUICK_LAUNCH : |
1266 base::DIR_DEFAULT_USER_QUICK_LAUNCH; | 1359 base::DIR_DEFAULT_USER_QUICK_LAUNCH; |
1267 break; | 1360 break; |
1268 case SHORTCUT_LOCATION_START_MENU: | 1361 case SHORTCUT_LOCATION_START_MENU: |
1269 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : | 1362 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : |
1270 base::DIR_COMMON_START_MENU; | 1363 base::DIR_COMMON_START_MENU; |
1271 add_folder_for_dist = true; | 1364 add_folder_for_dist = true; |
1272 break; | 1365 break; |
1366 case SHORTCUT_LOCATION_TASKBAR_PINS: | |
1367 if (base::win::GetVersion() < base::win::VERSION_WIN7) | |
gab
2013/04/30 19:20:33
I don't believe this should take care of this logi
huangs
2013/04/30 20:52:10
Modified in base_paths_win.cc.
There are many unn
gab
2013/04/30 22:30:22
I didn't meant to change it in this CL, I think it
grt (UTC plus 2)
2013/05/01 13:35:58
Could you explain?
huangs
2013/05/01 15:56:29
I was commenting on
https://chromiumcodereview.ap
| |
1368 return false; | |
1369 | |
1370 dir_key = base::DIR_TASKBAR_PINS; | |
1371 break; | |
1372 case SHORTCUT_LOCATION_APP_SHORTCUTS: | |
1373 return GetAppShortcutsFolder(dist, level, path); | |
1374 | |
1273 default: | 1375 default: |
1274 NOTREACHED(); | 1376 NOTREACHED(); |
1275 return false; | 1377 return false; |
1276 } | 1378 } |
1277 | 1379 |
1278 if (!PathService::Get(dir_key, path) || path->empty()) { | 1380 if (!PathService::Get(dir_key, path) || path->empty()) { |
1279 NOTREACHED() << dir_key; | 1381 NOTREACHED() << dir_key; |
1280 return false; | 1382 return false; |
1281 } | 1383 } |
1282 | 1384 |
1283 if (add_folder_for_dist) | 1385 if (add_folder_for_dist) |
1284 *path = path->Append(dist->GetAppShortCutName()); | 1386 *path = path->Append(dist->GetAppShortCutName()); |
1285 | 1387 |
1286 return true; | 1388 return true; |
1287 } | 1389 } |
1288 | 1390 |
1289 bool ShellUtil::CreateOrUpdateShortcut( | 1391 bool ShellUtil::CreateOrUpdateShortcut( |
1290 ShellUtil::ShortcutLocation location, | 1392 ShellUtil::ShortcutLocation location, |
1291 BrowserDistribution* dist, | 1393 BrowserDistribution* dist, |
1292 const ShellUtil::ShortcutProperties& properties, | 1394 const ShellUtil::ShortcutProperties& properties, |
1293 ShellUtil::ShortcutOperation operation) { | 1395 ShellUtil::ShortcutOperation operation) { |
1294 DCHECK(dist); | 1396 DCHECK(dist); |
1295 // |pin_to_taskbar| is only acknowledged when first creating the shortcut. | 1397 // |pin_to_taskbar| is only acknowledged when first creating the shortcut. |
1296 DCHECK(!properties.pin_to_taskbar || | 1398 DCHECK(!properties.pin_to_taskbar || |
1297 operation == SHELL_SHORTCUT_CREATE_ALWAYS || | 1399 operation == SHELL_SHORTCUT_CREATE_ALWAYS || |
1298 operation == SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL); | 1400 operation == SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL); |
1299 | 1401 |
1300 base::FilePath user_shortcut_path; | 1402 base::FilePath user_shortcut_path; |
1301 base::FilePath system_shortcut_path; | 1403 base::FilePath system_shortcut_path; |
1302 if (!GetShortcutPath(location, dist, SYSTEM_LEVEL, &system_shortcut_path) || | 1404 if (!GetShortcutPath(location, dist, SYSTEM_LEVEL, &system_shortcut_path)) { |
1303 system_shortcut_path.empty()) { | |
1304 NOTREACHED(); | 1405 NOTREACHED(); |
1305 return false; | 1406 return false; |
1306 } | 1407 } |
1307 | 1408 |
1308 string16 shortcut_name(ExtractShortcutNameFromProperties(dist, properties)); | 1409 string16 shortcut_name(ExtractShortcutNameFromProperties(dist, properties)); |
1309 system_shortcut_path = system_shortcut_path.Append(shortcut_name); | 1410 system_shortcut_path = system_shortcut_path.Append(shortcut_name); |
1310 | 1411 |
1311 base::FilePath* chosen_path; | 1412 base::FilePath* chosen_path; |
1312 bool should_install_shortcut = true; | 1413 bool should_install_shortcut = true; |
1313 if (properties.level == SYSTEM_LEVEL) { | 1414 if (properties.level == SYSTEM_LEVEL) { |
1314 // Install the system-level shortcut if requested. | 1415 // Install the system-level shortcut if requested. |
1315 chosen_path = &system_shortcut_path; | 1416 chosen_path = &system_shortcut_path; |
1316 } else if (operation != SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL || | 1417 } else if (operation != SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL || |
1317 !file_util::PathExists(system_shortcut_path)) { | 1418 !file_util::PathExists(system_shortcut_path)) { |
1318 // Otherwise install the user-level shortcut, unless the system-level | 1419 // Otherwise install the user-level shortcut, unless the system-level |
1319 // variant of this shortcut is present on the machine and |operation| states | 1420 // variant of this shortcut is present on the machine and |operation| states |
1320 // not to create a user-level shortcut in that case. | 1421 // not to create a user-level shortcut in that case. |
1321 if (!GetShortcutPath(location, dist, CURRENT_USER, &user_shortcut_path) || | 1422 if (!GetShortcutPath(location, dist, CURRENT_USER, &user_shortcut_path)) { |
1322 user_shortcut_path.empty()) { | |
1323 NOTREACHED(); | 1423 NOTREACHED(); |
1324 return false; | 1424 return false; |
1325 } | 1425 } |
1326 user_shortcut_path = user_shortcut_path.Append(shortcut_name); | 1426 user_shortcut_path = user_shortcut_path.Append(shortcut_name); |
1327 chosen_path = &user_shortcut_path; | 1427 chosen_path = &user_shortcut_path; |
1328 } else { | 1428 } else { |
1329 // Do not install any shortcut if we are told to install a user-level | 1429 // Do not install any shortcut if we are told to install a user-level |
1330 // shortcut, but the system-level variant of that shortcut is present. | 1430 // shortcut, but the system-level variant of that shortcut is present. |
1331 // Other actions (e.g., pinning) can still happen with respect to the | 1431 // Other actions (e.g., pinning) can still happen with respect to the |
1332 // existing system-level shortcut however. | 1432 // existing system-level shortcut however. |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1851 } else if (elevate_if_not_admin && | 1951 } else if (elevate_if_not_admin && |
1852 base::win::GetVersion() >= base::win::VERSION_VISTA) { | 1952 base::win::GetVersion() >= base::win::VERSION_VISTA) { |
1853 // Elevate to do the whole job | 1953 // Elevate to do the whole job |
1854 return ElevateAndRegisterChrome(dist, chrome_exe, suffix, protocol); | 1954 return ElevateAndRegisterChrome(dist, chrome_exe, suffix, protocol); |
1855 } else { | 1955 } else { |
1856 // Admin rights are required to register capabilities before Windows 8. | 1956 // Admin rights are required to register capabilities before Windows 8. |
1857 return false; | 1957 return false; |
1858 } | 1958 } |
1859 } | 1959 } |
1860 | 1960 |
1861 bool ShellUtil::RemoveShortcut(ShellUtil::ShortcutLocation location, | 1961 // static |
1862 BrowserDistribution* dist, | 1962 bool ShellUtil::RemoveShortcuts(ShellUtil::ShortcutLocation location, |
1863 const base::FilePath& target_exe, | 1963 BrowserDistribution* dist, |
1864 ShellChange level, | 1964 ShellChange level, |
1865 const string16* shortcut_name) { | 1965 const base::FilePath& target_exe) { |
1866 const bool delete_folder = (location == SHORTCUT_LOCATION_START_MENU); | 1966 const FileOperationCallback file_op = |
1867 | 1967 (location == SHORTCUT_LOCATION_TASKBAR_PINS) ? |
1868 base::FilePath shortcut_folder; | 1968 base::Bind(&ShortcutOpUnpin) : base::Bind(&ShortcutOpUnpinAndDelete); |
gab
2013/04/30 19:20:33
indent this line 4 more spaces in.
huangs
2013/04/30 20:52:10
Done.
| |
1869 if (!GetShortcutPath(location, dist, level, &shortcut_folder) || | 1969 bool success = true; |
grt (UTC plus 2)
2013/04/30 19:59:53
bool success = BatchShortcutAction(...);
huangs
2013/04/30 20:52:10
Now returning directly, so got rid of variable |su
| |
1870 shortcut_folder.empty()) { | 1970 if (!BatchShortcutAction(file_op, location, dist, level, target_exe)) |
1871 NOTREACHED(); | 1971 success = false; |
1872 return false; | 1972 if (location == SHORTCUT_LOCATION_START_MENU && |
gab
2013/04/30 19:20:33
Put this first and only do the BatchShortcutAction
huangs
2013/04/30 20:52:10
Done; doing 3 distinct things for 3 separate cases
| |
1973 !RemoveShortcutFolder(location, dist, level)) { | |
1974 success = false; | |
1873 } | 1975 } |
1874 | 1976 return success; |
1875 if (!delete_folder && !shortcut_name) { | |
1876 file_util::FileEnumerator enumerator(shortcut_folder, false, | |
1877 file_util::FileEnumerator::FILES); | |
1878 bool had_failures = false; | |
1879 for (base::FilePath path = enumerator.Next(); !path.empty(); | |
1880 path = enumerator.Next()) { | |
1881 if (path.Extension() != installer::kLnkExt) | |
1882 continue; | |
1883 | |
1884 if (!MaybeRemoveShortcutAtPath(path, target_exe, delete_folder)) | |
1885 had_failures = true; | |
1886 } | |
1887 return !had_failures; | |
1888 } | |
1889 | |
1890 const string16 shortcut_base_name( | |
1891 (shortcut_name ? *shortcut_name : dist->GetAppShortCutName()) + | |
1892 installer::kLnkExt); | |
1893 const base::FilePath shortcut_path( | |
1894 shortcut_folder.Append(shortcut_base_name)); | |
1895 if (!file_util::PathExists(shortcut_path)) | |
1896 return true; | |
1897 | |
1898 return MaybeRemoveShortcutAtPath(shortcut_path, target_exe, delete_folder); | |
1899 } | 1977 } |
1900 | 1978 |
1901 void ShellUtil::RemoveTaskbarShortcuts(const string16& target_exe) { | 1979 // static |
1902 if (base::win::GetVersion() < base::win::VERSION_WIN7) | 1980 void ShellUtil::RemoveStartScreenShortcuts(BrowserDistribution* dist, |
gab
2013/04/30 19:20:33
Once again, I think this can be merged in RemoveSh
huangs
2013/04/30 20:52:10
Done. Key Changes:
- Updated the single caller fro
| |
1981 const base::FilePath& target_exe) { | |
1982 if (base::win::GetVersion() < base::win::VERSION_WIN8) | |
1903 return; | 1983 return; |
1904 | 1984 |
1905 base::FilePath taskbar_pins_path; | 1985 ShellChange level = |
1906 if (!PathService::Get(base::DIR_TASKBAR_PINS, &taskbar_pins_path) || | 1986 InstallUtil::IsPerUserInstall(target_exe.value().c_str()) ? |
1907 !file_util::PathExists(taskbar_pins_path)) { | 1987 ShellUtil::CURRENT_USER : ShellUtil::SYSTEM_LEVEL; |
1908 LOG(ERROR) << "Couldn't find path to taskbar pins."; | 1988 VLOG(1) << "Removing start screen shortcuts."; |
1989 if (!RemoveShortcutFolder(SHORTCUT_LOCATION_APP_SHORTCUTS, dist, level)) | |
1990 LOG(ERROR) << "Failed to remove start screen shortcuts."; | |
1991 } | |
1992 | |
1993 // static | |
1994 bool ShellUtil::RetargetShortcuts(ShellUtil::ShortcutLocation location, | |
1995 BrowserDistribution* dist, | |
1996 ShellChange level, | |
1997 const base::FilePath& old_target_exe, | |
1998 const base::FilePath& new_target_exe) { | |
1999 return BatchShortcutAction(base::Bind(&ShortcutOpSetTarget, new_target_exe), | |
2000 location, dist, level, old_target_exe); | |
2001 } | |
2002 | |
2003 // static | |
2004 void ShellUtil::RetargetStartScreenShortcuts( | |
gab
2013/04/30 19:20:33
This can also easily be folded in RetargetShortcut
huangs
2013/04/30 20:52:10
Done.
| |
2005 BrowserDistribution* dist, | |
2006 const base::FilePath& old_target_exe, | |
2007 const base::FilePath& new_target_exe) { | |
2008 if (base::win::GetVersion() < base::win::VERSION_WIN8) | |
1909 return; | 2009 return; |
1910 } | |
1911 | 2010 |
1912 file_util::FileEnumerator shortcuts_enum( | 2011 ShortcutLocation location = SHORTCUT_LOCATION_APP_SHORTCUTS; |
1913 taskbar_pins_path, false, | 2012 ShellChange level = |
1914 file_util::FileEnumerator::FILES, FILE_PATH_LITERAL("*.lnk")); | 2013 InstallUtil::IsPerUserInstall(old_target_exe.value().c_str()) ? |
1915 | 2014 ShellUtil::CURRENT_USER : ShellUtil::SYSTEM_LEVEL; |
1916 base::FilePath target_path(target_exe); | 2015 VLOG(1) << "Retargeting start screen shortcuts."; |
1917 InstallUtil::ProgramCompare target_compare(target_path); | 2016 if (!BatchShortcutAction(base::Bind(&ShortcutOpSetTarget, new_target_exe), |
1918 for (base::FilePath shortcut_path = shortcuts_enum.Next(); | 2017 location, dist, level, old_target_exe)) { |
1919 !shortcut_path.empty(); | 2018 LOG(ERROR) << "Failed to retarget start screen shortcuts."; |
1920 shortcut_path = shortcuts_enum.Next()) { | |
1921 base::FilePath read_target; | |
1922 if (!base::win::ResolveShortcut(shortcut_path, &read_target, NULL)) { | |
1923 LOG(ERROR) << "Couldn't resolve shortcut at " << shortcut_path.value(); | |
1924 continue; | |
1925 } | |
1926 if (target_compare.EvaluatePath(read_target)) { | |
1927 // Unpin this shortcut if it points to |target_exe|. | |
1928 base::win::TaskbarUnpinShortcutLink(shortcut_path.value().c_str()); | |
1929 } | |
1930 } | 2019 } |
1931 } | 2020 } |
1932 | 2021 |
1933 void ShellUtil::RemoveStartScreenShortcuts(BrowserDistribution* dist, | |
1934 const string16& target_exe) { | |
1935 if (base::win::GetVersion() < base::win::VERSION_WIN8) | |
1936 return; | |
1937 | |
1938 base::FilePath app_shortcuts_path; | |
1939 if (!PathService::Get(base::DIR_APP_SHORTCUTS, &app_shortcuts_path)) { | |
1940 LOG(ERROR) << "Could not get application shortcuts location to delete" | |
1941 << " start screen shortcuts."; | |
1942 return; | |
1943 } | |
1944 | |
1945 app_shortcuts_path = app_shortcuts_path.Append( | |
1946 GetBrowserModelId(dist, | |
1947 InstallUtil::IsPerUserInstall(target_exe.c_str()))); | |
1948 if (!file_util::DirectoryExists(app_shortcuts_path)) { | |
1949 VLOG(1) << "No start screen shortcuts to delete."; | |
1950 return; | |
1951 } | |
1952 | |
1953 VLOG(1) << "Removing start screen shortcuts from " | |
1954 << app_shortcuts_path.value(); | |
1955 if (!file_util::Delete(app_shortcuts_path, true)) { | |
1956 LOG(ERROR) << "Failed to remove start screen shortcuts from " | |
1957 << app_shortcuts_path.value(); | |
1958 } | |
1959 } | |
1960 | |
1961 bool ShellUtil::GetUserSpecificRegistrySuffix(string16* suffix) { | 2022 bool ShellUtil::GetUserSpecificRegistrySuffix(string16* suffix) { |
1962 // Use a thread-safe cache for the user's suffix. | 2023 // Use a thread-safe cache for the user's suffix. |
1963 static base::LazyInstance<UserSpecificRegistrySuffix>::Leaky suffix_instance = | 2024 static base::LazyInstance<UserSpecificRegistrySuffix>::Leaky suffix_instance = |
1964 LAZY_INSTANCE_INITIALIZER; | 2025 LAZY_INSTANCE_INITIALIZER; |
1965 return suffix_instance.Get().GetSuffix(suffix); | 2026 return suffix_instance.Get().GetSuffix(suffix); |
1966 } | 2027 } |
1967 | 2028 |
1968 bool ShellUtil::GetOldUserSpecificRegistrySuffix(string16* suffix) { | 2029 bool ShellUtil::GetOldUserSpecificRegistrySuffix(string16* suffix) { |
1969 wchar_t user_name[256]; | 2030 wchar_t user_name[256]; |
1970 DWORD size = arraysize(user_name); | 2031 DWORD size = arraysize(user_name); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2018 // are any left...). | 2079 // are any left...). |
2019 if (free_bits >= 8 && next_byte_index < size) { | 2080 if (free_bits >= 8 && next_byte_index < size) { |
2020 free_bits -= 8; | 2081 free_bits -= 8; |
2021 bit_stream += bytes[next_byte_index++] << free_bits; | 2082 bit_stream += bytes[next_byte_index++] << free_bits; |
2022 } | 2083 } |
2023 } | 2084 } |
2024 | 2085 |
2025 DCHECK_EQ(ret.length(), encoded_length); | 2086 DCHECK_EQ(ret.length(), encoded_length); |
2026 return ret; | 2087 return ret; |
2027 } | 2088 } |
OLD | NEW |