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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/event_recorder.h" | 9 #include "base/event_recorder.h" |
10 #include "base/histogram.h" | |
10 #include "base/path_service.h" | 11 #include "base/path_service.h" |
11 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/sys_info.h" | |
12 #include "chrome/app/result_codes.h" | 14 #include "chrome/app/result_codes.h" |
13 #include "chrome/browser/browser_list.h" | 15 #include "chrome/browser/browser_list.h" |
14 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/extensions/extensions_service.h" | 17 #include "chrome/browser/extensions/extensions_service.h" |
16 #include "chrome/browser/net/dns_global.h" | 18 #include "chrome/browser/net/dns_global.h" |
17 #include "chrome/browser/profile.h" | 19 #include "chrome/browser/profile.h" |
18 #include "chrome/browser/renderer_host/render_process_host.h" | 20 #include "chrome/browser/renderer_host/render_process_host.h" |
19 #include "chrome/browser/session_startup_pref.h" | 21 #include "chrome/browser/session_startup_pref.h" |
20 #include "chrome/common/chrome_constants.h" | 22 #include "chrome/common/chrome_constants.h" |
21 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 if (command_line.HasSwitch(switches::kIncognito) && | 126 if (command_line.HasSwitch(switches::kIncognito) && |
125 pref.type == SessionStartupPref::LAST) { | 127 pref.type == SessionStartupPref::LAST) { |
126 // We don't store session information when incognito. If the user has | 128 // We don't store session information when incognito. If the user has |
127 // chosen to restore last session and launched incognito, fallback to | 129 // chosen to restore last session and launched incognito, fallback to |
128 // default launch behavior. | 130 // default launch behavior. |
129 pref.type = SessionStartupPref::DEFAULT; | 131 pref.type = SessionStartupPref::DEFAULT; |
130 } | 132 } |
131 return pref; | 133 return pref; |
132 } | 134 } |
133 | 135 |
136 enum LaunchMode { | |
137 LM_TO_BE_DECIDED = 0, // Possibly direct launch or via a shortcut. | |
138 LM_AS_WEBAPP, // Launched as a installed web application. | |
139 LM_WITH_URLS, // Launched with urls in the cmd line. | |
140 LM_SHORTCUT_NONE, // Not launched from a shortcut. | |
141 LM_SHORTCUT_NONAME, // Launched from shortcut but no name available. | |
142 LM_SHORTCUT_UNKNOWN, // Launched from user-defined shortcut. | |
143 LM_SHORTCUT_QUICKLAUNCH, // Launched from the quick launch bar. | |
144 LM_SHORTCUT_DESKTOP, // Launched from a desktop shortcut. | |
145 LM_SHORTCUT_STARTMENU, // Launched from start menu. | |
146 LM_LINUX_MAC_BEOS // Other OS buckets start here. | |
147 }; | |
148 | |
149 #if defined(OS_WIN) | |
150 // Undocumented flag in the startup info structure tells us what shortcut was | |
151 // used to launch the browser. See http://www.catch22.net/tuts/undoc01 for | |
152 // more information. Confirmed to work on XP, Vista and Win7. | |
153 LaunchMode GetLaunchSortcutKind() { | |
dhhwai
2009/02/06 23:47:50
spelling should be: GetLaunchShortcutKind
| |
154 STARTUPINFOW si = { sizeof(si) }; | |
155 GetStartupInfoW(&si); | |
156 if (si.dwFlags & 0x800) { | |
157 if (!si.lpTitle) | |
158 return LM_SHORTCUT_NONAME; | |
159 std::wstring shortcut(si.lpTitle); | |
160 // The windows quick launch path is not localized. | |
161 if (shortcut.find(L"\\Quick Launch\\") != std::wstring::npos) | |
162 return LM_SHORTCUT_QUICKLAUNCH; | |
163 std::wstring appdata_path = base::SysInfo::GetEnvVar(L"USERPROFILE"); | |
164 if (!appdata_path.empty() && | |
165 shortcut.find(appdata_path) != std::wstring::npos) | |
166 return LM_SHORTCUT_DESKTOP; | |
167 return LM_SHORTCUT_UNKNOWN; | |
168 } | |
169 return LM_SHORTCUT_NONE; | |
170 } | |
171 #else | |
172 // TODO(cpu): Port to other platforms. | |
173 LaunchMode GetLaunchSortcutKind() { | |
dhhwai
2009/02/06 23:47:50
spelling should be: GetLaunchShortcutKind
| |
174 return LM_LINUX_MAC_BEOS; | |
175 } | |
176 #endif | |
177 | |
178 // Log in a histogram the frequency of launching by the different methods. See | |
179 // LaunchMode enum for the actual values of the buckets. | |
180 void RecordLaunchModeHistogram(LaunchMode mode) { | |
181 int bucket = (mode == LM_TO_BE_DECIDED) ? GetLaunchSortcutKind() : mode; | |
182 UMA_HISTOGRAM_COUNTS_100(L"Launch.Modes", bucket); | |
183 } | |
184 | |
134 } // namespace | 185 } // namespace |
135 | 186 |
136 static bool in_startup = false; | 187 static bool in_startup = false; |
137 | 188 |
138 // static | 189 // static |
139 bool BrowserInit::InProcessStartup() { | 190 bool BrowserInit::InProcessStartup() { |
140 return in_startup; | 191 return in_startup; |
141 } | 192 } |
142 | 193 |
143 // LaunchWithProfile ---------------------------------------------------------- | 194 // LaunchWithProfile ---------------------------------------------------------- |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 webkit_glue::SetUserAgent(WideToUTF8( | 234 webkit_glue::SetUserAgent(WideToUTF8( |
184 command_line_.GetSwitchValue(switches::kUserAgent))); | 235 command_line_.GetSwitchValue(switches::kUserAgent))); |
185 // TODO(port): hook this up when we bring in webkit. | 236 // TODO(port): hook this up when we bring in webkit. |
186 #endif | 237 #endif |
187 } | 238 } |
188 | 239 |
189 // Open the required browser windows and tabs. | 240 // Open the required browser windows and tabs. |
190 // First, see if we're being run as a web application (thin frame window). | 241 // First, see if we're being run as a web application (thin frame window). |
191 if (!OpenApplicationURL(profile)) { | 242 if (!OpenApplicationURL(profile)) { |
192 std::vector<GURL> urls_to_open = GetURLsFromCommandLine(profile_); | 243 std::vector<GURL> urls_to_open = GetURLsFromCommandLine(profile_); |
244 RecordLaunchModeHistogram(urls_to_open.empty()? | |
245 LM_TO_BE_DECIDED : LM_WITH_URLS); | |
193 // Always attempt to restore the last session. OpenStartupURLs only opens | 246 // Always attempt to restore the last session. OpenStartupURLs only opens |
194 // the home pages if no additional URLs were passed on the command line. | 247 // the home pages if no additional URLs were passed on the command line. |
195 if (!OpenStartupURLs(process_startup, urls_to_open)) { | 248 if (!OpenStartupURLs(process_startup, urls_to_open)) { |
196 // Add the home page and any special first run URLs. | 249 // Add the home page and any special first run URLs. |
197 AddStartupURLs(&urls_to_open); | 250 AddStartupURLs(&urls_to_open); |
198 OpenURLsInBrowser(BrowserList::GetLastActive(), process_startup, | 251 OpenURLsInBrowser(BrowserList::GetLastActive(), process_startup, |
199 urls_to_open); | 252 urls_to_open); |
200 } | 253 } |
254 } else { | |
255 RecordLaunchModeHistogram(LM_AS_WEBAPP); | |
201 } | 256 } |
202 | 257 |
203 // If we're recording or playing back, startup the EventRecorder now | 258 // If we're recording or playing back, startup the EventRecorder now |
204 // unless otherwise specified. | 259 // unless otherwise specified. |
205 if (!command_line_.HasSwitch(switches::kNoEvents)) { | 260 if (!command_line_.HasSwitch(switches::kNoEvents)) { |
206 std::wstring script_path; | 261 std::wstring script_path; |
207 PathService::Get(chrome::FILE_RECORDED_SCRIPT, &script_path); | 262 PathService::Get(chrome::FILE_RECORDED_SCRIPT, &script_path); |
208 | 263 |
209 bool record_mode = command_line_.HasSwitch(switches::kRecordMode); | 264 bool record_mode = command_line_.HasSwitch(switches::kRecordMode); |
210 bool playback_mode = command_line_.HasSwitch(switches::kPlaybackMode); | 265 bool playback_mode = command_line_.HasSwitch(switches::kPlaybackMode); |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
489 bool launched = lwp.Launch(profile, process_startup); | 544 bool launched = lwp.Launch(profile, process_startup); |
490 if (!launched) { | 545 if (!launched) { |
491 LOG(ERROR) << "launch error"; | 546 LOG(ERROR) << "launch error"; |
492 if (return_code != NULL) | 547 if (return_code != NULL) |
493 *return_code = ResultCodes::INVALID_CMDLINE_URL; | 548 *return_code = ResultCodes::INVALID_CMDLINE_URL; |
494 return false; | 549 return false; |
495 } | 550 } |
496 | 551 |
497 return true; | 552 return true; |
498 } | 553 } |
OLD | NEW |