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

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
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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 #if defined(ENABLE_WEBRTC) 216 #if defined(ENABLE_WEBRTC)
216 #include "chrome/browser/media/webrtc_log_util.h" 217 #include "chrome/browser/media/webrtc_log_util.h"
217 #endif // defined(ENABLE_WEBRTC) 218 #endif // defined(ENABLE_WEBRTC)
218 219
219 #if defined(USE_AURA) 220 #if defined(USE_AURA)
220 #include "ui/aura/env.h" 221 #include "ui/aura/env.h"
221 #endif // defined(USE_AURA) 222 #endif // defined(USE_AURA)
222 223
223 using content::BrowserThread; 224 using content::BrowserThread;
224 225
226
227
228 namespace {
229 using StartupCompleteFlag = base::CancellationFlag;
gab 2015/03/10 15:00:32 Feels weird to use "CancellationFlag" here althoug
michaeln 2015/03/10 19:46:26 ^^^ this
gab 2015/03/10 19:55:27 One simple way to do this would be to rename the c
230 base::LazyInstance<StartupCompleteFlag>::Leaky g_startup_complete_flag;
231 }
232
233 namespace chrome {
234
235 bool IsBrowserStartupComplete() {
236 return g_startup_complete_flag.Get().IsSet();
237 }
238
239 void SetBrowserStartupIsComplete() {
240 g_startup_complete_flag.Get().Set();
241 }
242
243 }
244
225 namespace { 245 namespace {
226 246
227 // This function provides some ways to test crash and assertion handling 247 // This function provides some ways to test crash and assertion handling
228 // behavior of the program. 248 // behavior of the program.
229 void HandleTestParameters(const base::CommandLine& command_line) { 249 void HandleTestParameters(const base::CommandLine& command_line) {
230 // This parameter causes a null pointer crash (crash reporter trigger). 250 // This parameter causes a null pointer crash (crash reporter trigger).
231 if (command_line.HasSwitch(switches::kBrowserCrashTest)) { 251 if (command_line.HasSwitch(switches::kBrowserCrashTest)) {
232 int* bad_pointer = NULL; 252 int* bad_pointer = NULL;
233 *bad_pointer = 0; 253 *bad_pointer = 0;
234 } 254 }
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 local_state_(NULL), 601 local_state_(NULL),
582 restart_last_session_(false) { 602 restart_last_session_(false) {
583 // If we're running tests (ui_task is non-null). 603 // If we're running tests (ui_task is non-null).
584 if (parameters.ui_task) 604 if (parameters.ui_task)
585 browser_defaults::enable_help_app = false; 605 browser_defaults::enable_help_app = false;
586 606
587 // Chrome disallows cookies by default. All code paths that want to use 607 // 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 608 // cookies need to go through one of Chrome's URLRequestContexts which have
589 // a ChromeNetworkDelegate attached that selectively allows cookies again. 609 // a ChromeNetworkDelegate attached that selectively allows cookies again.
590 net::URLRequest::SetDefaultCookiePolicyToBlock(); 610 net::URLRequest::SetDefaultCookiePolicyToBlock();
611
612 g_startup_complete_flag.Get();
591 } 613 }
592 614
593 ChromeBrowserMainParts::~ChromeBrowserMainParts() { 615 ChromeBrowserMainParts::~ChromeBrowserMainParts() {
594 for (int i = static_cast<int>(chrome_extra_parts_.size())-1; i >= 0; --i) 616 for (int i = static_cast<int>(chrome_extra_parts_.size())-1; i >= 0; --i)
595 delete chrome_extra_parts_[i]; 617 delete chrome_extra_parts_[i];
596 chrome_extra_parts_.clear(); 618 chrome_extra_parts_.clear();
597 } 619 }
598 620
599 // This will be called after the command-line has been mutated by about:flags 621 // This will be called after the command-line has been mutated by about:flags
600 void ChromeBrowserMainParts::SetupMetricsAndFieldTrials() { 622 void ChromeBrowserMainParts::SetupMetricsAndFieldTrials() {
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 #if !defined(OS_ANDROID) 1121 #if !defined(OS_ANDROID)
1100 // Allow ProcessSingleton to process messages. 1122 // Allow ProcessSingleton to process messages.
1101 process_singleton_->Unlock(); 1123 process_singleton_->Unlock();
1102 #endif // !defined(OS_ANDROID) 1124 #endif // !defined(OS_ANDROID)
1103 #if defined(ENABLE_WEBRTC) 1125 #if defined(ENABLE_WEBRTC)
1104 // Set up a task to delete old WebRTC log files for all profiles. Use a delay 1126 // Set up a task to delete old WebRTC log files for all profiles. Use a delay
1105 // to reduce the impact on startup time. 1127 // to reduce the impact on startup time.
1106 BrowserThread::PostDelayedTask( 1128 BrowserThread::PostDelayedTask(
1107 BrowserThread::UI, 1129 BrowserThread::UI,
1108 FROM_HERE, 1130 FROM_HERE,
1109 base::Bind(&WebRtcLogUtil::DeleteOldWebRtcLogFilesForAllProfiles), 1131 base::Bind(&WebRtcLogUtil::DeleteOldWebRtcLogFilesForAllProfiles),
michaeln 2015/03/10 19:46:26 This might be a good candidate for PostAfterStartu
1110 base::TimeDelta::FromMinutes(1)); 1132 base::TimeDelta::FromMinutes(1));
1111 #endif // defined(ENABLE_WEBRTC) 1133 #endif // defined(ENABLE_WEBRTC)
1134
1135 // Failsafe for signaling startup completion.
jam 2015/03/10 23:04:34 why do we need a failsafe? under what circumstanc
michaeln 2015/03/10 23:54:54 The first page is closed prior to getting to the l
1136 BrowserThread::PostDelayedTask(
1137 BrowserThread::UI,
1138 FROM_HERE,
1139 base::Bind(&chrome::SetBrowserStartupIsComplete),
1140 base::TimeDelta::FromMinutes(3));
gab 2015/03/10 15:00:32 Is PostBrowserStart() called in background mode la
michaeln 2015/03/10 19:46:26 I'm really not sure about which of these methods g
gab 2015/03/10 19:55:27 Makes sense to post it in a safe and early spot IM
1112 } 1141 }
1113 1142
1114 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { 1143 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
1115 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreMainMessageLoopRunImpl"); 1144 TRACE_EVENT0("startup", "ChromeBrowserMainParts::PreMainMessageLoopRunImpl");
1116 SCOPED_UMA_HISTOGRAM_LONG_TIMER("Startup.PreMainMessageLoopRunImplLongTime"); 1145 SCOPED_UMA_HISTOGRAM_LONG_TIMER("Startup.PreMainMessageLoopRunImplLongTime");
1117 const base::TimeTicks start_time_step1 = base::TimeTicks::Now(); 1146 const base::TimeTicks start_time_step1 = base::TimeTicks::Now();
1118 // Android updates the metrics service dynamically depending on whether the 1147 // Android updates the metrics service dynamically depending on whether the
1119 // application is in the foreground or not. Do not start here. 1148 // application is in the foreground or not. Do not start here.
1120 #if !defined(OS_ANDROID) 1149 #if !defined(OS_ANDROID)
1121 // Now that the file thread has been started, start recording. 1150 // 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(); 1757 chromeos::CrosSettings::Shutdown();
1729 #endif // defined(OS_CHROMEOS) 1758 #endif // defined(OS_CHROMEOS)
1730 #endif // defined(OS_ANDROID) 1759 #endif // defined(OS_ANDROID)
1731 } 1760 }
1732 1761
1733 // Public members: 1762 // Public members:
1734 1763
1735 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) { 1764 void ChromeBrowserMainParts::AddParts(ChromeBrowserMainExtraParts* parts) {
1736 chrome_extra_parts_.push_back(parts); 1765 chrome_extra_parts_.push_back(parts);
1737 } 1766 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698