diff options
author | mgiuca@chromium.org <mgiuca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-03 04:42:17 +0000 |
---|---|---|
committer | mgiuca@chromium.org <mgiuca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-03 04:42:17 +0000 |
commit | cf610e64c266bbfd179392afe3d0d5ea3d70d642 (patch) | |
tree | 6bde75c83a8e37aadf3c9412302ccf9edb371df6 | |
parent | 9faa02dd3761bdfde3354637643375e948681b7e (diff) | |
download | chromium_src-cf610e64c266bbfd179392afe3d0d5ea3d70d642.zip chromium_src-cf610e64c266bbfd179392afe3d0d5ea3d70d642.tar.gz chromium_src-cf610e64c266bbfd179392afe3d0d5ea3d70d642.tar.bz2 |
Once-off automatic app shortcut creation no longer creates duplicate shortcuts.
Fixes Windows-only issue introduced in SVN 207832 where if there were any
existing shortcuts, a duplicate would be created. Now detects whether there is
already a shortcut for the same profile and app ID, and if so, does not create
another one.
BUG=253806
TEST=Remove "shortcuts_have_been_created" in preferences, and restart Chrome;
should not create duplicate shortcuts.
TEST=Install same app in two profiles, delete shortcut in default profile, edit
prefs again and restart; should create a second shortcut for the app in the
default profile.
Review URL: https://chromiumcodereview.appspot.com/17591016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@209888 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | apps/shortcut_manager.cc | 6 | ||||
-rw-r--r-- | chrome/browser/ui/app_list/app_list_service_mac.mm | 6 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/browser_window_cocoa.mm | 3 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.cc | 4 | ||||
-rw-r--r-- | chrome/browser/ui/views/create_application_shortcut_view.cc | 3 | ||||
-rw-r--r-- | chrome/browser/web_applications/web_app.cc | 11 | ||||
-rw-r--r-- | chrome/browser/web_applications/web_app.h | 17 | ||||
-rw-r--r-- | chrome/browser/web_applications/web_app_android.cc | 3 | ||||
-rw-r--r-- | chrome/browser/web_applications/web_app_linux.cc | 6 | ||||
-rw-r--r-- | chrome/browser/web_applications/web_app_mac.mm | 3 | ||||
-rw-r--r-- | chrome/browser/web_applications/web_app_win.cc | 24 |
11 files changed, 63 insertions, 23 deletions
diff --git a/apps/shortcut_manager.cc b/apps/shortcut_manager.cc index d03cf5ca..8c4e001 100644 --- a/apps/shortcut_manager.cc +++ b/apps/shortcut_manager.cc @@ -31,7 +31,8 @@ using extensions::Extension; namespace { -// Creates a shortcut for an application in the applications menu. +// Creates a shortcut for an application in the applications menu, if there is +// not already one present. void CreateShortcutsInApplicationsMenu( const ShellIntegration::ShortcutInfo& shortcut_info) { ShellIntegration::ShortcutLocations creation_locations; @@ -39,7 +40,8 @@ void CreateShortcutsInApplicationsMenu( // Create the shortcut in the Chrome Apps subdir. creation_locations.applications_menu_subdir = web_app::GetAppShortcutsSubdirName(); - web_app::CreateShortcuts(shortcut_info, creation_locations); + web_app::CreateShortcuts(shortcut_info, creation_locations, + web_app::DONT_CREATE_DUPLICATE_SHORTCUTS); } bool ShouldCreateShortcutFor(const extensions::Extension* extension) { diff --git a/chrome/browser/ui/app_list/app_list_service_mac.mm b/chrome/browser/ui/app_list/app_list_service_mac.mm index f6435e5..2637424 100644 --- a/chrome/browser/ui/app_list/app_list_service_mac.mm +++ b/chrome/browser/ui/app_list/app_list_service_mac.mm @@ -166,7 +166,8 @@ void CreateAppListShim(const base::FilePath& profile_path) { // TODO(tapted): Create a dock icon using chrome/browser/mac/dock.h . web_app::CreateShortcuts(shortcut_info, - ShellIntegration::ShortcutLocations()); + ShellIntegration::ShortcutLocations(), + web_app::ALLOW_DUPLICATE_SHORTCUTS); } // Check that there is an app list shim. If enabling and there is not, make one. @@ -195,7 +196,8 @@ void CheckAppListShimOnFileThread(const base::FilePath& profile_path) { void CreateShortcutsInDefaultLocation( const ShellIntegration::ShortcutInfo& shortcut_info) { web_app::CreateShortcuts(shortcut_info, - ShellIntegration::ShortcutLocations()); + ShellIntegration::ShortcutLocations(), + web_app::ALLOW_DUPLICATE_SHORTCUTS); } AppListControllerDelegateCocoa::AppListControllerDelegateCocoa() {} diff --git a/chrome/browser/ui/cocoa/browser_window_cocoa.mm b/chrome/browser/ui/cocoa/browser_window_cocoa.mm index 54346bb..5c7d583 100644 --- a/chrome/browser/ui/cocoa/browser_window_cocoa.mm +++ b/chrome/browser/ui/cocoa/browser_window_cocoa.mm @@ -109,7 +109,8 @@ NSPoint GetPointForBubble(content::WebContents* web_contents, void CreateShortcuts(const ShellIntegration::ShortcutInfo& shortcut_info) { // creation_locations will be ignored by CreatePlatformShortcuts on Mac. ShellIntegration::ShortcutLocations creation_locations; - web_app::CreateShortcuts(shortcut_info, creation_locations); + web_app::CreateShortcuts(shortcut_info, creation_locations, + web_app::ALLOW_DUPLICATE_SHORTCUTS); } } // namespace diff --git a/chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.cc b/chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.cc index d8fdd0f..48eb200c 100644 --- a/chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.cc +++ b/chrome/browser/ui/gtk/create_application_shortcuts_dialog_gtk.cc @@ -347,7 +347,9 @@ void CreateChromeApplicationShortcutsDialogGtk::CreateDesktopShortcut( const ShellIntegration::ShortcutLocations& creation_locations) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); - if (web_app::CreateShortcutsOnFileThread(shortcut_info, creation_locations)) { + if (web_app::CreateShortcutsOnFileThread( + shortcut_info, creation_locations, + web_app::ALLOW_DUPLICATE_SHORTCUTS)) { Release(); } else { BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, diff --git a/chrome/browser/ui/views/create_application_shortcut_view.cc b/chrome/browser/ui/views/create_application_shortcut_view.cc index 2b4092c..80e346f 100644 --- a/chrome/browser/ui/views/create_application_shortcut_view.cc +++ b/chrome/browser/ui/views/create_application_shortcut_view.cc @@ -382,7 +382,8 @@ bool CreateApplicationShortcutView::Accept() { creation_locations.in_quick_launch_bar = false; #endif - web_app::CreateShortcuts(shortcut_info_, creation_locations); + web_app::CreateShortcuts(shortcut_info_, creation_locations, + web_app::ALLOW_DUPLICATE_SHORTCUTS); return true; } diff --git a/chrome/browser/web_applications/web_app.cc b/chrome/browser/web_applications/web_app.cc index de8e048..06a12f7 100644 --- a/chrome/browser/web_applications/web_app.cc +++ b/chrome/browser/web_applications/web_app.cc @@ -149,14 +149,15 @@ std::string GetExtensionIdFromApplicationName(const std::string& app_name) { void CreateShortcuts( const ShellIntegration::ShortcutInfo& shortcut_info, - const ShellIntegration::ShortcutLocations& creation_locations) { + const ShellIntegration::ShortcutLocations& creation_locations, + ShortcutCreationPolicy creation_policy) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); BrowserThread::PostTask( BrowserThread::FILE, FROM_HERE, base::Bind(base::IgnoreResult(&CreateShortcutsOnFileThread), - shortcut_info, creation_locations)); + shortcut_info, creation_locations, creation_policy)); } void DeleteAllShortcuts(const ShellIntegration::ShortcutInfo& shortcut_info) { @@ -180,14 +181,16 @@ void UpdateAllShortcuts(const string16& old_app_title, bool CreateShortcutsOnFileThread( const ShellIntegration::ShortcutInfo& shortcut_info, - const ShellIntegration::ShortcutLocations& creation_locations) { + const ShellIntegration::ShortcutLocations& creation_locations, + ShortcutCreationPolicy creation_policy) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); base::FilePath shortcut_data_dir = GetWebAppDataDirectory( shortcut_info.profile_path, shortcut_info.extension_id, shortcut_info.url); return internals::CreatePlatformShortcuts(shortcut_data_dir, shortcut_info, - creation_locations); + creation_locations, + creation_policy); } bool IsValidUrl(const GURL& url) { diff --git a/chrome/browser/web_applications/web_app.h b/chrome/browser/web_applications/web_app.h index 7436663..1fc5a5a 100644 --- a/chrome/browser/web_applications/web_app.h +++ b/chrome/browser/web_applications/web_app.h @@ -24,6 +24,14 @@ class ImageFamily; namespace web_app { +// Policy on whether to create duplicate shortcuts. +enum ShortcutCreationPolicy { + // Duplicate shortcuts may be created, at the discretion of the + // implementation. + ALLOW_DUPLICATE_SHORTCUTS, + DONT_CREATE_DUPLICATE_SHORTCUTS +}; + // Gets the user data directory for given web app. The path for the directory is // based on |extension_id|. If |extension_id| is empty then |url| is used // to construct a unique ID. @@ -56,7 +64,8 @@ std::string GetExtensionIdFromApplicationName(const std::string& app_name); // |creation_locations| contains information about where to create them. void CreateShortcuts( const ShellIntegration::ShortcutInfo& shortcut_info, - const ShellIntegration::ShortcutLocations& creation_locations); + const ShellIntegration::ShortcutLocations& creation_locations, + ShortcutCreationPolicy creation_policy); // Delete all the shortcuts that have been created for the given // |shortcut_data| in the profile with |profile_path|. @@ -75,7 +84,8 @@ void UpdateAllShortcuts(const string16& old_app_title, // |creation_locations| contains information about where to create them. bool CreateShortcutsOnFileThread( const ShellIntegration::ShortcutInfo& shortcut_info, - const ShellIntegration::ShortcutLocations& creation_locations); + const ShellIntegration::ShortcutLocations& creation_locations, + ShortcutCreationPolicy creation_policy); // Returns true if given url is a valid web app url. bool IsValidUrl(const GURL& url); @@ -114,7 +124,8 @@ std::vector<base::FilePath> GetShortcutPaths( bool CreatePlatformShortcuts( const base::FilePath& shortcut_data_path, const ShellIntegration::ShortcutInfo& shortcut_info, - const ShellIntegration::ShortcutLocations& creation_locations); + const ShellIntegration::ShortcutLocations& creation_locations, + ShortcutCreationPolicy creation_policy); // Delete all the shortcuts we have added for this extension. This is the // platform specific implementation of the DeleteAllShortcuts function, and diff --git a/chrome/browser/web_applications/web_app_android.cc b/chrome/browser/web_applications/web_app_android.cc index 61c9445..bce8a52 100644 --- a/chrome/browser/web_applications/web_app_android.cc +++ b/chrome/browser/web_applications/web_app_android.cc @@ -10,7 +10,8 @@ namespace internals { bool CreatePlatformShortcuts( const base::FilePath& web_app_path, const ShellIntegration::ShortcutInfo& shortcut_info, - const ShellIntegration::ShortcutLocations& creation_locations) { + const ShellIntegration::ShortcutLocations& creation_locations, + ShortcutCreationPolicy creation_policy) { return true; } diff --git a/chrome/browser/web_applications/web_app_linux.cc b/chrome/browser/web_applications/web_app_linux.cc index a602918..09aaf91 100644 --- a/chrome/browser/web_applications/web_app_linux.cc +++ b/chrome/browser/web_applications/web_app_linux.cc @@ -16,7 +16,8 @@ namespace internals { bool CreatePlatformShortcuts( const base::FilePath& web_app_path, const ShellIntegration::ShortcutInfo& shortcut_info, - const ShellIntegration::ShortcutLocations& creation_locations) { + const ShellIntegration::ShortcutLocations& creation_locations, + ShortcutCreationPolicy /*creation_policy*/) { DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); return ShellIntegrationLinux::CreateDesktopShortcut( shortcut_info, creation_locations); @@ -50,7 +51,8 @@ void UpdatePlatformShortcuts( // currently in a different location). creation_locations.applications_menu_subdir = GetAppShortcutsSubdirName(); - CreatePlatformShortcuts(web_app_path, shortcut_info, creation_locations); + CreatePlatformShortcuts(web_app_path, shortcut_info, creation_locations, + ALLOW_DUPLICATE_SHORTCUTS); } void DeleteAllShortcutsForProfile(const base::FilePath& profile_path) { diff --git a/chrome/browser/web_applications/web_app_mac.mm b/chrome/browser/web_applications/web_app_mac.mm index 2717f9c..2743f32 100644 --- a/chrome/browser/web_applications/web_app_mac.mm +++ b/chrome/browser/web_applications/web_app_mac.mm @@ -598,7 +598,8 @@ namespace internals { bool CreatePlatformShortcuts( const base::FilePath& app_data_path, const ShellIntegration::ShortcutInfo& shortcut_info, - const ShellIntegration::ShortcutLocations& creation_locations) { + const ShellIntegration::ShortcutLocations& creation_locations, + ShortcutCreationPolicy /*creation_policy*/) { DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); WebAppShortcutCreator shortcut_creator( app_data_path, shortcut_info, base::mac::BaseBundleID()); diff --git a/chrome/browser/web_applications/web_app_win.cc b/chrome/browser/web_applications/web_app_win.cc index de5355a..6e19753 100644 --- a/chrome/browser/web_applications/web_app_win.cc +++ b/chrome/browser/web_applications/web_app_win.cc @@ -155,13 +155,15 @@ std::vector<base::FilePath> FindAppShortcutsByProfileAndTitle( // Creates application shortcuts in a given set of paths. // |shortcut_paths| is a list of directories in which shortcuts should be -// created. +// created. If |creation_policy| is DONT_CREATE_DUPLICATE_SHORTCUTS and there is +// an existing shortcut to this app for this profile, does nothing (succeeding). // Returns true on success, false on failure. // Must be called on the FILE thread. bool CreateShortcutsInPaths( const base::FilePath& web_app_path, const ShellIntegration::ShortcutInfo& shortcut_info, const std::vector<base::FilePath>& shortcut_paths, + web_app::ShortcutCreationPolicy creation_policy, std::vector<base::FilePath>* out_filenames) { // Ensure web_app_path exists. if (!file_util::PathExists(web_app_path) && @@ -213,6 +215,15 @@ bool CreateShortcutsInPaths( for (size_t i = 0; i < shortcut_paths.size(); ++i) { base::FilePath shortcut_file = shortcut_paths[i].Append(file_name). AddExtension(installer::kLnkExt); + if (creation_policy == web_app::DONT_CREATE_DUPLICATE_SHORTCUTS) { + // Check whether there is an existing shortcut to this app. + std::vector<base::FilePath> shortcut_files = + FindAppShortcutsByProfileAndTitle(shortcut_paths[i], + shortcut_info.profile_path, + shortcut_info.title); + if (!shortcut_files.empty()) + continue; + } if (shortcut_paths[i] != web_app_path) { int unique_number = file_util::GetUniquePathNumber(shortcut_file, FILE_PATH_LITERAL("")); @@ -324,7 +335,8 @@ base::FilePath CreateShortcutInWebAppDir( std::vector<base::FilePath> paths; paths.push_back(web_app_dir); std::vector<base::FilePath> out_filenames; - CreateShortcutsInPaths(web_app_dir, shortcut_info, paths, &out_filenames); + CreateShortcutsInPaths(web_app_dir, shortcut_info, paths, + ALLOW_DUPLICATE_SHORTCUTS, &out_filenames); DCHECK_EQ(out_filenames.size(), 1u); return out_filenames[0]; } @@ -354,7 +366,8 @@ bool CheckAndSaveIcon(const base::FilePath& icon_file, bool CreatePlatformShortcuts( const base::FilePath& web_app_path, const ShellIntegration::ShortcutInfo& shortcut_info, - const ShellIntegration::ShortcutLocations& creation_locations) { + const ShellIntegration::ShortcutLocations& creation_locations, + ShortcutCreationPolicy creation_policy) { DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); // Shortcut paths under which to create shortcuts. @@ -375,7 +388,7 @@ bool CreatePlatformShortcuts( return false; if (!CreateShortcutsInPaths(web_app_path, shortcut_info, shortcut_paths, - NULL)) + creation_policy, NULL)) return false; if (pin_to_taskbar) { @@ -411,7 +424,8 @@ void UpdatePlatformShortcuts( GetShortcutLocationsAndDeleteShortcuts( web_app_path, shortcut_info.profile_path, old_app_title, &was_pinned_to_taskbar, &shortcut_paths); - CreateShortcutsInPaths(web_app_path, shortcut_info, shortcut_paths, NULL); + CreateShortcutsInPaths(web_app_path, shortcut_info, shortcut_paths, + ALLOW_DUPLICATE_SHORTCUTS, NULL); // If the shortcut was pinned to the taskbar, // GetShortcutLocationsAndDeleteShortcuts will have deleted it. In that // case, re-pin it. |