| 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 #include "chrome/browser/chrome_browser_main_mac.h" | 5 #include "chrome/browser/chrome_browser_main_mac.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 #include <sys/sysctl.h> | |
| 9 | 8 |
| 10 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 11 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 12 #include "base/mac/bundle_locations.h" | 11 #include "base/mac/bundle_locations.h" |
| 13 #include "base/mac/mac_util.h" | 12 #include "base/mac/mac_util.h" |
| 14 #include "base/mac/scoped_nsobject.h" | 13 #include "base/mac/scoped_nsobject.h" |
| 15 #include "base/metrics/histogram.h" | |
| 16 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 17 #import "chrome/browser/app_controller_mac.h" | 15 #import "chrome/browser/app_controller_mac.h" |
| 18 #include "chrome/browser/apps/app_shim/app_shim_host_manager_mac.h" | 16 #include "chrome/browser/apps/app_shim/app_shim_host_manager_mac.h" |
| 19 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 20 #import "chrome/browser/chrome_browser_application_mac.h" | 18 #import "chrome/browser/chrome_browser_application_mac.h" |
| 21 #include "chrome/browser/mac/install_from_dmg.h" | 19 #include "chrome/browser/mac/install_from_dmg.h" |
| 22 #import "chrome/browser/mac/keystone_glue.h" | 20 #import "chrome/browser/mac/keystone_glue.h" |
| 23 #include "chrome/browser/mac/mac_startup_profiler.h" | 21 #include "chrome/browser/mac/mac_startup_profiler.h" |
| 24 #include "chrome/browser/ui/app_list/app_list_service.h" | 22 #include "chrome/browser/ui/app_list/app_list_service.h" |
| 25 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
| 26 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
| 27 #include "components/crash/app/crashpad_mac.h" | 25 #include "components/crash/app/crashpad_mac.h" |
| 28 #include "components/metrics/metrics_service.h" | 26 #include "components/metrics/metrics_service.h" |
| 29 #include "content/public/common/main_function_params.h" | 27 #include "content/public/common/main_function_params.h" |
| 30 #include "content/public/common/result_codes.h" | 28 #include "content/public/common/result_codes.h" |
| 31 #include "ui/base/l10n/l10n_util_mac.h" | 29 #include "ui/base/l10n/l10n_util_mac.h" |
| 32 #include "ui/base/resource/resource_bundle.h" | 30 #include "ui/base/resource/resource_bundle.h" |
| 33 #include "ui/base/resource/resource_handle.h" | 31 #include "ui/base/resource/resource_handle.h" |
| 34 | 32 |
| 35 namespace { | |
| 36 | |
| 37 // This is one enum instead of two so that the values can be correlated in a | |
| 38 // histogram. | |
| 39 enum CatSixtyFour { | |
| 40 // Older than any expected cat. | |
| 41 SABER_TOOTHED_CAT_32 = 0, | |
| 42 SABER_TOOTHED_CAT_64, | |
| 43 | |
| 44 // Known cats. | |
| 45 SNOW_LEOPARD_32, | |
| 46 SNOW_LEOPARD_64, | |
| 47 LION_32, // Unexpected, Lion requires a 64-bit CPU. | |
| 48 LION_64, | |
| 49 MOUNTAIN_LION_32, // Unexpected, Mountain Lion requires a 64-bit CPU. | |
| 50 MOUNTAIN_LION_64, | |
| 51 MAVERICKS_32, // Unexpected, Mavericks requires a 64-bit CPU. | |
| 52 MAVERICKS_64, | |
| 53 | |
| 54 // DON'T add new constants here. It's important to keep the constant values, | |
| 55 // um, constant. Add new constants at the bottom. | |
| 56 | |
| 57 // What if the bitsiness of the CPU can't be determined? | |
| 58 SABER_TOOTHED_CAT_DUNNO, | |
| 59 SNOW_LEOPARD_DUNNO, | |
| 60 LION_DUNNO, | |
| 61 MOUNTAIN_LION_DUNNO, | |
| 62 MAVERICKS_DUNNO, | |
| 63 | |
| 64 // More known cats. | |
| 65 YOSEMITE_32, // Unexpected, Yosemite requires a 64-bit CPU. | |
| 66 YOSEMITE_64, | |
| 67 YOSEMITE_DUNNO, | |
| 68 | |
| 69 // Newer than any known cat. | |
| 70 FUTURE_CAT_32, // Unexpected, it's unlikely Apple will un-obsolete old CPUs. | |
| 71 FUTURE_CAT_64, | |
| 72 FUTURE_CAT_DUNNO, | |
| 73 | |
| 74 // As new versions of Mac OS X are released with sillier and sillier names, | |
| 75 // rename the FUTURE_CAT enum values to match those names, and re-create | |
| 76 // FUTURE_CAT_[32|64|DUNNO] here. | |
| 77 | |
| 78 CAT_SIXTY_FOUR_MAX | |
| 79 }; | |
| 80 | |
| 81 CatSixtyFour CatSixtyFourValue() { | |
| 82 #if defined(ARCH_CPU_64_BITS) | |
| 83 // If 64-bit code is running, then it's established that this CPU can run | |
| 84 // 64-bit code, and no further inquiry is necessary. | |
| 85 int cpu64 = 1; | |
| 86 bool cpu64_known = true; | |
| 87 #else | |
| 88 // Check a sysctl conveniently provided by the kernel that identifies | |
| 89 // whether the CPU supports 64-bit operation. Note that this tests the | |
| 90 // actual hardware capabilities, not the bitsiness of the running process, | |
| 91 // and not the bitsiness of the running kernel. The value thus determines | |
| 92 // whether the CPU is capable of running 64-bit programs (in the presence of | |
| 93 // proper OS runtime support) without regard to whether the current program | |
| 94 // is 64-bit (it may not be) or whether the current kernel is (the kernel | |
| 95 // can launch cross-bitted user-space tasks). | |
| 96 | |
| 97 int cpu64; | |
| 98 size_t len = sizeof(cpu64); | |
| 99 const char kSysctlName[] = "hw.cpu64bit_capable"; | |
| 100 bool cpu64_known = sysctlbyname(kSysctlName, &cpu64, &len, NULL, 0) == 0; | |
| 101 if (!cpu64_known) { | |
| 102 PLOG(WARNING) << "sysctlbyname(\"" << kSysctlName << "\")"; | |
| 103 } | |
| 104 #endif | |
| 105 | |
| 106 if (base::mac::IsOSSnowLeopard()) { | |
| 107 return cpu64_known ? (cpu64 ? SNOW_LEOPARD_64 : SNOW_LEOPARD_32) : | |
| 108 SNOW_LEOPARD_DUNNO; | |
| 109 } | |
| 110 if (base::mac::IsOSLion()) { | |
| 111 return cpu64_known ? (cpu64 ? LION_64 : LION_32) : | |
| 112 LION_DUNNO; | |
| 113 } | |
| 114 if (base::mac::IsOSMountainLion()) { | |
| 115 return cpu64_known ? (cpu64 ? MOUNTAIN_LION_64 : MOUNTAIN_LION_32) : | |
| 116 MOUNTAIN_LION_DUNNO; | |
| 117 } | |
| 118 if (base::mac::IsOSMavericks()) { | |
| 119 return cpu64_known ? (cpu64 ? MAVERICKS_64 : MAVERICKS_32) : | |
| 120 MAVERICKS_DUNNO; | |
| 121 } | |
| 122 if (base::mac::IsOSYosemite()) { | |
| 123 return cpu64_known ? (cpu64 ? YOSEMITE_64 : YOSEMITE_32) : | |
| 124 YOSEMITE_DUNNO; | |
| 125 } | |
| 126 if (base::mac::IsOSLaterThanYosemite_DontCallThis()) { | |
| 127 return cpu64_known ? (cpu64 ? FUTURE_CAT_64 : FUTURE_CAT_32) : | |
| 128 FUTURE_CAT_DUNNO; | |
| 129 } | |
| 130 | |
| 131 // If it's not any of the expected OS versions or later than them, it must | |
| 132 // be prehistoric. | |
| 133 return cpu64_known ? (cpu64 ? SABER_TOOTHED_CAT_64 : SABER_TOOTHED_CAT_32) : | |
| 134 SABER_TOOTHED_CAT_DUNNO; | |
| 135 } | |
| 136 | |
| 137 void RecordCatSixtyFour() { | |
| 138 CatSixtyFour cat_sixty_four = CatSixtyFourValue(); | |
| 139 | |
| 140 // Set this higher than the highest value in the CatSixtyFour enum to provide | |
| 141 // some headroom and then leave it alone. See UMA_HISTOGRAM_ENUMERATION in | |
| 142 // base/metrics/histogram.h. | |
| 143 const int kMaxCatsAndSixtyFours = 32; | |
| 144 static_assert(kMaxCatsAndSixtyFours >= CAT_SIXTY_FOUR_MAX, | |
| 145 "kMaxCatsAndSixtyFours is too large"); | |
| 146 | |
| 147 UMA_HISTOGRAM_ENUMERATION("OSX.CatSixtyFour", | |
| 148 cat_sixty_four, | |
| 149 kMaxCatsAndSixtyFours); | |
| 150 } | |
| 151 | |
| 152 } // namespace | |
| 153 | |
| 154 // ChromeBrowserMainPartsMac --------------------------------------------------- | 33 // ChromeBrowserMainPartsMac --------------------------------------------------- |
| 155 | 34 |
| 156 ChromeBrowserMainPartsMac::ChromeBrowserMainPartsMac( | 35 ChromeBrowserMainPartsMac::ChromeBrowserMainPartsMac( |
| 157 const content::MainFunctionParams& parameters) | 36 const content::MainFunctionParams& parameters) |
| 158 : ChromeBrowserMainPartsPosix(parameters) { | 37 : ChromeBrowserMainPartsPosix(parameters) { |
| 159 } | 38 } |
| 160 | 39 |
| 161 ChromeBrowserMainPartsMac::~ChromeBrowserMainPartsMac() { | 40 ChromeBrowserMainPartsMac::~ChromeBrowserMainPartsMac() { |
| 162 } | 41 } |
| 163 | 42 |
| 164 void ChromeBrowserMainPartsMac::PreEarlyInitialization() { | 43 void ChromeBrowserMainPartsMac::PreEarlyInitialization() { |
| 165 ChromeBrowserMainPartsPosix::PreEarlyInitialization(); | 44 ChromeBrowserMainPartsPosix::PreEarlyInitialization(); |
| 166 | 45 |
| 167 if (base::mac::WasLaunchedAsLoginItemRestoreState()) { | 46 if (base::mac::WasLaunchedAsLoginItemRestoreState()) { |
| 168 base::CommandLine* singleton_command_line = | 47 base::CommandLine* singleton_command_line = |
| 169 base::CommandLine::ForCurrentProcess(); | 48 base::CommandLine::ForCurrentProcess(); |
| 170 singleton_command_line->AppendSwitch(switches::kRestoreLastSession); | 49 singleton_command_line->AppendSwitch(switches::kRestoreLastSession); |
| 171 } else if (base::mac::WasLaunchedAsHiddenLoginItem()) { | 50 } else if (base::mac::WasLaunchedAsHiddenLoginItem()) { |
| 172 base::CommandLine* singleton_command_line = | 51 base::CommandLine* singleton_command_line = |
| 173 base::CommandLine::ForCurrentProcess(); | 52 base::CommandLine::ForCurrentProcess(); |
| 174 singleton_command_line->AppendSwitch(switches::kNoStartupWindow); | 53 singleton_command_line->AppendSwitch(switches::kNoStartupWindow); |
| 175 } | 54 } |
| 176 | |
| 177 RecordCatSixtyFour(); | |
| 178 } | 55 } |
| 179 | 56 |
| 180 void ChromeBrowserMainPartsMac::PreMainMessageLoopStart() { | 57 void ChromeBrowserMainPartsMac::PreMainMessageLoopStart() { |
| 181 MacStartupProfiler::GetInstance()->Profile( | 58 MacStartupProfiler::GetInstance()->Profile( |
| 182 MacStartupProfiler::PRE_MAIN_MESSAGE_LOOP_START); | 59 MacStartupProfiler::PRE_MAIN_MESSAGE_LOOP_START); |
| 183 ChromeBrowserMainPartsPosix::PreMainMessageLoopStart(); | 60 ChromeBrowserMainPartsPosix::PreMainMessageLoopStart(); |
| 184 | 61 |
| 185 // Tell Cocoa to finish its initialization, which we want to do manually | 62 // Tell Cocoa to finish its initialization, which we want to do manually |
| 186 // instead of calling NSApplicationMain(). The primary reason is that NSAM() | 63 // instead of calling NSApplicationMain(). The primary reason is that NSAM() |
| 187 // never returns, which would leave all the objects currently on the stack | 64 // never returns, which would leave all the objects currently on the stack |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 ChromeBrowserMainPartsPosix::PostProfileInit(); | 171 ChromeBrowserMainPartsPosix::PostProfileInit(); |
| 295 | 172 |
| 296 g_browser_process->metrics_service()->RecordBreakpadRegistration( | 173 g_browser_process->metrics_service()->RecordBreakpadRegistration( |
| 297 crash_reporter::GetUploadsEnabled()); | 174 crash_reporter::GetUploadsEnabled()); |
| 298 } | 175 } |
| 299 | 176 |
| 300 void ChromeBrowserMainPartsMac::DidEndMainMessageLoop() { | 177 void ChromeBrowserMainPartsMac::DidEndMainMessageLoop() { |
| 301 AppController* appController = [NSApp delegate]; | 178 AppController* appController = [NSApp delegate]; |
| 302 [appController didEndMainMessageLoop]; | 179 [appController didEndMainMessageLoop]; |
| 303 } | 180 } |
| OLD | NEW |