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

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

Issue 14031025: Implementing unified Chrome / App Launcher flow, and migrating old stand-alone App Launcher. (Closed) Base URL: http://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removing Start Menu root stuff; cleanups. Created 7 years, 7 months 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
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 1189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 1200
1201 bool ShortcutOpDelete(const base::FilePath& shortcut_path) { 1201 bool ShortcutOpDelete(const base::FilePath& shortcut_path) {
1202 bool ret = file_util::Delete(shortcut_path, false); 1202 bool ret = file_util::Delete(shortcut_path, false);
1203 LOG_IF(ERROR, !ret) << "Failed to remove " << shortcut_path.value(); 1203 LOG_IF(ERROR, !ret) << "Failed to remove " << shortcut_path.value();
1204 return ret; 1204 return ret;
1205 } 1205 }
1206 1206
1207 bool ShortcutOpUpdate(const base::win::ShortcutProperties& shortcut_properties, 1207 bool ShortcutOpUpdate(const base::win::ShortcutProperties& shortcut_properties,
1208 const base::FilePath& shortcut_path) { 1208 const base::FilePath& shortcut_path) {
1209 bool ret = base::win::CreateOrUpdateShortcutLink( 1209 bool ret = base::win::CreateOrUpdateShortcutLink(
1210 shortcut_path, shortcut_properties, base::win::SHORTCUT_REPLACE_EXISTING); 1210 shortcut_path, shortcut_properties, base::win::SHORTCUT_UPDATE_EXISTING);
1211 LOG_IF(ERROR, !ret) << "Failed to update " << shortcut_path.value(); 1211 LOG_IF(ERROR, !ret) << "Failed to update " << shortcut_path.value();
1212 return ret; 1212 return ret;
1213 } 1213 }
1214 1214
1215 // {|location|, |dist|, |level|} determine |shortcut_folder|. 1215 // {|location|, |dist|, |level|} determine |shortcut_folder|.
1216 // Applies |shortcut_operation| to each shortcut in |shortcut_folder| that 1216 // Applies |shortcut_operation| to shortcuts in |shortcut_folder| that
1217 // targets |target_exe|. 1217 // targets |target_exe|, and have filenames matching |filename_filter|.
1218 // Returns true if all operations are successful. All intended operations are 1218 // Returns true if all operations are successful. All intended operations are
1219 // attempted even if failures occur. 1219 // attempted even if failures occur.
1220 bool BatchShortcutAction(const FileOperationCallback& shortcut_operation, 1220 bool BatchShortcutActionFilteredByName(
1221 ShellUtil::ShortcutLocation location, 1221 const FileOperationCallback& shortcut_operation,
1222 BrowserDistribution* dist, 1222 ShellUtil::ShortcutLocation location,
1223 ShellUtil::ShellChange level, 1223 BrowserDistribution* dist,
1224 const base::FilePath& target_exe) { 1224 ShellUtil::ShellChange level,
1225 const base::FilePath& target_exe,
1226 const string16& filename_filter) {
1225 DCHECK(!shortcut_operation.is_null()); 1227 DCHECK(!shortcut_operation.is_null());
1226 base::FilePath shortcut_folder; 1228 base::FilePath shortcut_folder;
1227 if (!ShellUtil::GetShortcutPath(location, dist, level, &shortcut_folder)) { 1229 if (!ShellUtil::GetShortcutPath(location, dist, level, &shortcut_folder)) {
1228 LOG(WARNING) << "Cannot find path at location " << location; 1230 LOG(WARNING) << "Cannot find path at location " << location;
1229 return false; 1231 return false;
1230 } 1232 }
1231 1233
1232 bool success = true; 1234 bool success = true;
1233 InstallUtil::ProgramCompare target_compare(target_exe); 1235 InstallUtil::ProgramCompare target_compare(target_exe);
1234 file_util::FileEnumerator enumerator( 1236 file_util::FileEnumerator enumerator(
1235 shortcut_folder, false, file_util::FileEnumerator::FILES, 1237 shortcut_folder, false, file_util::FileEnumerator::FILES,
1236 string16(L"*") + installer::kLnkExt); 1238 filename_filter);
1237 base::FilePath target_path; 1239 base::FilePath original_target_exe;
1238 for (base::FilePath shortcut_path = enumerator.Next(); 1240 for (base::FilePath shortcut_file = enumerator.Next();
1239 !shortcut_path.empty(); 1241 !shortcut_file.empty();
1240 shortcut_path = enumerator.Next()) { 1242 shortcut_file = enumerator.Next()) {
1241 if (base::win::ResolveShortcut(shortcut_path, &target_path, NULL)) { 1243 if (base::win::ResolveShortcut(shortcut_file, &original_target_exe, NULL)) {
1242 if (target_compare.EvaluatePath(target_path) && 1244 if (target_compare.EvaluatePath(original_target_exe) &&
1243 !shortcut_operation.Run(shortcut_path)) { 1245 !shortcut_operation.Run(shortcut_file)) {
1244 success = false; 1246 success = false;
1245 } 1247 }
1246 } else { 1248 } else {
1247 LOG(ERROR) << "Cannot resolve shortcut at " << shortcut_path.value(); 1249 LOG(ERROR) << "Cannot resolve shortcut at " << shortcut_file.value();
1248 success = false; 1250 success = false;
1249 } 1251 }
1250 } 1252 }
1251 return success; 1253 return success;
1252 } 1254 }
1253 1255
1256 // Adaptor to FilteredBatchShortcutAction() to process all files.
1257 bool BatchShortcutAction(const FileOperationCallback& shortcut_operation,
1258 ShellUtil::ShortcutLocation location,
1259 BrowserDistribution* dist,
1260 ShellUtil::ShellChange level,
1261 const base::FilePath& target_exe) {
1262 return BatchShortcutActionFilteredByName(
1263 shortcut_operation, location, dist, level, target_exe,
1264 string16(L"*") + installer::kLnkExt);
1265 }
1266
1254 // Removes folder spsecified by {|location|, |dist|, |level|}. 1267 // Removes folder spsecified by {|location|, |dist|, |level|}.
1255 bool RemoveShortcutFolder(ShellUtil::ShortcutLocation location, 1268 bool RemoveShortcutFolder(ShellUtil::ShortcutLocation location,
1256 BrowserDistribution* dist, 1269 BrowserDistribution* dist,
1257 ShellUtil::ShellChange level) { 1270 ShellUtil::ShellChange level) {
1258 1271
1259 // Explicitly whitelist locations, since accidental calls can be very harmful. 1272 // Explicitly whitelist locations, since accidental calls can be very harmful.
1260 if (location != ShellUtil::SHORTCUT_LOCATION_START_MENU && 1273 if (location != ShellUtil::SHORTCUT_LOCATION_START_MENU &&
1261 location != ShellUtil::SHORTCUT_LOCATION_APP_SHORTCUTS) { 1274 location != ShellUtil::SHORTCUT_LOCATION_APP_SHORTCUTS) {
1262 NOTREACHED(); 1275 NOTREACHED();
1263 return false; 1276 return false;
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1390 NOTREACHED(); 1403 NOTREACHED();
1391 return false; 1404 return false;
1392 } 1405 }
1393 1406
1394 if (!PathService::Get(dir_key, path) || path->empty()) { 1407 if (!PathService::Get(dir_key, path) || path->empty()) {
1395 NOTREACHED() << dir_key; 1408 NOTREACHED() << dir_key;
1396 return false; 1409 return false;
1397 } 1410 }
1398 1411
1399 if (add_folder_for_dist) 1412 if (add_folder_for_dist)
1400 *path = path->Append(dist->GetAppShortCutName()); 1413 *path = path->Append(dist->GetAppShortCutFolderName());
1401 1414
1402 return true; 1415 return true;
1403 } 1416 }
1404 1417
1405 bool ShellUtil::CreateOrUpdateShortcut( 1418 bool ShellUtil::CreateOrUpdateShortcut(
1406 ShellUtil::ShortcutLocation location, 1419 ShellUtil::ShortcutLocation location,
1407 BrowserDistribution* dist, 1420 BrowserDistribution* dist,
1408 const ShellUtil::ShortcutProperties& properties, 1421 const ShellUtil::ShortcutProperties& properties,
1409 ShellUtil::ShortcutOperation operation) { 1422 ShellUtil::ShortcutOperation operation) {
1410 // Explicitly whitelist locations to which this is applicable. 1423 // Explicitly whitelist locations to which this is applicable.
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
2013 const ShellUtil::ShortcutProperties& properties) { 2026 const ShellUtil::ShortcutProperties& properties) {
2014 if (!ShellUtil::ShortcutLocationIsSupported(location)) 2027 if (!ShellUtil::ShortcutLocationIsSupported(location))
2015 return true; // Vacuous success. 2028 return true; // Vacuous success.
2016 2029
2017 base::win::ShortcutProperties shortcut_properties( 2030 base::win::ShortcutProperties shortcut_properties(
2018 TranslateShortcutProperties(properties)); 2031 TranslateShortcutProperties(properties));
2019 return BatchShortcutAction(base::Bind(&ShortcutOpUpdate, shortcut_properties), 2032 return BatchShortcutAction(base::Bind(&ShortcutOpUpdate, shortcut_properties),
2020 location, dist, level, target_exe); 2033 location, dist, level, target_exe);
2021 } 2034 }
2022 2035
2036 // static
2037 bool ShellUtil::UpdateShortcutsFilteredByName(
2038 ShellUtil::ShortcutLocation location,
2039 BrowserDistribution* dist,
2040 ShellChange level,
2041 const string16& name_filter,
2042 const base::FilePath& target_exe,
2043 const ShellUtil::ShortcutProperties& properties) {
2044 DCHECK(EndsWith(name_filter, installer::kLnkExt, false));
2045
2046 if (!ShellUtil::ShortcutLocationIsSupported(location))
2047 return true; // Vacuous success.
2048
2049 base::win::ShortcutProperties shortcut_properties(
2050 TranslateShortcutProperties(properties));
2051 return BatchShortcutActionFilteredByName(
2052 base::Bind(&ShortcutOpUpdate, shortcut_properties),
2053 location, dist, level, target_exe, name_filter);
2054 }
2055
2023 bool ShellUtil::GetUserSpecificRegistrySuffix(string16* suffix) { 2056 bool ShellUtil::GetUserSpecificRegistrySuffix(string16* suffix) {
2024 // Use a thread-safe cache for the user's suffix. 2057 // Use a thread-safe cache for the user's suffix.
2025 static base::LazyInstance<UserSpecificRegistrySuffix>::Leaky suffix_instance = 2058 static base::LazyInstance<UserSpecificRegistrySuffix>::Leaky suffix_instance =
2026 LAZY_INSTANCE_INITIALIZER; 2059 LAZY_INSTANCE_INITIALIZER;
2027 return suffix_instance.Get().GetSuffix(suffix); 2060 return suffix_instance.Get().GetSuffix(suffix);
2028 } 2061 }
2029 2062
2030 bool ShellUtil::GetOldUserSpecificRegistrySuffix(string16* suffix) { 2063 bool ShellUtil::GetOldUserSpecificRegistrySuffix(string16* suffix) {
2031 wchar_t user_name[256]; 2064 wchar_t user_name[256];
2032 DWORD size = arraysize(user_name); 2065 DWORD size = arraysize(user_name);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2080 // are any left...). 2113 // are any left...).
2081 if (free_bits >= 8 && next_byte_index < size) { 2114 if (free_bits >= 8 && next_byte_index < size) {
2082 free_bits -= 8; 2115 free_bits -= 8;
2083 bit_stream += bytes[next_byte_index++] << free_bits; 2116 bit_stream += bytes[next_byte_index++] << free_bits;
2084 } 2117 }
2085 } 2118 }
2086 2119
2087 DCHECK_EQ(ret.length(), encoded_length); 2120 DCHECK_EQ(ret.length(), encoded_length);
2088 return ret; 2121 return ret;
2089 } 2122 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698