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