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

Unified Diff: chrome/browser/web_applications/web_app_mac.mm

Issue 12912003: [mac] Create app shortcuts in a subfolder of /Applications (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fail if dirname of chrome apps dir doesn't exist or isn't a directory. Created 7 years, 9 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
Index: chrome/browser/web_applications/web_app_mac.mm
diff --git a/chrome/browser/web_applications/web_app_mac.mm b/chrome/browser/web_applications/web_app_mac.mm
index 2c6154800a6a4b4f57b95639328c727be7316053..dc6b9300179c7ee3c408193301a8dd78da2d44dd 100644
--- a/chrome/browser/web_applications/web_app_mac.mm
+++ b/chrome/browser/web_applications/web_app_mac.mm
@@ -80,11 +80,24 @@ bool AddBitmapImageRepToIconFamily(IconFamily* icon_family,
}
}
+base::FilePath GetWritableApplicationsDirectory() {
+ base::FilePath path;
+ if (base::mac::GetLocalDirectory(NSApplicationDirectory, &path) &&
+ file_util::PathIsWritable(path)) {
+ return path;
+ }
+ if (base::mac::GetUserDirectory(NSApplicationDirectory, &path))
+ return path;
+ return base::FilePath();
+}
+
} // namespace
namespace web_app {
+const char kChromeAppDirName[] = "Chrome Apps.localized";
+
WebAppShortcutCreator::WebAppShortcutCreator(
const base::FilePath& user_data_dir,
const ShellIntegration::ShortcutInfo& shortcut_info,
@@ -119,7 +132,15 @@ bool WebAppShortcutCreator::CreateShortcut() {
if (!UpdateIcon(staging_path))
return false;
- base::FilePath dst_path = GetDestinationPath(app_file_name);
+ base::FilePath dst_path = GetDestinationPath();
+ if (dst_path.empty() || !file_util::DirectoryExists(dst_path.DirName())) {
+ LOG(ERROR) << "Couldn't find an Applications directory to copy app to.";
+ return false;
+ }
+ if (!file_util::CreateDirectory(dst_path)) {
+ LOG(ERROR) << "Creating directory " << dst_path.value() << " failed.";
+ return false;
+ }
if (!file_util::CopyDirectory(staging_path, dst_path, true)) {
LOG(ERROR) << "Copying app to dst path: " << dst_path.value() << " failed";
return false;
@@ -137,18 +158,11 @@ base::FilePath WebAppShortcutCreator::GetAppLoaderPath() const {
base::mac::NSToCFCast(@"app_mode_loader.app"));
}
-base::FilePath WebAppShortcutCreator::GetDestinationPath(
- const base::FilePath& app_file_name) const {
- base::FilePath path;
- if (base::mac::GetLocalDirectory(NSApplicationDirectory, &path) &&
- file_util::PathIsWritable(path)) {
- return path;
- }
-
- if (base::mac::GetUserDirectory(NSApplicationDirectory, &path))
+base::FilePath WebAppShortcutCreator::GetDestinationPath() const {
+ base::FilePath path = GetWritableApplicationsDirectory();
+ if (path.empty())
return path;
-
- return base::FilePath();
+ return path.Append(kChromeAppDirName);
}
bool WebAppShortcutCreator::UpdatePlist(const base::FilePath& app_path) const {
« no previous file with comments | « chrome/browser/web_applications/web_app_mac.h ('k') | chrome/browser/web_applications/web_app_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698