| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser_main.h" | 5 #include "chrome/browser/browser_main.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 #endif | 205 #endif |
| 206 | 206 |
| 207 #if defined(TOOLKIT_USES_GTK) | 207 #if defined(TOOLKIT_USES_GTK) |
| 208 #include "ui/gfx/gtk_util.h" | 208 #include "ui/gfx/gtk_util.h" |
| 209 #endif | 209 #endif |
| 210 | 210 |
| 211 #if defined(TOUCH_UI) | 211 #if defined(TOUCH_UI) |
| 212 #include "views/touchui/touch_factory.h" | 212 #include "views/touchui/touch_factory.h" |
| 213 #endif | 213 #endif |
| 214 | 214 |
| 215 namespace { | |
| 216 void SetSocketReusePolicy(int warmest_socket_trial_group, | |
| 217 const int socket_policy[], | |
| 218 int num_groups) { | |
| 219 const int* result = std::find(socket_policy, socket_policy + num_groups, | |
| 220 warmest_socket_trial_group); | |
| 221 DCHECK_NE(result, socket_policy + num_groups) | |
| 222 << "Not a valid socket reuse policy group"; | |
| 223 net::SetSocketReusePolicy(result - socket_policy); | |
| 224 } | |
| 225 } | |
| 226 | |
| 227 namespace net { | 215 namespace net { |
| 228 class NetLog; | 216 class NetLog; |
| 229 } // namespace net | 217 } // namespace net |
| 230 | 218 |
| 231 // This code is specific to the Windows-only PreReadExperiment field-trial. | 219 namespace { |
| 232 static void AddPreReadHistogramTime(const char* name, base::TimeDelta time) { | 220 void SetSocketReusePolicy(int warmest_socket_trial_group, |
| 233 const base::TimeDelta kMin(base::TimeDelta::FromMilliseconds(1)); | 221 const int socket_policy[], |
| 234 const base::TimeDelta kMax(base::TimeDelta::FromHours(1)); | 222 int num_groups); |
| 235 static const size_t kBuckets(100); | 223 } // namespace |
| 236 | |
| 237 // FactoryTimeGet will always return a pointer to the same histogram object, | |
| 238 // keyed on its name. There's no need for us to store it explicitly anywhere. | |
| 239 base::Histogram* counter = base::Histogram::FactoryTimeGet( | |
| 240 name, kMin, kMax, kBuckets, base::Histogram::kUmaTargetedHistogramFlag); | |
| 241 | |
| 242 counter->AddTime(time); | |
| 243 } | |
| 244 | |
| 245 // This code is specific to the Windows-only PreReadExperiment field-trial. | |
| 246 void RecordPreReadExperimentTime(const char* name, base::TimeDelta time) { | |
| 247 DCHECK(name != NULL); | |
| 248 | |
| 249 // This gets called with different histogram names, so we don't want to use | |
| 250 // the UMA_HISTOGRAM_CUSTOM_TIMES macro--it uses a static variable, and the | |
| 251 // first call wins. | |
| 252 AddPreReadHistogramTime(name, time); | |
| 253 | |
| 254 #if defined(OS_WIN) | |
| 255 static const char kEnvVar[] = "CHROME_PRE_READ_EXPERIMENT"; | |
| 256 | |
| 257 // The pre-read experiment is Windows specific. | |
| 258 scoped_ptr<base::Environment> env(base::Environment::Create()); | |
| 259 DCHECK(env.get() != NULL); | |
| 260 | |
| 261 // Only record the sub-histogram result if the experiment is running | |
| 262 // (environment variable is set, and valid). | |
| 263 std::string pre_read; | |
| 264 if (env->GetVar(kEnvVar, &pre_read) && (pre_read == "0" || pre_read == "1")) { | |
| 265 std::string uma_name(name); | |
| 266 uma_name += "_PreRead"; | |
| 267 uma_name += pre_read == "1" ? "Enabled" : "Disabled"; | |
| 268 AddPreReadHistogramTime(uma_name.c_str(), time); | |
| 269 } | |
| 270 #endif | |
| 271 } | |
| 272 | 224 |
| 273 // BrowserMainParts ------------------------------------------------------------ | 225 // BrowserMainParts ------------------------------------------------------------ |
| 274 | 226 |
| 275 BrowserMainParts::BrowserMainParts(const MainFunctionParams& parameters) | 227 BrowserMainParts::BrowserMainParts(const MainFunctionParams& parameters) |
| 276 : parameters_(parameters), | 228 : parameters_(parameters), |
| 277 parsed_command_line_(parameters.command_line_) { | 229 parsed_command_line_(parameters.command_line_) { |
| 278 } | 230 } |
| 279 | 231 |
| 280 BrowserMainParts::~BrowserMainParts() { | 232 BrowserMainParts::~BrowserMainParts() { |
| 281 } | 233 } |
| (...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1258 std::string trans_label = gfx::ConvertAcceleratorsFromWindowsStyle( | 1210 std::string trans_label = gfx::ConvertAcceleratorsFromWindowsStyle( |
| 1259 l10n_util::GetStringUTF8(trans->resource_id)); | 1211 l10n_util::GetStringUTF8(trans->resource_id)); |
| 1260 stock_item.label = g_strdup(trans_label.c_str()); | 1212 stock_item.label = g_strdup(trans_label.c_str()); |
| 1261 gtk_stock_add(&stock_item, 1); | 1213 gtk_stock_add(&stock_item, 1); |
| 1262 g_free(stock_item.label); | 1214 g_free(stock_item.label); |
| 1263 } | 1215 } |
| 1264 } | 1216 } |
| 1265 } | 1217 } |
| 1266 #endif // defined(OS_CHROMEOS) | 1218 #endif // defined(OS_CHROMEOS) |
| 1267 | 1219 |
| 1268 } // namespace | 1220 void SetSocketReusePolicy(int warmest_socket_trial_group, |
| 1269 | 1221 const int socket_policy[], |
| 1270 #if defined(OS_CHROMEOS) | 1222 int num_groups) { |
| 1271 // Allows authenticator to be invoked without adding refcounting. The instances | 1223 const int* result = std::find(socket_policy, socket_policy + num_groups, |
| 1272 // will delete themselves upon completion. | 1224 warmest_socket_trial_group); |
| 1273 DISABLE_RUNNABLE_METHOD_REFCOUNT(StubLogin); | 1225 DCHECK_NE(result, socket_policy + num_groups) |
| 1274 #endif | 1226 << "Not a valid socket reuse policy group"; |
| 1275 | 1227 net::SetSocketReusePolicy(result - socket_policy); |
| 1276 #if defined(OS_WIN) | |
| 1277 #define DLLEXPORT __declspec(dllexport) | |
| 1278 | |
| 1279 // We use extern C for the prototype DLLEXPORT to avoid C++ name mangling. | |
| 1280 extern "C" { | |
| 1281 DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded(); | |
| 1282 } | 1228 } |
| 1283 | 1229 |
| 1284 DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded() { | 1230 // This code is specific to the Windows-only PreReadExperiment field-trial. |
| 1285 // Need an instance of AtExitManager to handle singleton creations and | 1231 void AddPreReadHistogramTime(const char* name, base::TimeDelta time) { |
| 1286 // deletions. We need this new instance because, the old instance created | 1232 const base::TimeDelta kMin(base::TimeDelta::FromMilliseconds(1)); |
| 1287 // in ChromeMain() got destructed when the function returned. | 1233 const base::TimeDelta kMax(base::TimeDelta::FromHours(1)); |
| 1288 base::AtExitManager exit_manager; | 1234 static const size_t kBuckets(100); |
| 1289 upgrade_util::RelaunchChromeBrowserWithNewCommandLineIfNeeded(); | 1235 |
| 1236 // FactoryTimeGet will always return a pointer to the same histogram object, |
| 1237 // keyed on its name. There's no need for us to store it explicitly anywhere. |
| 1238 base::Histogram* counter = base::Histogram::FactoryTimeGet( |
| 1239 name, kMin, kMax, kBuckets, base::Histogram::kUmaTargetedHistogramFlag); |
| 1240 |
| 1241 counter->AddTime(time); |
| 1290 } | 1242 } |
| 1291 #endif | |
| 1292 | 1243 |
| 1293 #if defined(USE_LINUX_BREAKPAD) | 1244 #if defined(USE_LINUX_BREAKPAD) |
| 1294 bool IsCrashReportingEnabled(const PrefService* local_state) { | 1245 bool IsCrashReportingEnabled(const PrefService* local_state) { |
| 1295 // Check whether we should initialize the crash reporter. It may be disabled | 1246 // Check whether we should initialize the crash reporter. It may be disabled |
| 1296 // through configuration policy or user preference. It must be disabled for | 1247 // through configuration policy or user preference. It must be disabled for |
| 1297 // Guest mode on Chrome OS in Stable channel. | 1248 // Guest mode on Chrome OS in Stable channel. |
| 1298 // The kHeadless environment variable overrides the decision, but only if the | 1249 // The kHeadless environment variable overrides the decision, but only if the |
| 1299 // crash service is under control of the user. It is used by QA testing | 1250 // crash service is under control of the user. It is used by QA testing |
| 1300 // infrastructure to switch on generation of crash reports. | 1251 // infrastructure to switch on generation of crash reports. |
| 1301 #if defined(OS_CHROMEOS) | 1252 #if defined(OS_CHROMEOS) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1314 CHECK(metrics_reporting_enabled); | 1265 CHECK(metrics_reporting_enabled); |
| 1315 bool breakpad_enabled = | 1266 bool breakpad_enabled = |
| 1316 local_state->GetBoolean(prefs::kMetricsReportingEnabled); | 1267 local_state->GetBoolean(prefs::kMetricsReportingEnabled); |
| 1317 if (!breakpad_enabled && metrics_reporting_enabled->IsUserModifiable()) | 1268 if (!breakpad_enabled && metrics_reporting_enabled->IsUserModifiable()) |
| 1318 breakpad_enabled = getenv(env_vars::kHeadless) != NULL; | 1269 breakpad_enabled = getenv(env_vars::kHeadless) != NULL; |
| 1319 #endif // #if defined(OS_CHROMEOS) | 1270 #endif // #if defined(OS_CHROMEOS) |
| 1320 return breakpad_enabled; | 1271 return breakpad_enabled; |
| 1321 } | 1272 } |
| 1322 #endif // #if defined(USE_LINUX_BREAKPAD) | 1273 #endif // #if defined(USE_LINUX_BREAKPAD) |
| 1323 | 1274 |
| 1275 } // namespace |
| 1276 |
| 1277 #if defined(OS_CHROMEOS) |
| 1278 // Allows authenticator to be invoked without adding refcounting. The instances |
| 1279 // will delete themselves upon completion. |
| 1280 DISABLE_RUNNABLE_METHOD_REFCOUNT(StubLogin); |
| 1281 #endif |
| 1282 |
| 1283 #if defined(OS_WIN) |
| 1284 #define DLLEXPORT __declspec(dllexport) |
| 1285 |
| 1286 // We use extern C for the prototype DLLEXPORT to avoid C++ name mangling. |
| 1287 extern "C" { |
| 1288 DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded(); |
| 1289 } |
| 1290 |
| 1291 DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded() { |
| 1292 // Need an instance of AtExitManager to handle singleton creations and |
| 1293 // deletions. We need this new instance because, the old instance created |
| 1294 // in ChromeMain() got destructed when the function returned. |
| 1295 base::AtExitManager exit_manager; |
| 1296 upgrade_util::RelaunchChromeBrowserWithNewCommandLineIfNeeded(); |
| 1297 } |
| 1298 #endif |
| 1299 |
| 1324 // Main routine for running as the Browser process. | 1300 // Main routine for running as the Browser process. |
| 1325 int BrowserMain(const MainFunctionParams& parameters) { | 1301 int BrowserMain(const MainFunctionParams& parameters) { |
| 1326 TRACE_EVENT_BEGIN_ETW("BrowserMain", 0, ""); | 1302 TRACE_EVENT_BEGIN_ETW("BrowserMain", 0, ""); |
| 1327 | 1303 |
| 1328 // Override the default ContentBrowserClient to let Chrome participate in | 1304 // Override the default ContentBrowserClient to let Chrome participate in |
| 1329 // content logic. | 1305 // content logic. |
| 1330 chrome::ChromeContentBrowserClient browser_client; | 1306 chrome::ChromeContentBrowserClient browser_client; |
| 1331 content::GetContentClient()->set_browser(&browser_client); | 1307 content::GetContentClient()->set_browser(&browser_client); |
| 1332 | 1308 |
| 1333 // If we're running tests (ui_task is non-null). | 1309 // If we're running tests (ui_task is non-null). |
| (...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2155 #if defined(OS_CHROMEOS) | 2131 #if defined(OS_CHROMEOS) |
| 2156 // To be precise, logout (browser shutdown) is not yet done, but the | 2132 // To be precise, logout (browser shutdown) is not yet done, but the |
| 2157 // remaining work is negligible, hence we say LogoutDone here. | 2133 // remaining work is negligible, hence we say LogoutDone here. |
| 2158 chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("LogoutDone", | 2134 chromeos::BootTimesLoader::Get()->AddLogoutTimeMarker("LogoutDone", |
| 2159 false); | 2135 false); |
| 2160 chromeos::BootTimesLoader::Get()->WriteLogoutTimes(); | 2136 chromeos::BootTimesLoader::Get()->WriteLogoutTimes(); |
| 2161 #endif | 2137 #endif |
| 2162 TRACE_EVENT_END_ETW("BrowserMain", 0, 0); | 2138 TRACE_EVENT_END_ETW("BrowserMain", 0, 0); |
| 2163 return result_code; | 2139 return result_code; |
| 2164 } | 2140 } |
| 2141 |
| 2142 // This code is specific to the Windows-only PreReadExperiment field-trial. |
| 2143 void RecordPreReadExperimentTime(const char* name, base::TimeDelta time) { |
| 2144 DCHECK(name != NULL); |
| 2145 |
| 2146 // This gets called with different histogram names, so we don't want to use |
| 2147 // the UMA_HISTOGRAM_CUSTOM_TIMES macro--it uses a static variable, and the |
| 2148 // first call wins. |
| 2149 AddPreReadHistogramTime(name, time); |
| 2150 |
| 2151 #if defined(OS_WIN) |
| 2152 static const char kEnvVar[] = "CHROME_PRE_READ_EXPERIMENT"; |
| 2153 |
| 2154 // The pre-read experiment is Windows specific. |
| 2155 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 2156 DCHECK(env.get() != NULL); |
| 2157 |
| 2158 // Only record the sub-histogram result if the experiment is running |
| 2159 // (environment variable is set, and valid). |
| 2160 std::string pre_read; |
| 2161 if (env->GetVar(kEnvVar, &pre_read) && (pre_read == "0" || pre_read == "1")) { |
| 2162 std::string uma_name(name); |
| 2163 uma_name += "_PreRead"; |
| 2164 uma_name += pre_read == "1" ? "Enabled" : "Disabled"; |
| 2165 AddPreReadHistogramTime(uma_name.c_str(), time); |
| 2166 } |
| 2167 #endif |
| 2168 } |
| OLD | NEW |