Chromium Code Reviews| 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 <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" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/files/file_enumerator.h" | 12 #include "base/files/file_enumerator.h" |
| 13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 14 #include "base/mac/foundation_util.h" | 14 #include "base/mac/foundation_util.h" |
| 15 #include "base/mac/launch_services_util.h" | 15 #include "base/mac/launch_services_util.h" |
| 16 #include "base/mac/mac_util.h" | 16 #include "base/mac/mac_util.h" |
| 17 #include "base/mac/scoped_cftyperef.h" | 17 #include "base/mac/scoped_cftyperef.h" |
| 18 #include "base/mac/scoped_nsobject.h" | 18 #include "base/mac/scoped_nsobject.h" |
| 19 #include "base/metrics/histogram.h" | |
| 19 #include "base/path_service.h" | 20 #include "base/path_service.h" |
| 20 #include "base/process/process_handle.h" | 21 #include "base/process/process_handle.h" |
| 21 #include "base/strings/string16.h" | 22 #include "base/strings/string16.h" |
| 22 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
| 23 #include "base/strings/string_split.h" | 24 #include "base/strings/string_split.h" |
| 24 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
| 25 #include "base/strings/sys_string_conversions.h" | 26 #include "base/strings/sys_string_conversions.h" |
| 26 #include "base/strings/utf_string_conversions.h" | 27 #include "base/strings/utf_string_conversions.h" |
| 27 #include "chrome/browser/browser_process.h" | 28 #include "chrome/browser/browser_process.h" |
| 28 #import "chrome/browser/mac/dock.h" | 29 #import "chrome/browser/mac/dock.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 50 #include "ui/base/resource/resource_bundle.h" | 51 #include "ui/base/resource/resource_bundle.h" |
| 51 #include "ui/gfx/image/image_family.h" | 52 #include "ui/gfx/image/image_family.h" |
| 52 | 53 |
| 53 bool g_app_shims_allow_update_and_launch_in_tests = false; | 54 bool g_app_shims_allow_update_and_launch_in_tests = false; |
| 54 | 55 |
| 55 namespace { | 56 namespace { |
| 56 | 57 |
| 57 // Launch Services Key to run as an agent app, which doesn't launch in the dock. | 58 // Launch Services Key to run as an agent app, which doesn't launch in the dock. |
| 58 NSString* const kLSUIElement = @"LSUIElement"; | 59 NSString* const kLSUIElement = @"LSUIElement"; |
| 59 | 60 |
| 61 // When a --app-shim-error is triggered, this is used to record the relative | |
| 62 // bitness of the shim and Chrome. If they have the same bitness, then the shim | |
| 63 // failed for another reason. | |
| 64 // Order must be maintained as this is used in UMA. | |
| 65 enum AppShimError { | |
| 66 APP_SHIM_ERROR_UNKNOWN, // No details. | |
| 67 APP_SHIM_ERROR_BITNESS_SHIM_32_CHROME_64, // Common case. | |
| 68 APP_SHIM_ERROR_BITNESS_SHIM_64_CHROME_32, // Reverse case. | |
| 69 APP_SHIM_ERROR_BITNESS_BOTH_32, // Error case. | |
| 70 APP_SHIM_ERROR_BITNESS_BOTH_64, // Error case. | |
| 71 APP_SHIM_ERROR_COUNT, | |
| 72 }; | |
| 73 | |
| 60 class ScopedCarbonHandle { | 74 class ScopedCarbonHandle { |
| 61 public: | 75 public: |
| 62 ScopedCarbonHandle(size_t initial_size) : handle_(NewHandle(initial_size)) { | 76 ScopedCarbonHandle(size_t initial_size) : handle_(NewHandle(initial_size)) { |
| 63 DCHECK(handle_); | 77 DCHECK(handle_); |
| 64 DCHECK_EQ(noErr, MemError()); | 78 DCHECK_EQ(noErr, MemError()); |
| 65 } | 79 } |
| 66 ~ScopedCarbonHandle() { DisposeHandle(handle_); } | 80 ~ScopedCarbonHandle() { DisposeHandle(handle_); } |
| 67 | 81 |
| 68 Handle Get() { return handle_; } | 82 Handle Get() { return handle_; } |
| 69 char* Data() { return *handle_; } | 83 char* Data() { return *handle_; } |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 base::FilePath profile_base_name = base::mac::NSStringToFilePath( | 503 base::FilePath profile_base_name = base::mac::NSStringToFilePath( |
| 490 [plist valueForKey:app_mode::kCrAppModeProfileDirKey]); | 504 [plist valueForKey:app_mode::kCrAppModeProfileDirKey]); |
| 491 if (user_data_dir.DirName().DirName().BaseName() == profile_base_name) | 505 if (user_data_dir.DirName().DirName().BaseName() == profile_base_name) |
| 492 shortcut_info.profile_path = user_data_dir.DirName().DirName(); | 506 shortcut_info.profile_path = user_data_dir.DirName().DirName(); |
| 493 else | 507 else |
| 494 shortcut_info.profile_path = user_data_dir.Append(profile_base_name); | 508 shortcut_info.profile_path = user_data_dir.Append(profile_base_name); |
| 495 | 509 |
| 496 return shortcut_info; | 510 return shortcut_info; |
| 497 } | 511 } |
| 498 | 512 |
| 513 void RecordAppShimErrorAndRebuild(const CommandLine& command_line) { | |
|
tapted
2014/06/26 06:47:05
maybe rename this to make clear the thread it runs
jackhou1
2014/06/27 04:55:56
Moved this to the UI thread.
| |
| 514 std::string error_detail = | |
| 515 command_line.GetSwitchValueASCII(app_mode::kAppShimErrorDetail); | |
| 516 int error_enum = APP_SHIM_ERROR_UNKNOWN; | |
| 517 | |
| 518 #if defined(ARCH_CPU_32_BITS) | |
| 519 if (error_detail == app_mode::kAppShimErrorDetail32Bit) | |
| 520 error_enum = APP_SHIM_ERROR_BITNESS_BOTH_32; | |
|
tapted
2014/06/26 06:47:05
So.... I think we can determine shim bitness from
jackhou1
2014/06/27 04:55:57
I think the main benefit would be not having to up
tapted
2014/06/27 05:10:48
The mapping should be pretty simple:
<38: no
38:
jackhou1
2014/07/01 04:30:39
Okay, changed this to just read the plist. I also
| |
| 521 else if (error_detail == app_mode::kAppShimErrorDetail64Bit) | |
| 522 error_enum = APP_SHIM_ERROR_BITNESS_SHIM_64_CHROME_32; | |
| 523 #elif defined(ARCH_CPU_64_BITS) | |
| 524 if (error_detail == app_mode::kAppShimErrorDetail32Bit) | |
| 525 error_enum = APP_SHIM_ERROR_BITNESS_SHIM_32_CHROME_64; | |
| 526 else if (error_detail == app_mode::kAppShimErrorDetail64Bit) | |
| 527 error_enum = APP_SHIM_ERROR_BITNESS_BOTH_64; | |
| 528 #endif | |
| 529 | |
| 530 UMA_HISTOGRAM_ENUMERATION("Apps.AppShimError", | |
| 531 error_enum, | |
| 532 APP_SHIM_ERROR_COUNT); | |
| 533 | |
| 534 web_app::ShortcutInfo info = BuildShortcutInfoFromBundle( | |
| 535 command_line.GetSwitchValuePath(app_mode::kAppShimError)); | |
| 536 content::BrowserThread::PostTask( | |
| 537 content::BrowserThread::UI, | |
| 538 FROM_HERE, | |
| 539 base::Bind(&RebuildAppAndLaunch, info)); | |
| 540 } | |
| 541 | |
| 499 void UpdateFileTypes(NSMutableDictionary* plist, | 542 void UpdateFileTypes(NSMutableDictionary* plist, |
| 500 const extensions::FileHandlersInfo& file_handlers_info) { | 543 const extensions::FileHandlersInfo& file_handlers_info) { |
| 501 NSMutableArray* document_types = | 544 NSMutableArray* document_types = |
| 502 [NSMutableArray arrayWithCapacity:file_handlers_info.size()]; | 545 [NSMutableArray arrayWithCapacity:file_handlers_info.size()]; |
| 503 | 546 |
| 504 for (extensions::FileHandlersInfo::const_iterator info_it = | 547 for (extensions::FileHandlersInfo::const_iterator info_it = |
| 505 file_handlers_info.begin(); | 548 file_handlers_info.begin(); |
| 506 info_it != file_handlers_info.end(); | 549 info_it != file_handlers_info.end(); |
| 507 ++info_it) { | 550 ++info_it) { |
| 508 const extensions::FileHandlerInfo& info = *info_it; | 551 const extensions::FileHandlerInfo& info = *info_it; |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 929 content::BrowserThread::PostTask( | 972 content::BrowserThread::PostTask( |
| 930 content::BrowserThread::FILE, | 973 content::BrowserThread::FILE, |
| 931 FROM_HERE, | 974 FROM_HERE, |
| 932 base::Bind(&LaunchShimOnFileThread, shortcut_info, false)); | 975 base::Bind(&LaunchShimOnFileThread, shortcut_info, false)); |
| 933 } | 976 } |
| 934 | 977 |
| 935 bool MaybeRebuildShortcut(const CommandLine& command_line) { | 978 bool MaybeRebuildShortcut(const CommandLine& command_line) { |
| 936 if (!command_line.HasSwitch(app_mode::kAppShimError)) | 979 if (!command_line.HasSwitch(app_mode::kAppShimError)) |
| 937 return false; | 980 return false; |
| 938 | 981 |
| 939 base::PostTaskAndReplyWithResult( | 982 content::BrowserThread::GetBlockingPool()->PostTask( |
| 940 content::BrowserThread::GetBlockingPool(), | |
| 941 FROM_HERE, | 983 FROM_HERE, |
| 942 base::Bind(&BuildShortcutInfoFromBundle, | 984 base::Bind(&RecordAppShimErrorAndRebuild, command_line)); |
|
tapted
2014/06/26 06:47:05
this will do a deep-copy of the command line objec
jackhou1
2014/06/27 04:55:56
Done.
| |
| 943 command_line.GetSwitchValuePath(app_mode::kAppShimError)), | |
| 944 base::Bind(&RebuildAppAndLaunch)); | |
| 945 return true; | 985 return true; |
| 946 } | 986 } |
| 947 | 987 |
| 948 // Called when the app's ShortcutInfo (with icon) is loaded when creating app | 988 // Called when the app's ShortcutInfo (with icon) is loaded when creating app |
| 949 // shortcuts. | 989 // shortcuts. |
| 950 void CreateAppShortcutInfoLoaded( | 990 void CreateAppShortcutInfoLoaded( |
| 951 Profile* profile, | 991 Profile* profile, |
| 952 const extensions::Extension* app, | 992 const extensions::Extension* app, |
| 953 const base::Callback<void(bool)>& close_callback, | 993 const base::Callback<void(bool)>& close_callback, |
| 954 const ShortcutInfo& shortcut_info) { | 994 const ShortcutInfo& shortcut_info) { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1089 web_app::UpdateShortcutInfoAndIconForApp( | 1129 web_app::UpdateShortcutInfoAndIconForApp( |
| 1090 app, | 1130 app, |
| 1091 profile, | 1131 profile, |
| 1092 base::Bind(&web_app::CreateAppShortcutInfoLoaded, | 1132 base::Bind(&web_app::CreateAppShortcutInfoLoaded, |
| 1093 profile, | 1133 profile, |
| 1094 app, | 1134 app, |
| 1095 close_callback)); | 1135 close_callback)); |
| 1096 } | 1136 } |
| 1097 | 1137 |
| 1098 } // namespace chrome | 1138 } // namespace chrome |
| OLD | NEW |