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

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

Issue 356893002: Add UMA for --app-shim-error. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 6 years, 5 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 | Annotate | Revision Log
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"
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
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. These are chosen to track the change from 32-bit to 64-bit.
63 // Order must be maintained as this is used in UMA.
64 enum AppShimError {
65 APP_SHIM_ERROR_UNKNOWN,
66 APP_SHIM_ERROR_37_OR_LOWER,
67 APP_SHIM_ERROR_38,
68 APP_SHIM_ERROR_39_OR_HIGHER,
69 APP_SHIM_ERROR_COUNT,
70 };
71
60 class ScopedCarbonHandle { 72 class ScopedCarbonHandle {
61 public: 73 public:
62 ScopedCarbonHandle(size_t initial_size) : handle_(NewHandle(initial_size)) { 74 ScopedCarbonHandle(size_t initial_size) : handle_(NewHandle(initial_size)) {
63 DCHECK(handle_); 75 DCHECK(handle_);
64 DCHECK_EQ(noErr, MemError()); 76 DCHECK_EQ(noErr, MemError());
65 } 77 }
66 ~ScopedCarbonHandle() { DisposeHandle(handle_); } 78 ~ScopedCarbonHandle() { DisposeHandle(handle_); }
67 79
68 Handle Get() { return handle_; } 80 Handle Get() { return handle_; }
69 char* Data() { return *handle_; } 81 char* Data() { return *handle_; }
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 base::FilePath profile_base_name = base::mac::NSStringToFilePath( 501 base::FilePath profile_base_name = base::mac::NSStringToFilePath(
490 [plist valueForKey:app_mode::kCrAppModeProfileDirKey]); 502 [plist valueForKey:app_mode::kCrAppModeProfileDirKey]);
491 if (user_data_dir.DirName().DirName().BaseName() == profile_base_name) 503 if (user_data_dir.DirName().DirName().BaseName() == profile_base_name)
492 shortcut_info.profile_path = user_data_dir.DirName().DirName(); 504 shortcut_info.profile_path = user_data_dir.DirName().DirName();
493 else 505 else
494 shortcut_info.profile_path = user_data_dir.Append(profile_base_name); 506 shortcut_info.profile_path = user_data_dir.Append(profile_base_name);
495 507
496 return shortcut_info; 508 return shortcut_info;
497 } 509 }
498 510
511 web_app::ShortcutInfo RecordAppShimErrorAndBuildShortcutInfo(
512 const base::FilePath& bundle_path) {
513 NSDictionary* plist = ReadPlist(GetPlistPath(bundle_path));
514 int version = [[[[plist valueForKey:app_mode::kCFBundleShortVersionStringKey]
Robert Sesek 2014/07/01 14:10:39 May want to use base/version.h.
jackhou1 2014/07/02 03:18:12 Done.
515 componentsSeparatedByString:@"."] objectAtIndex:0] intValue];
516 AppShimError error_enum;
517 if (version < 38)
tapted 2014/07/01 12:48:11 probably needs `version > 0 &&..` here so the unkn
jackhou1 2014/07/02 03:18:12 Done.
518 error_enum = APP_SHIM_ERROR_37_OR_LOWER;
519 else if (version == 38)
520 error_enum = APP_SHIM_ERROR_38;
521 else if (version > 38)
522 error_enum = APP_SHIM_ERROR_39_OR_HIGHER;
523 else
524 error_enum = APP_SHIM_ERROR_UNKNOWN;
525 UMA_HISTOGRAM_ENUMERATION("Apps.AppShimError",
Robert Sesek 2014/07/01 14:10:39 Would it make more sense to just histogram the |ve
jackhou1 2014/07/02 03:18:11 Done.
526 error_enum,
527 APP_SHIM_ERROR_COUNT);
528
529 return BuildShortcutInfoFromBundle(bundle_path);
530 }
531
499 void UpdateFileTypes(NSMutableDictionary* plist, 532 void UpdateFileTypes(NSMutableDictionary* plist,
500 const extensions::FileHandlersInfo& file_handlers_info) { 533 const extensions::FileHandlersInfo& file_handlers_info) {
501 NSMutableArray* document_types = 534 NSMutableArray* document_types =
502 [NSMutableArray arrayWithCapacity:file_handlers_info.size()]; 535 [NSMutableArray arrayWithCapacity:file_handlers_info.size()];
503 536
504 for (extensions::FileHandlersInfo::const_iterator info_it = 537 for (extensions::FileHandlersInfo::const_iterator info_it =
505 file_handlers_info.begin(); 538 file_handlers_info.begin();
506 info_it != file_handlers_info.end(); 539 info_it != file_handlers_info.end();
507 ++info_it) { 540 ++info_it) {
508 const extensions::FileHandlerInfo& info = *info_it; 541 const extensions::FileHandlerInfo& info = *info_it;
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 base::Bind(&LaunchShimOnFileThread, shortcut_info, false)); 965 base::Bind(&LaunchShimOnFileThread, shortcut_info, false));
933 } 966 }
934 967
935 bool MaybeRebuildShortcut(const CommandLine& command_line) { 968 bool MaybeRebuildShortcut(const CommandLine& command_line) {
936 if (!command_line.HasSwitch(app_mode::kAppShimError)) 969 if (!command_line.HasSwitch(app_mode::kAppShimError))
937 return false; 970 return false;
938 971
939 base::PostTaskAndReplyWithResult( 972 base::PostTaskAndReplyWithResult(
940 content::BrowserThread::GetBlockingPool(), 973 content::BrowserThread::GetBlockingPool(),
941 FROM_HERE, 974 FROM_HERE,
942 base::Bind(&BuildShortcutInfoFromBundle, 975 base::Bind(&RecordAppShimErrorAndBuildShortcutInfo,
943 command_line.GetSwitchValuePath(app_mode::kAppShimError)), 976 command_line.GetSwitchValuePath(app_mode::kAppShimError)),
944 base::Bind(&RebuildAppAndLaunch)); 977 base::Bind(&RebuildAppAndLaunch));
945 return true; 978 return true;
946 } 979 }
947 980
948 // Called when the app's ShortcutInfo (with icon) is loaded when creating app 981 // Called when the app's ShortcutInfo (with icon) is loaded when creating app
949 // shortcuts. 982 // shortcuts.
950 void CreateAppShortcutInfoLoaded( 983 void CreateAppShortcutInfoLoaded(
951 Profile* profile, 984 Profile* profile,
952 const extensions::Extension* app, 985 const extensions::Extension* app,
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 web_app::UpdateShortcutInfoAndIconForApp( 1122 web_app::UpdateShortcutInfoAndIconForApp(
1090 app, 1123 app,
1091 profile, 1124 profile,
1092 base::Bind(&web_app::CreateAppShortcutInfoLoaded, 1125 base::Bind(&web_app::CreateAppShortcutInfoLoaded,
1093 profile, 1126 profile,
1094 app, 1127 app,
1095 close_callback)); 1128 close_callback));
1096 } 1129 }
1097 1130
1098 } // namespace chrome 1131 } // namespace chrome
OLDNEW
« no previous file with comments | « no previous file | chrome/common/mac/app_mode_common.h » ('j') | tools/metrics/histograms/histograms.xml » ('J')

Powered by Google App Engine
This is Rietveld 408576698