Chromium Code Reviews| 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.h" | 5 #include "chrome/browser/chrome_browser_main.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 #include "base/prefs/pref_value_store.h" | 24 #include "base/prefs/pref_value_store.h" |
| 25 #include "base/prefs/scoped_user_pref_update.h" | 25 #include "base/prefs/scoped_user_pref_update.h" |
| 26 #include "base/process/process_info.h" | 26 #include "base/process/process_info.h" |
| 27 #include "base/profiler/scoped_tracker.h" | 27 #include "base/profiler/scoped_tracker.h" |
| 28 #include "base/run_loop.h" | 28 #include "base/run_loop.h" |
| 29 #include "base/strings/string_number_conversions.h" | 29 #include "base/strings/string_number_conversions.h" |
| 30 #include "base/strings/string_piece.h" | 30 #include "base/strings/string_piece.h" |
| 31 #include "base/strings/string_split.h" | 31 #include "base/strings/string_split.h" |
| 32 #include "base/strings/sys_string_conversions.h" | 32 #include "base/strings/sys_string_conversions.h" |
| 33 #include "base/strings/utf_string_conversions.h" | 33 #include "base/strings/utf_string_conversions.h" |
| 34 #include "base/synchronization/cancellation_flag.h" | |
| 34 #include "base/sys_info.h" | 35 #include "base/sys_info.h" |
| 35 #include "base/threading/platform_thread.h" | 36 #include "base/threading/platform_thread.h" |
| 36 #include "base/time/time.h" | 37 #include "base/time/time.h" |
| 37 #include "base/trace_event/trace_event.h" | 38 #include "base/trace_event/trace_event.h" |
| 38 #include "base/values.h" | 39 #include "base/values.h" |
| 39 #include "build/build_config.h" | 40 #include "build/build_config.h" |
| 40 #include "cc/base/switches.h" | 41 #include "cc/base/switches.h" |
| 41 #include "chrome/browser/about_flags.h" | 42 #include "chrome/browser/about_flags.h" |
| 42 #include "chrome/browser/browser_process.h" | 43 #include "chrome/browser/browser_process.h" |
| 43 #include "chrome/browser/browser_process_impl.h" | 44 #include "chrome/browser/browser_process_impl.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h" | 79 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h" |
| 79 #include "chrome/browser/process_singleton.h" | 80 #include "chrome/browser/process_singleton.h" |
| 80 #include "chrome/browser/profiles/profile.h" | 81 #include "chrome/browser/profiles/profile.h" |
| 81 #include "chrome/browser/profiles/profile_manager.h" | 82 #include "chrome/browser/profiles/profile_manager.h" |
| 82 #include "chrome/browser/profiles/profiles_state.h" | 83 #include "chrome/browser/profiles/profiles_state.h" |
| 83 #include "chrome/browser/shell_integration.h" | 84 #include "chrome/browser/shell_integration.h" |
| 84 #include "chrome/browser/translate/translate_service.h" | 85 #include "chrome/browser/translate/translate_service.h" |
| 85 #include "chrome/browser/ui/app_list/app_list_service.h" | 86 #include "chrome/browser/ui/app_list/app_list_service.h" |
| 86 #include "chrome/browser/ui/browser.h" | 87 #include "chrome/browser/ui/browser.h" |
| 87 #include "chrome/browser/ui/browser_finder.h" | 88 #include "chrome/browser/ui/browser_finder.h" |
| 89 #include "chrome/browser/ui/browser_iterator.h" | |
| 88 #include "chrome/browser/ui/host_desktop.h" | 90 #include "chrome/browser/ui/host_desktop.h" |
| 89 #include "chrome/browser/ui/startup/bad_flags_prompt.h" | 91 #include "chrome/browser/ui/startup/bad_flags_prompt.h" |
| 90 #include "chrome/browser/ui/startup/default_browser_prompt.h" | 92 #include "chrome/browser/ui/startup/default_browser_prompt.h" |
| 91 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 93 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
| 94 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 92 #include "chrome/browser/ui/uma_browsing_activity_observer.h" | 95 #include "chrome/browser/ui/uma_browsing_activity_observer.h" |
| 93 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" | 96 #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" |
| 94 #include "chrome/common/chrome_constants.h" | 97 #include "chrome/common/chrome_constants.h" |
| 95 #include "chrome/common/chrome_paths.h" | 98 #include "chrome/common/chrome_paths.h" |
| 96 #include "chrome/common/chrome_result_codes.h" | 99 #include "chrome/common/chrome_result_codes.h" |
| 97 #include "chrome/common/chrome_switches.h" | 100 #include "chrome/common/chrome_switches.h" |
| 98 #include "chrome/common/chrome_version_info.h" | 101 #include "chrome/common/chrome_version_info.h" |
| 99 #include "chrome/common/crash_keys.h" | 102 #include "chrome/common/crash_keys.h" |
| 100 #include "chrome/common/env_vars.h" | 103 #include "chrome/common/env_vars.h" |
| 101 #include "chrome/common/logging_chrome.h" | 104 #include "chrome/common/logging_chrome.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 | 217 |
| 215 #if defined(ENABLE_WEBRTC) | 218 #if defined(ENABLE_WEBRTC) |
| 216 #include "chrome/browser/media/webrtc_log_util.h" | 219 #include "chrome/browser/media/webrtc_log_util.h" |
| 217 #endif // defined(ENABLE_WEBRTC) | 220 #endif // defined(ENABLE_WEBRTC) |
| 218 | 221 |
| 219 #if defined(USE_AURA) | 222 #if defined(USE_AURA) |
| 220 #include "ui/aura/env.h" | 223 #include "ui/aura/env.h" |
| 221 #endif // defined(USE_AURA) | 224 #endif // defined(USE_AURA) |
| 222 | 225 |
| 223 using content::BrowserThread; | 226 using content::BrowserThread; |
| 227 using content::WebContents; | |
| 228 using content::WebContentsObserver; | |
| 224 | 229 |
| 225 namespace { | 230 namespace { |
| 226 | 231 |
| 232 // The basis for when tasks posted via PostAfterStartupTasks begin running. | |
| 233 using StartupCompleteFlag = base::CancellationFlag; | |
| 234 base::LazyInstance<StartupCompleteFlag>::Leaky g_startup_complete_flag; | |
| 235 | |
| 236 void SetBrowserStartupIsComplete() { | |
| 237 g_startup_complete_flag.Get().Set(); | |
| 238 } | |
| 239 | |
| 240 // Observes the first page load and set the startup complete flag accordingly. | |
| 241 class StartupObserver : public WebContentsObserver { | |
|
jam
2015/03/23 23:19:44
nit: this would be much smaller lines if the metho
michaeln
2015/03/24 23:01:11
Done.
| |
| 242 public: | |
| 243 StartupObserver() : weak_factory_(this) {} | |
| 244 ~StartupObserver() override {} | |
| 245 | |
| 246 void Start(); | |
| 247 | |
| 248 private: | |
| 249 void OnStartupComplete(); | |
| 250 void OnFailsafeTimeout(); | |
| 251 | |
| 252 // WebContentsObserver overrides | |
| 253 void DidFinishLoad(content::RenderFrameHost* render_frame_host, | |
| 254 const GURL& validated_url) override; | |
| 255 void DidFailLoad(content::RenderFrameHost* render_frame_host, | |
| 256 const GURL& validated_url, | |
| 257 int error_code, | |
| 258 const base::string16& error_description) override; | |
| 259 void WebContentsDestroyed() override; | |
| 260 | |
| 261 base::WeakPtrFactory<StartupObserver> weak_factory_; | |
| 262 }; | |
|
cmumford
2015/03/23 23:57:20
Not sure: Is DISALLOW_COPY_AND_ASSIGN required for
michaeln
2015/03/24 23:01:12
Done.
| |
| 263 | |
| 264 void StartupObserver::Start() { | |
| 265 // Signal completion quickly when there is no first page to load. | |
| 266 int kShortDelaySecs = 3; | |
|
cmumford
2015/03/23 23:57:19
const int kShortDelaySecs = 3;
michaeln
2015/03/24 23:01:11
Done.
| |
| 267 base::TimeDelta delay = base::TimeDelta::FromSeconds(kShortDelaySecs); | |
| 268 | |
| 269 #if !defined(OS_ANDROID) | |
|
michaeln
2015/03/23 20:24:23
FUD: Initially mimic'ing chrome_browser_main_extra
| |
| 270 WebContents* contents = nullptr; | |
| 271 for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) { | |
| 272 contents = (*iter)->tab_strip_model()->GetActiveWebContents(); | |
| 273 if (contents) | |
| 274 break; | |
| 275 } | |
| 276 | |
| 277 if (contents) { | |
| 278 // Give the page time to finish loading. | |
| 279 const int kLongerDelayMins = 3; | |
| 280 Observe(contents); | |
| 281 delay = base::TimeDelta::FromMinutes(kLongerDelayMins); | |
| 282 } | |
| 283 #endif // !defined(OS_ANDROID) | |
| 284 | |
| 285 BrowserThread::PostDelayedTask( | |
| 286 BrowserThread::UI, FROM_HERE, | |
| 287 base::Bind(&StartupObserver::OnFailsafeTimeout, | |
| 288 weak_factory_.GetWeakPtr()), | |
| 289 delay); | |
| 290 } | |
| 291 | |
| 292 void StartupObserver::OnStartupComplete() { | |
| 293 SetBrowserStartupIsComplete(); | |
| 294 delete this; | |
| 295 } | |
| 296 | |
| 297 void StartupObserver::OnFailsafeTimeout() { | |
| 298 OnStartupComplete(); | |
| 299 } | |
| 300 | |
| 301 void StartupObserver::DidFinishLoad(content::RenderFrameHost* render_frame_host, | |
| 302 const GURL& validated_url) { | |
| 303 if (web_contents()->GetMainFrame() == render_frame_host) | |
|
cmumford
2015/03/23 23:57:19
The rest of Chrome does if (!render_frame_host->Ge
michaeln
2015/03/24 23:01:11
thnx, done
| |
| 304 OnStartupComplete(); | |
| 305 } | |
| 306 | |
| 307 void StartupObserver::DidFailLoad(content::RenderFrameHost* render_frame_host, | |
| 308 const GURL& validated_url, | |
| 309 int error_code, | |
| 310 const base::string16& error_description) { | |
| 311 if (web_contents()->GetMainFrame() == render_frame_host) | |
| 312 OnStartupComplete(); | |
| 313 } | |
| 314 | |
| 315 void StartupObserver::WebContentsDestroyed() { | |
| 316 OnStartupComplete(); | |
| 317 } | |
| 318 | |
| 227 // This function provides some ways to test crash and assertion handling | 319 // This function provides some ways to test crash and assertion handling |
| 228 // behavior of the program. | 320 // behavior of the program. |
| 229 void HandleTestParameters(const base::CommandLine& command_line) { | 321 void HandleTestParameters(const base::CommandLine& command_line) { |
| 230 // This parameter causes a null pointer crash (crash reporter trigger). | 322 // This parameter causes a null pointer crash (crash reporter trigger). |
| 231 if (command_line.HasSwitch(switches::kBrowserCrashTest)) { | 323 if (command_line.HasSwitch(switches::kBrowserCrashTest)) { |
| 232 int* bad_pointer = NULL; | 324 int* bad_pointer = NULL; |
| 233 *bad_pointer = 0; | 325 *bad_pointer = 0; |
| 234 } | 326 } |
| 235 } | 327 } |
| 236 | 328 |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 581 local_state_(NULL), | 673 local_state_(NULL), |
| 582 restart_last_session_(false) { | 674 restart_last_session_(false) { |
| 583 // If we're running tests (ui_task is non-null). | 675 // If we're running tests (ui_task is non-null). |
| 584 if (parameters.ui_task) | 676 if (parameters.ui_task) |
| 585 browser_defaults::enable_help_app = false; | 677 browser_defaults::enable_help_app = false; |
| 586 | 678 |
| 587 // Chrome disallows cookies by default. All code paths that want to use | 679 // Chrome disallows cookies by default. All code paths that want to use |
| 588 // cookies need to go through one of Chrome's URLRequestContexts which have | 680 // cookies need to go through one of Chrome's URLRequestContexts which have |
| 589 // a ChromeNetworkDelegate attached that selectively allows cookies again. | 681 // a ChromeNetworkDelegate attached that selectively allows cookies again. |
| 590 net::URLRequest::SetDefaultCookiePolicyToBlock(); | 682 net::URLRequest::SetDefaultCookiePolicyToBlock(); |
| 683 | |
| 684 // Be sure to allocate the lazy instance on the main thread. | |
| 685 g_startup_complete_flag.Get(); | |
| 591 } | 686 } |
| 592 | 687 |
| 593 ChromeBrowserMainParts::~ChromeBrowserMainParts() { | 688 ChromeBrowserMainParts::~ChromeBrowserMainParts() { |
| 594 for (int i = static_cast<int>(chrome_extra_parts_.size())-1; i >= 0; --i) | 689 for (int i = static_cast<int>(chrome_extra_parts_.size())-1; i >= 0; --i) |
| 595 delete chrome_extra_parts_[i]; | 690 delete chrome_extra_parts_[i]; |
| 596 chrome_extra_parts_.clear(); | 691 chrome_extra_parts_.clear(); |
| 597 } | 692 } |
| 598 | 693 |
| 599 // This will be called after the command-line has been mutated by about:flags | 694 // This will be called after the command-line has been mutated by about:flags |
| 600 void ChromeBrowserMainParts::SetupMetricsAndFieldTrials() { | 695 void ChromeBrowserMainParts::SetupMetricsAndFieldTrials() { |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1102 #endif // !defined(OS_ANDROID) | 1197 #endif // !defined(OS_ANDROID) |
| 1103 #if defined(ENABLE_WEBRTC) | 1198 #if defined(ENABLE_WEBRTC) |
| 1104 // Set up a task to delete old WebRTC log files for all profiles. Use a delay | 1199 // Set up a task to delete old WebRTC log files for all profiles. Use a delay |
| 1105 // to reduce the impact on startup time. | 1200 // to reduce the impact on startup time. |
| 1106 BrowserThread::PostDelayedTask( | 1201 BrowserThread::PostDelayedTask( |
| 1107 BrowserThread::UI, | 1202 BrowserThread::UI, |
| 1108 FROM_HERE, | 1203 FROM_HERE, |
| 1109 base::Bind(&WebRtcLogUtil::DeleteOldWebRtcLogFilesForAllProfiles), | 1204 base::Bind(&WebRtcLogUtil::DeleteOldWebRtcLogFilesForAllProfiles), |
| 1110 base::TimeDelta::FromMinutes(1)); | 1205 base::TimeDelta::FromMinutes(1)); |
| 1111 #endif // defined(ENABLE_WEBRTC) | 1206 #endif // defined(ENABLE_WEBRTC) |
| 1207 | |
| 1208 // The observer is self-deleting. | |
| 1209 (new StartupObserver)->Start(); | |
| 1112 } | 1210 } |
| 1113 | 1211 |
| 1114 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { | 1212 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { |
| 1115 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreMainMessageLoopRunImpl"); | 1213 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreMainMessageLoopRunImpl"); |
| 1116 SCOPED_UMA_HISTOGRAM_LONG_TIMER("Startup.PreMainMessageLoopRunImplLongTime"); | 1214 SCOPED_UMA_HISTOGRAM_LONG_TIMER("Startup.PreMainMessageLoopRunImplLongTime"); |
| 1117 const base::TimeTicks start_time_step1 = base::TimeTicks::Now(); | 1215 const base::TimeTicks start_time_step1 = base::TimeTicks::Now(); |
| 1118 // Android updates the metrics service dynamically depending on whether the | 1216 // Android updates the metrics service dynamically depending on whether the |
| 1119 // application is in the foreground or not. Do not start here. | 1217 // application is in the foreground or not. Do not start here. |
| 1120 #if !defined(OS_ANDROID) | 1218 #if !defined(OS_ANDROID) |
| 1121 // Now that the file thread has been started, start recording. | 1219 // Now that the file thread has been started, start recording. |
| (...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1728 chromeos::CrosSettings::Shutdown(); | 1826 chromeos::CrosSettings::Shutdown(); |
| 1729 #endif // defined(OS_CHROMEOS) | 1827 #endif // defined(OS_CHROMEOS) |
| 1730 #endif // defined(OS_ANDROID) | 1828 #endif // defined(OS_ANDROID) |
| 1731 } | 1829 } |
| 1732 | 1830 |
| 1733 // Public members: | 1831 // Public members: |
| 1734 | 1832 |
| 1735 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { | 1833 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { |
| 1736 chrome_extra_parts_.push_back(parts); | 1834 chrome_extra_parts_.push_back(parts); |
| 1737 } | 1835 } |
| 1836 | |
| 1837 bool IsBrowserStartupComplete() { | |
| 1838 return g_startup_complete_flag.Get().IsSet(); | |
| 1839 } | |
| OLD | NEW |