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

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

Issue 22382007: On user-level Chrome self-destruct, make user-created shortcuts target system-level chrome.exe. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync. Created 7 years, 4 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 | Annotate | Revision Log
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 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 return true; 1196 return true;
1197 } 1197 }
1198 1198
1199 // Shortcut filters for BatchShortcutAction(). 1199 // Shortcut filters for BatchShortcutAction().
1200 1200
1201 typedef base::Callback<bool(const base::FilePath& /*shortcut_path*/, 1201 typedef base::Callback<bool(const base::FilePath& /*shortcut_path*/,
1202 const string16& /*args*/)> 1202 const string16& /*args*/)>
1203 ShortcutFilterCallback; 1203 ShortcutFilterCallback;
1204 1204
1205 // FilterTargetEq is a shortcut filter that matches only shortcuts that have a 1205 // FilterTargetEq is a shortcut filter that matches only shortcuts that have a
1206 // specific target. 1206 // specific target, and optionally matches shortcuts that have non-empty
1207 // arguments.
1207 class FilterTargetEq { 1208 class FilterTargetEq {
1208 public: 1209 public:
1209 explicit FilterTargetEq(const base::FilePath& desired_target_exe); 1210 FilterTargetEq(const base::FilePath& desired_target_exe, bool require_args);
1210 1211
1211 // Returns true if filter rules are satisfied, i.e.: 1212 // Returns true if filter rules are satisfied, i.e.:
1212 // - |target_path| matches |desired_target_compare_|. 1213 // - |target_path|'s target == |desired_target_compare_|, and
1214 // - |args| is non-empty (if |require_args_| == true).
1213 bool Match(const base::FilePath& target_path, const string16& args) const; 1215 bool Match(const base::FilePath& target_path, const string16& args) const;
1214 1216
1215 // A convenience routine to create a callback to call Match(). 1217 // A convenience routine to create a callback to call Match().
1216 // The callback is only valid during the lifetime of the FilterTargetEq 1218 // The callback is only valid during the lifetime of the FilterTargetEq
1217 // instance. 1219 // instance.
1218 ShortcutFilterCallback AsShortcutFilterCallback(); 1220 ShortcutFilterCallback AsShortcutFilterCallback();
1219 1221
1220 private: 1222 private:
1221 InstallUtil::ProgramCompare desired_target_compare_; 1223 InstallUtil::ProgramCompare desired_target_compare_;
1224
1225 bool require_args_;
1222 }; 1226 };
1223 1227
1224 FilterTargetEq::FilterTargetEq(const base::FilePath& desired_target_exe) 1228 FilterTargetEq::FilterTargetEq(const base::FilePath& desired_target_exe,
1225 : desired_target_compare_(desired_target_exe) {} 1229 bool require_args)
1230 : desired_target_compare_(desired_target_exe),
1231 require_args_(require_args) {}
1226 1232
1227 bool FilterTargetEq::Match(const base::FilePath& target_path, 1233 bool FilterTargetEq::Match(const base::FilePath& target_path,
1228 const string16& args) const { 1234 const string16& args) const {
1229 return desired_target_compare_.EvaluatePath(target_path); 1235 if (!desired_target_compare_.EvaluatePath(target_path))
1236 return false;
1237 if (require_args_ && args.empty())
1238 return false;
1239 return true;
1230 } 1240 }
1231 1241
1232 ShortcutFilterCallback FilterTargetEq::AsShortcutFilterCallback() { 1242 ShortcutFilterCallback FilterTargetEq::AsShortcutFilterCallback() {
1233 return base::Bind(&FilterTargetEq::Match, base::Unretained(this)); 1243 return base::Bind(&FilterTargetEq::Match, base::Unretained(this));
1234 } 1244 }
1235 1245
1236 // Shortcut operations for BatchShortcutAction(). 1246 // Shortcut operations for BatchShortcutAction().
1237 1247
1238 typedef base::Callback<bool(const base::FilePath& /*shortcut_path*/)> 1248 typedef base::Callback<bool(const base::FilePath& /*shortcut_path*/)>
1239 ShortcutOperationCallback; 1249 ShortcutOperationCallback;
(...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after
2035 } 2045 }
2036 2046
2037 // static 2047 // static
2038 bool ShellUtil::RemoveShortcuts(ShellUtil::ShortcutLocation location, 2048 bool ShellUtil::RemoveShortcuts(ShellUtil::ShortcutLocation location,
2039 BrowserDistribution* dist, 2049 BrowserDistribution* dist,
2040 ShellChange level, 2050 ShellChange level,
2041 const base::FilePath& target_exe) { 2051 const base::FilePath& target_exe) {
2042 if (!ShellUtil::ShortcutLocationIsSupported(location)) 2052 if (!ShellUtil::ShortcutLocationIsSupported(location))
2043 return true; // Vacuous success. 2053 return true; // Vacuous success.
2044 2054
2045 FilterTargetEq shortcut_filter(target_exe); 2055 FilterTargetEq shortcut_filter(target_exe, false);
2046 // Main operation to apply to each shortcut in the directory specified. 2056 // Main operation to apply to each shortcut in the directory specified.
2047 ShortcutOperationCallback shortcut_operation( 2057 ShortcutOperationCallback shortcut_operation(
2048 location == SHORTCUT_LOCATION_TASKBAR_PINS ? 2058 location == SHORTCUT_LOCATION_TASKBAR_PINS ?
2049 base::Bind(&ShortcutOpUnpin) : base::Bind(&ShortcutOpDelete)); 2059 base::Bind(&ShortcutOpUnpin) : base::Bind(&ShortcutOpDelete));
2050 bool success = BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(), 2060 bool success = BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(),
2051 shortcut_operation, location, dist, level); 2061 shortcut_operation, location, dist, level);
2052 // Remove chrome-specific shortcut folders if they are now empty. 2062 // Remove chrome-specific shortcut folders if they are now empty.
2053 if (success && 2063 if (success &&
2054 (location == SHORTCUT_LOCATION_START_MENU || 2064 (location == SHORTCUT_LOCATION_START_MENU ||
2055 location == SHORTCUT_LOCATION_APP_SHORTCUTS)) { 2065 location == SHORTCUT_LOCATION_APP_SHORTCUTS)) {
2056 success = RemoveShortcutFolderIfEmpty(location, dist, level); 2066 success = RemoveShortcutFolderIfEmpty(location, dist, level);
2057 } 2067 }
2058 return success; 2068 return success;
2059 } 2069 }
2060 2070
2061 // static 2071 // static
2062 bool ShellUtil::UpdateShortcuts( 2072 bool ShellUtil::UpdateShortcuts(
2063 ShellUtil::ShortcutLocation location, 2073 ShellUtil::ShortcutLocation location,
2064 BrowserDistribution* dist, 2074 BrowserDistribution* dist,
2065 ShellChange level, 2075 ShellChange level,
2066 const base::FilePath& target_exe, 2076 const base::FilePath& target_exe,
2077 bool require_args,
2067 const ShellUtil::ShortcutProperties& properties) { 2078 const ShellUtil::ShortcutProperties& properties) {
2068 if (!ShellUtil::ShortcutLocationIsSupported(location)) 2079 if (!ShellUtil::ShortcutLocationIsSupported(location))
2069 return true; // Vacuous success. 2080 return true; // Vacuous success.
2070 2081
2071 FilterTargetEq shortcut_filter(target_exe); 2082 FilterTargetEq shortcut_filter(target_exe, require_args);
2072 ShortcutOperationCallback shortcut_operation( 2083 ShortcutOperationCallback shortcut_operation(
2073 base::Bind(&ShortcutOpUpdate, TranslateShortcutProperties(properties))); 2084 base::Bind(&ShortcutOpUpdate, TranslateShortcutProperties(properties)));
2074 return BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(), 2085 return BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(),
2075 shortcut_operation, location, dist, level); 2086 shortcut_operation, location, dist, level);
2076 } 2087 }
2077 2088
2078 bool ShellUtil::GetUserSpecificRegistrySuffix(string16* suffix) { 2089 bool ShellUtil::GetUserSpecificRegistrySuffix(string16* suffix) {
2079 // Use a thread-safe cache for the user's suffix. 2090 // Use a thread-safe cache for the user's suffix.
2080 static base::LazyInstance<UserSpecificRegistrySuffix>::Leaky suffix_instance = 2091 static base::LazyInstance<UserSpecificRegistrySuffix>::Leaky suffix_instance =
2081 LAZY_INSTANCE_INITIALIZER; 2092 LAZY_INSTANCE_INITIALIZER;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2135 // are any left...). 2146 // are any left...).
2136 if (free_bits >= 8 && next_byte_index < size) { 2147 if (free_bits >= 8 && next_byte_index < size) {
2137 free_bits -= 8; 2148 free_bits -= 8;
2138 bit_stream += bytes[next_byte_index++] << free_bits; 2149 bit_stream += bytes[next_byte_index++] << free_bits;
2139 } 2150 }
2140 } 2151 }
2141 2152
2142 DCHECK_EQ(ret.length(), encoded_length); 2153 DCHECK_EQ(ret.length(), encoded_length);
2143 return ret; 2154 return ret;
2144 } 2155 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698