Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(359)

Side by Side Diff: chrome/browser/chrome_browser_main.cc

Issue 949293002: Implement a poor man's PostAfterStartupTask() function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/chrome_browser_main.h ('k') | chrome/browser/chrome_content_browser_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
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;
224 227
225 namespace { 228 namespace {
226 229
230 using StartupCompleteFlag = base::CancellationFlag;
231 base::LazyInstance<StartupCompleteFlag>::Leaky g_startup_complete_flag;
232
233 // Used to monitor the first page load to inform PostAfterStartupTask.
234 class StartupObserver : public content::WebContentsObserver {
235 public:
236 static void Start();
237
238 private:
239 static content::WebContents* GetFirstWebContents();
240 static void SetBrowserStartupIsComplete();
michaeln 2015/03/20 00:21:28 i'll probably have to expose SetBrowserStartupIsCo
241
242 explicit StartupObserver(content::WebContents* web_contents)
243 : content::WebContentsObserver(web_contents) {}
244
245 // WebContentsObserver overrides
246 void DidFinishLoad(content::RenderFrameHost* render_frame_host,
247 const GURL& validated_url) override;
248 void DidFailLoad(content::RenderFrameHost* render_frame_host,
249 const GURL& validated_url,
250 int error_code,
251 const base::string16& error_description) override;
252 void WebContentsDestroyed() override;
253 };
254
255 void StartupObserver::Start() {
256 // Signal completion quickly when there is no first page to load.
257 int kDefaultDelaySecs = 3;
258 base::TimeDelta delay = base::TimeDelta::FromSeconds(kDefaultDelaySecs);
259
260 #if !defined(OS_ANDROID)
261 content::WebContents* web_contents = GetFirstWebContents();
262 if (web_contents) {
263 // StartupObserver is self deleting.
264 new StartupObserver(web_contents);
265
266 // In case startup oberver never signals completion.
267 const int kFailsafeDelayMins = 3;
268 delay = base::TimeDelta::FromMinutes(kFailsafeDelayMins);
269 }
270 #endif // !defined(OS_ANDROID)
271
272 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE,
273 base::Bind(&SetBrowserStartupIsComplete),
274 delay);
275 }
276
277 content::WebContents* StartupObserver::GetFirstWebContents() {
278 for (chrome::BrowserIterator iterator; !iterator.done(); iterator.Next()) {
279 Browser* browser = *iterator;
280 content::WebContents* web_contents =
281 browser->tab_strip_model()->GetActiveWebContents();
282 if (web_contents)
283 return web_contents;
284 }
285 return nullptr;
286 }
287
288 void StartupObserver::SetBrowserStartupIsComplete() {
289 g_startup_complete_flag.Get().Set();
290 }
291
292 void StartupObserver::DidFinishLoad(content::RenderFrameHost* render_frame_host,
293 const GURL& validated_url) {
294 SetBrowserStartupIsComplete();
295 delete this;
296 }
297
298 void StartupObserver::DidFailLoad(content::RenderFrameHost* render_frame_host,
299 const GURL& validated_url,
300 int error_code,
301 const base::string16& error_description) {
302 SetBrowserStartupIsComplete();
303 delete this;
304 }
305
306 void StartupObserver::WebContentsDestroyed() {
307 SetBrowserStartupIsComplete();
308 delete this;
309 }
310
227 // This function provides some ways to test crash and assertion handling 311 // This function provides some ways to test crash and assertion handling
228 // behavior of the program. 312 // behavior of the program.
229 void HandleTestParameters(const base::CommandLine& command_line) { 313 void HandleTestParameters(const base::CommandLine& command_line) {
230 // This parameter causes a null pointer crash (crash reporter trigger). 314 // This parameter causes a null pointer crash (crash reporter trigger).
231 if (command_line.HasSwitch(switches::kBrowserCrashTest)) { 315 if (command_line.HasSwitch(switches::kBrowserCrashTest)) {
232 int* bad_pointer = NULL; 316 int* bad_pointer = NULL;
233 *bad_pointer = 0; 317 *bad_pointer = 0;
234 } 318 }
235 } 319 }
236 320
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 local_state_(NULL), 665 local_state_(NULL),
582 restart_last_session_(false) { 666 restart_last_session_(false) {
583 // If we're running tests (ui_task is non-null). 667 // If we're running tests (ui_task is non-null).
584 if (parameters.ui_task) 668 if (parameters.ui_task)
585 browser_defaults::enable_help_app = false; 669 browser_defaults::enable_help_app = false;
586 670
587 // Chrome disallows cookies by default. All code paths that want to use 671 // 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 672 // cookies need to go through one of Chrome's URLRequestContexts which have
589 // a ChromeNetworkDelegate attached that selectively allows cookies again. 673 // a ChromeNetworkDelegate attached that selectively allows cookies again.
590 net::URLRequest::SetDefaultCookiePolicyToBlock(); 674 net::URLRequest::SetDefaultCookiePolicyToBlock();
675
676 // Be sure to allocate the lazy instance on the main thread.
677 g_startup_complete_flag.Get();
591 } 678 }
592 679
593 ChromeBrowserMainParts::~ChromeBrowserMainParts() { 680 ChromeBrowserMainParts::~ChromeBrowserMainParts() {
594 for (int i = static_cast<int>(chrome_extra_parts_.size())-1; i >= 0; --i) 681 for (int i = static_cast<int>(chrome_extra_parts_.size())-1; i >= 0; --i)
595 delete chrome_extra_parts_[i]; 682 delete chrome_extra_parts_[i];
596 chrome_extra_parts_.clear(); 683 chrome_extra_parts_.clear();
597 } 684 }
598 685
599 // This will be called after the command-line has been mutated by about:flags 686 // This will be called after the command-line has been mutated by about:flags
600 void ChromeBrowserMainParts::SetupMetricsAndFieldTrials() { 687 void ChromeBrowserMainParts::SetupMetricsAndFieldTrials() {
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 #endif // !defined(OS_ANDROID) 1189 #endif // !defined(OS_ANDROID)
1103 #if defined(ENABLE_WEBRTC) 1190 #if defined(ENABLE_WEBRTC)
1104 // Set up a task to delete old WebRTC log files for all profiles. Use a delay 1191 // Set up a task to delete old WebRTC log files for all profiles. Use a delay
1105 // to reduce the impact on startup time. 1192 // to reduce the impact on startup time.
1106 BrowserThread::PostDelayedTask( 1193 BrowserThread::PostDelayedTask(
1107 BrowserThread::UI, 1194 BrowserThread::UI,
1108 FROM_HERE, 1195 FROM_HERE,
1109 base::Bind(&WebRtcLogUtil::DeleteOldWebRtcLogFilesForAllProfiles), 1196 base::Bind(&WebRtcLogUtil::DeleteOldWebRtcLogFilesForAllProfiles),
1110 base::TimeDelta::FromMinutes(1)); 1197 base::TimeDelta::FromMinutes(1));
1111 #endif // defined(ENABLE_WEBRTC) 1198 #endif // defined(ENABLE_WEBRTC)
1199 StartupObserver::Start();
1112 } 1200 }
1113 1201
1114 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { 1202 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
1115 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreMainMessageLoopRunImpl"); 1203 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreMainMessageLoopRunImpl");
1116 SCOPED_UMA_HISTOGRAM_LONG_TIMER("Startup.PreMainMessageLoopRunImplLongTime"); 1204 SCOPED_UMA_HISTOGRAM_LONG_TIMER("Startup.PreMainMessageLoopRunImplLongTime");
1117 const base::TimeTicks start_time_step1 = base::TimeTicks::Now(); 1205 const base::TimeTicks start_time_step1 = base::TimeTicks::Now();
1118 // Android updates the metrics service dynamically depending on whether the 1206 // Android updates the metrics service dynamically depending on whether the
1119 // application is in the foreground or not. Do not start here. 1207 // application is in the foreground or not. Do not start here.
1120 #if !defined(OS_ANDROID) 1208 #if !defined(OS_ANDROID)
1121 // Now that the file thread has been started, start recording. 1209 // Now that the file thread has been started, start recording.
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
1728 chromeos::CrosSettings::Shutdown(); 1816 chromeos::CrosSettings::Shutdown();
1729 #endif // defined(OS_CHROMEOS) 1817 #endif // defined(OS_CHROMEOS)
1730 #endif // defined(OS_ANDROID) 1818 #endif // defined(OS_ANDROID)
1731 } 1819 }
1732 1820
1733 // Public members: 1821 // Public members:
1734 1822
1735 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { 1823 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) {
1736 chrome_extra_parts_.push_back(parts); 1824 chrome_extra_parts_.push_back(parts);
1737 } 1825 }
1826
1827 bool IsBrowserStartupComplete() {
1828 return g_startup_complete_flag.Get().IsSet();
1829 }
OLDNEW
« no previous file with comments | « chrome/browser/chrome_browser_main.h ('k') | chrome/browser/chrome_content_browser_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698