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

Side by Side Diff: chrome/browser/web_applications/web_app_mac.mm

Issue 2621163005: Remove all use of FileHandlersInfo from desktop shortcut creation. (Closed)
Patch Set: Mac tests: Remove FileHandlersInfo references (plus tiny rebase). Created 3 years, 10 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 unified diff | Download patch
OLDNEW
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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 } 245 }
246 246
247 base::FilePath GetAppLoaderPath() { 247 base::FilePath GetAppLoaderPath() {
248 return base::mac::PathForFrameworkBundleResource( 248 return base::mac::PathForFrameworkBundleResource(
249 base::mac::NSToCFCast(@"app_mode_loader.app")); 249 base::mac::NSToCFCast(@"app_mode_loader.app"));
250 } 250 }
251 251
252 void UpdatePlatformShortcutsInternal( 252 void UpdatePlatformShortcutsInternal(
253 const base::FilePath& app_data_path, 253 const base::FilePath& app_data_path,
254 const base::string16& old_app_title, 254 const base::string16& old_app_title,
255 const web_app::ShortcutInfo& shortcut_info, 255 const web_app::ShortcutInfo& shortcut_info) {
256 const extensions::FileHandlersInfo& file_handlers_info) {
257 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); 256 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
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, &shortcut_info, 262 web_app::WebAppShortcutCreator shortcut_creator(app_data_path,
264 file_handlers_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 std::unique_ptr<web_app::ShortcutInfo> shortcut_info) {
270 const extensions::FileHandlersInfo& file_handlers_info) {
271 base::FilePath shortcut_data_dir = web_app::GetWebAppDataDirectory( 269 base::FilePath shortcut_data_dir = web_app::GetWebAppDataDirectory(
272 shortcut_info->profile_path, shortcut_info->extension_id, GURL()); 270 shortcut_info->profile_path, shortcut_info->extension_id, GURL());
273 UpdatePlatformShortcutsInternal(shortcut_data_dir, base::string16(), 271 UpdatePlatformShortcutsInternal(shortcut_data_dir, base::string16(),
274 *shortcut_info, file_handlers_info); 272 *shortcut_info);
275 LaunchShimOnFileThread(std::move(shortcut_info), true); 273 LaunchShimOnFileThread(std::move(shortcut_info), true);
276 } 274 }
277 275
278 void UpdateAndLaunchShim( 276 void UpdateAndLaunchShim(std::unique_ptr<web_app::ShortcutInfo> shortcut_info) {
279 std::unique_ptr<web_app::ShortcutInfo> shortcut_info, 277 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE,
280 const extensions::FileHandlersInfo& file_handlers_info) { 278 base::Bind(&UpdateAndLaunchShimOnFileThread,
281 content::BrowserThread::PostTask( 279 base::Passed(&shortcut_info)));
282 content::BrowserThread::FILE, FROM_HERE,
283 base::Bind(&UpdateAndLaunchShimOnFileThread, base::Passed(&shortcut_info),
284 file_handlers_info));
285 } 280 }
286 281
287 void RebuildAppAndLaunch(std::unique_ptr<web_app::ShortcutInfo> shortcut_info) { 282 void RebuildAppAndLaunch(std::unique_ptr<web_app::ShortcutInfo> shortcut_info) {
288 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 283 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
289 if (shortcut_info->extension_id == app_mode::kAppListModeId) { 284 if (shortcut_info->extension_id == app_mode::kAppListModeId) {
290 AppListService* app_list_service = AppListService::Get(); 285 AppListService* app_list_service = AppListService::Get();
291 app_list_service->CreateShortcut(); 286 app_list_service->CreateShortcut();
292 app_list_service->Show(); 287 app_list_service->Show();
293 return; 288 return;
294 } 289 }
295 290
296 ProfileManager* profile_manager = g_browser_process->profile_manager(); 291 ProfileManager* profile_manager = g_browser_process->profile_manager();
297 Profile* profile = 292 Profile* profile =
298 profile_manager->GetProfileByPath(shortcut_info->profile_path); 293 profile_manager->GetProfileByPath(shortcut_info->profile_path);
299 if (!profile || !profile_manager->IsValidProfile(profile)) 294 if (!profile || !profile_manager->IsValidProfile(profile))
300 return; 295 return;
301 296
302 extensions::ExtensionRegistry* registry = 297 extensions::ExtensionRegistry* registry =
303 extensions::ExtensionRegistry::Get(profile); 298 extensions::ExtensionRegistry::Get(profile);
304 const extensions::Extension* extension = registry->GetExtensionById( 299 const extensions::Extension* extension = registry->GetExtensionById(
305 shortcut_info->extension_id, extensions::ExtensionRegistry::ENABLED); 300 shortcut_info->extension_id, extensions::ExtensionRegistry::ENABLED);
306 if (!extension || !extension->is_platform_app()) 301 if (!extension || !extension->is_platform_app())
307 return; 302 return;
308 303
309 web_app::GetInfoForApp(extension, profile, base::Bind(&UpdateAndLaunchShim)); 304 web_app::GetShortcutInfoForApp(extension, profile,
305 base::Bind(&UpdateAndLaunchShim));
310 } 306 }
311 307
312 base::FilePath GetLocalizableAppShortcutsSubdirName() { 308 base::FilePath GetLocalizableAppShortcutsSubdirName() {
313 static const char kChromiumAppDirName[] = "Chromium Apps.localized"; 309 static const char kChromiumAppDirName[] = "Chromium Apps.localized";
314 static const char kChromeAppDirName[] = "Chrome Apps.localized"; 310 static const char kChromeAppDirName[] = "Chrome Apps.localized";
315 static const char kChromeCanaryAppDirName[] = "Chrome Canary Apps.localized"; 311 static const char kChromeCanaryAppDirName[] = "Chrome Canary Apps.localized";
316 312
317 switch (chrome::GetChannel()) { 313 switch (chrome::GetChannel()) {
318 case version_info::Channel::UNKNOWN: 314 case version_info::Channel::UNKNOWN:
319 return base::FilePath(kChromiumAppDirName); 315 return base::FilePath(kChromiumAppDirName);
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 if (full_version.IsValid()) 520 if (full_version.IsValid())
525 major_version = full_version.components()[0]; 521 major_version = full_version.components()[0];
526 UMA_HISTOGRAM_SPARSE_SLOWLY("Apps.AppShimErrorVersion", major_version); 522 UMA_HISTOGRAM_SPARSE_SLOWLY("Apps.AppShimErrorVersion", major_version);
527 523
528 return BuildShortcutInfoFromBundle(bundle_path); 524 return BuildShortcutInfoFromBundle(bundle_path);
529 } 525 }
530 526
531 void RevealAppShimInFinderForAppOnFileThread( 527 void RevealAppShimInFinderForAppOnFileThread(
532 std::unique_ptr<web_app::ShortcutInfo> shortcut_info, 528 std::unique_ptr<web_app::ShortcutInfo> shortcut_info,
533 const base::FilePath& app_path) { 529 const base::FilePath& app_path) {
534 web_app::WebAppShortcutCreator shortcut_creator( 530 web_app::WebAppShortcutCreator shortcut_creator(app_path,
535 app_path, shortcut_info.get(), extensions::FileHandlersInfo()); 531 shortcut_info.get());
536 shortcut_creator.RevealAppShimInFinder(); 532 shortcut_creator.RevealAppShimInFinder();
537 } 533 }
538 534
539 // Mac-specific version of web_app::ShouldCreateShortcutFor() used during batch 535 // Mac-specific version of web_app::ShouldCreateShortcutFor() used during batch
540 // upgrades to ensure all shortcuts a user may still have are repaired when 536 // upgrades to ensure all shortcuts a user may still have are repaired when
541 // required by a Chrome upgrade. 537 // required by a Chrome upgrade.
542 bool ShouldUpgradeShortcutFor(Profile* profile, 538 bool ShouldUpgradeShortcutFor(Profile* profile,
543 const extensions::Extension* extension) { 539 const extensions::Extension* extension) {
544 if (extension->location() == extensions::Manifest::COMPONENT || 540 if (extension->location() == extensions::Manifest::COMPONENT ||
545 !extensions::ui_util::CanDisplayInAppLauncher(extension, profile)) { 541 !extensions::ui_util::CanDisplayInAppLauncher(extension, profile)) {
546 return false; 542 return false;
547 } 543 }
548 544
549 return extension->is_app(); 545 return extension->is_app();
550 } 546 }
551 547
552 } // namespace 548 } // namespace
553 549
554 namespace web_app { 550 namespace web_app {
555 551
556 WebAppShortcutCreator::WebAppShortcutCreator( 552 WebAppShortcutCreator::WebAppShortcutCreator(const base::FilePath& app_data_dir,
557 const base::FilePath& app_data_dir, 553 const ShortcutInfo* shortcut_info)
558 const ShortcutInfo* shortcut_info, 554 : app_data_dir_(app_data_dir), info_(shortcut_info) {
559 const extensions::FileHandlersInfo& file_handlers_info)
560 : app_data_dir_(app_data_dir),
561 info_(shortcut_info),
562 file_handlers_info_(file_handlers_info) {
563 DCHECK(shortcut_info); 555 DCHECK(shortcut_info);
564 } 556 }
565 557
566 WebAppShortcutCreator::~WebAppShortcutCreator() {} 558 WebAppShortcutCreator::~WebAppShortcutCreator() {}
567 559
568 base::FilePath WebAppShortcutCreator::GetApplicationsShortcutPath() const { 560 base::FilePath WebAppShortcutCreator::GetApplicationsShortcutPath() const {
569 base::FilePath applications_dir = GetApplicationsDirname(); 561 base::FilePath applications_dir = GetApplicationsDirname();
570 return applications_dir.empty() ? 562 return applications_dir.empty() ?
571 base::FilePath() : applications_dir.Append(GetShortcutBasename()); 563 base::FilePath() : applications_dir.Append(GetShortcutBasename());
572 } 564 }
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 // Check if the Chrome apps folder exists, otherwise go up to ~/Applications. 959 // Check if the Chrome apps folder exists, otherwise go up to ~/Applications.
968 if (!base::PathExists(app_path)) 960 if (!base::PathExists(app_path))
969 app_path = app_path.DirName(); 961 app_path = app_path.DirName();
970 // Since |app_path| is a directory, use openFile to show the contents of 962 // Since |app_path| is a directory, use openFile to show the contents of
971 // that directory in Finder. 963 // that directory in Finder.
972 [[NSWorkspace sharedWorkspace] 964 [[NSWorkspace sharedWorkspace]
973 openFile:base::mac::FilePathToNSString(app_path)]; 965 openFile:base::mac::FilePathToNSString(app_path)];
974 } 966 }
975 967
976 base::FilePath GetAppInstallPath(const ShortcutInfo& shortcut_info) { 968 base::FilePath GetAppInstallPath(const ShortcutInfo& shortcut_info) {
977 WebAppShortcutCreator shortcut_creator(base::FilePath(), &shortcut_info, 969 WebAppShortcutCreator shortcut_creator(base::FilePath(), &shortcut_info);
978 extensions::FileHandlersInfo());
979 return shortcut_creator.GetApplicationsShortcutPath(); 970 return shortcut_creator.GetApplicationsShortcutPath();
980 } 971 }
981 972
982 void MaybeLaunchShortcut(std::unique_ptr<ShortcutInfo> shortcut_info) { 973 void MaybeLaunchShortcut(std::unique_ptr<ShortcutInfo> shortcut_info) {
983 if (AppShimsDisabledForTest() && 974 if (AppShimsDisabledForTest() &&
984 !g_app_shims_allow_update_and_launch_in_tests) { 975 !g_app_shims_allow_update_and_launch_in_tests) {
985 return; 976 return;
986 } 977 }
987 978
988 content::BrowserThread::PostTask( 979 content::BrowserThread::PostTask(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 content::BrowserThread::FILE, FROM_HERE, 1025 content::BrowserThread::FILE, FROM_HERE,
1035 base::Bind(&RevealAppShimInFinderForAppOnFileThread, 1026 base::Bind(&RevealAppShimInFinderForAppOnFileThread,
1036 base::Passed(&shortcut_info), app->path())); 1027 base::Passed(&shortcut_info), app->path()));
1037 } 1028 }
1038 1029
1039 namespace internals { 1030 namespace internals {
1040 1031
1041 bool CreatePlatformShortcuts( 1032 bool CreatePlatformShortcuts(
1042 const base::FilePath& app_data_path, 1033 const base::FilePath& app_data_path,
1043 std::unique_ptr<ShortcutInfo> shortcut_info, 1034 std::unique_ptr<ShortcutInfo> shortcut_info,
1044 const extensions::FileHandlersInfo& file_handlers_info,
1045 const ShortcutLocations& creation_locations, 1035 const ShortcutLocations& creation_locations,
1046 ShortcutCreationReason creation_reason) { 1036 ShortcutCreationReason creation_reason) {
1047 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); 1037 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
1048 if (AppShimsDisabledForTest()) 1038 if (AppShimsDisabledForTest())
1049 return true; 1039 return true;
1050 1040
1051 WebAppShortcutCreator shortcut_creator(app_data_path, shortcut_info.get(), 1041 WebAppShortcutCreator shortcut_creator(app_data_path, shortcut_info.get());
1052 file_handlers_info);
1053 return shortcut_creator.CreateShortcuts(creation_reason, creation_locations); 1042 return shortcut_creator.CreateShortcuts(creation_reason, creation_locations);
1054 } 1043 }
1055 1044
1056 void DeletePlatformShortcuts(const base::FilePath& app_data_path, 1045 void DeletePlatformShortcuts(const base::FilePath& app_data_path,
1057 std::unique_ptr<ShortcutInfo> shortcut_info) { 1046 std::unique_ptr<ShortcutInfo> shortcut_info) {
1058 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); 1047 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE);
1059 WebAppShortcutCreator shortcut_creator(app_data_path, shortcut_info.get(), 1048 WebAppShortcutCreator shortcut_creator(app_data_path, shortcut_info.get());
1060 extensions::FileHandlersInfo());
1061 shortcut_creator.DeleteShortcuts(); 1049 shortcut_creator.DeleteShortcuts();
1062 } 1050 }
1063 1051
1064 void UpdatePlatformShortcuts( 1052 void UpdatePlatformShortcuts(const base::FilePath& app_data_path,
1065 const base::FilePath& app_data_path, 1053 const base::string16& old_app_title,
1066 const base::string16& old_app_title, 1054 std::unique_ptr<ShortcutInfo> shortcut_info) {
1067 std::unique_ptr<ShortcutInfo> shortcut_info, 1055 UpdatePlatformShortcutsInternal(app_data_path, old_app_title, *shortcut_info);
1068 const extensions::FileHandlersInfo& file_handlers_info) {
1069 UpdatePlatformShortcutsInternal(app_data_path, old_app_title, *shortcut_info,
1070 file_handlers_info);
1071 } 1056 }
1072 1057
1073 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path) { 1058 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path) {
1074 const std::string profile_base_name = profile_path.BaseName().value(); 1059 const std::string profile_base_name = profile_path.BaseName().value();
1075 std::vector<base::FilePath> bundles = GetAllAppBundlesInPath( 1060 std::vector<base::FilePath> bundles = GetAllAppBundlesInPath(
1076 profile_path.Append(chrome::kWebAppDirname), profile_base_name); 1061 profile_path.Append(chrome::kWebAppDirname), profile_base_name);
1077 1062
1078 for (std::vector<base::FilePath>::const_iterator it = bundles.begin(); 1063 for (std::vector<base::FilePath>::const_iterator it = bundles.begin();
1079 it != bundles.end(); ++it) { 1064 it != bundles.end(); ++it) {
1080 std::unique_ptr<web_app::ShortcutInfo> shortcut_info = 1065 std::unique_ptr<web_app::ShortcutInfo> shortcut_info =
1081 BuildShortcutInfoFromBundle(*it); 1066 BuildShortcutInfoFromBundle(*it);
1082 WebAppShortcutCreator shortcut_creator(it->DirName(), shortcut_info.get(), 1067 WebAppShortcutCreator shortcut_creator(it->DirName(), shortcut_info.get());
1083 extensions::FileHandlersInfo());
1084 shortcut_creator.DeleteShortcuts(); 1068 shortcut_creator.DeleteShortcuts();
1085 } 1069 }
1086 } 1070 }
1087 1071
1088 } // namespace internals 1072 } // namespace internals
1089 1073
1090 } // namespace web_app 1074 } // namespace web_app
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698