Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: chrome/installer/util/shell_util.cc

Issue 13864015: Move app launcher and chrome apps shortcut strings into the installer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@migrate_app_id_fix
Patch Set: fix win compile, change LOG(INFO)s to VLOG(1) Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/installer/util/shell_util.h ('k') | chrome/installer/util/shell_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 1299 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 } 1310 }
1311 1311
1312 1312
1313 // If the folder specified by {|location|, |dist|, |level|} is empty, remove it. 1313 // If the folder specified by {|location|, |dist|, |level|} is empty, remove it.
1314 // Otherwise do nothing. Returns true on success, including the vacuous case 1314 // Otherwise do nothing. Returns true on success, including the vacuous case
1315 // where no deletion occurred because directory is non-empty. 1315 // where no deletion occurred because directory is non-empty.
1316 bool RemoveShortcutFolderIfEmpty(ShellUtil::ShortcutLocation location, 1316 bool RemoveShortcutFolderIfEmpty(ShellUtil::ShortcutLocation location,
1317 BrowserDistribution* dist, 1317 BrowserDistribution* dist,
1318 ShellUtil::ShellChange level) { 1318 ShellUtil::ShellChange level) {
1319 // Explicitly whitelist locations, since accidental calls can be very harmful. 1319 // Explicitly whitelist locations, since accidental calls can be very harmful.
1320 if (location != ShellUtil::SHORTCUT_LOCATION_START_MENU && 1320 if (location != ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR &&
1321 location != ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR &&
1321 location != ShellUtil::SHORTCUT_LOCATION_APP_SHORTCUTS) { 1322 location != ShellUtil::SHORTCUT_LOCATION_APP_SHORTCUTS) {
1322 NOTREACHED(); 1323 NOTREACHED();
1323 return false; 1324 return false;
1324 } 1325 }
1325 1326
1326 base::FilePath shortcut_folder; 1327 base::FilePath shortcut_folder;
1327 if (!ShellUtil::GetShortcutPath(location, dist, level, &shortcut_folder)) { 1328 if (!ShellUtil::GetShortcutPath(location, dist, level, &shortcut_folder)) {
1328 LOG(WARNING) << "Cannot find path at location " << location; 1329 LOG(WARNING) << "Cannot find path at location " << location;
1329 return false; 1330 return false;
1330 } 1331 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1381 bool ShellUtil::QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist, 1382 bool ShellUtil::QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist,
1382 const string16& chrome_exe, 1383 const string16& chrome_exe,
1383 const string16& suffix) { 1384 const string16& suffix) {
1384 return QuickIsChromeRegistered(dist, chrome_exe, suffix, 1385 return QuickIsChromeRegistered(dist, chrome_exe, suffix,
1385 CONFIRM_SHELL_REGISTRATION_IN_HKLM); 1386 CONFIRM_SHELL_REGISTRATION_IN_HKLM);
1386 } 1387 }
1387 1388
1388 bool ShellUtil::ShortcutLocationIsSupported( 1389 bool ShellUtil::ShortcutLocationIsSupported(
1389 ShellUtil::ShortcutLocation location) { 1390 ShellUtil::ShortcutLocation location) {
1390 switch (location) { 1391 switch (location) {
1391 case SHORTCUT_LOCATION_DESKTOP: 1392 case SHORTCUT_LOCATION_DESKTOP: // Falls through.
1392 return true; 1393 case SHORTCUT_LOCATION_QUICK_LAUNCH: // Falls through.
1393 case SHORTCUT_LOCATION_QUICK_LAUNCH: 1394 case SHORTCUT_LOCATION_START_MENU_ROOT: // Falls through.
1394 return true; 1395 case SHORTCUT_LOCATION_START_MENU_CHROME_DIR: // Falls through.
1395 case SHORTCUT_LOCATION_START_MENU: 1396 case SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR:
1396 return true; 1397 return true;
1397 case SHORTCUT_LOCATION_TASKBAR_PINS: 1398 case SHORTCUT_LOCATION_TASKBAR_PINS:
1398 return base::win::GetVersion() >= base::win::VERSION_WIN7; 1399 return base::win::GetVersion() >= base::win::VERSION_WIN7;
1399 case SHORTCUT_LOCATION_APP_SHORTCUTS: 1400 case SHORTCUT_LOCATION_APP_SHORTCUTS:
1400 return base::win::GetVersion() >= base::win::VERSION_WIN8; 1401 return base::win::GetVersion() >= base::win::VERSION_WIN8;
1401 default: 1402 default:
1402 NOTREACHED(); 1403 NOTREACHED();
1403 return false; 1404 return false;
1404 } 1405 }
1405 } 1406 }
1406 1407
1407 bool ShellUtil::GetShortcutPath(ShellUtil::ShortcutLocation location, 1408 bool ShellUtil::GetShortcutPath(ShellUtil::ShortcutLocation location,
1408 BrowserDistribution* dist, 1409 BrowserDistribution* dist,
1409 ShellChange level, 1410 ShellChange level,
1410 base::FilePath* path) { 1411 base::FilePath* path) {
1411 DCHECK(path); 1412 DCHECK(path);
1412 int dir_key = -1; 1413 int dir_key = -1;
1413 bool add_folder_for_dist = false; 1414 base::string16 folder_to_append;
1414 switch (location) { 1415 switch (location) {
1415 case SHORTCUT_LOCATION_DESKTOP: 1416 case SHORTCUT_LOCATION_DESKTOP:
1416 dir_key = (level == CURRENT_USER) ? base::DIR_USER_DESKTOP : 1417 dir_key = (level == CURRENT_USER) ? base::DIR_USER_DESKTOP :
1417 base::DIR_COMMON_DESKTOP; 1418 base::DIR_COMMON_DESKTOP;
1418 break; 1419 break;
1419 case SHORTCUT_LOCATION_QUICK_LAUNCH: 1420 case SHORTCUT_LOCATION_QUICK_LAUNCH:
1420 dir_key = (level == CURRENT_USER) ? base::DIR_USER_QUICK_LAUNCH : 1421 dir_key = (level == CURRENT_USER) ? base::DIR_USER_QUICK_LAUNCH :
1421 base::DIR_DEFAULT_USER_QUICK_LAUNCH; 1422 base::DIR_DEFAULT_USER_QUICK_LAUNCH;
1422 break; 1423 break;
1423 case SHORTCUT_LOCATION_START_MENU: 1424 case SHORTCUT_LOCATION_START_MENU_ROOT:
1424 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : 1425 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU :
1425 base::DIR_COMMON_START_MENU; 1426 base::DIR_COMMON_START_MENU;
1426 add_folder_for_dist = true; 1427 break;
1428 case SHORTCUT_LOCATION_START_MENU_CHROME_DIR:
1429 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU :
1430 base::DIR_COMMON_START_MENU;
1431 folder_to_append = dist->GetStartMenuShortcutSubfolder(
1432 BrowserDistribution::SUBFOLDER_CHROME);
1433 break;
1434 case SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR:
1435 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU :
1436 base::DIR_COMMON_START_MENU;
1437 folder_to_append = dist->GetStartMenuShortcutSubfolder(
1438 BrowserDistribution::SUBFOLDER_APPS);
1427 break; 1439 break;
1428 case SHORTCUT_LOCATION_TASKBAR_PINS: 1440 case SHORTCUT_LOCATION_TASKBAR_PINS:
1429 dir_key = base::DIR_TASKBAR_PINS; 1441 dir_key = base::DIR_TASKBAR_PINS;
1430 break; 1442 break;
1431 case SHORTCUT_LOCATION_APP_SHORTCUTS: 1443 case SHORTCUT_LOCATION_APP_SHORTCUTS:
1432 // TODO(huangs): Move GetAppShortcutsFolder() logic into base_paths_win. 1444 // TODO(huangs): Move GetAppShortcutsFolder() logic into base_paths_win.
1433 return GetAppShortcutsFolder(dist, level, path); 1445 return GetAppShortcutsFolder(dist, level, path);
1434 1446
1435 default: 1447 default:
1436 NOTREACHED(); 1448 NOTREACHED();
1437 return false; 1449 return false;
1438 } 1450 }
1439 1451
1440 if (!PathService::Get(dir_key, path) || path->empty()) { 1452 if (!PathService::Get(dir_key, path) || path->empty()) {
1441 NOTREACHED() << dir_key; 1453 NOTREACHED() << dir_key;
1442 return false; 1454 return false;
1443 } 1455 }
1444 1456
1445 if (add_folder_for_dist) { 1457 if (!folder_to_append.empty())
1446 *path = path->Append(dist->GetStartMenuShortcutSubfolder( 1458 *path = path->Append(folder_to_append);
1447 BrowserDistribution::SUBFOLDER_CHROME));
1448 }
1449 1459
1450 return true; 1460 return true;
1451 } 1461 }
1452 1462
1453 bool ShellUtil::CreateOrUpdateShortcut( 1463 bool ShellUtil::CreateOrUpdateShortcut(
1454 ShellUtil::ShortcutLocation location, 1464 ShellUtil::ShortcutLocation location,
1455 BrowserDistribution* dist, 1465 BrowserDistribution* dist,
1456 const ShellUtil::ShortcutProperties& properties, 1466 const ShellUtil::ShortcutProperties& properties,
1457 ShellUtil::ShortcutOperation operation) { 1467 ShellUtil::ShortcutOperation operation) {
1458 // Explicitly whitelist locations to which this is applicable. 1468 // Explicitly whitelist locations to which this is applicable.
1459 if (location != SHORTCUT_LOCATION_DESKTOP && 1469 if (location != SHORTCUT_LOCATION_DESKTOP &&
1460 location != SHORTCUT_LOCATION_QUICK_LAUNCH && 1470 location != SHORTCUT_LOCATION_QUICK_LAUNCH &&
1461 location != SHORTCUT_LOCATION_START_MENU) { 1471 location != SHORTCUT_LOCATION_START_MENU_ROOT &&
1472 location != SHORTCUT_LOCATION_START_MENU_CHROME_DIR &&
1473 location != SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR) {
1462 NOTREACHED(); 1474 NOTREACHED();
1463 return false; 1475 return false;
1464 } 1476 }
1465 1477
1466 DCHECK(dist); 1478 DCHECK(dist);
1467 // |pin_to_taskbar| is only acknowledged when first creating the shortcut. 1479 // |pin_to_taskbar| is only acknowledged when first creating the shortcut.
1468 DCHECK(!properties.pin_to_taskbar || 1480 DCHECK(!properties.pin_to_taskbar ||
1469 operation == SHELL_SHORTCUT_CREATE_ALWAYS || 1481 operation == SHELL_SHORTCUT_CREATE_ALWAYS ||
1470 operation == SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL); 1482 operation == SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL);
1471 1483
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
2063 2075
2064 FilterTargetEq shortcut_filter(target_exe, false); 2076 FilterTargetEq shortcut_filter(target_exe, false);
2065 // Main operation to apply to each shortcut in the directory specified. 2077 // Main operation to apply to each shortcut in the directory specified.
2066 ShortcutOperationCallback shortcut_operation( 2078 ShortcutOperationCallback shortcut_operation(
2067 location == SHORTCUT_LOCATION_TASKBAR_PINS ? 2079 location == SHORTCUT_LOCATION_TASKBAR_PINS ?
2068 base::Bind(&ShortcutOpUnpin) : base::Bind(&ShortcutOpDelete)); 2080 base::Bind(&ShortcutOpUnpin) : base::Bind(&ShortcutOpDelete));
2069 bool success = BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(), 2081 bool success = BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(),
2070 shortcut_operation, location, dist, level); 2082 shortcut_operation, location, dist, level);
2071 // Remove chrome-specific shortcut folders if they are now empty. 2083 // Remove chrome-specific shortcut folders if they are now empty.
2072 if (success && 2084 if (success &&
2073 (location == SHORTCUT_LOCATION_START_MENU || 2085 (location == SHORTCUT_LOCATION_START_MENU_CHROME_DIR ||
2086 location == SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR ||
2074 location == SHORTCUT_LOCATION_APP_SHORTCUTS)) { 2087 location == SHORTCUT_LOCATION_APP_SHORTCUTS)) {
2075 success = RemoveShortcutFolderIfEmpty(location, dist, level); 2088 success = RemoveShortcutFolderIfEmpty(location, dist, level);
2076 } 2089 }
2077 return success; 2090 return success;
2078 } 2091 }
2079 2092
2080 // static 2093 // static
2081 bool ShellUtil::UpdateShortcutsWithArgs( 2094 bool ShellUtil::UpdateShortcutsWithArgs(
2082 ShellUtil::ShortcutLocation location, 2095 ShellUtil::ShortcutLocation location,
2083 BrowserDistribution* dist, 2096 BrowserDistribution* dist,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2154 // are any left...). 2167 // are any left...).
2155 if (free_bits >= 8 && next_byte_index < size) { 2168 if (free_bits >= 8 && next_byte_index < size) {
2156 free_bits -= 8; 2169 free_bits -= 8;
2157 bit_stream += bytes[next_byte_index++] << free_bits; 2170 bit_stream += bytes[next_byte_index++] << free_bits;
2158 } 2171 }
2159 } 2172 }
2160 2173
2161 DCHECK_EQ(ret.length(), encoded_length); 2174 DCHECK_EQ(ret.length(), encoded_length);
2162 return ret; 2175 return ret;
2163 } 2176 }
OLDNEW
« no previous file with comments | « chrome/installer/util/shell_util.h ('k') | chrome/installer/util/shell_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698