| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "chrome/browser/web_applications/web_app_mac.h" | 5 #import "chrome/browser/web_applications/web_app_mac.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 NSDictionary* plist = ReadPlist(GetPlistPath(bundle_path)); | 207 NSDictionary* plist = ReadPlist(GetPlistPath(bundle_path)); |
| 208 base::FilePath user_data_dir; | 208 base::FilePath user_data_dir; |
| 209 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 209 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 210 DCHECK(!user_data_dir.empty()); | 210 DCHECK(!user_data_dir.empty()); |
| 211 return base::StartsWith( | 211 return base::StartsWith( |
| 212 base::SysNSStringToUTF8( | 212 base::SysNSStringToUTF8( |
| 213 [plist valueForKey:app_mode::kCrAppModeUserDataDirKey]), | 213 [plist valueForKey:app_mode::kCrAppModeUserDataDirKey]), |
| 214 user_data_dir.value(), base::CompareCase::SENSITIVE); | 214 user_data_dir.value(), base::CompareCase::SENSITIVE); |
| 215 } | 215 } |
| 216 | 216 |
| 217 void LaunchShimOnFileThread( | 217 void LaunchShimOnFileThread(web_app::ShortcutInfo* shortcut_info, |
| 218 std::unique_ptr<web_app::ShortcutInfo> shortcut_info, | 218 bool launched_after_rebuild) { |
| 219 bool launched_after_rebuild) { | |
| 220 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); | 219 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
| 221 base::FilePath shim_path = web_app::GetAppInstallPath(*shortcut_info); | 220 base::FilePath shim_path = web_app::GetAppInstallPath(*shortcut_info); |
| 222 | 221 |
| 223 if (shim_path.empty() || | 222 if (shim_path.empty() || |
| 224 !base::PathExists(shim_path) || | 223 !base::PathExists(shim_path) || |
| 225 !HasSameUserDataDir(shim_path)) { | 224 !HasSameUserDataDir(shim_path)) { |
| 226 // The user may have deleted the copy in the Applications folder, use the | 225 // The user may have deleted the copy in the Applications folder, use the |
| 227 // one in the web app's |app_data_dir_|. | 226 // one in the web app's |app_data_dir_|. |
| 228 base::FilePath app_data_dir = web_app::GetWebAppDataDirectory( | 227 base::FilePath app_data_dir = web_app::GetWebAppDataDirectory( |
| 229 shortcut_info->profile_path, shortcut_info->extension_id, GURL()); | 228 shortcut_info->profile_path, shortcut_info->extension_id, GURL()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 258 if (AppShimsDisabledForTest() && | 257 if (AppShimsDisabledForTest() && |
| 259 !g_app_shims_allow_update_and_launch_in_tests) { | 258 !g_app_shims_allow_update_and_launch_in_tests) { |
| 260 return; | 259 return; |
| 261 } | 260 } |
| 262 | 261 |
| 263 web_app::WebAppShortcutCreator shortcut_creator(app_data_path, | 262 web_app::WebAppShortcutCreator shortcut_creator(app_data_path, |
| 264 &shortcut_info); | 263 &shortcut_info); |
| 265 shortcut_creator.UpdateShortcuts(); | 264 shortcut_creator.UpdateShortcuts(); |
| 266 } | 265 } |
| 267 | 266 |
| 268 void UpdateAndLaunchShimOnFileThread( | 267 void UpdateAndLaunchShimOnFileThread(web_app::ShortcutInfo* shortcut_info) { |
| 269 std::unique_ptr<web_app::ShortcutInfo> shortcut_info) { | |
| 270 base::FilePath shortcut_data_dir = web_app::GetWebAppDataDirectory( | 268 base::FilePath shortcut_data_dir = web_app::GetWebAppDataDirectory( |
| 271 shortcut_info->profile_path, shortcut_info->extension_id, GURL()); | 269 shortcut_info->profile_path, shortcut_info->extension_id, GURL()); |
| 272 UpdatePlatformShortcutsInternal(shortcut_data_dir, base::string16(), | 270 UpdatePlatformShortcutsInternal(shortcut_data_dir, base::string16(), |
| 273 *shortcut_info); | 271 *shortcut_info); |
| 274 LaunchShimOnFileThread(std::move(shortcut_info), true); | 272 LaunchShimOnFileThread(shortcut_info, true); |
| 275 } | 273 } |
| 276 | 274 |
| 277 void UpdateAndLaunchShim(std::unique_ptr<web_app::ShortcutInfo> shortcut_info) { | 275 void UpdateAndLaunchShim(std::unique_ptr<web_app::ShortcutInfo> shortcut_info) { |
| 278 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, | 276 auto* shortcut_info_ptr = shortcut_info.get(); |
| 279 base::Bind(&UpdateAndLaunchShimOnFileThread, | 277 content::BrowserThread::PostTaskAndReply( |
| 280 base::Passed(&shortcut_info))); | 278 content::BrowserThread::FILE, FROM_HERE, |
| 279 base::Bind(&UpdateAndLaunchShimOnFileThread, shortcut_info_ptr), |
| 280 base::Bind(&web_app::internals::DeleteShortcutInfoOnUIThread, |
| 281 base::Passed(&shortcut_info), base::Closure())); |
| 281 } | 282 } |
| 282 | 283 |
| 283 void RebuildAppAndLaunch(std::unique_ptr<web_app::ShortcutInfo> shortcut_info) { | 284 void RebuildAppAndLaunch(std::unique_ptr<web_app::ShortcutInfo> shortcut_info) { |
| 284 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 285 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 285 if (shortcut_info->extension_id == app_mode::kAppListModeId) { | 286 if (shortcut_info->extension_id == app_mode::kAppListModeId) { |
| 286 AppListService* app_list_service = AppListService::Get(); | 287 AppListService* app_list_service = AppListService::Get(); |
| 287 app_list_service->CreateShortcut(); | 288 app_list_service->CreateShortcut(); |
| 288 app_list_service->Show(); | 289 app_list_service->Show(); |
| 289 return; | 290 return; |
| 290 } | 291 } |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 base::Version full_version(base::SysNSStringToUTF8(version_string)); | 520 base::Version full_version(base::SysNSStringToUTF8(version_string)); |
| 520 uint32_t major_version = 0; | 521 uint32_t major_version = 0; |
| 521 if (full_version.IsValid()) | 522 if (full_version.IsValid()) |
| 522 major_version = full_version.components()[0]; | 523 major_version = full_version.components()[0]; |
| 523 UMA_HISTOGRAM_SPARSE_SLOWLY("Apps.AppShimErrorVersion", major_version); | 524 UMA_HISTOGRAM_SPARSE_SLOWLY("Apps.AppShimErrorVersion", major_version); |
| 524 | 525 |
| 525 return BuildShortcutInfoFromBundle(bundle_path); | 526 return BuildShortcutInfoFromBundle(bundle_path); |
| 526 } | 527 } |
| 527 | 528 |
| 528 void RevealAppShimInFinderForAppOnFileThread( | 529 void RevealAppShimInFinderForAppOnFileThread( |
| 529 std::unique_ptr<web_app::ShortcutInfo> shortcut_info, | 530 web_app::ShortcutInfo* shortcut_info, |
| 530 const base::FilePath& app_path) { | 531 const base::FilePath& app_path) { |
| 531 web_app::WebAppShortcutCreator shortcut_creator(app_path, | 532 web_app::WebAppShortcutCreator shortcut_creator(app_path, shortcut_info); |
| 532 shortcut_info.get()); | |
| 533 shortcut_creator.RevealAppShimInFinder(); | 533 shortcut_creator.RevealAppShimInFinder(); |
| 534 } | 534 } |
| 535 | 535 |
| 536 // Mac-specific version of web_app::ShouldCreateShortcutFor() used during batch | 536 // Mac-specific version of web_app::ShouldCreateShortcutFor() used during batch |
| 537 // upgrades to ensure all shortcuts a user may still have are repaired when | 537 // upgrades to ensure all shortcuts a user may still have are repaired when |
| 538 // required by a Chrome upgrade. | 538 // required by a Chrome upgrade. |
| 539 bool ShouldUpgradeShortcutFor(Profile* profile, | 539 bool ShouldUpgradeShortcutFor(Profile* profile, |
| 540 const extensions::Extension* extension) { | 540 const extensions::Extension* extension) { |
| 541 if (extension->location() == extensions::Manifest::COMPONENT || | 541 if (extension->location() == extensions::Manifest::COMPONENT || |
| 542 !extensions::ui_util::CanDisplayInAppLauncher(extension, profile)) { | 542 !extensions::ui_util::CanDisplayInAppLauncher(extension, profile)) { |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 WebAppShortcutCreator shortcut_creator(base::FilePath(), &shortcut_info); | 970 WebAppShortcutCreator shortcut_creator(base::FilePath(), &shortcut_info); |
| 971 return shortcut_creator.GetApplicationsShortcutPath(); | 971 return shortcut_creator.GetApplicationsShortcutPath(); |
| 972 } | 972 } |
| 973 | 973 |
| 974 void MaybeLaunchShortcut(std::unique_ptr<ShortcutInfo> shortcut_info) { | 974 void MaybeLaunchShortcut(std::unique_ptr<ShortcutInfo> shortcut_info) { |
| 975 if (AppShimsDisabledForTest() && | 975 if (AppShimsDisabledForTest() && |
| 976 !g_app_shims_allow_update_and_launch_in_tests) { | 976 !g_app_shims_allow_update_and_launch_in_tests) { |
| 977 return; | 977 return; |
| 978 } | 978 } |
| 979 | 979 |
| 980 content::BrowserThread::PostTask( | 980 auto* shortcut_info_ptr = shortcut_info.get(); |
| 981 content::BrowserThread::PostTaskAndReply( |
| 981 content::BrowserThread::FILE, FROM_HERE, | 982 content::BrowserThread::FILE, FROM_HERE, |
| 982 base::Bind(&LaunchShimOnFileThread, base::Passed(&shortcut_info), false)); | 983 base::Bind(&LaunchShimOnFileThread, shortcut_info_ptr, false), |
| 984 base::Bind(&web_app::internals::DeleteShortcutInfoOnUIThread, |
| 985 base::Passed(&shortcut_info), base::Closure())); |
| 983 } | 986 } |
| 984 | 987 |
| 985 bool MaybeRebuildShortcut(const base::CommandLine& command_line) { | 988 bool MaybeRebuildShortcut(const base::CommandLine& command_line) { |
| 986 if (!command_line.HasSwitch(app_mode::kAppShimError)) | 989 if (!command_line.HasSwitch(app_mode::kAppShimError)) |
| 987 return false; | 990 return false; |
| 988 | 991 |
| 989 base::PostTaskWithTraitsAndReplyWithResult( | 992 base::PostTaskWithTraitsAndReplyWithResult( |
| 990 FROM_HERE, base::TaskTraits().MayBlock().WithPriority( | 993 FROM_HERE, base::TaskTraits().MayBlock().WithPriority( |
| 991 base::TaskPriority::BACKGROUND), | 994 base::TaskPriority::BACKGROUND), |
| 992 base::Bind(&RecordAppShimErrorAndBuildShortcutInfo, | 995 base::Bind(&RecordAppShimErrorAndBuildShortcutInfo, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1015 web_app::UpdateAllShortcuts(base::string16(), profile, extension, | 1018 web_app::UpdateAllShortcuts(base::string16(), profile, extension, |
| 1016 latch->NoOpClosure()); | 1019 latch->NoOpClosure()); |
| 1017 } | 1020 } |
| 1018 } | 1021 } |
| 1019 } | 1022 } |
| 1020 | 1023 |
| 1021 void RevealAppShimInFinderForApp(Profile* profile, | 1024 void RevealAppShimInFinderForApp(Profile* profile, |
| 1022 const extensions::Extension* app) { | 1025 const extensions::Extension* app) { |
| 1023 std::unique_ptr<web_app::ShortcutInfo> shortcut_info = | 1026 std::unique_ptr<web_app::ShortcutInfo> shortcut_info = |
| 1024 ShortcutInfoForExtensionAndProfile(app, profile); | 1027 ShortcutInfoForExtensionAndProfile(app, profile); |
| 1025 content::BrowserThread::PostTask( | 1028 auto* shortcut_info_ptr = shortcut_info.get(); |
| 1029 content::BrowserThread::PostTaskAndReply( |
| 1026 content::BrowserThread::FILE, FROM_HERE, | 1030 content::BrowserThread::FILE, FROM_HERE, |
| 1027 base::Bind(&RevealAppShimInFinderForAppOnFileThread, | 1031 base::Bind(&RevealAppShimInFinderForAppOnFileThread, shortcut_info_ptr, |
| 1028 base::Passed(&shortcut_info), app->path())); | 1032 app->path()), |
| 1033 base::Bind(&web_app::internals::DeleteShortcutInfoOnUIThread, |
| 1034 base::Passed(&shortcut_info), base::Closure())); |
| 1029 } | 1035 } |
| 1030 | 1036 |
| 1031 namespace internals { | 1037 namespace internals { |
| 1032 | 1038 |
| 1033 bool CreatePlatformShortcuts( | 1039 bool CreatePlatformShortcuts(const base::FilePath& app_data_path, |
| 1034 const base::FilePath& app_data_path, | 1040 ShortcutInfo* shortcut_info, |
| 1035 std::unique_ptr<ShortcutInfo> shortcut_info, | 1041 const ShortcutLocations& creation_locations, |
| 1036 const ShortcutLocations& creation_locations, | 1042 ShortcutCreationReason creation_reason) { |
| 1037 ShortcutCreationReason creation_reason) { | |
| 1038 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); | 1043 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
| 1039 if (AppShimsDisabledForTest()) | 1044 if (AppShimsDisabledForTest()) |
| 1040 return true; | 1045 return true; |
| 1041 | 1046 |
| 1042 WebAppShortcutCreator shortcut_creator(app_data_path, shortcut_info.get()); | 1047 WebAppShortcutCreator shortcut_creator(app_data_path, shortcut_info); |
| 1043 return shortcut_creator.CreateShortcuts(creation_reason, creation_locations); | 1048 return shortcut_creator.CreateShortcuts(creation_reason, creation_locations); |
| 1044 } | 1049 } |
| 1045 | 1050 |
| 1046 void DeletePlatformShortcuts(const base::FilePath& app_data_path, | 1051 void DeletePlatformShortcuts(const base::FilePath& app_data_path, |
| 1047 std::unique_ptr<ShortcutInfo> shortcut_info) { | 1052 ShortcutInfo* shortcut_info) { |
| 1048 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); | 1053 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
| 1049 WebAppShortcutCreator shortcut_creator(app_data_path, shortcut_info.get()); | 1054 WebAppShortcutCreator shortcut_creator(app_data_path, shortcut_info); |
| 1050 shortcut_creator.DeleteShortcuts(); | 1055 shortcut_creator.DeleteShortcuts(); |
| 1051 } | 1056 } |
| 1052 | 1057 |
| 1053 void UpdatePlatformShortcuts(const base::FilePath& app_data_path, | 1058 void UpdatePlatformShortcuts(const base::FilePath& app_data_path, |
| 1054 const base::string16& old_app_title, | 1059 const base::string16& old_app_title, |
| 1055 std::unique_ptr<ShortcutInfo> shortcut_info) { | 1060 ShortcutInfo* shortcut_info) { |
| 1056 UpdatePlatformShortcutsInternal(app_data_path, old_app_title, *shortcut_info); | 1061 UpdatePlatformShortcutsInternal(app_data_path, old_app_title, *shortcut_info); |
| 1057 } | 1062 } |
| 1058 | 1063 |
| 1059 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path) { | 1064 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path) { |
| 1060 const std::string profile_base_name = profile_path.BaseName().value(); | 1065 const std::string profile_base_name = profile_path.BaseName().value(); |
| 1061 std::vector<base::FilePath> bundles = GetAllAppBundlesInPath( | 1066 std::vector<base::FilePath> bundles = GetAllAppBundlesInPath( |
| 1062 profile_path.Append(chrome::kWebAppDirname), profile_base_name); | 1067 profile_path.Append(chrome::kWebAppDirname), profile_base_name); |
| 1063 | 1068 |
| 1064 for (std::vector<base::FilePath>::const_iterator it = bundles.begin(); | 1069 for (std::vector<base::FilePath>::const_iterator it = bundles.begin(); |
| 1065 it != bundles.end(); ++it) { | 1070 it != bundles.end(); ++it) { |
| 1066 std::unique_ptr<web_app::ShortcutInfo> shortcut_info = | 1071 std::unique_ptr<web_app::ShortcutInfo> shortcut_info = |
| 1067 BuildShortcutInfoFromBundle(*it); | 1072 BuildShortcutInfoFromBundle(*it); |
| 1068 WebAppShortcutCreator shortcut_creator(it->DirName(), shortcut_info.get()); | 1073 WebAppShortcutCreator shortcut_creator(it->DirName(), shortcut_info.get()); |
| 1069 shortcut_creator.DeleteShortcuts(); | 1074 shortcut_creator.DeleteShortcuts(); |
| 1070 } | 1075 } |
| 1071 } | 1076 } |
| 1072 | 1077 |
| 1073 } // namespace internals | 1078 } // namespace internals |
| 1074 | 1079 |
| 1075 } // namespace web_app | 1080 } // namespace web_app |
| OLD | NEW |