summaryrefslogtreecommitdiffstats
path: root/chrome/browser/web_applications
diff options
context:
space:
mode:
authormgiuca@chromium.org <mgiuca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-03 04:42:17 +0000
committermgiuca@chromium.org <mgiuca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-03 04:42:17 +0000
commitcf610e64c266bbfd179392afe3d0d5ea3d70d642 (patch)
tree6bde75c83a8e37aadf3c9412302ccf9edb371df6 /chrome/browser/web_applications
parent9faa02dd3761bdfde3354637643375e948681b7e (diff)
downloadchromium_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
Diffstat (limited to 'chrome/browser/web_applications')
-rw-r--r--chrome/browser/web_applications/web_app.cc11
-rw-r--r--chrome/browser/web_applications/web_app.h17
-rw-r--r--chrome/browser/web_applications/web_app_android.cc3
-rw-r--r--chrome/browser/web_applications/web_app_linux.cc6
-rw-r--r--chrome/browser/web_applications/web_app_mac.mm3
-rw-r--r--chrome/browser/web_applications/web_app_win.cc24
6 files changed, 48 insertions, 16 deletions
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.