summaryrefslogtreecommitdiffstats
path: root/chrome/browser/web_applications
diff options
context:
space:
mode:
authorjackhou@chromium.org <jackhou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-08 04:41:28 +0000
committerjackhou@chromium.org <jackhou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-08 04:41:28 +0000
commit148850857860a6044c4a3dc6b203ad3e014e0b33 (patch)
tree4be95ccc5e19dc66c4ae36e4c54667b01fc98cb0 /chrome/browser/web_applications
parent3b1f8af592c1fec8066b837efbeb4183e1c9ee46 (diff)
downloadchromium_src-148850857860a6044c4a3dc6b203ad3e014e0b33.zip
chromium_src-148850857860a6044c4a3dc6b203ad3e014e0b33.tar.gz
chromium_src-148850857860a6044c4a3dc6b203ad3e014e0b33.tar.bz2
Make ShortcutManager directly pass Profile* and Extension* to web_app::CreateShortcuts.
This simplifies ShortcutManager as it no longer needs to create a ShortcutInfo. It also means we can add file handler info to just web_app.cc. The remaining code paths for "web_app::CreateShortcut*" are: create_application_shortcut_view create_application_shortcuts_dialog_gtk app_list_view_delegate.cc app_list_service_mac.mm All of the above do not need to pass file handler info. BUG=356889 COLLABORATOR=mgiuca@chromium.org Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=261665 Review URL: https://codereview.chromium.org/205563005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262307 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/web_applications')
-rw-r--r--chrome/browser/web_applications/web_app.cc76
-rw-r--r--chrome/browser/web_applications/web_app.h43
-rw-r--r--chrome/browser/web_applications/web_app_mac.mm22
3 files changed, 83 insertions, 58 deletions
diff --git a/chrome/browser/web_applications/web_app.cc b/chrome/browser/web_applications/web_app.cc
index 0d90975..c31ccb7 100644
--- a/chrome/browser/web_applications/web_app.cc
+++ b/chrome/browser/web_applications/web_app.cc
@@ -86,6 +86,17 @@ void UpdateShortcutsOnFileThread(
shortcut_data_dir, old_app_title, shortcut_info);
}
+void UpdateAllShortcutsForShortcutInfo(
+ const base::string16& old_app_title,
+ const ShellIntegration::ShortcutInfo& shortcut_info) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ BrowserThread::PostTask(
+ BrowserThread::FILE,
+ FROM_HERE,
+ base::Bind(&UpdateShortcutsOnFileThread, old_app_title, shortcut_info));
+}
+
void OnImageLoaded(ShellIntegration::ShortcutInfo shortcut_info,
web_app::ShortcutInfoCallback callback,
const gfx::ImageFamily& image_family) {
@@ -134,6 +145,19 @@ base::FilePath GetSanitizedFileName(const base::string16& name) {
return base::FilePath(file_name);
}
+bool CreateShortcutsOnFileThread(
+ ShortcutCreationReason reason,
+ const ShellIntegration::ShortcutLocations& locations,
+ const ShellIntegration::ShortcutInfo& shortcut_info) {
+ 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, locations, reason);
+}
+
} // namespace internals
void GetShortcutInfoForTab(content::WebContents* web_contents,
@@ -298,50 +322,52 @@ std::string GetExtensionIdFromApplicationName(const std::string& app_name) {
return app_name.substr(prefix.length());
}
-void CreateShortcuts(
- const ShellIntegration::ShortcutInfo& shortcut_info,
- const ShellIntegration::ShortcutLocations& creation_locations,
- ShortcutCreationReason creation_reason) {
+void CreateShortcutsForShortcutInfo(
+ web_app::ShortcutCreationReason reason,
+ const ShellIntegration::ShortcutLocations& locations,
+ const ShellIntegration::ShortcutInfo& shortcut_info) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
BrowserThread::PostTask(
BrowserThread::FILE,
FROM_HERE,
- base::Bind(base::IgnoreResult(&CreateShortcutsOnFileThread),
- shortcut_info, creation_locations, creation_reason));
+ base::Bind(
+ base::IgnoreResult(&web_app::internals::CreateShortcutsOnFileThread),
+ reason, locations, shortcut_info));
}
-void DeleteAllShortcuts(const ShellIntegration::ShortcutInfo& shortcut_info) {
+void CreateShortcuts(
+ ShortcutCreationReason reason,
+ const ShellIntegration::ShortcutLocations& locations,
+ Profile* profile,
+ const extensions::Extension* app) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- BrowserThread::PostTask(
- BrowserThread::FILE,
- FROM_HERE,
- base::Bind(&DeleteShortcutsOnFileThread, shortcut_info));
+ web_app::UpdateShortcutInfoAndIconForApp(
+ app,
+ profile,
+ base::Bind(&CreateShortcutsForShortcutInfo, reason, locations));
}
-void UpdateAllShortcuts(const base::string16& old_app_title,
- const ShellIntegration::ShortcutInfo& shortcut_info) {
+void DeleteAllShortcuts(Profile* profile, const extensions::Extension* app) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
BrowserThread::PostTask(
BrowserThread::FILE,
FROM_HERE,
- base::Bind(&UpdateShortcutsOnFileThread, old_app_title, shortcut_info));
+ base::Bind(&DeleteShortcutsOnFileThread,
+ web_app::ShortcutInfoForExtensionAndProfile(app, profile)));
}
-bool CreateShortcutsOnFileThread(
- const ShellIntegration::ShortcutInfo& shortcut_info,
- const ShellIntegration::ShortcutLocations& creation_locations,
- ShortcutCreationReason creation_reason) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+void UpdateAllShortcuts(const base::string16& old_app_title,
+ Profile* profile,
+ const extensions::Extension* app) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- 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_reason);
+ web_app::UpdateShortcutInfoAndIconForApp(
+ app,
+ profile,
+ base::Bind(&UpdateAllShortcutsForShortcutInfo, old_app_title));
}
bool IsValidUrl(const GURL& url) {
diff --git a/chrome/browser/web_applications/web_app.h b/chrome/browser/web_applications/web_app.h
index 79ea5a5..468bdba 100644
--- a/chrome/browser/web_applications/web_app.h
+++ b/chrome/browser/web_applications/web_app.h
@@ -90,33 +90,31 @@ std::string GenerateApplicationNameFromExtensionId(const std::string& id);
// Extracts the extension id from the app name.
std::string GetExtensionIdFromApplicationName(const std::string& app_name);
-// Creates shortcuts for web application based on given shortcut data.
+// Create shortcuts for web application based on given shortcut data.
// |shortcut_info| contains information about the shortcuts to create, and
// |creation_locations| contains information about where to create them.
+void CreateShortcutsForShortcutInfo(
+ web_app::ShortcutCreationReason reason,
+ const ShellIntegration::ShortcutLocations& locations,
+ const ShellIntegration::ShortcutInfo& shortcut_info);
+
+// Creates shortcuts for an app.
void CreateShortcuts(
- const ShellIntegration::ShortcutInfo& shortcut_info,
- const ShellIntegration::ShortcutLocations& creation_locations,
- ShortcutCreationReason creation_reason);
+ ShortcutCreationReason reason,
+ const ShellIntegration::ShortcutLocations& locations,
+ Profile* profile,
+ const extensions::Extension* app);
-// Delete all the shortcuts that have been created for the given
-// |shortcut_data| in the profile with |profile_path|.
-void DeleteAllShortcuts(const ShellIntegration::ShortcutInfo& shortcut_info);
+// Delete all shortcuts that have been created for the given profile and
+// extension.
+void DeleteAllShortcuts(Profile* profile, const extensions::Extension* app);
// Updates shortcuts for web application based on given shortcut data. This
// refreshes existing shortcuts and their icons, but does not create new ones.
// |old_app_title| contains the title of the app prior to this update.
-// |shortcut_info| contains information about the shortcuts to update.
void UpdateAllShortcuts(const base::string16& old_app_title,
- const ShellIntegration::ShortcutInfo& shortcut_info);
-
-// Creates a shortcut. Must be called on the file thread. This is used to
-// implement CreateShortcuts() above, and can also be used directly from the
-// file thread. |shortcut_info| contains info about the shortcut to create, and
-// |creation_locations| contains information about where to create them.
-bool CreateShortcutsOnFileThread(
- const ShellIntegration::ShortcutInfo& shortcut_info,
- const ShellIntegration::ShortcutLocations& creation_locations,
- ShortcutCreationReason creation_reason);
+ Profile* profile,
+ const extensions::Extension* app);
// Returns true if given url is a valid web app url.
bool IsValidUrl(const GURL& url);
@@ -145,6 +143,15 @@ std::vector<base::FilePath> GetShortcutPaths(
const ShellIntegration::ShortcutLocations& creation_locations);
#endif
+// Creates a shortcut. Must be called on the file thread. This is used to
+// implement CreateShortcuts() above, and can also be used directly from the
+// file thread. |shortcut_info| contains info about the shortcut to create, and
+// |creation_locations| contains information about where to create them.
+bool CreateShortcutsOnFileThread(
+ ShortcutCreationReason reason,
+ const ShellIntegration::ShortcutLocations& locations,
+ const ShellIntegration::ShortcutInfo& shortcut_info);
+
// Implemented for each platform, does the platform specific parts of creating
// shortcuts. Used internally by CreateShortcutsOnFileThread.
// |shortcut_data_path| is where to store any resources created for the
diff --git a/chrome/browser/web_applications/web_app_mac.mm b/chrome/browser/web_applications/web_app_mac.mm
index 903f243..46b689b 100644
--- a/chrome/browser/web_applications/web_app_mac.mm
+++ b/chrome/browser/web_applications/web_app_mac.mm
@@ -417,17 +417,6 @@ ShellIntegration::ShortcutInfo BuildShortcutInfoFromBundle(
return shortcut_info;
}
-void CreateShortcutsAndRunCallback(
- const base::Closure& close_callback,
- 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::SHORTCUT_CREATION_BY_USER);
- if (!close_callback.is_null())
- close_callback.Run();
-}
-
} // namespace
namespace chrome {
@@ -437,10 +426,13 @@ void ShowCreateChromeAppShortcutsDialog(gfx::NativeWindow /*parent_window*/,
const extensions::Extension* app,
const base::Closure& close_callback) {
// Normally we would show a dialog, but since we always create the app
- // shortcut in /Applications there are no options for the user to choose.
- web_app::UpdateShortcutInfoAndIconForApp(
- app, profile,
- base::Bind(&CreateShortcutsAndRunCallback, close_callback));
+ // shortcut in ~/Applications there are no options for the user to choose.
+ web_app::CreateShortcuts(web_app::SHORTCUT_CREATION_BY_USER,
+ ShellIntegration::ShortcutLocations(),
+ profile,
+ app);
+ if (!close_callback.is_null())
+ close_callback.Run();
}
} // namespace chrome