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/sparse_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" |
| 28 #include "base/version.h" |
27 #include "chrome/browser/browser_process.h" | 29 #include "chrome/browser/browser_process.h" |
28 #import "chrome/browser/mac/dock.h" | 30 #import "chrome/browser/mac/dock.h" |
29 #include "chrome/browser/browser_process.h" | 31 #include "chrome/browser/browser_process.h" |
30 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
31 #include "chrome/browser/profiles/profile_manager.h" | 33 #include "chrome/browser/profiles/profile_manager.h" |
32 #include "chrome/browser/shell_integration.h" | 34 #include "chrome/browser/shell_integration.h" |
33 #include "chrome/browser/ui/app_list/app_list_service.h" | 35 #include "chrome/browser/ui/app_list/app_list_service.h" |
34 #include "chrome/common/chrome_constants.h" | 36 #include "chrome/common/chrome_constants.h" |
35 #include "chrome/common/chrome_paths.h" | 37 #include "chrome/common/chrome_paths.h" |
36 #include "chrome/common/chrome_switches.h" | 38 #include "chrome/common/chrome_switches.h" |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 base::FilePath profile_base_name = base::mac::NSStringToFilePath( | 490 base::FilePath profile_base_name = base::mac::NSStringToFilePath( |
489 [plist valueForKey:app_mode::kCrAppModeProfileDirKey]); | 491 [plist valueForKey:app_mode::kCrAppModeProfileDirKey]); |
490 if (user_data_dir.DirName().DirName().BaseName() == profile_base_name) | 492 if (user_data_dir.DirName().DirName().BaseName() == profile_base_name) |
491 shortcut_info.profile_path = user_data_dir.DirName().DirName(); | 493 shortcut_info.profile_path = user_data_dir.DirName().DirName(); |
492 else | 494 else |
493 shortcut_info.profile_path = user_data_dir.Append(profile_base_name); | 495 shortcut_info.profile_path = user_data_dir.Append(profile_base_name); |
494 | 496 |
495 return shortcut_info; | 497 return shortcut_info; |
496 } | 498 } |
497 | 499 |
| 500 web_app::ShortcutInfo RecordAppShimErrorAndBuildShortcutInfo( |
| 501 const base::FilePath& bundle_path) { |
| 502 NSDictionary* plist = ReadPlist(GetPlistPath(bundle_path)); |
| 503 base::Version full_version(base::SysNSStringToUTF8( |
| 504 [plist valueForKey:app_mode::kCFBundleShortVersionStringKey])); |
| 505 int major_version = 0; |
| 506 if (full_version.IsValid()) |
| 507 major_version = full_version.components()[0]; |
| 508 UMA_HISTOGRAM_SPARSE_SLOWLY("Apps.AppShimErrorVersion", major_version); |
| 509 |
| 510 return BuildShortcutInfoFromBundle(bundle_path); |
| 511 } |
| 512 |
498 void UpdateFileTypes(NSMutableDictionary* plist, | 513 void UpdateFileTypes(NSMutableDictionary* plist, |
499 const extensions::FileHandlersInfo& file_handlers_info) { | 514 const extensions::FileHandlersInfo& file_handlers_info) { |
500 NSMutableArray* document_types = | 515 NSMutableArray* document_types = |
501 [NSMutableArray arrayWithCapacity:file_handlers_info.size()]; | 516 [NSMutableArray arrayWithCapacity:file_handlers_info.size()]; |
502 | 517 |
503 for (extensions::FileHandlersInfo::const_iterator info_it = | 518 for (extensions::FileHandlersInfo::const_iterator info_it = |
504 file_handlers_info.begin(); | 519 file_handlers_info.begin(); |
505 info_it != file_handlers_info.end(); | 520 info_it != file_handlers_info.end(); |
506 ++info_it) { | 521 ++info_it) { |
507 const extensions::FileHandlerInfo& info = *info_it; | 522 const extensions::FileHandlerInfo& info = *info_it; |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 base::Bind(&LaunchShimOnFileThread, shortcut_info, false)); | 946 base::Bind(&LaunchShimOnFileThread, shortcut_info, false)); |
932 } | 947 } |
933 | 948 |
934 bool MaybeRebuildShortcut(const CommandLine& command_line) { | 949 bool MaybeRebuildShortcut(const CommandLine& command_line) { |
935 if (!command_line.HasSwitch(app_mode::kAppShimError)) | 950 if (!command_line.HasSwitch(app_mode::kAppShimError)) |
936 return false; | 951 return false; |
937 | 952 |
938 base::PostTaskAndReplyWithResult( | 953 base::PostTaskAndReplyWithResult( |
939 content::BrowserThread::GetBlockingPool(), | 954 content::BrowserThread::GetBlockingPool(), |
940 FROM_HERE, | 955 FROM_HERE, |
941 base::Bind(&BuildShortcutInfoFromBundle, | 956 base::Bind(&RecordAppShimErrorAndBuildShortcutInfo, |
942 command_line.GetSwitchValuePath(app_mode::kAppShimError)), | 957 command_line.GetSwitchValuePath(app_mode::kAppShimError)), |
943 base::Bind(&RebuildAppAndLaunch)); | 958 base::Bind(&RebuildAppAndLaunch)); |
944 return true; | 959 return true; |
945 } | 960 } |
946 | 961 |
947 // Called when the app's ShortcutInfo (with icon) is loaded when creating app | 962 // Called when the app's ShortcutInfo (with icon) is loaded when creating app |
948 // shortcuts. | 963 // shortcuts. |
949 void CreateAppShortcutInfoLoaded( | 964 void CreateAppShortcutInfoLoaded( |
950 Profile* profile, | 965 Profile* profile, |
951 const extensions::Extension* app, | 966 const extensions::Extension* app, |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1088 web_app::GetShortcutInfoForApp( | 1103 web_app::GetShortcutInfoForApp( |
1089 app, | 1104 app, |
1090 profile, | 1105 profile, |
1091 base::Bind(&web_app::CreateAppShortcutInfoLoaded, | 1106 base::Bind(&web_app::CreateAppShortcutInfoLoaded, |
1092 profile, | 1107 profile, |
1093 app, | 1108 app, |
1094 close_callback)); | 1109 close_callback)); |
1095 } | 1110 } |
1096 | 1111 |
1097 } // namespace chrome | 1112 } // namespace chrome |
OLD | NEW |