Chromium Code Reviews| 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 "chrome/browser/browser_init.h" | 5 #include "chrome/browser/browser_init.h" |
| 6 | 6 |
| 7 #include <shellapi.h> | 7 #include <shellapi.h> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/event_recorder.h" | 11 #include "base/event_recorder.h" |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.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/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "base/sys_info.h" | |
| 16 #include "base/win_util.h" | 17 #include "base/win_util.h" |
| 17 #include "chrome/app/locales/locale_settings.h" | 18 #include "chrome/app/locales/locale_settings.h" |
| 18 #include "chrome/app/result_codes.h" | 19 #include "chrome/app/result_codes.h" |
| 19 #include "chrome/browser/automation/automation_provider.h" | 20 #include "chrome/browser/automation/automation_provider.h" |
| 20 #include "chrome/browser/browser_list.h" | 21 #include "chrome/browser/browser_list.h" |
| 21 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
| 22 #include "chrome/browser/dom_ui/new_tab_ui.h" | 23 #include "chrome/browser/dom_ui/new_tab_ui.h" |
| 23 #include "chrome/browser/first_run.h" | 24 #include "chrome/browser/first_run.h" |
| 24 #include "chrome/browser/navigation_controller.h" | 25 #include "chrome/browser/navigation_controller.h" |
| 25 #include "chrome/browser/net/dns_global.h" | 26 #include "chrome/browser/net/dns_global.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 } | 70 } |
| 70 | 71 |
| 71 SessionStartupPref GetSessionStartupPref(Profile* profile, | 72 SessionStartupPref GetSessionStartupPref(Profile* profile, |
| 72 const CommandLine& command_line) { | 73 const CommandLine& command_line) { |
| 73 SessionStartupPref pref = SessionStartupPref::GetStartupPref(profile); | 74 SessionStartupPref pref = SessionStartupPref::GetStartupPref(profile); |
| 74 if (command_line.HasSwitch(switches::kRestoreLastSession)) | 75 if (command_line.HasSwitch(switches::kRestoreLastSession)) |
| 75 pref.type = SessionStartupPref::LAST; | 76 pref.type = SessionStartupPref::LAST; |
| 76 return pref; | 77 return pref; |
| 77 } | 78 } |
| 78 | 79 |
| 80 enum LaunchMode { | |
| 81 LM_TO_BE_DECIDED = 0, // Possibly direct launch or via a shortcut. | |
| 82 LM_AS_WEBAPP, // Launched as a installed web application. | |
| 83 LM_WITH_URLS, // Launched with urls in the cmd line. | |
| 84 LM_SHORTCUT_NONE, // Not launched from a shortcut. | |
| 85 LM_SHORTCUT_NONAME, // Launched from shortcut but no name available. | |
| 86 LM_SHORTCUT_UNKNOWN, // Launched from user-defined shortcut. | |
| 87 LM_SHORTCUT_QUICKLAUNCH, // Launched from the quick launch bar. | |
| 88 LM_SHORTCUT_DESKTOP, // Launched from a desktop shortcut. | |
| 89 LM_SHORTCUT_STARTMENU, // Launched from start menu. | |
| 90 LM_LINUX_MAC_BEOS // Other OS buckets start here. | |
| 91 }; | |
| 92 | |
| 93 #if defined(OS_WIN) | |
| 94 // Undocumented flag in the startup info structure tells us what shortcut was | |
| 95 // used to launch the browser. See http://www.catch22.net/tuts/undoc01 for | |
| 96 // more information. Confirmed to work on XP, Vista and Win7. | |
| 97 LaunchMode GetLaunchShortcutKind() { | |
| 98 STARTUPINFOW si = { sizeof(si) }; | |
| 99 GetStartupInfoW(&si); | |
| 100 if (si.dwFlags & 0x800) { | |
| 101 if (!si.lpTitle) | |
| 102 return LM_SHORTCUT_NONAME; | |
| 103 std::wstring shortcut(si.lpTitle); | |
| 104 // The windows quick launch path is not localized. | |
| 105 if (shortcut.find(L"\\Quick Launch\\") != std::wstring::npos) | |
| 106 return LM_SHORTCUT_QUICKLAUNCH; | |
| 107 std::wstring appdata_path = base::SysInfo::GetEnvVar(L"USERPROFILE"); | |
| 108 if (!appdata_path.empty() && | |
| 109 shortcut.find(appdata_path) != std::wstring::npos) | |
| 110 return LM_SHORTCUT_DESKTOP; | |
| 111 return LM_SHORTCUT_UNKNOWN; | |
| 112 } | |
| 113 return LM_SHORTCUT_NONE; | |
| 114 } | |
| 115 #else | |
| 116 // TODO(cpu): Port to other platforms. | |
| 117 LaunchMode GetLaunchShortcutKind() { | |
| 118 return LM_LINUX_MAC_BEOS; | |
| 119 } | |
| 120 #endif | |
| 121 | |
| 122 // Log in a histogram the frequency of launching by the different methods. See | |
| 123 // LaunchMode enum for the actual values of the buckets. | |
| 124 void RecordLaunchModeHistogram(LaunchMode mode) { | |
| 125 int bucket = (mode == LM_TO_BE_DECIDED) ? GetLaunchShortcutKind() : mode; | |
| 126 UMA_HISTOGRAM_COUNTS_100(L"Launch.Modes", bucket); | |
| 127 } | |
| 128 | |
| 79 } // namespace | 129 } // namespace |
| 80 | 130 |
| 81 // MessageWindow -------------------------------------------------------------- | 131 // MessageWindow -------------------------------------------------------------- |
| 82 | 132 |
| 83 static bool in_startup = false; | 133 static bool in_startup = false; |
| 84 | 134 |
| 85 // static | 135 // static |
| 86 bool BrowserInit::InProcessStartup() { | 136 bool BrowserInit::InProcessStartup() { |
| 87 return in_startup; | 137 return in_startup; |
| 88 } | 138 } |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 422 | 472 |
| 423 if (parsed_command_line.HasSwitch(switches::kEnableFileCookies)) | 473 if (parsed_command_line.HasSwitch(switches::kEnableFileCookies)) |
| 424 net::CookieMonster::EnableFileScheme(); | 474 net::CookieMonster::EnableFileScheme(); |
| 425 | 475 |
| 426 if (parsed_command_line.HasSwitch(switches::kUserAgent)) { | 476 if (parsed_command_line.HasSwitch(switches::kUserAgent)) { |
| 427 webkit_glue::SetUserAgent(WideToUTF8( | 477 webkit_glue::SetUserAgent(WideToUTF8( |
| 428 parsed_command_line.GetSwitchValue(switches::kUserAgent))); | 478 parsed_command_line.GetSwitchValue(switches::kUserAgent))); |
| 429 } | 479 } |
| 430 | 480 |
| 431 #ifndef NDEBUG | 481 #ifndef NDEBUG |
| 482 // Because this is debug-only in 154, we cannot record histograms for | |
| 483 // LM_AS_WEBAPP. | |
|
cpu_(ooo_6.6-7.5)
2009/03/01 02:17:03
!Gasp!
| |
| 432 if (parsed_command_line.HasSwitch(switches::kApp)) { | 484 if (parsed_command_line.HasSwitch(switches::kApp)) { |
| 433 NOTREACHED(); | 485 NOTREACHED(); |
| 434 } | 486 } |
| 435 #endif // NDEBUG | 487 #endif // NDEBUG |
| 436 | 488 |
| 437 std::vector<GURL> urls_to_open = GetURLsFromCommandLine(parsed_command_line, | 489 std::vector<GURL> urls_to_open = GetURLsFromCommandLine(parsed_command_line, |
| 438 profile_); | 490 profile_); |
| 491 RecordLaunchModeHistogram(urls_to_open.empty()? | |
| 492 LM_TO_BE_DECIDED : LM_WITH_URLS); | |
| 439 | 493 |
| 440 Browser* browser = NULL; | 494 Browser* browser = NULL; |
| 441 | 495 |
| 442 // Always attempt to restore the last session. OpenStartupURLs only opens the | 496 // Always attempt to restore the last session. OpenStartupURLs only opens the |
| 443 // home pages if no additional URLs were passed on the command line. | 497 // home pages if no additional URLs were passed on the command line. |
| 444 bool opened_startup_urls = | 498 bool opened_startup_urls = |
| 445 OpenStartupURLs(process_startup, parsed_command_line, urls_to_open); | 499 OpenStartupURLs(process_startup, parsed_command_line, urls_to_open); |
| 446 | 500 |
| 447 if (!opened_startup_urls) { | 501 if (!opened_startup_urls) { |
| 448 if (urls_to_open.empty()) { | 502 if (urls_to_open.empty()) { |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 716 if (!launched) { | 770 if (!launched) { |
| 717 LOG(ERROR) << "launch error"; | 771 LOG(ERROR) << "launch error"; |
| 718 if (return_code != NULL) { | 772 if (return_code != NULL) { |
| 719 *return_code = ResultCodes::INVALID_CMDLINE_URL; | 773 *return_code = ResultCodes::INVALID_CMDLINE_URL; |
| 720 } | 774 } |
| 721 return false; | 775 return false; |
| 722 } | 776 } |
| 723 | 777 |
| 724 return true; | 778 return true; |
| 725 } | 779 } |
| OLD | NEW |