| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <windows.h> | 5 #include <windows.h> |
| 6 #include <shellapi.h> | 6 #include <shellapi.h> |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 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/gfx/vector_canvas.h" | 12 #include "base/gfx/vector_canvas.h" |
| 13 #include "base/histogram.h" | 13 #include "base/histogram.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/registry.h" | 15 #include "base/registry.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "base/tracked_objects.h" | 17 #include "base/tracked_objects.h" |
| 18 #include "base/win_util.h" | 18 #include "base/win_util.h" |
| 19 #include "chrome/app/result_codes.h" | 19 #include "chrome/app/result_codes.h" |
| 20 #include "chrome/browser/automation/automation_provider.h" | 20 #include "chrome/browser/automation/automation_provider.h" |
| 21 #include "chrome/browser/browser.h" | 21 #include "chrome/browser/browser.h" |
| 22 #include "chrome/browser/browser_init.h" | 22 #include "chrome/browser/browser_init.h" |
| 23 #include "chrome/browser/browser_list.h" | 23 #include "chrome/browser/browser_list.h" |
| 24 #include "chrome/browser/browser_prefs.h" | 24 #include "chrome/browser/browser_prefs.h" |
| 25 #include "chrome/browser/browser_process_impl.h" | 25 #include "chrome/browser/browser_process_impl.h" |
| 26 #include "chrome/browser/browser_shutdown.h" | 26 #include "chrome/browser/browser_shutdown.h" |
| 27 #include "chrome/browser/browser_trial.h" |
| 27 #include "chrome/browser/cert_store.h" | 28 #include "chrome/browser/cert_store.h" |
| 28 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" | 29 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" |
| 29 #include "chrome/browser/first_run.h" | 30 #include "chrome/browser/first_run.h" |
| 30 #include "chrome/browser/jankometer.h" | 31 #include "chrome/browser/jankometer.h" |
| 31 #include "chrome/browser/metrics_service.h" | 32 #include "chrome/browser/metrics_service.h" |
| 32 #include "chrome/browser/net/dns_global.h" | 33 #include "chrome/browser/net/dns_global.h" |
| 33 #include "chrome/browser/net/sdch_dictionary_fetcher.h" | 34 #include "chrome/browser/net/sdch_dictionary_fetcher.h" |
| 34 #include "chrome/browser/plugin_service.h" | 35 #include "chrome/browser/plugin_service.h" |
| 35 #include "chrome/browser/printing/print_job_manager.h" | 36 #include "chrome/browser/printing/print_job_manager.h" |
| 36 #include "chrome/browser/rlz/rlz.h" | 37 #include "chrome/browser/rlz/rlz.h" |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 bool CheckMachineLevelInstall() { | 232 bool CheckMachineLevelInstall() { |
| 232 scoped_ptr<installer::Version> version(InstallUtil::GetChromeVersion(true)); | 233 scoped_ptr<installer::Version> version(InstallUtil::GetChromeVersion(true)); |
| 233 if (version.get()) { | 234 if (version.get()) { |
| 234 std::wstring exe; | 235 std::wstring exe; |
| 235 PathService::Get(base::DIR_EXE, &exe); | 236 PathService::Get(base::DIR_EXE, &exe); |
| 236 std::transform(exe.begin(), exe.end(), exe.begin(), tolower); | 237 std::transform(exe.begin(), exe.end(), exe.begin(), tolower); |
| 237 std::wstring user_exe_path = installer::GetChromeInstallPath(false); | 238 std::wstring user_exe_path = installer::GetChromeInstallPath(false); |
| 238 std::transform(user_exe_path.begin(), user_exe_path.end(), | 239 std::transform(user_exe_path.begin(), user_exe_path.end(), |
| 239 user_exe_path.begin(), tolower); | 240 user_exe_path.begin(), tolower); |
| 240 if (exe == user_exe_path) { | 241 if (exe == user_exe_path) { |
| 241 const std::wstring text = | 242 const std::wstring text = |
| 242 l10n_util::GetString(IDS_MACHINE_LEVEL_INSTALL_CONFLICT); | 243 l10n_util::GetString(IDS_MACHINE_LEVEL_INSTALL_CONFLICT); |
| 243 const std::wstring caption = l10n_util::GetString(IDS_PRODUCT_NAME); | 244 const std::wstring caption = l10n_util::GetString(IDS_PRODUCT_NAME); |
| 244 const UINT flags = MB_OK | MB_ICONERROR | MB_TOPMOST; | 245 const UINT flags = MB_OK | MB_ICONERROR | MB_TOPMOST; |
| 245 win_util::MessageBox(NULL, text, caption, flags); | 246 win_util::MessageBox(NULL, text, caption, flags); |
| 246 std::wstring uninstall_cmd = InstallUtil::GetChromeUninstallCmd(false); | 247 std::wstring uninstall_cmd = InstallUtil::GetChromeUninstallCmd(false); |
| 247 if (!uninstall_cmd.empty()) { | 248 if (!uninstall_cmd.empty()) { |
| 248 uninstall_cmd.append(L" --"); | 249 uninstall_cmd.append(L" --"); |
| 249 uninstall_cmd.append(installer_util::switches::kForceUninstall); | 250 uninstall_cmd.append(installer_util::switches::kForceUninstall); |
| 250 uninstall_cmd.append(L" --"); | 251 uninstall_cmd.append(L" --"); |
| 251 uninstall_cmd.append(installer_util::switches::kDoNotRemoveSharedItems); | 252 uninstall_cmd.append(installer_util::switches::kDoNotRemoveSharedItems); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 273 sandbox::BrokerServices* broker_services) { | 274 sandbox::BrokerServices* broker_services) { |
| 274 // WARNING: If we get a WM_ENDSESSION objects created on the stack here | 275 // WARNING: If we get a WM_ENDSESSION objects created on the stack here |
| 275 // are NOT deleted. If you need something to run during WM_ENDSESSION add it | 276 // are NOT deleted. If you need something to run during WM_ENDSESSION add it |
| 276 // to browser_shutdown::Shutdown or BrowserProcess::EndSession. | 277 // to browser_shutdown::Shutdown or BrowserProcess::EndSession. |
| 277 | 278 |
| 278 // TODO(beng, brettw): someday, break this out into sub functions with well | 279 // TODO(beng, brettw): someday, break this out into sub functions with well |
| 279 // defined roles (e.g. pre/post-profile startup, etc). | 280 // defined roles (e.g. pre/post-profile startup, etc). |
| 280 | 281 |
| 281 MessageLoop main_message_loop(MessageLoop::TYPE_UI); | 282 MessageLoop main_message_loop(MessageLoop::TYPE_UI); |
| 282 | 283 |
| 284 // Initialize statistical testing infrastructure. |
| 285 FieldTrialList field_trial; |
| 286 |
| 283 std::wstring app_name = chrome::kBrowserAppName; | 287 std::wstring app_name = chrome::kBrowserAppName; |
| 284 std::string thread_name_string = WideToASCII(app_name + L"_BrowserMain"); | 288 std::string thread_name_string = WideToASCII(app_name + L"_BrowserMain"); |
| 285 | 289 |
| 286 const char* thread_name = thread_name_string.c_str(); | 290 const char* thread_name = thread_name_string.c_str(); |
| 287 PlatformThread::SetName(thread_name); | 291 PlatformThread::SetName(thread_name); |
| 288 main_message_loop.set_thread_name(thread_name); | 292 main_message_loop.set_thread_name(thread_name); |
| 289 bool already_running = CreateUniqueChromeEvent(); | 293 bool already_running = CreateUniqueChromeEvent(); |
| 290 | 294 |
| 291 #if defined(OS_WIN) | 295 #if defined(OS_WIN) |
| 292 // Make the selection of network stacks early on before any consumers try to | 296 // Make the selection of network stacks early on before any consumers try to |
| (...skipping 20 matching lines...) Expand all Loading... |
| 313 // BrowserProcessImpl's constructor should set g_browser_process. | 317 // BrowserProcessImpl's constructor should set g_browser_process. |
| 314 DCHECK(g_browser_process); | 318 DCHECK(g_browser_process); |
| 315 | 319 |
| 316 // Load local state. This includes the application locale so we know which | 320 // Load local state. This includes the application locale so we know which |
| 317 // locale dll to load. | 321 // locale dll to load. |
| 318 PrefService* local_state = browser_process->local_state(); | 322 PrefService* local_state = browser_process->local_state(); |
| 319 DCHECK(local_state); | 323 DCHECK(local_state); |
| 320 | 324 |
| 321 bool is_first_run = FirstRun::IsChromeFirstRun() || | 325 bool is_first_run = FirstRun::IsChromeFirstRun() || |
| 322 parsed_command_line.HasSwitch(switches::kFirstRun); | 326 parsed_command_line.HasSwitch(switches::kFirstRun); |
| 323 bool first_run_ui_bypass = false; | 327 bool first_run_ui_bypass = false; |
| 324 | 328 |
| 325 // Initialize ResourceBundle which handles files loaded from external | 329 // Initialize ResourceBundle which handles files loaded from external |
| 326 // sources. This has to be done before uninstall code path and before prefs | 330 // sources. This has to be done before uninstall code path and before prefs |
| 327 // are registered. | 331 // are registered. |
| 328 local_state->RegisterStringPref(prefs::kApplicationLocale, L""); | 332 local_state->RegisterStringPref(prefs::kApplicationLocale, L""); |
| 329 local_state->RegisterBooleanPref(prefs::kMetricsReportingEnabled, false); | 333 local_state->RegisterBooleanPref(prefs::kMetricsReportingEnabled, false); |
| 330 | 334 |
| 331 // During first run we read the google_update registry key to find what | 335 // During first run we read the google_update registry key to find what |
| 332 // language the user selected when downloading the installer. This | 336 // language the user selected when downloading the installer. This |
| 333 // becomes our default language in the prefs. | 337 // becomes our default language in the prefs. |
| 334 if (is_first_run) { | 338 if (is_first_run) { |
| 335 std::wstring install_lang; | 339 std::wstring install_lang; |
| 336 if (GoogleUpdateSettings::GetLanguage(&install_lang)) | 340 if (GoogleUpdateSettings::GetLanguage(&install_lang)) |
| 337 local_state->SetString(prefs::kApplicationLocale, install_lang); | 341 local_state->SetString(prefs::kApplicationLocale, install_lang); |
| 338 if (GoogleUpdateSettings::GetCollectStatsConsent()) | 342 if (GoogleUpdateSettings::GetCollectStatsConsent()) |
| 339 local_state->SetBoolean(prefs::kMetricsReportingEnabled, true); | 343 local_state->SetBoolean(prefs::kMetricsReportingEnabled, true); |
| 340 // On first run, we need to process the master preferences before the | 344 // On first run, we need to process the master preferences before the |
| 341 // browser's profile_manager object is created. | 345 // browser's profile_manager object is created. |
| 342 FirstRun::MasterPrefResult master_pref_res = | 346 FirstRun::MasterPrefResult master_pref_res = |
| 343 FirstRun::ProcessMasterPreferences(user_data_dir, std::wstring()); | 347 FirstRun::ProcessMasterPreferences(user_data_dir, std::wstring()); |
| 344 first_run_ui_bypass = | 348 first_run_ui_bypass = |
| 345 (master_pref_res == FirstRun::MASTER_PROFILE_NO_FIRST_RUN_UI); | 349 (master_pref_res == FirstRun::MASTER_PROFILE_NO_FIRST_RUN_UI); |
| 346 } | 350 } |
| 347 | 351 |
| 348 ResourceBundle::InitSharedInstance( | 352 ResourceBundle::InitSharedInstance( |
| 349 local_state->GetString(prefs::kApplicationLocale)); | 353 local_state->GetString(prefs::kApplicationLocale)); |
| 350 // We only load the theme dll in the browser process. | 354 // We only load the theme dll in the browser process. |
| 351 ResourceBundle::GetSharedInstance().LoadThemeResources(); | 355 ResourceBundle::GetSharedInstance().LoadThemeResources(); |
| 352 | 356 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 | 502 |
| 499 // Register our global network handler for chrome-resource:// URLs. | 503 // Register our global network handler for chrome-resource:// URLs. |
| 500 RegisterURLRequestChromeJob(); | 504 RegisterURLRequestChromeJob(); |
| 501 | 505 |
| 502 // TODO(brettw): we may want to move this to the browser window somewhere so | 506 // TODO(brettw): we may want to move this to the browser window somewhere so |
| 503 // that if it pops up a dialog box, the user gets it as the child of the | 507 // that if it pops up a dialog box, the user gets it as the child of the |
| 504 // browser window instead of a disembodied floating box blocking startup. | 508 // browser window instead of a disembodied floating box blocking startup. |
| 505 ShellIntegration::VerifyInstallation(); | 509 ShellIntegration::VerifyInstallation(); |
| 506 | 510 |
| 507 browser_process->InitBrokerServices(broker_services); | 511 browser_process->InitBrokerServices(broker_services); |
| 508 | 512 |
| 509 // In unittest mode, this will do nothing. In normal mode, this will create | 513 // In unittest mode, this will do nothing. In normal mode, this will create |
| 510 // the global GoogleURLTracker instance, which will promptly go to sleep for | 514 // the global GoogleURLTracker instance, which will promptly go to sleep for |
| 511 // five seconds (to avoid slowing startup), and wake up afterwards to see if | 515 // five seconds (to avoid slowing startup), and wake up afterwards to see if |
| 512 // it should do anything else. If we don't cause this creation now, it won't | 516 // it should do anything else. If we don't cause this creation now, it won't |
| 513 // happen until someone else asks for the tracker, at which point we may no | 517 // happen until someone else asks for the tracker, at which point we may no |
| 514 // longer want to sleep for five seconds. | 518 // longer want to sleep for five seconds. |
| 515 // | 519 // |
| 516 // A simpler way of doing all this would be to have some function which could | 520 // A simpler way of doing all this would be to have some function which could |
| 517 // give the time elapsed since startup, and simply have the tracker check that | 521 // give the time elapsed since startup, and simply have the tracker check that |
| 518 // when asked to initialize itself, but this doesn't seem to exist. | 522 // when asked to initialize itself, but this doesn't seem to exist. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 537 } | 541 } |
| 538 | 542 |
| 539 MetricsService* metrics = NULL; | 543 MetricsService* metrics = NULL; |
| 540 if (!parsed_command_line.HasSwitch(switches::kDisableMetrics)) { | 544 if (!parsed_command_line.HasSwitch(switches::kDisableMetrics)) { |
| 541 if (parsed_command_line.HasSwitch(switches::kMetricsRecordingOnly)) { | 545 if (parsed_command_line.HasSwitch(switches::kMetricsRecordingOnly)) { |
| 542 local_state->transient()->SetBoolean(prefs::kMetricsReportingEnabled, | 546 local_state->transient()->SetBoolean(prefs::kMetricsReportingEnabled, |
| 543 false); | 547 false); |
| 544 } | 548 } |
| 545 metrics = browser_process->metrics_service(); | 549 metrics = browser_process->metrics_service(); |
| 546 DCHECK(metrics); | 550 DCHECK(metrics); |
| 547 | 551 |
| 548 // If we're testing then we don't care what the user | 552 // If we're testing then we don't care what the user preference is, we turn |
| 549 // preference is, we turn on recording, but not reporting, otherwise tests | 553 // on recording, but not reporting, otherwise tests fail. |
| 550 // fail. | |
| 551 if (parsed_command_line.HasSwitch(switches::kMetricsRecordingOnly)) { | 554 if (parsed_command_line.HasSwitch(switches::kMetricsRecordingOnly)) { |
| 552 metrics->StartRecordingOnly(); | 555 metrics->StartRecordingOnly(); |
| 553 } else { | 556 } else { |
| 554 // If the user permits metrics reporting with the checkbox in the | 557 // If the user permits metrics reporting with the checkbox in the |
| 555 // prefs, we turn on recording. | 558 // prefs, we turn on recording. |
| 556 bool enabled = local_state->GetBoolean(prefs::kMetricsReportingEnabled); | 559 bool enabled = local_state->GetBoolean(prefs::kMetricsReportingEnabled); |
| 557 | 560 |
| 558 metrics->SetUserPermitsUpload(enabled); | 561 metrics->SetUserPermitsUpload(enabled); |
| 559 if (enabled) | 562 if (enabled) |
| 560 metrics->Start(); | 563 metrics->Start(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 // unsafe to do this cleanup if other threads are still active. | 598 // unsafe to do this cleanup if other threads are still active. |
| 596 // It is also very unnecessary, so I'm only doing this in debug to satisfy | 599 // It is also very unnecessary, so I'm only doing this in debug to satisfy |
| 597 // purify. | 600 // purify. |
| 598 if (tracking_objects) | 601 if (tracking_objects) |
| 599 tracked_objects::ThreadData::ShutdownSingleThreadedCleanup(); | 602 tracked_objects::ThreadData::ShutdownSingleThreadedCleanup(); |
| 600 #endif // NDEBUG | 603 #endif // NDEBUG |
| 601 | 604 |
| 602 return result_code; | 605 return result_code; |
| 603 } | 606 } |
| 604 | 607 |
| OLD | NEW |