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

Side by Side Diff: base/file_util.h

Issue 10914109: Refactoring and tests for the highly undertested file_util::CreateOrUpdateShortcutLink() method. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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
« no previous file with comments | « no previous file | base/file_util_unittest.cc » ('j') | base/file_util_unittest.cc » ('J')
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 contains utility functions for dealing with the local 5 // This file contains utility functions for dealing with the local
6 // filesystem. 6 // filesystem.
7 7
8 #ifndef BASE_FILE_UTIL_H_ 8 #ifndef BASE_FILE_UTIL_H_
9 #define BASE_FILE_UTIL_H_ 9 #define BASE_FILE_UTIL_H_
10 10
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 // a file which the symlink points to. 219 // a file which the symlink points to.
220 BASE_EXPORT bool GetPosixFilePermissions(const FilePath& path, 220 BASE_EXPORT bool GetPosixFilePermissions(const FilePath& path,
221 int* mode); 221 int* mode);
222 // Sets the permission of the given |path|. If |path| is symbolic link, sets 222 // Sets the permission of the given |path|. If |path| is symbolic link, sets
223 // the permission of a file which the symlink points to. 223 // the permission of a file which the symlink points to.
224 BASE_EXPORT bool SetPosixFilePermissions(const FilePath& path, 224 BASE_EXPORT bool SetPosixFilePermissions(const FilePath& path,
225 int mode); 225 int mode);
226 #endif // defined(OS_POSIX) 226 #endif // defined(OS_POSIX)
227 227
228 #if defined(OS_WIN) 228 #if defined(OS_WIN)
229 enum ShortcutOptions { 229 enum ShortcutOperation {
230 SHORTCUT_NO_OPTIONS = 0,
231 // Set DualMode property for Windows 8 Metro-enabled shortcuts.
232 SHORTCUT_DUAL_MODE = 1 << 0,
233 // Create a new shortcut (overwriting if necessary). 230 // Create a new shortcut (overwriting if necessary).
234 SHORTCUT_CREATE_ALWAYS = 1 << 1, 231 SHORTCUT_CREATE_ALWAYS = 0,
232 // Update specified (non-null) properties only on an existing shortcut.
233 SHORTCUT_UPDATE_EXISTING,
234 };
235
236 // Propoerties for shortcuts. Properties set will be applied to the shortcut
robertshield 2012/09/06 02:37:34 nit: *Properties
gab 2012/09/06 04:20:02 Done.
237 // on creation/update, others will be ignored.
238 // Callers are encouraged to use the setters provided which take care of
239 // setting |bitfield| as desired.
240 struct ShortcutProperties {
241 enum IndividualProperties {
242 PROPERTIES_TARGET = 1 << 0,
243 PROPERTIES_WORKING_DIR = 1 << 1,
244 PROPERTIES_ARGUMENTS = 1 << 2,
245 PROPERTIES_DESCRIPTION = 1 << 3,
246 PROPERTIES_ICON = 1 << 4,
247 PROPERTIES_APP_ID = 1 << 5,
248 PROPERTIES_DUAL_MODE = 1 << 6,
249 };
250
251 ShortcutProperties() : bitfield(0U) {}
252
253 void set_target(const string16& target_in) {
254 target = target_in;
255 bitfield |= PROPERTIES_TARGET;
256 }
257
258 void set_working_dir(const string16& working_dir_in) {
259 working_dir = working_dir_in;
260 bitfield |= PROPERTIES_WORKING_DIR;
261 }
262
263 void set_arguments(const string16& arguments_in) {
264 arguments = arguments_in;
265 bitfield |= PROPERTIES_ARGUMENTS;
266 }
267
268 void set_description(const string16& description_in) {
269 description = description_in;
270 bitfield |= PROPERTIES_DESCRIPTION;
271 }
272
273 void set_icon(const string16& icon_in, int icon_index_in) {
274 icon = icon_in;
275 icon_index = icon_index_in;
276 bitfield |= PROPERTIES_ICON;
277 }
278
279 void set_app_id(const string16& app_id_in) {
280 app_id = app_id_in;
281 bitfield |= PROPERTIES_APP_ID;
282 }
283
284 void set_dual_mode(bool dual_mode_in) {
285 dual_mode = dual_mode_in;
286 bitfield |= PROPERTIES_DUAL_MODE;
287 }
288
289 // The target to launch from this shortcut. This is mandatory when creating
290 // a shortcut.
291 string16 target;
292 // The name of the working directory when launching the shortcut.
293 string16 working_dir;
294 // The arguments to be applied to |target| when launching from this shortcut.
295 // The length of this string must be less than MAX_PATH.
296 string16 arguments;
297 // The localized description of the shortcut.
298 // The length of this string must be less than MAX_PATH.
299 string16 description;
300 // The path to the icon (can be a dll or exe, in which case |icon_index| is
301 // the resource id).
302 string16 icon;
303 int icon_index;
304 // The app model id for the shortcut (Win7+).
305 string16 app_id;
306 // Whether this is a dual mode shortcut (Win8+).
307 // For now this property can only be set to true (i.e. once set it cannot be
308 // unset).
309 // TODO (gab): Make it possible to set this property to false.
310 bool dual_mode;
311 // Bitfield made of IndividualProperties. Properties set in |bitfield| will
312 // be set on the shortcut, others will be ignored.
313 uint32 bitfield;
robertshield 2012/09/06 02:37:34 bitfield is a bad name for a member. Consider 'opt
gab 2012/09/06 04:20:02 Done.
235 }; 314 };
236 315
237 // Resolve Windows shortcut (.LNK file) 316 // Resolve Windows shortcut (.LNK file)
238 // This methods tries to resolve a shortcut .LNK file. The path of the shortcut 317 // This methods tries to resolve a shortcut .LNK file. The path of the shortcut
239 // to resolve is in |shortcut_path|. If |target_path| is not NULL, the target 318 // to resolve is in |shortcut_path|. If |target_path| is not NULL, the target
240 // will be resolved and placed in |target_path|. If |args| is not NULL, the 319 // will be resolved and placed in |target_path|. If |args| is not NULL, the
241 // arguments will be retrieved and placed in |args|. The function returns true 320 // arguments will be retrieved and placed in |args|. The function returns true
242 // if all requested fields are are found successfully. 321 // if all requested fields are are found successfully.
243 // Callers can safely use the same variable for both |shortcut_path| and 322 // Callers can safely use the same variable for both |shortcut_path| and
244 // |target_path|. 323 // |target_path|.
245 BASE_EXPORT bool ResolveShortcut(const FilePath& shortcut_path, 324 BASE_EXPORT bool ResolveShortcut(const FilePath& shortcut_path,
246 FilePath* target_path, 325 FilePath* target_path,
247 string16* args); 326 string16* args);
248 327
249 // Creates (or updates) a Windows shortcut (.LNK file) 328 // This method creates (or updates) a shortcut link at |shortcut_path| using the
250 // This method creates (or updates) a shortcut link using the information given. 329 // information given through |properties|.
251 // Ensure you have initialized COM before calling into this function. 330 // Ensure you have initialized COM before calling into this function.
252 // |destination| is required. |source| is required when SHORTCUT_CREATE_ALWAYS 331 // |operation|: a choice from the ShortcutOperation enum.
253 // is specified in |options|. All other parameters are optional and may be NULL. 332 // If |operation| is SHORTCUT_UPDATE_EXISTING| and |shortcut_path| does not
robertshield 2012/09/06 02:37:34 nit: SHORTCUT_UPDATE_EXISTING (no |)
gab 2012/09/06 04:20:02 Whoopsy!
254 // |source| is the existing file, |destination| is the new link file to be
255 // created; for best results pass the filename with the .lnk extension.
256 // The |icon| can specify a dll or exe in which case the icon index is the
257 // resource id. |app_id| is the app model id for the shortcut on Win7.
258 // |options|: bitfield for which the options come from ShortcutOptions.
259 // If SHORTCUT_CREATE_ALWAYS is not set in |options|, only specified (non-null)
260 // properties on an existing shortcut will be modified. If the shortcut does not
261 // exist, this method is a no-op and returns false. 333 // exist, this method is a no-op and returns false.
262 BASE_EXPORT bool CreateOrUpdateShortcutLink(const wchar_t *source, 334 BASE_EXPORT bool CreateOrUpdateShortcutLink(
263 const wchar_t *destination, 335 const string16& shortcut_path,
264 const wchar_t *working_dir, 336 const ShortcutProperties& properties,
265 const wchar_t *arguments, 337 ShortcutOperation operation);
266 const wchar_t *description,
267 const wchar_t *icon,
268 int icon_index,
269 const wchar_t* app_id,
270 uint32 options);
271 338
272 // Pins a shortcut to the Windows 7 taskbar. The shortcut file must already 339 // Pins a shortcut to the Windows 7 taskbar. The shortcut file must already
273 // exist and be a shortcut that points to an executable. 340 // exist and be a shortcut that points to an executable.
274 BASE_EXPORT bool TaskbarPinShortcutLink(const wchar_t* shortcut); 341 BASE_EXPORT bool TaskbarPinShortcutLink(const wchar_t* shortcut);
275 342
276 // Unpins a shortcut from the Windows 7 taskbar. The shortcut must exist and 343 // Unpins a shortcut from the Windows 7 taskbar. The shortcut must exist and
277 // already be pinned to the taskbar. 344 // already be pinned to the taskbar.
278 BASE_EXPORT bool TaskbarUnpinShortcutLink(const wchar_t* shortcut); 345 BASE_EXPORT bool TaskbarUnpinShortcutLink(const wchar_t* shortcut);
279 346
280 // Copy from_path to to_path recursively and then delete from_path recursively. 347 // Copy from_path to to_path recursively and then delete from_path recursively.
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 }; 738 };
672 739
673 // Attempts determine the FileSystemType for |path|. 740 // Attempts determine the FileSystemType for |path|.
674 // Returns false if |path| doesn't exist. 741 // Returns false if |path| doesn't exist.
675 BASE_EXPORT bool GetFileSystemType(const FilePath& path, FileSystemType* type); 742 BASE_EXPORT bool GetFileSystemType(const FilePath& path, FileSystemType* type);
676 #endif 743 #endif
677 744
678 } // namespace file_util 745 } // namespace file_util
679 746
680 #endif // BASE_FILE_UTIL_H_ 747 #endif // BASE_FILE_UTIL_H_
OLDNEW
« no previous file with comments | « no previous file | base/file_util_unittest.cc » ('j') | base/file_util_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698