summaryrefslogtreecommitdiffstats
path: root/chrome/browser/web_applications
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/web_applications')
-rw-r--r--chrome/browser/web_applications/web_app_mac.h3
-rw-r--r--chrome/browser/web_applications/web_app_mac.mm38
-rw-r--r--chrome/browser/web_applications/web_app_mac_unittest.mm8
3 files changed, 31 insertions, 18 deletions
diff --git a/chrome/browser/web_applications/web_app_mac.h b/chrome/browser/web_applications/web_app_mac.h
index 177142a..8f9b90c 100644
--- a/chrome/browser/web_applications/web_app_mac.h
+++ b/chrome/browser/web_applications/web_app_mac.h
@@ -43,8 +43,7 @@ class WebAppShortcutCreator {
base::FilePath GetAppLoaderPath() const;
// Returns a path to the destination where the app should be written to.
- virtual base::FilePath GetDestinationPath(
- const base::FilePath& app_file_name) const;
+ virtual base::FilePath GetDestinationPath() const;
// Updates the plist inside |app_path| with information about the app.
bool UpdatePlist(const base::FilePath& app_path) const;
diff --git a/chrome/browser/web_applications/web_app_mac.mm b/chrome/browser/web_applications/web_app_mac.mm
index 2c61548..dc6b930 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 {
diff --git a/chrome/browser/web_applications/web_app_mac_unittest.mm b/chrome/browser/web_applications/web_app_mac_unittest.mm
index 75643f62..069a584 100644
--- a/chrome/browser/web_applications/web_app_mac_unittest.mm
+++ b/chrome/browser/web_applications/web_app_mac_unittest.mm
@@ -38,7 +38,7 @@ class WebAppShortcutCreatorMock : public web_app::WebAppShortcutCreator {
UTF8ToUTF16("fake.cfbundleidentifier")) {
}
- MOCK_CONST_METHOD1(GetDestinationPath, base::FilePath(const base::FilePath&));
+ MOCK_CONST_METHOD0(GetDestinationPath, base::FilePath());
MOCK_CONST_METHOD1(RevealGeneratedBundleInFinder,
void (const base::FilePath&));
};
@@ -67,7 +67,7 @@ TEST(WebAppShortcutCreatorTest, CreateShortcut) {
base::FilePath dst_path = dst_folder.Append(UTF16ToUTF8(info.title) + ".app");
NiceMock<WebAppShortcutCreatorMock> shortcut_creator(info);
- EXPECT_CALL(shortcut_creator, GetDestinationPath(_))
+ EXPECT_CALL(shortcut_creator, GetDestinationPath())
.WillRepeatedly(Return(dst_folder));
EXPECT_CALL(shortcut_creator, RevealGeneratedBundleInFinder(dst_path));
@@ -105,7 +105,7 @@ TEST(WebAppShortcutCreatorTest, RunShortcut) {
base::FilePath dst_path = dst_folder.Append(UTF16ToUTF8(info.title) + ".app");
NiceMock<WebAppShortcutCreatorMock> shortcut_creator(info);
- EXPECT_CALL(shortcut_creator, GetDestinationPath(_))
+ EXPECT_CALL(shortcut_creator, GetDestinationPath())
.WillRepeatedly(Return(dst_folder));
EXPECT_CALL(shortcut_creator, RevealGeneratedBundleInFinder(dst_path));
@@ -126,7 +126,7 @@ TEST(WebAppShortcutCreatorTest, CreateFailure) {
scoped_temp_dir.path().Append("not-existent").Append("name.app");
NiceMock<WebAppShortcutCreatorMock> shortcut_creator(GetShortcutInfo());
- EXPECT_CALL(shortcut_creator, GetDestinationPath(_))
+ EXPECT_CALL(shortcut_creator, GetDestinationPath())
.WillRepeatedly(Return(non_existent_path));
EXPECT_FALSE(shortcut_creator.CreateShortcut());
}