| 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 web_app::ShortcutInfo* 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, |
| 280 base::Unretained(shortcut_info_ptr)), |
| 281 base::Bind(&web_app::internals::DeleteShortcutInfoOnUIThread, |
| 282 base::Passed(&shortcut_info), base::Closure())); |
| 281 } | 283 } |
| 282 | 284 |
| 283 void RebuildAppAndLaunch(std::unique_ptr<web_app::ShortcutInfo> shortcut_info) { | 285 void RebuildAppAndLaunch(std::unique_ptr<web_app::ShortcutInfo> shortcut_info) { |
| 284 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 286 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 285 if (shortcut_info->extension_id == app_mode::kAppListModeId) { | 287 if (shortcut_info->extension_id == app_mode::kAppListModeId) { |
| 286 AppListService* app_list_service = AppListService::Get(); | 288 AppListService* app_list_service = AppListService::Get(); |
| 287 app_list_service->CreateShortcut(); | 289 app_list_service->CreateShortcut(); |
| 288 app_list_service->Show(); | 290 app_list_service->Show(); |
| 289 return; | 291 return; |
| 290 } | 292 } |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 base::Version full_version(base::SysNSStringToUTF8(version_string)); | 521 base::Version full_version(base::SysNSStringToUTF8(version_string)); |
| 520 uint32_t major_version = 0; | 522 uint32_t major_version = 0; |
| 521 if (full_version.IsValid()) | 523 if (full_version.IsValid()) |
| 522 major_version = full_version.components()[0]; | 524 major_version = full_version.components()[0]; |
| 523 UMA_HISTOGRAM_SPARSE_SLOWLY("Apps.AppShimErrorVersion", major_version); | 525 UMA_HISTOGRAM_SPARSE_SLOWLY("Apps.AppShimErrorVersion", major_version); |
| 524 | 526 |
| 525 return BuildShortcutInfoFromBundle(bundle_path); | 527 return BuildShortcutInfoFromBundle(bundle_path); |
| 526 } | 528 } |
| 527 | 529 |
| 528 void RevealAppShimInFinderForAppOnFileThread( | 530 void RevealAppShimInFinderForAppOnFileThread( |
| 529 std::unique_ptr<web_app::ShortcutInfo> shortcut_info, | 531 web_app::ShortcutInfo* shortcut_info, |
| 530 const base::FilePath& app_path) { | 532 const base::FilePath& app_path) { |
| 531 web_app::WebAppShortcutCreator shortcut_creator(app_path, | 533 web_app::WebAppShortcutCreator shortcut_creator(app_path, shortcut_info); |
| 532 shortcut_info.get()); | |
| 533 shortcut_creator.RevealAppShimInFinder(); | 534 shortcut_creator.RevealAppShimInFinder(); |
| 534 } | 535 } |
| 535 | 536 |
| 536 // Mac-specific version of web_app::ShouldCreateShortcutFor() used during batch | 537 // Mac-specific version of web_app::ShouldCreateShortcutFor() used during batch |
| 537 // upgrades to ensure all shortcuts a user may still have are repaired when | 538 // upgrades to ensure all shortcuts a user may still have are repaired when |
| 538 // required by a Chrome upgrade. | 539 // required by a Chrome upgrade. |
| 539 bool ShouldUpgradeShortcutFor(Profile* profile, | 540 bool ShouldUpgradeShortcutFor(Profile* profile, |
| 540 const extensions::Extension* extension) { | 541 const extensions::Extension* extension) { |
| 541 if (extension->location() == extensions::Manifest::COMPONENT || | 542 if (extension->location() == extensions::Manifest::COMPONENT || |
| 542 !extensions::ui_util::CanDisplayInAppLauncher(extension, profile)) { | 543 !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); | 971 WebAppShortcutCreator shortcut_creator(base::FilePath(), &shortcut_info); |
| 971 return shortcut_creator.GetApplicationsShortcutPath(); | 972 return shortcut_creator.GetApplicationsShortcutPath(); |
| 972 } | 973 } |
| 973 | 974 |
| 974 void MaybeLaunchShortcut(std::unique_ptr<ShortcutInfo> shortcut_info) { | 975 void MaybeLaunchShortcut(std::unique_ptr<ShortcutInfo> shortcut_info) { |
| 975 if (AppShimsDisabledForTest() && | 976 if (AppShimsDisabledForTest() && |
| 976 !g_app_shims_allow_update_and_launch_in_tests) { | 977 !g_app_shims_allow_update_and_launch_in_tests) { |
| 977 return; | 978 return; |
| 978 } | 979 } |
| 979 | 980 |
| 980 content::BrowserThread::PostTask( | 981 web_app::ShortcutInfo* shortcut_info_ptr = shortcut_info.get(); |
| 982 content::BrowserThread::PostTaskAndReply( |
| 981 content::BrowserThread::FILE, FROM_HERE, | 983 content::BrowserThread::FILE, FROM_HERE, |
| 982 base::Bind(&LaunchShimOnFileThread, base::Passed(&shortcut_info), false)); | 984 base::Bind(&LaunchShimOnFileThread, base::Unretained(shortcut_info_ptr), |
| 985 false), |
| 986 base::Bind(&web_app::internals::DeleteShortcutInfoOnUIThread, |
| 987 base::Passed(&shortcut_info), base::Closure())); |
| 983 } | 988 } |
| 984 | 989 |
| 985 bool MaybeRebuildShortcut(const base::CommandLine& command_line) { | 990 bool MaybeRebuildShortcut(const base::CommandLine& command_line) { |
| 986 if (!command_line.HasSwitch(app_mode::kAppShimError)) | 991 if (!command_line.HasSwitch(app_mode::kAppShimError)) |
| 987 return false; | 992 return false; |
| 988 | 993 |
| 989 base::PostTaskWithTraitsAndReplyWithResult( | 994 base::PostTaskWithTraitsAndReplyWithResult( |
| 990 FROM_HERE, base::TaskTraits().MayBlock().WithPriority( | 995 FROM_HERE, base::TaskTraits().MayBlock().WithPriority( |
| 991 base::TaskPriority::BACKGROUND), | 996 base::TaskPriority::BACKGROUND), |
| 992 base::Bind(&RecordAppShimErrorAndBuildShortcutInfo, | 997 base::Bind(&RecordAppShimErrorAndBuildShortcutInfo, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1015 web_app::UpdateAllShortcuts(base::string16(), profile, extension, | 1020 web_app::UpdateAllShortcuts(base::string16(), profile, extension, |
| 1016 latch->NoOpClosure()); | 1021 latch->NoOpClosure()); |
| 1017 } | 1022 } |
| 1018 } | 1023 } |
| 1019 } | 1024 } |
| 1020 | 1025 |
| 1021 void RevealAppShimInFinderForApp(Profile* profile, | 1026 void RevealAppShimInFinderForApp(Profile* profile, |
| 1022 const extensions::Extension* app) { | 1027 const extensions::Extension* app) { |
| 1023 std::unique_ptr<web_app::ShortcutInfo> shortcut_info = | 1028 std::unique_ptr<web_app::ShortcutInfo> shortcut_info = |
| 1024 ShortcutInfoForExtensionAndProfile(app, profile); | 1029 ShortcutInfoForExtensionAndProfile(app, profile); |
| 1025 content::BrowserThread::PostTask( | 1030 web_app::ShortcutInfo* shortcut_info_ptr = shortcut_info.get(); |
| 1031 content::BrowserThread::PostTaskAndReply( |
| 1026 content::BrowserThread::FILE, FROM_HERE, | 1032 content::BrowserThread::FILE, FROM_HERE, |
| 1027 base::Bind(&RevealAppShimInFinderForAppOnFileThread, | 1033 base::Bind(&RevealAppShimInFinderForAppOnFileThread, |
| 1028 base::Passed(&shortcut_info), app->path())); | 1034 base::Unretained(shortcut_info_ptr), app->path()), |
| 1035 base::Bind(&web_app::internals::DeleteShortcutInfoOnUIThread, |
| 1036 base::Passed(&shortcut_info), base::Closure())); |
| 1029 } | 1037 } |
| 1030 | 1038 |
| 1031 namespace internals { | 1039 namespace internals { |
| 1032 | 1040 |
| 1033 bool CreatePlatformShortcuts( | 1041 bool CreatePlatformShortcuts(const base::FilePath& app_data_path, |
| 1034 const base::FilePath& app_data_path, | 1042 ShortcutInfo* shortcut_info, |
| 1035 std::unique_ptr<ShortcutInfo> shortcut_info, | 1043 const ShortcutLocations& creation_locations, |
| 1036 const ShortcutLocations& creation_locations, | 1044 ShortcutCreationReason creation_reason) { |
| 1037 ShortcutCreationReason creation_reason) { | |
| 1038 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); | 1045 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
| 1039 if (AppShimsDisabledForTest()) | 1046 if (AppShimsDisabledForTest()) |
| 1040 return true; | 1047 return true; |
| 1041 | 1048 |
| 1042 WebAppShortcutCreator shortcut_creator(app_data_path, shortcut_info.get()); | 1049 WebAppShortcutCreator shortcut_creator(app_data_path, shortcut_info); |
| 1043 return shortcut_creator.CreateShortcuts(creation_reason, creation_locations); | 1050 return shortcut_creator.CreateShortcuts(creation_reason, creation_locations); |
| 1044 } | 1051 } |
| 1045 | 1052 |
| 1046 void DeletePlatformShortcuts(const base::FilePath& app_data_path, | 1053 void DeletePlatformShortcuts(const base::FilePath& app_data_path, |
| 1047 std::unique_ptr<ShortcutInfo> shortcut_info) { | 1054 ShortcutInfo* shortcut_info) { |
| 1048 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); | 1055 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
| 1049 WebAppShortcutCreator shortcut_creator(app_data_path, shortcut_info.get()); | 1056 WebAppShortcutCreator shortcut_creator(app_data_path, shortcut_info); |
| 1050 shortcut_creator.DeleteShortcuts(); | 1057 shortcut_creator.DeleteShortcuts(); |
| 1051 } | 1058 } |
| 1052 | 1059 |
| 1053 void UpdatePlatformShortcuts(const base::FilePath& app_data_path, | 1060 void UpdatePlatformShortcuts(const base::FilePath& app_data_path, |
| 1054 const base::string16& old_app_title, | 1061 const base::string16& old_app_title, |
| 1055 std::unique_ptr<ShortcutInfo> shortcut_info) { | 1062 ShortcutInfo* shortcut_info) { |
| 1056 UpdatePlatformShortcutsInternal(app_data_path, old_app_title, *shortcut_info); | 1063 UpdatePlatformShortcutsInternal(app_data_path, old_app_title, *shortcut_info); |
| 1057 } | 1064 } |
| 1058 | 1065 |
| 1059 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path) { | 1066 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path) { |
| 1060 const std::string profile_base_name = profile_path.BaseName().value(); | 1067 const std::string profile_base_name = profile_path.BaseName().value(); |
| 1061 std::vector<base::FilePath> bundles = GetAllAppBundlesInPath( | 1068 std::vector<base::FilePath> bundles = GetAllAppBundlesInPath( |
| 1062 profile_path.Append(chrome::kWebAppDirname), profile_base_name); | 1069 profile_path.Append(chrome::kWebAppDirname), profile_base_name); |
| 1063 | 1070 |
| 1064 for (std::vector<base::FilePath>::const_iterator it = bundles.begin(); | 1071 for (std::vector<base::FilePath>::const_iterator it = bundles.begin(); |
| 1065 it != bundles.end(); ++it) { | 1072 it != bundles.end(); ++it) { |
| 1066 std::unique_ptr<web_app::ShortcutInfo> shortcut_info = | 1073 std::unique_ptr<web_app::ShortcutInfo> shortcut_info = |
| 1067 BuildShortcutInfoFromBundle(*it); | 1074 BuildShortcutInfoFromBundle(*it); |
| 1068 WebAppShortcutCreator shortcut_creator(it->DirName(), shortcut_info.get()); | 1075 WebAppShortcutCreator shortcut_creator(it->DirName(), shortcut_info.get()); |
| 1069 shortcut_creator.DeleteShortcuts(); | 1076 shortcut_creator.DeleteShortcuts(); |
| 1070 } | 1077 } |
| 1071 } | 1078 } |
| 1072 | 1079 |
| 1073 } // namespace internals | 1080 } // namespace internals |
| 1074 | 1081 |
| 1075 } // namespace web_app | 1082 } // namespace web_app |
| OLD | NEW |