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" |
(...skipping 1234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1245 success = false; | 1245 success = false; |
1246 } | 1246 } |
1247 } else { | 1247 } else { |
1248 LOG(ERROR) << "Cannot resolve shortcut at " << shortcut_path.value(); | 1248 LOG(ERROR) << "Cannot resolve shortcut at " << shortcut_path.value(); |
1249 success = false; | 1249 success = false; |
1250 } | 1250 } |
1251 } | 1251 } |
1252 return success; | 1252 return success; |
1253 } | 1253 } |
1254 | 1254 |
1255 // Removes folder spsecified by {|location|, |dist|, |level|}. | 1255 // If the folder specified by {|location|, |dist|, |level|} is empty, remove it. |
1256 bool RemoveShortcutFolder(ShellUtil::ShortcutLocation location, | 1256 // Otherwise do nothing. Returns true on success, including the vacuous case |
1257 BrowserDistribution* dist, | 1257 // where no deletion occurred because directory is non-empty. |
gab
2013/08/12 20:09:36
nit: s/because directory/because the directory
huangs
2013/08/12 20:27:16
Done.
| |
1258 ShellUtil::ShellChange level) { | 1258 bool RemoveShortcutFolderIfEmpty(ShellUtil::ShortcutLocation location, |
1259 BrowserDistribution* dist, | |
1260 ShellUtil::ShellChange level) { | |
1259 | 1261 |
1260 // Explicitly whitelist locations, since accidental calls can be very harmful. | 1262 // Explicitly whitelist locations, since accidental calls can be very harmful. |
1261 if (location != ShellUtil::SHORTCUT_LOCATION_START_MENU && | 1263 if (location != ShellUtil::SHORTCUT_LOCATION_START_MENU && |
1262 location != ShellUtil::SHORTCUT_LOCATION_APP_SHORTCUTS) { | 1264 location != ShellUtil::SHORTCUT_LOCATION_APP_SHORTCUTS) { |
1263 NOTREACHED(); | 1265 NOTREACHED(); |
1264 return false; | 1266 return false; |
1265 } | 1267 } |
1266 | 1268 |
1267 base::FilePath shortcut_folder; | 1269 base::FilePath shortcut_folder; |
1268 if (!ShellUtil::GetShortcutPath(location, dist, level, &shortcut_folder)) { | 1270 if (!ShellUtil::GetShortcutPath(location, dist, level, &shortcut_folder)) { |
1269 LOG(WARNING) << "Cannot find path at location " << location; | 1271 LOG(WARNING) << "Cannot find path at location " << location; |
1270 return false; | 1272 return false; |
1271 } | 1273 } |
1272 if (!base::DeleteFile(shortcut_folder, true)) { | 1274 if (file_util::IsDirectoryEmpty(shortcut_folder) && |
1275 !base::DeleteFile(shortcut_folder, true)) { | |
1273 LOG(ERROR) << "Cannot remove folder " << shortcut_folder.value(); | 1276 LOG(ERROR) << "Cannot remove folder " << shortcut_folder.value(); |
1274 return false; | 1277 return false; |
1275 } | 1278 } |
1276 return true; | 1279 return true; |
1277 } | 1280 } |
1278 | 1281 |
1279 } // namespace | 1282 } // namespace |
1280 | 1283 |
1281 const wchar_t* ShellUtil::kRegDefaultIcon = L"\\DefaultIcon"; | 1284 const wchar_t* ShellUtil::kRegDefaultIcon = L"\\DefaultIcon"; |
1282 const wchar_t* ShellUtil::kRegShellPath = L"\\shell"; | 1285 const wchar_t* ShellUtil::kRegShellPath = L"\\shell"; |
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1985 // static | 1988 // static |
1986 bool ShellUtil::RemoveShortcuts(ShellUtil::ShortcutLocation location, | 1989 bool ShellUtil::RemoveShortcuts(ShellUtil::ShortcutLocation location, |
1987 BrowserDistribution* dist, | 1990 BrowserDistribution* dist, |
1988 ShellChange level, | 1991 ShellChange level, |
1989 const base::FilePath& target_exe) { | 1992 const base::FilePath& target_exe) { |
1990 if (!ShellUtil::ShortcutLocationIsSupported(location)) | 1993 if (!ShellUtil::ShortcutLocationIsSupported(location)) |
1991 return true; // Vacuous success. | 1994 return true; // Vacuous success. |
1992 | 1995 |
1993 switch (location) { | 1996 switch (location) { |
1994 case SHORTCUT_LOCATION_START_MENU: // Falls through. | 1997 case SHORTCUT_LOCATION_START_MENU: // Falls through. |
1995 case SHORTCUT_LOCATION_APP_SHORTCUTS: | 1998 case SHORTCUT_LOCATION_APP_SHORTCUTS: { |
1996 return RemoveShortcutFolder(location, dist, level); | 1999 bool delete_success = |
2000 BatchShortcutAction(base::Bind(&ShortcutOpDelete), location, | |
2001 dist, level, target_exe); | |
2002 bool rmdir_success = RemoveShortcutFolderIfEmpty(location, dist, level); | |
2003 return delete_success && rmdir_success; | |
2004 } | |
1997 | 2005 |
1998 case SHORTCUT_LOCATION_TASKBAR_PINS: | 2006 case SHORTCUT_LOCATION_TASKBAR_PINS: |
1999 return BatchShortcutAction(base::Bind(&ShortcutOpUnpin), location, dist, | 2007 return BatchShortcutAction(base::Bind(&ShortcutOpUnpin), location, dist, |
2000 level, target_exe); | 2008 level, target_exe); |
2001 | 2009 |
2002 default: | 2010 default: |
2003 return BatchShortcutAction(base::Bind(&ShortcutOpDelete), location, dist, | 2011 return BatchShortcutAction(base::Bind(&ShortcutOpDelete), location, dist, |
2004 level, target_exe); | 2012 level, target_exe); |
2005 } | 2013 } |
2006 } | 2014 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2081 // are any left...). | 2089 // are any left...). |
2082 if (free_bits >= 8 && next_byte_index < size) { | 2090 if (free_bits >= 8 && next_byte_index < size) { |
2083 free_bits -= 8; | 2091 free_bits -= 8; |
2084 bit_stream += bytes[next_byte_index++] << free_bits; | 2092 bit_stream += bytes[next_byte_index++] << free_bits; |
2085 } | 2093 } |
2086 } | 2094 } |
2087 | 2095 |
2088 DCHECK_EQ(ret.length(), encoded_length); | 2096 DCHECK_EQ(ret.length(), encoded_length); |
2089 return ret; | 2097 return ret; |
2090 } | 2098 } |
OLD | NEW |