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

Unified 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: better path matching 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/file_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/file_util.h
diff --git a/base/file_util.h b/base/file_util.h
index 66fe51c38dc17dbc013142ad44b307e76a3cbea0..dda0fa873d8c3e2cbc34e70633184a443723547e 100644
--- a/base/file_util.h
+++ b/base/file_util.h
@@ -27,6 +27,7 @@
#include "base/base_export.h"
#include "base/basictypes.h"
#include "base/file_path.h"
+#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/platform_file.h"
#include "base/string16.h"
@@ -34,7 +35,6 @@
#if defined(OS_POSIX)
#include "base/eintr_wrapper.h"
#include "base/file_descriptor_posix.h"
-#include "base/logging.h"
#endif
namespace base {
@@ -226,12 +226,95 @@ BASE_EXPORT bool SetPosixFilePermissions(const FilePath& path,
#endif // defined(OS_POSIX)
#if defined(OS_WIN)
-enum ShortcutOptions {
- SHORTCUT_NO_OPTIONS = 0,
- // Set DualMode property for Windows 8 Metro-enabled shortcuts.
- SHORTCUT_DUAL_MODE = 1 << 0,
+enum ShortcutOperation {
// Create a new shortcut (overwriting if necessary).
- SHORTCUT_CREATE_ALWAYS = 1 << 1,
+ SHORTCUT_CREATE_ALWAYS = 0,
+ // Update specified (non-null) properties only on an existing shortcut.
+ SHORTCUT_UPDATE_EXISTING,
+};
+
+// Properties for shortcuts. Properties set will be applied to the shortcut on
+// creation/update, others will be ignored.
+// Callers are encouraged to use the setters provided which take care of
+// setting |options| as desired.
+struct ShortcutProperties {
+ enum IndividualProperties {
+ PROPERTIES_TARGET = 1 << 0,
+ PROPERTIES_WORKING_DIR = 1 << 1,
+ PROPERTIES_ARGUMENTS = 1 << 2,
+ PROPERTIES_DESCRIPTION = 1 << 3,
+ PROPERTIES_ICON = 1 << 4,
+ PROPERTIES_APP_ID = 1 << 5,
+ PROPERTIES_DUAL_MODE = 1 << 6,
+ };
+
+ ShortcutProperties() : options(0U) {}
+
+ void set_target(const string16& target_in) {
+ target = target_in;
+ options |= PROPERTIES_TARGET;
+ }
+
+ void set_working_dir(const string16& working_dir_in) {
+ working_dir = working_dir_in;
+ options |= PROPERTIES_WORKING_DIR;
+ }
+
+ void set_arguments(const string16& arguments_in) {
+ // Size restriction as per MSDN at http://goo.gl/TJ7q5.
+ DCHECK(arguments_in.size() < MAX_PATH);
+ arguments = arguments_in;
+ options |= PROPERTIES_ARGUMENTS;
+ }
+
+ void set_description(const string16& description_in) {
+ // Size restriction as per MSDN at http://goo.gl/OdNQq.
+ DCHECK(description_in.size() < MAX_PATH);
+ description = description_in;
+ options |= PROPERTIES_DESCRIPTION;
+ }
+
+ void set_icon(const string16& icon_in, int icon_index_in) {
+ icon = icon_in;
+ icon_index = icon_index_in;
+ options |= PROPERTIES_ICON;
+ }
+
+ void set_app_id(const string16& app_id_in) {
+ app_id = app_id_in;
+ options |= PROPERTIES_APP_ID;
+ }
+
+ void set_dual_mode(bool dual_mode_in) {
+ dual_mode = dual_mode_in;
+ options |= PROPERTIES_DUAL_MODE;
+ }
+
+ // The target to launch from this shortcut. This is mandatory when creating
+ // a shortcut.
+ string16 target;
brettw 2012/09/08 18:28:48 Should some of these be FilePaths instead? On Wind
gab 2012/09/10 17:35:34 Done.
+ // The name of the working directory when launching the shortcut.
+ string16 working_dir;
+ // The arguments to be applied to |target| when launching from this shortcut.
+ // The length of this string must be less than MAX_PATH.
+ string16 arguments;
+ // The localized description of the shortcut.
+ // The length of this string must be less than MAX_PATH.
+ string16 description;
+ // The path to the icon (can be a dll or exe, in which case |icon_index| is
+ // the resource id).
+ string16 icon;
+ int icon_index;
+ // The app model id for the shortcut (Win7+).
+ string16 app_id;
+ // Whether this is a dual mode shortcut (Win8+).
+ // For now this property can only be set to true (i.e. once set it cannot be
+ // unset).
+ // TODO (gab): Make it possible to set this property to false.
+ bool dual_mode;
+ // Bitfield made of IndividualProperties. Properties set in |options| will be
+ // set on the shortcut, others will be ignored.
+ uint32 options;
};
// Resolve Windows shortcut (.LNK file)
@@ -246,28 +329,16 @@ BASE_EXPORT bool ResolveShortcut(const FilePath& shortcut_path,
FilePath* target_path,
string16* args);
-// Creates (or updates) a Windows shortcut (.LNK file)
-// This method creates (or updates) a shortcut link using the information given.
+// This method creates (or updates) a shortcut link at |shortcut_path| using the
+// information given through |properties|.
// Ensure you have initialized COM before calling into this function.
-// |destination| is required. |source| is required when SHORTCUT_CREATE_ALWAYS
-// is specified in |options|. All other parameters are optional and may be NULL.
-// |source| is the existing file, |destination| is the new link file to be
-// created; for best results pass the filename with the .lnk extension.
-// The |icon| can specify a dll or exe in which case the icon index is the
-// resource id. |app_id| is the app model id for the shortcut on Win7.
-// |options|: bitfield for which the options come from ShortcutOptions.
-// If SHORTCUT_CREATE_ALWAYS is not set in |options|, only specified (non-null)
-// properties on an existing shortcut will be modified. If the shortcut does not
+// |operation|: a choice from the ShortcutOperation enum.
+// If |operation| is SHORTCUT_UPDATE_EXISTING and |shortcut_path| does not
// exist, this method is a no-op and returns false.
-BASE_EXPORT bool CreateOrUpdateShortcutLink(const wchar_t *source,
- const wchar_t *destination,
- const wchar_t *working_dir,
- const wchar_t *arguments,
- const wchar_t *description,
- const wchar_t *icon,
- int icon_index,
- const wchar_t* app_id,
- uint32 options);
+BASE_EXPORT bool CreateOrUpdateShortcutLink(
+ const string16& shortcut_path,
+ const ShortcutProperties& properties,
+ ShortcutOperation operation);
// Pins a shortcut to the Windows 7 taskbar. The shortcut file must already
// exist and be a shortcut that points to an executable.
« no previous file with comments | « no previous file | base/file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698