Chromium Code Reviews| 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 1253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1264 } | 1264 } |
| 1265 | 1265 |
| 1266 bool ShortcutOpUpdate(const base::win::ShortcutProperties& shortcut_properties, | 1266 bool ShortcutOpUpdate(const base::win::ShortcutProperties& shortcut_properties, |
| 1267 const base::FilePath& shortcut_path) { | 1267 const base::FilePath& shortcut_path) { |
| 1268 bool ret = base::win::CreateOrUpdateShortcutLink( | 1268 bool ret = base::win::CreateOrUpdateShortcutLink( |
| 1269 shortcut_path, shortcut_properties, base::win::SHORTCUT_UPDATE_EXISTING); | 1269 shortcut_path, shortcut_properties, base::win::SHORTCUT_UPDATE_EXISTING); |
| 1270 LOG_IF(ERROR, !ret) << "Failed to update " << shortcut_path.value(); | 1270 LOG_IF(ERROR, !ret) << "Failed to update " << shortcut_path.value(); |
| 1271 return ret; | 1271 return ret; |
| 1272 } | 1272 } |
| 1273 | 1273 |
| 1274 bool ShortcutOpRetarget(const base::FilePath& old_target_path, | |
| 1275 const base::FilePath& new_target_path, | |
| 1276 const base::FilePath& shortcut_path) { | |
| 1277 base::win::ShortcutProperties old_prop; | |
| 1278 if (base::win::ResolveShortcutProperties(shortcut_path, | |
|
gab
2013/12/23 14:25:01
Wrap |shortcut_path| as well.
gab
2013/12/23 14:25:01
Unless you strongly oppose, I don't think we shoul
huangs
2013/12/30 20:15:10
Done, but |old_prop| now gets wrapped, too, so now
huangs
2013/12/30 20:15:10
Makes sense. Restructured code a bit.
| |
| 1279 base::win::ShortcutProperties::PROPERTIES_ICON, &old_prop)) { | |
|
gab
2013/12/23 14:25:01
Both the ShortcutFilter and this action will end u
huangs
2013/12/30 20:15:10
Yeah I felt a bit dirty about this. :)
I think we
| |
| 1280 base::win::ShortcutProperties new_prop; | |
| 1281 new_prop.set_target(new_target_path); | |
| 1282 if (old_prop.icon == old_target_path) | |
|
gab
2013/12/23 14:25:01
tl;dr; use InstallUtil::ProgramCompare here.
Stri
huangs
2013/12/30 20:15:10
Ah yes. Done.
| |
| 1283 new_prop.set_icon(new_target_path, old_prop.icon_index); | |
| 1284 if (base::win::CreateOrUpdateShortcutLink( | |
| 1285 shortcut_path, new_prop, base::win::SHORTCUT_UPDATE_EXISTING)) { | |
| 1286 return true; | |
| 1287 } | |
| 1288 } | |
| 1289 LOG(ERROR) << "Failed to retarget " << shortcut_path.value(); | |
|
gab
2013/12/23 14:25:01
Rather than putting a generic ERROR at the bottom,
huangs
2013/12/30 20:15:10
There is only 1 error now, though I'm adding warni
| |
| 1290 return false; | |
| 1291 } | |
| 1292 | |
| 1274 // {|location|, |dist|, |level|} determine |shortcut_folder|. | 1293 // {|location|, |dist|, |level|} determine |shortcut_folder|. |
| 1275 // For each shortcut in |shortcut_folder| that match |shortcut_filter|, apply | 1294 // For each shortcut in |shortcut_folder| that match |shortcut_filter|, apply |
| 1276 // |shortcut_operation|. Returns true if all operations are successful. | 1295 // |shortcut_operation|. Returns true if all operations are successful. |
| 1277 // All intended operations are attempted, even if failures occur. | 1296 // All intended operations are attempted, even if failures occur. |
| 1278 bool BatchShortcutAction(const ShortcutFilterCallback& shortcut_filter, | 1297 bool BatchShortcutAction(const ShortcutFilterCallback& shortcut_filter, |
| 1279 const ShortcutOperationCallback& shortcut_operation, | 1298 const ShortcutOperationCallback& shortcut_operation, |
| 1280 ShellUtil::ShortcutLocation location, | 1299 ShellUtil::ShortcutLocation location, |
| 1281 BrowserDistribution* dist, | 1300 BrowserDistribution* dist, |
| 1282 ShellUtil::ShellChange level) { | 1301 ShellUtil::ShellChange level) { |
| 1283 DCHECK(!shortcut_operation.is_null()); | 1302 DCHECK(!shortcut_operation.is_null()); |
| (...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2100 if (!ShellUtil::ShortcutLocationIsSupported(location)) | 2119 if (!ShellUtil::ShortcutLocationIsSupported(location)) |
| 2101 return true; // Vacuous success. | 2120 return true; // Vacuous success. |
| 2102 | 2121 |
| 2103 FilterTargetEq shortcut_filter(target_exe, true); | 2122 FilterTargetEq shortcut_filter(target_exe, true); |
| 2104 ShortcutOperationCallback shortcut_operation( | 2123 ShortcutOperationCallback shortcut_operation( |
| 2105 base::Bind(&ShortcutOpUpdate, TranslateShortcutProperties(properties))); | 2124 base::Bind(&ShortcutOpUpdate, TranslateShortcutProperties(properties))); |
| 2106 return BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(), | 2125 return BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(), |
| 2107 shortcut_operation, location, dist, level); | 2126 shortcut_operation, location, dist, level); |
| 2108 } | 2127 } |
| 2109 | 2128 |
| 2129 // static | |
| 2130 bool ShellUtil::RetargetShortcutsWithArgs( | |
| 2131 ShellUtil::ShortcutLocation location, | |
| 2132 BrowserDistribution* dist, | |
| 2133 ShellChange level, | |
| 2134 const base::FilePath& old_target_exe, | |
| 2135 const base::FilePath& new_target_exe) { | |
| 2136 if (!ShellUtil::ShortcutLocationIsSupported(location)) | |
| 2137 return true; // Vacuous success. | |
| 2138 | |
| 2139 FilterTargetEq shortcut_filter(old_target_exe, true); | |
| 2140 ShortcutOperationCallback shortcut_operation( | |
| 2141 base::Bind(&ShortcutOpRetarget, old_target_exe, new_target_exe)); | |
| 2142 return BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(), | |
| 2143 shortcut_operation, location, dist, level); | |
| 2144 } | |
| 2145 | |
| 2110 bool ShellUtil::GetUserSpecificRegistrySuffix(string16* suffix) { | 2146 bool ShellUtil::GetUserSpecificRegistrySuffix(string16* suffix) { |
| 2111 // Use a thread-safe cache for the user's suffix. | 2147 // Use a thread-safe cache for the user's suffix. |
| 2112 static base::LazyInstance<UserSpecificRegistrySuffix>::Leaky suffix_instance = | 2148 static base::LazyInstance<UserSpecificRegistrySuffix>::Leaky suffix_instance = |
| 2113 LAZY_INSTANCE_INITIALIZER; | 2149 LAZY_INSTANCE_INITIALIZER; |
| 2114 return suffix_instance.Get().GetSuffix(suffix); | 2150 return suffix_instance.Get().GetSuffix(suffix); |
| 2115 } | 2151 } |
| 2116 | 2152 |
| 2117 bool ShellUtil::GetOldUserSpecificRegistrySuffix(string16* suffix) { | 2153 bool ShellUtil::GetOldUserSpecificRegistrySuffix(string16* suffix) { |
| 2118 wchar_t user_name[256]; | 2154 wchar_t user_name[256]; |
| 2119 DWORD size = arraysize(user_name); | 2155 DWORD size = arraysize(user_name); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2167 // are any left...). | 2203 // are any left...). |
| 2168 if (free_bits >= 8 && next_byte_index < size) { | 2204 if (free_bits >= 8 && next_byte_index < size) { |
| 2169 free_bits -= 8; | 2205 free_bits -= 8; |
| 2170 bit_stream += bytes[next_byte_index++] << free_bits; | 2206 bit_stream += bytes[next_byte_index++] << free_bits; |
| 2171 } | 2207 } |
| 2172 } | 2208 } |
| 2173 | 2209 |
| 2174 DCHECK_EQ(ret.length(), encoded_length); | 2210 DCHECK_EQ(ret.length(), encoded_length); |
| 2175 return ret; | 2211 return ret; |
| 2176 } | 2212 } |
| OLD | NEW |