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 version of | |
62 // the app shim. | |
tapted
2014/07/01 05:53:58
nit: mention that buckets are chosen to track the
jackhou1
2014/07/01 07:37:51
Done.
| |
63 // Order must be maintained as this is used in UMA. | |
64 enum AppShimError { | |
65 APP_SHIM_ERROR_37_OR_LOWER, | |
66 APP_SHIM_ERROR_38, | |
67 APP_SHIM_ERROR_39_OR_HIGHER, | |
68 APP_SHIM_ERROR_COUNT, | |
69 }; | |
70 | |
60 class ScopedCarbonHandle { | 71 class ScopedCarbonHandle { |
61 public: | 72 public: |
62 ScopedCarbonHandle(size_t initial_size) : handle_(NewHandle(initial_size)) { | 73 ScopedCarbonHandle(size_t initial_size) : handle_(NewHandle(initial_size)) { |
63 DCHECK(handle_); | 74 DCHECK(handle_); |
64 DCHECK_EQ(noErr, MemError()); | 75 DCHECK_EQ(noErr, MemError()); |
65 } | 76 } |
66 ~ScopedCarbonHandle() { DisposeHandle(handle_); } | 77 ~ScopedCarbonHandle() { DisposeHandle(handle_); } |
67 | 78 |
68 Handle Get() { return handle_; } | 79 Handle Get() { return handle_; } |
69 char* Data() { return *handle_; } | 80 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( | 500 base::FilePath profile_base_name = base::mac::NSStringToFilePath( |
490 [plist valueForKey:app_mode::kCrAppModeProfileDirKey]); | 501 [plist valueForKey:app_mode::kCrAppModeProfileDirKey]); |
491 if (user_data_dir.DirName().DirName().BaseName() == profile_base_name) | 502 if (user_data_dir.DirName().DirName().BaseName() == profile_base_name) |
492 shortcut_info.profile_path = user_data_dir.DirName().DirName(); | 503 shortcut_info.profile_path = user_data_dir.DirName().DirName(); |
493 else | 504 else |
494 shortcut_info.profile_path = user_data_dir.Append(profile_base_name); | 505 shortcut_info.profile_path = user_data_dir.Append(profile_base_name); |
495 | 506 |
496 return shortcut_info; | 507 return shortcut_info; |
497 } | 508 } |
498 | 509 |
510 web_app::ShortcutInfo RecordAppShimErrorAndBuildShortcutInfo( | |
511 const base::FilePath& bundle_path) { | |
512 NSDictionary* plist = ReadPlist(GetPlistPath(bundle_path)); | |
513 int version = [[[[plist valueForKey:app_mode::kCFBundleShortVersionStringKey] | |
514 componentsSeparatedByString:@"."] objectAtIndex:0] intValue]; | |
tapted
2014/07/01 05:53:59
since we're rebuilding a possibly corrupt shim.. p
jackhou1
2014/07/01 07:37:51
Done.
I tried breaking the field in various ways
| |
515 int error_enum; | |
tapted
2014/07/01 05:53:58
int -> AppShimError?
jackhou1
2014/07/01 07:37:51
Done.
| |
516 if (version < 38) | |
517 error_enum = APP_SHIM_ERROR_37_OR_LOWER; | |
518 else if (version == 38) | |
519 error_enum = APP_SHIM_ERROR_38; | |
520 else | |
521 error_enum = APP_SHIM_ERROR_39_OR_HIGHER; | |
522 UMA_HISTOGRAM_ENUMERATION("Apps.AppShimError", | |
523 error_enum, | |
524 APP_SHIM_ERROR_COUNT); | |
525 | |
526 return BuildShortcutInfoFromBundle(bundle_path); | |
527 } | |
528 | |
499 void UpdateFileTypes(NSMutableDictionary* plist, | 529 void UpdateFileTypes(NSMutableDictionary* plist, |
500 const extensions::FileHandlersInfo& file_handlers_info) { | 530 const extensions::FileHandlersInfo& file_handlers_info) { |
501 NSMutableArray* document_types = | 531 NSMutableArray* document_types = |
502 [NSMutableArray arrayWithCapacity:file_handlers_info.size()]; | 532 [NSMutableArray arrayWithCapacity:file_handlers_info.size()]; |
503 | 533 |
504 for (extensions::FileHandlersInfo::const_iterator info_it = | 534 for (extensions::FileHandlersInfo::const_iterator info_it = |
505 file_handlers_info.begin(); | 535 file_handlers_info.begin(); |
506 info_it != file_handlers_info.end(); | 536 info_it != file_handlers_info.end(); |
507 ++info_it) { | 537 ++info_it) { |
508 const extensions::FileHandlerInfo& info = *info_it; | 538 const extensions::FileHandlerInfo& info = *info_it; |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
932 base::Bind(&LaunchShimOnFileThread, shortcut_info, false)); | 962 base::Bind(&LaunchShimOnFileThread, shortcut_info, false)); |
933 } | 963 } |
934 | 964 |
935 bool MaybeRebuildShortcut(const CommandLine& command_line) { | 965 bool MaybeRebuildShortcut(const CommandLine& command_line) { |
936 if (!command_line.HasSwitch(app_mode::kAppShimError)) | 966 if (!command_line.HasSwitch(app_mode::kAppShimError)) |
937 return false; | 967 return false; |
938 | 968 |
939 base::PostTaskAndReplyWithResult( | 969 base::PostTaskAndReplyWithResult( |
940 content::BrowserThread::GetBlockingPool(), | 970 content::BrowserThread::GetBlockingPool(), |
941 FROM_HERE, | 971 FROM_HERE, |
942 base::Bind(&BuildShortcutInfoFromBundle, | 972 base::Bind(&RecordAppShimErrorAndBuildShortcutInfo, |
943 command_line.GetSwitchValuePath(app_mode::kAppShimError)), | 973 command_line.GetSwitchValuePath(app_mode::kAppShimError)), |
944 base::Bind(&RebuildAppAndLaunch)); | 974 base::Bind(&RebuildAppAndLaunch)); |
945 return true; | 975 return true; |
946 } | 976 } |
947 | 977 |
948 // Called when the app's ShortcutInfo (with icon) is loaded when creating app | 978 // Called when the app's ShortcutInfo (with icon) is loaded when creating app |
949 // shortcuts. | 979 // shortcuts. |
950 void CreateAppShortcutInfoLoaded( | 980 void CreateAppShortcutInfoLoaded( |
951 Profile* profile, | 981 Profile* profile, |
952 const extensions::Extension* app, | 982 const extensions::Extension* app, |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1089 web_app::UpdateShortcutInfoAndIconForApp( | 1119 web_app::UpdateShortcutInfoAndIconForApp( |
1090 app, | 1120 app, |
1091 profile, | 1121 profile, |
1092 base::Bind(&web_app::CreateAppShortcutInfoLoaded, | 1122 base::Bind(&web_app::CreateAppShortcutInfoLoaded, |
1093 profile, | 1123 profile, |
1094 app, | 1124 app, |
1095 close_callback)); | 1125 close_callback)); |
1096 } | 1126 } |
1097 | 1127 |
1098 } // namespace chrome | 1128 } // namespace chrome |
OLD | NEW |