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

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

Issue 1038573002: Fixed thread-unsafe use of gfx::Image in app shortcut creation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 8 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 <Carbon/Carbon.h> 7 #import <Carbon/Carbon.h>
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 base::FilePath user_data_dir; 212 base::FilePath user_data_dir;
213 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); 213 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
214 DCHECK(!user_data_dir.empty()); 214 DCHECK(!user_data_dir.empty());
215 return StartsWithASCII( 215 return StartsWithASCII(
216 base::SysNSStringToUTF8( 216 base::SysNSStringToUTF8(
217 [plist valueForKey:app_mode::kCrAppModeUserDataDirKey]), 217 [plist valueForKey:app_mode::kCrAppModeUserDataDirKey]),
218 user_data_dir.value(), 218 user_data_dir.value(),
219 true /* case_sensitive */); 219 true /* case_sensitive */);
220 } 220 }
221 221
222 void LaunchShimOnFileThread(const web_app::ShortcutInfo& shortcut_info, 222 void LaunchShimOnFileThread(scoped_ptr<web_app::ShortcutInfo> shortcut_info,
223 bool launched_after_rebuild) { 223 bool launched_after_rebuild) {
224 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 224 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
225 base::FilePath shim_path = web_app::GetAppInstallPath(shortcut_info); 225 base::FilePath shim_path = web_app::GetAppInstallPath(*shortcut_info);
226 226
227 if (shim_path.empty() || 227 if (shim_path.empty() ||
228 !base::PathExists(shim_path) || 228 !base::PathExists(shim_path) ||
229 !HasSameUserDataDir(shim_path)) { 229 !HasSameUserDataDir(shim_path)) {
230 // The user may have deleted the copy in the Applications folder, use the 230 // The user may have deleted the copy in the Applications folder, use the
231 // one in the web app's |app_data_dir_|. 231 // one in the web app's |app_data_dir_|.
232 base::FilePath app_data_dir = web_app::GetWebAppDataDirectory( 232 base::FilePath app_data_dir = web_app::GetWebAppDataDirectory(
233 shortcut_info.profile_path, shortcut_info.extension_id, GURL()); 233 shortcut_info->profile_path, shortcut_info->extension_id, GURL());
234 shim_path = app_data_dir.Append(shim_path.BaseName()); 234 shim_path = app_data_dir.Append(shim_path.BaseName());
235 } 235 }
236 236
237 if (!base::PathExists(shim_path)) 237 if (!base::PathExists(shim_path))
238 return; 238 return;
239 239
240 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); 240 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
241 command_line.AppendSwitchASCII( 241 command_line.AppendSwitchASCII(
242 app_mode::kLaunchedByChromeProcessId, 242 app_mode::kLaunchedByChromeProcessId,
243 base::IntToString(base::GetCurrentProcId())); 243 base::IntToString(base::GetCurrentProcId()));
244 if (launched_after_rebuild) 244 if (launched_after_rebuild)
245 command_line.AppendSwitch(app_mode::kLaunchedAfterRebuild); 245 command_line.AppendSwitch(app_mode::kLaunchedAfterRebuild);
246 // Launch without activating (kLSLaunchDontSwitch). 246 // Launch without activating (kLSLaunchDontSwitch).
247 base::mac::OpenApplicationWithPath( 247 base::mac::OpenApplicationWithPath(
248 shim_path, command_line, kLSLaunchDefaults | kLSLaunchDontSwitch, NULL); 248 shim_path, command_line, kLSLaunchDefaults | kLSLaunchDontSwitch, NULL);
249 } 249 }
250 250
251 base::FilePath GetAppLoaderPath() { 251 base::FilePath GetAppLoaderPath() {
252 return base::mac::PathForFrameworkBundleResource( 252 return base::mac::PathForFrameworkBundleResource(
253 base::mac::NSToCFCast(@"app_mode_loader.app")); 253 base::mac::NSToCFCast(@"app_mode_loader.app"));
254 } 254 }
255 255
256 void UpdateAndLaunchShimOnFileThread( 256 void UpdatePlatformShortcutsInternal(
257 const base::FilePath& app_data_path,
258 const base::string16& old_app_title,
257 const web_app::ShortcutInfo& shortcut_info, 259 const web_app::ShortcutInfo& shortcut_info,
258 const extensions::FileHandlersInfo& file_handlers_info) { 260 const extensions::FileHandlersInfo& file_handlers_info) {
261 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
262 if (AppShimsDisabledForTest() &&
263 !g_app_shims_allow_update_and_launch_in_tests) {
264 return;
265 }
266
267 web_app::WebAppShortcutCreator shortcut_creator(app_data_path, shortcut_info,
268 file_handlers_info);
269 shortcut_creator.UpdateShortcuts();
270 }
271
272 void UpdateAndLaunchShimOnFileThread(
273 scoped_ptr<web_app::ShortcutInfo> shortcut_info,
274 const extensions::FileHandlersInfo& file_handlers_info) {
259 base::FilePath shortcut_data_dir = web_app::GetWebAppDataDirectory( 275 base::FilePath shortcut_data_dir = web_app::GetWebAppDataDirectory(
260 shortcut_info.profile_path, shortcut_info.extension_id, GURL()); 276 shortcut_info->profile_path, shortcut_info->extension_id, GURL());
261 web_app::internals::UpdatePlatformShortcuts( 277 UpdatePlatformShortcutsInternal(shortcut_data_dir, base::string16(),
262 shortcut_data_dir, base::string16(), shortcut_info, file_handlers_info); 278 *shortcut_info, file_handlers_info);
263 LaunchShimOnFileThread(shortcut_info, true); 279 LaunchShimOnFileThread(shortcut_info.Pass(), true);
264 } 280 }
265 281
266 void UpdateAndLaunchShim( 282 void UpdateAndLaunchShim(
267 const web_app::ShortcutInfo& shortcut_info, 283 scoped_ptr<web_app::ShortcutInfo> shortcut_info,
268 const extensions::FileHandlersInfo& file_handlers_info) { 284 const extensions::FileHandlersInfo& file_handlers_info) {
269 content::BrowserThread::PostTask( 285 content::BrowserThread::PostTask(
270 content::BrowserThread::FILE, 286 content::BrowserThread::FILE, FROM_HERE,
271 FROM_HERE, 287 base::Bind(&UpdateAndLaunchShimOnFileThread, base::Passed(&shortcut_info),
272 base::Bind( 288 file_handlers_info));
273 &UpdateAndLaunchShimOnFileThread, shortcut_info, file_handlers_info));
274 } 289 }
275 290
276 void RebuildAppAndLaunch(const web_app::ShortcutInfo& shortcut_info) { 291 void RebuildAppAndLaunch(scoped_ptr<web_app::ShortcutInfo> shortcut_info) {
277 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 292 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
278 if (shortcut_info.extension_id == app_mode::kAppListModeId) { 293 if (shortcut_info->extension_id == app_mode::kAppListModeId) {
279 AppListService* app_list_service = 294 AppListService* app_list_service =
280 AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE); 295 AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE);
281 app_list_service->CreateShortcut(); 296 app_list_service->CreateShortcut();
282 app_list_service->Show(); 297 app_list_service->Show();
283 return; 298 return;
284 } 299 }
285 300
286 ProfileManager* profile_manager = g_browser_process->profile_manager(); 301 ProfileManager* profile_manager = g_browser_process->profile_manager();
287 Profile* profile = 302 Profile* profile =
288 profile_manager->GetProfileByPath(shortcut_info.profile_path); 303 profile_manager->GetProfileByPath(shortcut_info->profile_path);
289 if (!profile || !profile_manager->IsValidProfile(profile)) 304 if (!profile || !profile_manager->IsValidProfile(profile))
290 return; 305 return;
291 306
292 extensions::ExtensionRegistry* registry = 307 extensions::ExtensionRegistry* registry =
293 extensions::ExtensionRegistry::Get(profile); 308 extensions::ExtensionRegistry::Get(profile);
294 const extensions::Extension* extension = registry->GetExtensionById( 309 const extensions::Extension* extension = registry->GetExtensionById(
295 shortcut_info.extension_id, extensions::ExtensionRegistry::ENABLED); 310 shortcut_info->extension_id, extensions::ExtensionRegistry::ENABLED);
296 if (!extension || !extension->is_platform_app()) 311 if (!extension || !extension->is_platform_app())
297 return; 312 return;
298 313
299 web_app::GetInfoForApp(extension, profile, base::Bind(&UpdateAndLaunchShim)); 314 web_app::GetInfoForApp(extension, profile, base::Bind(&UpdateAndLaunchShim));
300 } 315 }
301 316
302 base::FilePath GetLocalizableAppShortcutsSubdirName() { 317 base::FilePath GetLocalizableAppShortcutsSubdirName() {
303 static const char kChromiumAppDirName[] = "Chromium Apps.localized"; 318 static const char kChromiumAppDirName[] = "Chromium Apps.localized";
304 static const char kChromeAppDirName[] = "Chrome Apps.localized"; 319 static const char kChromeAppDirName[] = "Chrome Apps.localized";
305 static const char kChromeCanaryAppDirName[] = "Chrome Canary Apps.localized"; 320 static const char kChromeCanaryAppDirName[] = "Chrome Canary Apps.localized";
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 base::FileEnumerator::DIRECTORIES); 476 base::FileEnumerator::DIRECTORIES);
462 for (base::FilePath bundle_path = enumerator.Next(); 477 for (base::FilePath bundle_path = enumerator.Next();
463 !bundle_path.empty(); bundle_path = enumerator.Next()) { 478 !bundle_path.empty(); bundle_path = enumerator.Next()) {
464 if (IsShimForProfile(bundle_path.BaseName(), profile_base_name)) 479 if (IsShimForProfile(bundle_path.BaseName(), profile_base_name))
465 bundle_paths.push_back(bundle_path); 480 bundle_paths.push_back(bundle_path);
466 } 481 }
467 482
468 return bundle_paths; 483 return bundle_paths;
469 } 484 }
470 485
471 web_app::ShortcutInfo BuildShortcutInfoFromBundle( 486 scoped_ptr<web_app::ShortcutInfo> BuildShortcutInfoFromBundle(
472 const base::FilePath& bundle_path) { 487 const base::FilePath& bundle_path) {
473 NSDictionary* plist = ReadPlist(GetPlistPath(bundle_path)); 488 NSDictionary* plist = ReadPlist(GetPlistPath(bundle_path));
474 489
475 web_app::ShortcutInfo shortcut_info; 490 scoped_ptr<web_app::ShortcutInfo> shortcut_info(new web_app::ShortcutInfo);
476 shortcut_info.extension_id = base::SysNSStringToUTF8( 491 shortcut_info->extension_id = base::SysNSStringToUTF8(
477 [plist valueForKey:app_mode::kCrAppModeShortcutIDKey]); 492 [plist valueForKey:app_mode::kCrAppModeShortcutIDKey]);
478 shortcut_info.is_platform_app = true; 493 shortcut_info->is_platform_app = true;
479 shortcut_info.url = GURL(base::SysNSStringToUTF8( 494 shortcut_info->url = GURL(base::SysNSStringToUTF8(
480 [plist valueForKey:app_mode::kCrAppModeShortcutURLKey])); 495 [plist valueForKey:app_mode::kCrAppModeShortcutURLKey]));
481 shortcut_info.title = base::SysNSStringToUTF16( 496 shortcut_info->title = base::SysNSStringToUTF16(
482 [plist valueForKey:app_mode::kCrAppModeShortcutNameKey]); 497 [plist valueForKey:app_mode::kCrAppModeShortcutNameKey]);
483 shortcut_info.profile_name = base::SysNSStringToUTF8( 498 shortcut_info->profile_name = base::SysNSStringToUTF8(
484 [plist valueForKey:app_mode::kCrAppModeProfileNameKey]); 499 [plist valueForKey:app_mode::kCrAppModeProfileNameKey]);
485 500
486 // Figure out the profile_path. Since the user_data_dir could contain the 501 // Figure out the profile_path. Since the user_data_dir could contain the
487 // path to the web app data dir. 502 // path to the web app data dir.
488 base::FilePath user_data_dir = base::mac::NSStringToFilePath( 503 base::FilePath user_data_dir = base::mac::NSStringToFilePath(
489 [plist valueForKey:app_mode::kCrAppModeUserDataDirKey]); 504 [plist valueForKey:app_mode::kCrAppModeUserDataDirKey]);
490 base::FilePath profile_base_name = base::mac::NSStringToFilePath( 505 base::FilePath profile_base_name = base::mac::NSStringToFilePath(
491 [plist valueForKey:app_mode::kCrAppModeProfileDirKey]); 506 [plist valueForKey:app_mode::kCrAppModeProfileDirKey]);
492 if (user_data_dir.DirName().DirName().BaseName() == profile_base_name) 507 if (user_data_dir.DirName().DirName().BaseName() == profile_base_name)
493 shortcut_info.profile_path = user_data_dir.DirName().DirName(); 508 shortcut_info->profile_path = user_data_dir.DirName().DirName();
494 else 509 else
495 shortcut_info.profile_path = user_data_dir.Append(profile_base_name); 510 shortcut_info->profile_path = user_data_dir.Append(profile_base_name);
496 511
497 return shortcut_info; 512 return shortcut_info;
498 } 513 }
499 514
500 web_app::ShortcutInfo RecordAppShimErrorAndBuildShortcutInfo( 515 scoped_ptr<web_app::ShortcutInfo> RecordAppShimErrorAndBuildShortcutInfo(
501 const base::FilePath& bundle_path) { 516 const base::FilePath& bundle_path) {
502 NSDictionary* plist = ReadPlist(GetPlistPath(bundle_path)); 517 NSDictionary* plist = ReadPlist(GetPlistPath(bundle_path));
503 NSString* version_string = [plist valueForKey:app_mode::kCrBundleVersionKey]; 518 NSString* version_string = [plist valueForKey:app_mode::kCrBundleVersionKey];
504 if (!version_string) { 519 if (!version_string) {
505 // Older bundles have the Chrome version in the following key. 520 // Older bundles have the Chrome version in the following key.
506 version_string = 521 version_string =
507 [plist valueForKey:app_mode::kCFBundleShortVersionStringKey]; 522 [plist valueForKey:app_mode::kCFBundleShortVersionStringKey];
508 } 523 }
509 base::Version full_version(base::SysNSStringToUTF8(version_string)); 524 base::Version full_version(base::SysNSStringToUTF8(version_string));
510 uint32_t major_version = 0; 525 uint32_t major_version = 0;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 app_mode::kCFBundleTypeRoleKey : app_mode::kBundleTypeRoleViewer 567 app_mode::kCFBundleTypeRoleKey : app_mode::kBundleTypeRoleViewer
553 }; 568 };
554 [document_types addObject:type_dictionary]; 569 [document_types addObject:type_dictionary];
555 } 570 }
556 571
557 [plist setObject:document_types 572 [plist setObject:document_types
558 forKey:app_mode::kCFBundleDocumentTypesKey]; 573 forKey:app_mode::kCFBundleDocumentTypesKey];
559 } 574 }
560 575
561 void RevealAppShimInFinderForAppOnFileThread( 576 void RevealAppShimInFinderForAppOnFileThread(
562 const web_app::ShortcutInfo& shortcut_info, 577 scoped_ptr<web_app::ShortcutInfo> shortcut_info,
563 const base::FilePath& app_path) { 578 const base::FilePath& app_path) {
564 web_app::WebAppShortcutCreator shortcut_creator( 579 web_app::WebAppShortcutCreator shortcut_creator(
565 app_path, shortcut_info, extensions::FileHandlersInfo()); 580 app_path, *shortcut_info, extensions::FileHandlersInfo());
566 shortcut_creator.RevealAppShimInFinder(); 581 shortcut_creator.RevealAppShimInFinder();
567 } 582 }
568 583
569 } // namespace 584 } // namespace
570 585
571 @interface CrCreateAppShortcutCheckboxObserver : NSObject { 586 @interface CrCreateAppShortcutCheckboxObserver : NSObject {
572 @private 587 @private
573 NSButton* checkbox_; 588 NSButton* checkbox_;
574 NSButton* continueButton_; 589 NSButton* continueButton_;
575 } 590 }
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 [[NSWorkspace sharedWorkspace] 1019 [[NSWorkspace sharedWorkspace]
1005 openFile:base::mac::FilePathToNSString(app_path)]; 1020 openFile:base::mac::FilePathToNSString(app_path)];
1006 } 1021 }
1007 1022
1008 base::FilePath GetAppInstallPath(const ShortcutInfo& shortcut_info) { 1023 base::FilePath GetAppInstallPath(const ShortcutInfo& shortcut_info) {
1009 WebAppShortcutCreator shortcut_creator( 1024 WebAppShortcutCreator shortcut_creator(
1010 base::FilePath(), shortcut_info, extensions::FileHandlersInfo()); 1025 base::FilePath(), shortcut_info, extensions::FileHandlersInfo());
1011 return shortcut_creator.GetApplicationsShortcutPath(); 1026 return shortcut_creator.GetApplicationsShortcutPath();
1012 } 1027 }
1013 1028
1014 void MaybeLaunchShortcut(const ShortcutInfo& shortcut_info) { 1029 void MaybeLaunchShortcut(scoped_ptr<ShortcutInfo> shortcut_info) {
1015 if (AppShimsDisabledForTest() && 1030 if (AppShimsDisabledForTest() &&
1016 !g_app_shims_allow_update_and_launch_in_tests) { 1031 !g_app_shims_allow_update_and_launch_in_tests) {
1017 return; 1032 return;
1018 } 1033 }
1019 1034
1020 content::BrowserThread::PostTask( 1035 content::BrowserThread::PostTask(
1021 content::BrowserThread::FILE, 1036 content::BrowserThread::FILE, FROM_HERE,
1022 FROM_HERE, 1037 base::Bind(&LaunchShimOnFileThread, base::Passed(&shortcut_info), false));
1023 base::Bind(&LaunchShimOnFileThread, shortcut_info, false));
1024 } 1038 }
1025 1039
1026 bool MaybeRebuildShortcut(const base::CommandLine& command_line) { 1040 bool MaybeRebuildShortcut(const base::CommandLine& command_line) {
1027 if (!command_line.HasSwitch(app_mode::kAppShimError)) 1041 if (!command_line.HasSwitch(app_mode::kAppShimError))
1028 return false; 1042 return false;
1029 1043
1030 base::PostTaskAndReplyWithResult( 1044 base::PostTaskAndReplyWithResult(
1031 content::BrowserThread::GetBlockingPool(), 1045 content::BrowserThread::GetBlockingPool(),
1032 FROM_HERE, 1046 FROM_HERE,
1033 base::Bind(&RecordAppShimErrorAndBuildShortcutInfo, 1047 base::Bind(&RecordAppShimErrorAndBuildShortcutInfo,
1034 command_line.GetSwitchValuePath(app_mode::kAppShimError)), 1048 command_line.GetSwitchValuePath(app_mode::kAppShimError)),
1035 base::Bind(&RebuildAppAndLaunch)); 1049 base::Bind(&RebuildAppAndLaunch));
1036 return true; 1050 return true;
1037 } 1051 }
1038 1052
1039 // Called when the app's ShortcutInfo (with icon) is loaded when creating app 1053 // Called when the app's ShortcutInfo (with icon) is loaded when creating app
1040 // shortcuts. 1054 // shortcuts.
1041 void CreateAppShortcutInfoLoaded( 1055 void CreateAppShortcutInfoLoaded(
1042 Profile* profile, 1056 Profile* profile,
1043 const extensions::Extension* app, 1057 const extensions::Extension* app,
1044 const base::Callback<void(bool)>& close_callback, 1058 const base::Callback<void(bool)>& close_callback,
1045 const ShortcutInfo& shortcut_info) { 1059 scoped_ptr<ShortcutInfo> shortcut_info) {
1046 base::scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]); 1060 base::scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]);
1047 1061
1048 NSButton* continue_button = [alert 1062 NSButton* continue_button = [alert
1049 addButtonWithTitle:l10n_util::GetNSString(IDS_CREATE_SHORTCUTS_COMMIT)]; 1063 addButtonWithTitle:l10n_util::GetNSString(IDS_CREATE_SHORTCUTS_COMMIT)];
1050 [continue_button setKeyEquivalent:kKeyEquivalentReturn]; 1064 [continue_button setKeyEquivalent:kKeyEquivalentReturn];
1051 1065
1052 NSButton* cancel_button = 1066 NSButton* cancel_button =
1053 [alert addButtonWithTitle:l10n_util::GetNSString(IDS_CANCEL)]; 1067 [alert addButtonWithTitle:l10n_util::GetNSString(IDS_CANCEL)];
1054 [cancel_button setKeyEquivalent:kKeyEquivalentEscape]; 1068 [cancel_button setKeyEquivalent:kKeyEquivalentEscape];
1055 1069
(...skipping 11 matching lines...) Expand all
1067 base::scoped_nsobject<CrCreateAppShortcutCheckboxObserver> checkbox_observer( 1081 base::scoped_nsobject<CrCreateAppShortcutCheckboxObserver> checkbox_observer(
1068 [[CrCreateAppShortcutCheckboxObserver alloc] 1082 [[CrCreateAppShortcutCheckboxObserver alloc]
1069 initWithCheckbox:application_folder_checkbox 1083 initWithCheckbox:application_folder_checkbox
1070 continueButton:continue_button]); 1084 continueButton:continue_button]);
1071 [checkbox_observer startObserving]; 1085 [checkbox_observer startObserving];
1072 1086
1073 [alert setAccessoryView:application_folder_checkbox]; 1087 [alert setAccessoryView:application_folder_checkbox];
1074 1088
1075 const int kIconPreviewSizePixels = 128; 1089 const int kIconPreviewSizePixels = 128;
1076 const int kIconPreviewTargetSize = 64; 1090 const int kIconPreviewTargetSize = 64;
1077 const gfx::Image* icon = shortcut_info.favicon.GetBest( 1091 const gfx::Image* icon = shortcut_info->favicon.GetBest(
1078 kIconPreviewSizePixels, kIconPreviewSizePixels); 1092 kIconPreviewSizePixels, kIconPreviewSizePixels);
1079 1093
1080 if (icon && !icon->IsEmpty()) { 1094 if (icon && !icon->IsEmpty()) {
1081 NSImage* icon_image = icon->ToNSImage(); 1095 NSImage* icon_image = icon->ToNSImage();
1082 [icon_image 1096 [icon_image
1083 setSize:NSMakeSize(kIconPreviewTargetSize, kIconPreviewTargetSize)]; 1097 setSize:NSMakeSize(kIconPreviewTargetSize, kIconPreviewTargetSize)];
1084 [alert setIcon:icon_image]; 1098 [alert setIcon:icon_image];
1085 } 1099 }
1086 1100
1087 bool dialog_accepted = false; 1101 bool dialog_accepted = false;
(...skipping 28 matching lines...) Expand all
1116 it->get())) { 1130 it->get())) {
1117 web_app::UpdateAllShortcuts(base::string16(), profile, it->get()); 1131 web_app::UpdateAllShortcuts(base::string16(), profile, it->get());
1118 } 1132 }
1119 } 1133 }
1120 1134
1121 callback.Run(); 1135 callback.Run();
1122 } 1136 }
1123 1137
1124 void RevealAppShimInFinderForApp(Profile* profile, 1138 void RevealAppShimInFinderForApp(Profile* profile,
1125 const extensions::Extension* app) { 1139 const extensions::Extension* app) {
1126 const web_app::ShortcutInfo shortcut_info = 1140 scoped_ptr<web_app::ShortcutInfo> shortcut_info =
1127 ShortcutInfoForExtensionAndProfile(app, profile); 1141 ShortcutInfoForExtensionAndProfile(app, profile);
1128 content::BrowserThread::PostTask( 1142 content::BrowserThread::PostTask(
1129 content::BrowserThread::FILE, FROM_HERE, 1143 content::BrowserThread::FILE, FROM_HERE,
1130 base::Bind(&RevealAppShimInFinderForAppOnFileThread, shortcut_info, 1144 base::Bind(&RevealAppShimInFinderForAppOnFileThread,
1131 app->path())); 1145 base::Passed(&shortcut_info), app->path()));
1132 } 1146 }
1133 1147
1134 namespace internals { 1148 namespace internals {
1135 1149
1136 bool CreatePlatformShortcuts( 1150 bool CreatePlatformShortcuts(
1137 const base::FilePath& app_data_path, 1151 const base::FilePath& app_data_path,
1138 const ShortcutInfo& shortcut_info, 1152 scoped_ptr<ShortcutInfo> shortcut_info,
1139 const extensions::FileHandlersInfo& file_handlers_info, 1153 const extensions::FileHandlersInfo& file_handlers_info,
1140 const ShortcutLocations& creation_locations, 1154 const ShortcutLocations& creation_locations,
1141 ShortcutCreationReason creation_reason) { 1155 ShortcutCreationReason creation_reason) {
1142 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 1156 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
1143 if (AppShimsDisabledForTest()) 1157 if (AppShimsDisabledForTest())
1144 return true; 1158 return true;
1145 1159
1146 WebAppShortcutCreator shortcut_creator( 1160 WebAppShortcutCreator shortcut_creator(app_data_path, *shortcut_info,
1147 app_data_path, shortcut_info, file_handlers_info); 1161 file_handlers_info);
1148 return shortcut_creator.CreateShortcuts(creation_reason, creation_locations); 1162 return shortcut_creator.CreateShortcuts(creation_reason, creation_locations);
1149 } 1163 }
1150 1164
1151 void DeletePlatformShortcuts(const base::FilePath& app_data_path, 1165 void DeletePlatformShortcuts(const base::FilePath& app_data_path,
1152 const ShortcutInfo& shortcut_info) { 1166 scoped_ptr<ShortcutInfo> shortcut_info) {
1153 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 1167 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
1154 WebAppShortcutCreator shortcut_creator( 1168 WebAppShortcutCreator shortcut_creator(app_data_path, *shortcut_info,
1155 app_data_path, shortcut_info, extensions::FileHandlersInfo()); 1169 extensions::FileHandlersInfo());
1156 shortcut_creator.DeleteShortcuts(); 1170 shortcut_creator.DeleteShortcuts();
1157 } 1171 }
1158 1172
1159 void UpdatePlatformShortcuts( 1173 void UpdatePlatformShortcuts(
1160 const base::FilePath& app_data_path, 1174 const base::FilePath& app_data_path,
1161 const base::string16& old_app_title, 1175 const base::string16& old_app_title,
1162 const ShortcutInfo& shortcut_info, 1176 scoped_ptr<ShortcutInfo> shortcut_info,
1163 const extensions::FileHandlersInfo& file_handlers_info) { 1177 const extensions::FileHandlersInfo& file_handlers_info) {
1164 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 1178 UpdatePlatformShortcutsInternal(app_data_path, old_app_title, *shortcut_info,
1165 if (AppShimsDisabledForTest() && 1179 file_handlers_info);
1166 !g_app_shims_allow_update_and_launch_in_tests) {
1167 return;
1168 }
1169
1170 WebAppShortcutCreator shortcut_creator(
1171 app_data_path, shortcut_info, file_handlers_info);
1172 shortcut_creator.UpdateShortcuts();
1173 } 1180 }
1174 1181
1175 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path) { 1182 void DeleteAllShortcutsForProfile(const base::FilePath& profile_path) {
1176 const std::string profile_base_name = profile_path.BaseName().value(); 1183 const std::string profile_base_name = profile_path.BaseName().value();
1177 std::vector<base::FilePath> bundles = GetAllAppBundlesInPath( 1184 std::vector<base::FilePath> bundles = GetAllAppBundlesInPath(
1178 profile_path.Append(chrome::kWebAppDirname), profile_base_name); 1185 profile_path.Append(chrome::kWebAppDirname), profile_base_name);
1179 1186
1180 for (std::vector<base::FilePath>::const_iterator it = bundles.begin(); 1187 for (std::vector<base::FilePath>::const_iterator it = bundles.begin();
1181 it != bundles.end(); ++it) { 1188 it != bundles.end(); ++it) {
1182 web_app::ShortcutInfo shortcut_info = 1189 scoped_ptr<web_app::ShortcutInfo> shortcut_info =
1183 BuildShortcutInfoFromBundle(*it); 1190 BuildShortcutInfoFromBundle(*it);
1184 WebAppShortcutCreator shortcut_creator( 1191 WebAppShortcutCreator shortcut_creator(it->DirName(), *shortcut_info,
1185 it->DirName(), shortcut_info, extensions::FileHandlersInfo()); 1192 extensions::FileHandlersInfo());
1186 shortcut_creator.DeleteShortcuts(); 1193 shortcut_creator.DeleteShortcuts();
1187 } 1194 }
1188 } 1195 }
1189 1196
1190 } // namespace internals 1197 } // namespace internals
1191 1198
1192 } // namespace web_app 1199 } // namespace web_app
1193 1200
1194 namespace chrome { 1201 namespace chrome {
1195 1202
1196 void ShowCreateChromeAppShortcutsDialog( 1203 void ShowCreateChromeAppShortcutsDialog(
1197 gfx::NativeWindow /*parent_window*/, 1204 gfx::NativeWindow /*parent_window*/,
1198 Profile* profile, 1205 Profile* profile,
1199 const extensions::Extension* app, 1206 const extensions::Extension* app,
1200 const base::Callback<void(bool)>& close_callback) { 1207 const base::Callback<void(bool)>& close_callback) {
1201 web_app::GetShortcutInfoForApp( 1208 web_app::GetShortcutInfoForApp(
1202 app, 1209 app,
1203 profile, 1210 profile,
1204 base::Bind(&web_app::CreateAppShortcutInfoLoaded, 1211 base::Bind(&web_app::CreateAppShortcutInfoLoaded,
1205 profile, 1212 profile,
1206 app, 1213 app,
1207 close_callback)); 1214 close_callback));
1208 } 1215 }
1209 1216
1210 } // namespace chrome 1217 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698