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

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

Issue 8477004: Have content/ create and destroy its own threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Introduce and use BrowserThreadDelegate, BMP::Pre/PostStartThread, to make this a safe refactoring. Created 9 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 #include "chrome/browser/profiles/profile.h" 69 #include "chrome/browser/profiles/profile.h"
70 #include "chrome/browser/profiles/profile_manager.h" 70 #include "chrome/browser/profiles/profile_manager.h"
71 #include "chrome/browser/search_engines/search_engine_type.h" 71 #include "chrome/browser/search_engines/search_engine_type.h"
72 #include "chrome/browser/search_engines/template_url.h" 72 #include "chrome/browser/search_engines/template_url.h"
73 #include "chrome/browser/search_engines/template_url_service.h" 73 #include "chrome/browser/search_engines/template_url_service.h"
74 #include "chrome/browser/search_engines/template_url_service_factory.h" 74 #include "chrome/browser/search_engines/template_url_service_factory.h"
75 #include "chrome/browser/service/service_process_control.h" 75 #include "chrome/browser/service/service_process_control.h"
76 #include "chrome/browser/shell_integration.h" 76 #include "chrome/browser/shell_integration.h"
77 #include "chrome/browser/translate/translate_manager.h" 77 #include "chrome/browser/translate/translate_manager.h"
78 #include "chrome/browser/ui/browser.h" 78 #include "chrome/browser/ui/browser.h"
79 #include "chrome/browser/ui/browser_init.h"
80 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" 79 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h"
81 #include "chrome/browser/web_resource/gpu_blacklist_updater.h" 80 #include "chrome/browser/web_resource/gpu_blacklist_updater.h"
82 #include "chrome/common/child_process_logging.h" 81 #include "chrome/common/child_process_logging.h"
83 #include "chrome/common/chrome_constants.h" 82 #include "chrome/common/chrome_constants.h"
84 #include "chrome/common/chrome_paths.h" 83 #include "chrome/common/chrome_paths.h"
85 #include "chrome/common/chrome_result_codes.h" 84 #include "chrome/common/chrome_result_codes.h"
86 #include "chrome/common/chrome_switches.h" 85 #include "chrome/common/chrome_switches.h"
87 #include "chrome/common/chrome_version_info.h" 86 #include "chrome/common/chrome_version_info.h"
88 #include "chrome/common/env_vars.h" 87 #include "chrome/common/env_vars.h"
89 #include "chrome/common/json_pref_store.h" 88 #include "chrome/common/json_pref_store.h"
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 net::URLRequestThrottlerManager::GetInstance()->set_enable_thread_checks( 302 net::URLRequestThrottlerManager::GetInstance()->set_enable_thread_checks(
304 true); 303 true);
305 304
306 // TODO(joi): Passing the NetLog here is temporary; once I switch the 305 // TODO(joi): Passing the NetLog here is temporary; once I switch the
307 // URLRequestThrottlerManager to be part of the URLRequestContext it will 306 // URLRequestThrottlerManager to be part of the URLRequestContext it will
308 // come from there. Doing it this way for now (2011/5/12) to try to fail 307 // come from there. Doing it this way for now (2011/5/12) to try to fail
309 // fast in case A/B experiment gives unexpected results. 308 // fast in case A/B experiment gives unexpected results.
310 net::URLRequestThrottlerManager::GetInstance()->set_net_log(net_log); 309 net::URLRequestThrottlerManager::GetInstance()->set_net_log(net_log);
311 } 310 }
312 311
313 // Creates key child threads. We need to do this explicitly since
314 // BrowserThread::PostTask silently deletes a posted task if the target message
315 // loop isn't created.
316 void CreateChildThreads(BrowserProcessImpl* process) {
317 process->db_thread();
318 process->file_thread();
319 process->process_launcher_thread();
320 process->cache_thread();
321 process->io_thread();
322 #if defined(OS_CHROMEOS)
323 process->web_socket_proxy_thread();
324 #endif
325 // Create watchdog thread after creating all other threads because it will
326 // watch the other threads and they must be running.
327 process->watchdog_thread();
328 }
329
330 // Returns the new local state object, guaranteed non-NULL. 312 // Returns the new local state object, guaranteed non-NULL.
331 PrefService* InitializeLocalState(const CommandLine& parsed_command_line, 313 PrefService* InitializeLocalState(const CommandLine& parsed_command_line,
332 bool is_first_run) { 314 bool is_first_run) {
333 FilePath local_state_path; 315 FilePath local_state_path;
334 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path); 316 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path);
335 bool local_state_file_exists = file_util::PathExists(local_state_path); 317 bool local_state_file_exists = file_util::PathExists(local_state_path);
336 318
337 // Load local state. This includes the application locale so we know which 319 // Load local state. This includes the application locale so we know which
338 // locale dll to load. 320 // locale dll to load.
339 PrefService* local_state = g_browser_process->local_state(); 321 PrefService* local_state = g_browser_process->local_state();
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 ChromeBrowserMainParts::ChromeBrowserMainParts( 650 ChromeBrowserMainParts::ChromeBrowserMainParts(
669 const content::MainFunctionParams& parameters) 651 const content::MainFunctionParams& parameters)
670 : parameters_(parameters), 652 : parameters_(parameters),
671 parsed_command_line_(parameters.command_line), 653 parsed_command_line_(parameters.command_line),
672 result_code_(content::RESULT_CODE_NORMAL_EXIT), 654 result_code_(content::RESULT_CODE_NORMAL_EXIT),
673 shutdown_watcher_(new ShutdownWatcherHelper()), 655 shutdown_watcher_(new ShutdownWatcherHelper()),
674 record_search_engine_(false), 656 record_search_engine_(false),
675 translate_manager_(NULL), 657 translate_manager_(NULL),
676 profile_(NULL), 658 profile_(NULL),
677 run_message_loop_(true), 659 run_message_loop_(true),
678 notify_result_(ProcessSingleton::PROCESS_NONE) { 660 notify_result_(ProcessSingleton::PROCESS_NONE),
661 is_first_run_(false),
662 first_run_ui_bypass_(false),
663 metrics_(NULL),
664 local_state_(NULL),
665 restart_last_session_(false) {
679 // If we're running tests (ui_task is non-null). 666 // If we're running tests (ui_task is non-null).
680 if (parameters.ui_task) 667 if (parameters.ui_task)
681 browser_defaults::enable_help_app = false; 668 browser_defaults::enable_help_app = false;
682 } 669 }
683 670
684 ChromeBrowserMainParts::~ChromeBrowserMainParts() { 671 ChromeBrowserMainParts::~ChromeBrowserMainParts() {
685 for (int i = static_cast<int>(chrome_extra_parts_.size())-1; i >= 0; --i) 672 for (int i = static_cast<int>(chrome_extra_parts_.size())-1; i >= 0; --i)
686 delete chrome_extra_parts_[i]; 673 delete chrome_extra_parts_[i];
687 chrome_extra_parts_.clear(); 674 chrome_extra_parts_.clear();
688 } 675 }
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 void ChromeBrowserMainParts::PreMainMessageLoopStart() { 1175 void ChromeBrowserMainParts::PreMainMessageLoopStart() {
1189 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) 1176 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1190 chrome_extra_parts_[i]->PreMainMessageLoopStart(); 1177 chrome_extra_parts_[i]->PreMainMessageLoopStart();
1191 } 1178 }
1192 1179
1193 void ChromeBrowserMainParts::PostMainMessageLoopStart() { 1180 void ChromeBrowserMainParts::PostMainMessageLoopStart() {
1194 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) 1181 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1195 chrome_extra_parts_[i]->PostMainMessageLoopStart(); 1182 chrome_extra_parts_[i]->PostMainMessageLoopStart();
1196 } 1183 }
1197 1184
1198 void ChromeBrowserMainParts::PreMainMessageLoopRun() { 1185 void ChromeBrowserMainParts::PreCreateThreads() {
1199 result_code_ = PreMainMessageLoopRunImpl(); 1186 result_code_ = PreCreateThreadsImpl();
1200 1187
1201 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) 1188 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1202 chrome_extra_parts_[i]->PreMainMessageLoopRun(); 1189 chrome_extra_parts_[i]->PreMainMessageLoopRun();
1203 } 1190 }
1204 1191
1205 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { 1192 void ChromeBrowserMainParts::PreStartThread(
1193 content::BrowserThread::ID thread_id) {
1194 browser_process_->PreStartThread(thread_id);
1195 }
1196
1197 void ChromeBrowserMainParts::PostStartThread(
1198 content::BrowserThread::ID thread_id) {
1199 browser_process_->PostStartThread(thread_id);
1200 switch (thread_id) {
1201 case BrowserThread::FILE:
1202 // Now the command line has been mutated based on about:flags,
1203 // and the file thread has been started, we can set up metrics
1204 // and initialize field trials.
1205 metrics_ = SetupMetricsAndFieldTrials(local_state_);
1206 break;
1207
1208 default:
1209 break;
1210 }
1211 }
1212
1213 void ChromeBrowserMainParts::PreMainMessageLoopRun() {
1214 result_code_ = PreMainMessageLoopRunImpl();
1215 }
1216
1217 int ChromeBrowserMainParts::PreCreateThreadsImpl() {
1206 run_message_loop_ = false; 1218 run_message_loop_ = false;
1207 FilePath user_data_dir;
1208 #if defined(OS_WIN) 1219 #if defined(OS_WIN)
1209 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); 1220 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_);
1210 #else 1221 #else
1211 // Getting the user data dir can fail if the directory isn't 1222 // Getting the user data dir can fail if the directory isn't
1212 // creatable, for example; on Windows in code below we bring up a 1223 // creatable, for example; on Windows in code below we bring up a
1213 // dialog prompting the user to pick a different directory. 1224 // dialog prompting the user to pick a different directory.
1214 // However, ProcessSingleton needs a real user_data_dir on Mac/Linux, 1225 // However, ProcessSingleton needs a real user_data_dir on Mac/Linux,
1215 // so it's better to fail here than fail mysteriously elsewhere. 1226 // so it's better to fail here than fail mysteriously elsewhere.
1216 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) 1227 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_))
1217 << "Must be able to get user data directory!"; 1228 << "Must be able to get user data directory!";
1218 #endif 1229 #endif
1219 1230
1220 process_singleton_.reset(new ProcessSingleton(user_data_dir)); 1231 process_singleton_.reset(new ProcessSingleton(user_data_dir_));
1221 1232
1222 bool is_first_run = FirstRun::IsChromeFirstRun() || 1233 is_first_run_ = FirstRun::IsChromeFirstRun() ||
1223 parsed_command_line().HasSwitch(switches::kFirstRun); 1234 parsed_command_line().HasSwitch(switches::kFirstRun);
1224 1235
1225 if (parsed_command_line().HasSwitch(switches::kImport) || 1236 if (parsed_command_line().HasSwitch(switches::kImport) ||
1226 parsed_command_line().HasSwitch(switches::kImportFromFile)) { 1237 parsed_command_line().HasSwitch(switches::kImportFromFile)) {
1227 // We use different BrowserProcess when importing so no GoogleURLTracker is 1238 // We use different BrowserProcess when importing so no GoogleURLTracker is
1228 // instantiated (as it makes a net::URLRequest and we don't have an IO 1239 // instantiated (as it makes a net::URLRequest and we don't have an IO
1229 // thread, see bug #1292702). 1240 // thread, see bug #1292702).
1230 browser_process_.reset(new FirstRunBrowserProcess(parsed_command_line())); 1241 browser_process_.reset(new FirstRunBrowserProcess(parsed_command_line()));
1231 is_first_run = false; 1242 is_first_run_ = false;
1232 } else { 1243 } else {
1233 browser_process_.reset(new BrowserProcessImpl(parsed_command_line())); 1244 browser_process_.reset(new BrowserProcessImpl(parsed_command_line()));
1234 } 1245 }
1235 1246
1236 if (parsed_command_line().HasSwitch(switches::kEnableProfiling)) { 1247 if (parsed_command_line().HasSwitch(switches::kEnableProfiling)) {
1237 // User wants to override default tracking status. 1248 // User wants to override default tracking status.
1238 std::string flag = 1249 std::string flag =
1239 parsed_command_line().GetSwitchValueASCII(switches::kEnableProfiling); 1250 parsed_command_line().GetSwitchValueASCII(switches::kEnableProfiling);
1240 bool enabled = flag.compare("0") != 0; 1251 bool enabled = flag.compare("0") != 0;
1241 tracked_objects::ThreadData::InitializeAndSetTrackingStatus(enabled); 1252 tracked_objects::ThreadData::InitializeAndSetTrackingStatus(enabled);
1242 } 1253 }
1243 1254
1244 // This forces the TabCloseableStateWatcher to be created and, on chromeos, 1255 // This forces the TabCloseableStateWatcher to be created and, on chromeos,
1245 // register for the notifications it needs to track the closeable state of 1256 // register for the notifications it needs to track the closeable state of
1246 // tabs. 1257 // tabs.
1247 g_browser_process->tab_closeable_state_watcher(); 1258 g_browser_process->tab_closeable_state_watcher();
1248 1259
1249 PrefService* local_state = InitializeLocalState(parsed_command_line(), 1260 local_state_ = InitializeLocalState(parsed_command_line(),
1250 is_first_run); 1261 is_first_run_);
1251 1262
1252 #if defined(USE_LINUX_BREAKPAD) 1263 #if defined(USE_LINUX_BREAKPAD)
1253 // Needs to be called after we have chrome::DIR_USER_DATA and 1264 // Needs to be called after we have chrome::DIR_USER_DATA and
1254 // g_browser_process. 1265 // g_browser_process.
1255 g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE, 1266 g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE,
1256 new GetLinuxDistroTask()); 1267 new GetLinuxDistroTask());
1257 1268
1258 if (IsCrashReportingEnabled(local_state)) 1269 if (IsCrashReportingEnabled(local_state_))
1259 InitCrashReporter(); 1270 InitCrashReporter();
1260 #endif 1271 #endif
1261 1272
1262 // If we're running tests (ui_task is non-null), then the ResourceBundle 1273 // If we're running tests (ui_task is non-null), then the ResourceBundle
1263 // has already been initialized. 1274 // has already been initialized.
1264 if (parameters().ui_task) { 1275 if (parameters().ui_task) {
1265 g_browser_process->SetApplicationLocale("en-US"); 1276 g_browser_process->SetApplicationLocale("en-US");
1266 } else { 1277 } else {
1267 // Mac starts it earlier in |PreMainMessageLoopStart()| (because it is 1278 // Mac starts it earlier in |PreMainMessageLoopStart()| (because it is
1268 // needed when loading the MainMenu.nib and the language doesn't depend on 1279 // needed when loading the MainMenu.nib and the language doesn't depend on
1269 // anything since it comes from Cocoa. 1280 // anything since it comes from Cocoa.
1270 #if defined(OS_MACOSX) 1281 #if defined(OS_MACOSX)
1271 g_browser_process->SetApplicationLocale(l10n_util::GetLocaleOverride()); 1282 g_browser_process->SetApplicationLocale(l10n_util::GetLocaleOverride());
1272 #else 1283 #else
1273 const std::string locale = 1284 const std::string locale =
1274 local_state->GetString(prefs::kApplicationLocale); 1285 local_state_->GetString(prefs::kApplicationLocale);
1275 // On a POSIX OS other than ChromeOS, the parameter that is passed to the 1286 // On a POSIX OS other than ChromeOS, the parameter that is passed to the
1276 // method InitSharedInstance is ignored. 1287 // method InitSharedInstance is ignored.
1277 const std::string loaded_locale = 1288 const std::string loaded_locale =
1278 ResourceBundle::InitSharedInstance(locale); 1289 ResourceBundle::InitSharedInstance(locale);
1279 if (loaded_locale.empty() && 1290 if (loaded_locale.empty() &&
1280 !parsed_command_line().HasSwitch(switches::kNoErrorDialogs)) { 1291 !parsed_command_line().HasSwitch(switches::kNoErrorDialogs)) {
1281 ShowMissingLocaleMessageBox(); 1292 ShowMissingLocaleMessageBox();
1282 return chrome::RESULT_CODE_MISSING_DATA; 1293 return chrome::RESULT_CODE_MISSING_DATA;
1283 } 1294 }
1284 CHECK(!loaded_locale.empty()) << "Locale could not be found for " << locale; 1295 CHECK(!loaded_locale.empty()) << "Locale could not be found for " << locale;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1324 // This needs to be called after the locale has been set. 1335 // This needs to be called after the locale has been set.
1325 RegisterTranslateableItems(); 1336 RegisterTranslateableItems();
1326 #endif 1337 #endif
1327 1338
1328 browser_init_.reset(new BrowserInit); 1339 browser_init_.reset(new BrowserInit);
1329 1340
1330 // On first run, we need to process the predictor preferences before the 1341 // On first run, we need to process the predictor preferences before the
1331 // browser's profile_manager object is created, but after ResourceBundle 1342 // browser's profile_manager object is created, but after ResourceBundle
1332 // is initialized. 1343 // is initialized.
1333 master_prefs_.reset(new FirstRun::MasterPrefs); 1344 master_prefs_.reset(new FirstRun::MasterPrefs);
1334 bool first_run_ui_bypass = false; // True to skip first run UI. 1345 first_run_ui_bypass_ = false; // True to skip first run UI.
1335 if (is_first_run) { 1346 if (is_first_run_) {
1336 first_run_ui_bypass = 1347 first_run_ui_bypass_ = !FirstRun::ProcessMasterPreferences(
1337 !FirstRun::ProcessMasterPreferences(user_data_dir, master_prefs_.get()); 1348 user_data_dir_, master_prefs_.get());
1338 AddFirstRunNewTabs(browser_init_.get(), master_prefs_->new_tabs); 1349 AddFirstRunNewTabs(browser_init_.get(), master_prefs_->new_tabs);
1339 1350
1340 // If we are running in App mode, we do not want to show the importer 1351 // If we are running in App mode, we do not want to show the importer
1341 // (first run) UI. 1352 // (first run) UI.
1342 if (!first_run_ui_bypass && 1353 if (!first_run_ui_bypass_ &&
1343 (parsed_command_line().HasSwitch(switches::kApp) || 1354 (parsed_command_line().HasSwitch(switches::kApp) ||
1344 parsed_command_line().HasSwitch(switches::kAppId) || 1355 parsed_command_line().HasSwitch(switches::kAppId) ||
1345 parsed_command_line().HasSwitch(switches::kNoFirstRun))) 1356 parsed_command_line().HasSwitch(switches::kNoFirstRun)))
1346 first_run_ui_bypass = true; 1357 first_run_ui_bypass_ = true;
1347 } 1358 }
1348 1359
1349 // TODO(viettrungluu): why don't we run this earlier? 1360 // TODO(viettrungluu): why don't we run this earlier?
1350 if (!parsed_command_line().HasSwitch(switches::kNoErrorDialogs)) 1361 if (!parsed_command_line().HasSwitch(switches::kNoErrorDialogs))
1351 WarnAboutMinimumSystemRequirements(); 1362 WarnAboutMinimumSystemRequirements();
1352 1363
1353 // Enable print preview once for supported platforms. 1364 // Enable print preview once for supported platforms.
1354 #if defined(GOOGLE_CHROME_BUILD) 1365 #if defined(GOOGLE_CHROME_BUILD)
1355 local_state->RegisterBooleanPref(prefs::kPrintingPrintPreviewEnabledOnce, 1366 local_state_->RegisterBooleanPref(prefs::kPrintingPrintPreviewEnabledOnce,
1356 false, 1367 false,
1357 PrefService::UNSYNCABLE_PREF); 1368 PrefService::UNSYNCABLE_PREF);
1358 if (!local_state->GetBoolean(prefs::kPrintingPrintPreviewEnabledOnce)) { 1369 if (!local_state_->GetBoolean(prefs::kPrintingPrintPreviewEnabledOnce)) {
1359 local_state->SetBoolean(prefs::kPrintingPrintPreviewEnabledOnce, true); 1370 local_state_->SetBoolean(prefs::kPrintingPrintPreviewEnabledOnce, true);
1360 about_flags::SetExperimentEnabled(local_state, "print-preview", true); 1371 about_flags::SetExperimentEnabled(local_state_, "print-preview", true);
1361 } 1372 }
1362 #endif 1373 #endif
1363 1374
1364 // Convert active labs into switches. Modifies the current command line. 1375 // Convert active labs into switches. Modifies the current command line.
1365 about_flags::ConvertFlagsToSwitches(local_state, 1376 about_flags::ConvertFlagsToSwitches(local_state_,
1366 CommandLine::ForCurrentProcess()); 1377 CommandLine::ForCurrentProcess());
1367 1378
1368 // Reset the command line in the crash report details, since we may have 1379 // Reset the command line in the crash report details, since we may have
1369 // just changed it to include experiments. 1380 // just changed it to include experiments.
1370 child_process_logging::SetCommandLine(CommandLine::ForCurrentProcess()); 1381 child_process_logging::SetCommandLine(CommandLine::ForCurrentProcess());
1371 1382
1372 InitializeNetworkOptions(parsed_command_line()); 1383 InitializeNetworkOptions(parsed_command_line());
1373 InitializeURLRequestThrottlerManager(browser_process_->net_log()); 1384 InitializeURLRequestThrottlerManager(browser_process_->net_log());
1374 1385
1375 // Initialize histogram synchronizer system. This is a singleton and is used 1386 // Initialize histogram synchronizer system. This is a singleton and is used
1376 // for posting tasks via NewRunnableMethod. Its deleted when it goes out of 1387 // for posting tasks via NewRunnableMethod. Its deleted when it goes out of
1377 // scope. Even though NewRunnableMethod does AddRef and Release, the object 1388 // scope. Even though NewRunnableMethod does AddRef and Release, the object
1378 // will not be deleted after the Task is executed. 1389 // will not be deleted after the Task is executed.
1379 histogram_synchronizer_ = new HistogramSynchronizer(); 1390 histogram_synchronizer_ = new HistogramSynchronizer();
1380 tracking_synchronizer_ = new chrome_browser_metrics::TrackingSynchronizer(); 1391 tracking_synchronizer_ = new chrome_browser_metrics::TrackingSynchronizer();
1381 1392
1382 // Now the command line has been mutated based on about:flags, we can
1383 // set up metrics and initialize field trials.
1384 MetricsService* metrics = SetupMetricsAndFieldTrials(local_state);
1385
1386 #if defined(USE_WEBKIT_COMPOSITOR) 1393 #if defined(USE_WEBKIT_COMPOSITOR)
1387 // We need to ensure WebKit has been initialized before we start the WebKit 1394 // We need to ensure WebKit has been initialized before we start the WebKit
1388 // compositor. This is done by the ResourceDispatcherHost on creation. 1395 // compositor. This is done by the ResourceDispatcherHost on creation.
1389 g_browser_process->resource_dispatcher_host(); 1396 g_browser_process->resource_dispatcher_host();
1390 #endif 1397 #endif
1391 1398
1392 // Now that all preferences have been registered, set the install date 1399 // Now that all preferences have been registered, set the install date
1393 // for the uninstall metrics if this is our first run. This only actually 1400 // for the uninstall metrics if this is our first run. This only actually
1394 // gets used if the user has metrics reporting enabled at uninstall time. 1401 // gets used if the user has metrics reporting enabled at uninstall time.
1395 int64 install_date = 1402 int64 install_date =
1396 local_state->GetInt64(prefs::kUninstallMetricsInstallDate); 1403 local_state_->GetInt64(prefs::kUninstallMetricsInstallDate);
1397 if (install_date == 0) { 1404 if (install_date == 0) {
1398 local_state->SetInt64(prefs::kUninstallMetricsInstallDate, 1405 local_state_->SetInt64(prefs::kUninstallMetricsInstallDate,
1399 base::Time::Now().ToTimeT()); 1406 base::Time::Now().ToTimeT());
1400 } 1407 }
1401 1408
1402 #if defined(OS_MACOSX) 1409 #if defined(OS_MACOSX)
1403 // Get the Keychain API to register for distributed notifications on the main 1410 // Get the Keychain API to register for distributed notifications on the main
1404 // thread, which has a proper CFRunloop, instead of later on the I/O thread, 1411 // thread, which has a proper CFRunloop, instead of later on the I/O thread,
1405 // which doesn't. This ensures those notifications will get delivered 1412 // which doesn't. This ensures those notifications will get delivered
1406 // properly. See issue 37766. 1413 // properly. See issue 37766.
1407 // (Note that the callback mask here is empty. I don't want to register for 1414 // (Note that the callback mask here is empty. I don't want to register for
1408 // any callbacks, I just want to initialize the mechanism.) 1415 // any callbacks, I just want to initialize the mechanism.)
1409 SecKeychainAddCallback(&KeychainCallback, 0, NULL); 1416 SecKeychainAddCallback(&KeychainCallback, 0, NULL);
1410 #endif 1417 #endif
1411 1418
1412 CreateChildThreads(browser_process_.get()); 1419 return content::RESULT_CODE_NORMAL_EXIT;
1420 }
1421
1422 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
1423 // Create watchdog thread after creating all other threads because it will
1424 // watch the other threads and they must be running.
1425 browser_process_->watchdog_thread();
1413 1426
1414 #if defined(OS_CHROMEOS) 1427 #if defined(OS_CHROMEOS)
1415 // Now that the file thread exists we can record our stats. 1428 // Now that the file thread exists we can record our stats.
1416 chromeos::BootTimesLoader::Get()->RecordChromeMainStats(); 1429 chromeos::BootTimesLoader::Get()->RecordChromeMainStats();
1417 1430
1418 #if defined(TOOLKIT_USES_GTK) 1431 #if defined(TOOLKIT_USES_GTK)
1419 // Read locale-specific GTK resource information. 1432 // Read locale-specific GTK resource information.
1420 std::string gtkrc = l10n_util::GetStringUTF8(IDS_LOCALE_GTKRC); 1433 std::string gtkrc = l10n_util::GetStringUTF8(IDS_LOCALE_GTKRC);
1421 if (!gtkrc.empty()) 1434 if (!gtkrc.empty())
1422 gtk_rc_parse_string(gtkrc.c_str()); 1435 gtk_rc_parse_string(gtkrc.c_str());
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1548 // Redirects Chrome logging to the user data dir. 1561 // Redirects Chrome logging to the user data dir.
1549 logging::RedirectChromeLogging(parsed_command_line()); 1562 logging::RedirectChromeLogging(parsed_command_line());
1550 1563
1551 // Initialize user policy before creating the profile so the profile 1564 // Initialize user policy before creating the profile so the profile
1552 // initialization code sees policy settings. 1565 // initialization code sees policy settings.
1553 g_browser_process->browser_policy_connector()->InitializeUserPolicy( 1566 g_browser_process->browser_policy_connector()->InitializeUserPolicy(
1554 username, false /* wait_for_policy_fetch */); 1567 username, false /* wait_for_policy_fetch */);
1555 } 1568 }
1556 #endif 1569 #endif
1557 1570
1558 if (is_first_run) { 1571 if (is_first_run_) {
1559 // Warn the ProfileManager that an import process will run, possibly 1572 // Warn the ProfileManager that an import process will run, possibly
1560 // locking the WebDataService directory of the next Profile created. 1573 // locking the WebDataService directory of the next Profile created.
1561 g_browser_process->profile_manager()->SetWillImport(); 1574 g_browser_process->profile_manager()->SetWillImport();
1562 } 1575 }
1563 1576
1564 profile_ = CreateProfile(parameters(), user_data_dir, parsed_command_line()); 1577 profile_ = CreateProfile(parameters(), user_data_dir_, parsed_command_line());
1565 if (!profile_) 1578 if (!profile_)
1566 return content::RESULT_CODE_NORMAL_EXIT; 1579 return content::RESULT_CODE_NORMAL_EXIT;
1567 1580
1568 // Autoload any profiles which are running background apps. 1581 // Autoload any profiles which are running background apps.
1569 // TODO(rlp): Do this on a separate thread. See http://crbug.com/99075. 1582 // TODO(rlp): Do this on a separate thread. See http://crbug.com/99075.
1570 if (!BackgroundModeManager::IsBackgroundModePermanentlyDisabled( 1583 if (!BackgroundModeManager::IsBackgroundModePermanentlyDisabled(
1571 &parsed_command_line())) { 1584 &parsed_command_line())) {
1572 g_browser_process->profile_manager()->AutoloadProfiles(); 1585 g_browser_process->profile_manager()->AutoloadProfiles();
1573 } 1586 }
1574 // Post-profile init --------------------------------------------------------- 1587 // Post-profile init ---------------------------------------------------------
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1638 // TODO(stevenjb): Move ChromeOS login code into PostProfileInitialized(). 1651 // TODO(stevenjb): Move ChromeOS login code into PostProfileInitialized().
1639 // (Requires making ChromeBrowserMainPartsChromeos a non "main" Parts). 1652 // (Requires making ChromeBrowserMainPartsChromeos a non "main" Parts).
1640 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) 1653 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1641 chrome_extra_parts_[i]->PostProfileInitialized(); 1654 chrome_extra_parts_[i]->PostProfileInitialized();
1642 1655
1643 // Show the First Run UI if this is the first time Chrome has been run on 1656 // Show the First Run UI if this is the first time Chrome has been run on
1644 // this computer, or we're being compelled to do so by a command line flag. 1657 // this computer, or we're being compelled to do so by a command line flag.
1645 // Note that this be done _after_ the PrefService is initialized and all 1658 // Note that this be done _after_ the PrefService is initialized and all
1646 // preferences are registered, since some of the code that the importer 1659 // preferences are registered, since some of the code that the importer
1647 // touches reads preferences. 1660 // touches reads preferences.
1648 if (is_first_run) { 1661 if (is_first_run_) {
1649 if (!first_run_ui_bypass) { 1662 if (!first_run_ui_bypass_) {
1650 FirstRun::AutoImport(profile_, 1663 FirstRun::AutoImport(profile_,
1651 master_prefs_->homepage_defined, 1664 master_prefs_->homepage_defined,
1652 master_prefs_->do_import_items, 1665 master_prefs_->do_import_items,
1653 master_prefs_->dont_import_items, 1666 master_prefs_->dont_import_items,
1654 master_prefs_->run_search_engine_experiment, 1667 master_prefs_->run_search_engine_experiment,
1655 master_prefs_->randomize_search_engine_experiment, 1668 master_prefs_->randomize_search_engine_experiment,
1656 master_prefs_->make_chrome_default, 1669 master_prefs_->make_chrome_default,
1657 process_singleton_.get()); 1670 process_singleton_.get());
1658 #if defined(OS_POSIX) 1671 #if defined(OS_POSIX)
1659 // On Windows, the download is tagged with enable/disable stats so there 1672 // On Windows, the download is tagged with enable/disable stats so there
1660 // is no need for this code. 1673 // is no need for this code.
1661 1674
1662 // If stats reporting was turned on by the first run dialog then toggle 1675 // If stats reporting was turned on by the first run dialog then toggle
1663 // the pref. 1676 // the pref.
1664 if (GoogleUpdateSettings::GetCollectStatsConsent()) 1677 if (GoogleUpdateSettings::GetCollectStatsConsent())
1665 local_state->SetBoolean(prefs::kMetricsReportingEnabled, true); 1678 local_state_->SetBoolean(prefs::kMetricsReportingEnabled, true);
1666 #endif // OS_POSIX 1679 #endif // OS_POSIX
1667 } // if (!first_run_ui_bypass) 1680 } // if (!first_run_ui_bypass_)
1668 1681
1669 Browser::SetNewHomePagePrefs(profile_->GetPrefs()); 1682 Browser::SetNewHomePagePrefs(profile_->GetPrefs());
1670 g_browser_process->profile_manager()->OnImportFinished(profile_); 1683 g_browser_process->profile_manager()->OnImportFinished(profile_);
1671 } // if (is_first_run) 1684 } // if (is_first_run)
1672 1685
1673 #if defined(OS_WIN) 1686 #if defined(OS_WIN)
1674 // Sets things up so that if we crash from this point on, a dialog will 1687 // Sets things up so that if we crash from this point on, a dialog will
1675 // popup asking the user to restart chrome. It is done this late to avoid 1688 // popup asking the user to restart chrome. It is done this late to avoid
1676 // testing against a bunch of special cases that are taken care early on. 1689 // testing against a bunch of special cases that are taken care early on.
1677 ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment( 1690 ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment(
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1776 1789
1777 #if defined(OS_WIN) && !defined(GOOGLE_CHROME_BUILD) 1790 #if defined(OS_WIN) && !defined(GOOGLE_CHROME_BUILD)
1778 if (parsed_command_line().HasSwitch(switches::kDebugPrint)) { 1791 if (parsed_command_line().HasSwitch(switches::kDebugPrint)) {
1779 FilePath path = 1792 FilePath path =
1780 parsed_command_line().GetSwitchValuePath(switches::kDebugPrint); 1793 parsed_command_line().GetSwitchValuePath(switches::kDebugPrint);
1781 printing::PrintedDocument::set_debug_dump_path(path); 1794 printing::PrintedDocument::set_debug_dump_path(path);
1782 } 1795 }
1783 #endif 1796 #endif
1784 1797
1785 HandleTestParameters(parsed_command_line()); 1798 HandleTestParameters(parsed_command_line());
1786 RecordBreakpadStatusUMA(metrics); 1799 RecordBreakpadStatusUMA(metrics_);
1787 about_flags::RecordUMAStatistics(local_state); 1800 about_flags::RecordUMAStatistics(local_state_);
1788 LanguageUsageMetrics::RecordAcceptLanguages( 1801 LanguageUsageMetrics::RecordAcceptLanguages(
1789 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); 1802 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
1790 LanguageUsageMetrics::RecordApplicationLanguage( 1803 LanguageUsageMetrics::RecordApplicationLanguage(
1791 g_browser_process->GetApplicationLocale()); 1804 g_browser_process->GetApplicationLocale());
1792 1805
1793 #if defined(OS_WIN) 1806 #if defined(OS_WIN)
1794 fragmentation_checker::RecordFragmentationMetricForCurrentModule(); 1807 fragmentation_checker::RecordFragmentationMetricForCurrentModule();
1795 #endif 1808 #endif
1796 1809
1797 #if defined(OS_CHROMEOS) 1810 #if defined(OS_CHROMEOS)
1798 metrics->StartExternalMetrics(); 1811 metrics_->StartExternalMetrics();
1799 1812
1800 // Initialize the audio handler on ChromeOS. 1813 // Initialize the audio handler on ChromeOS.
1801 chromeos::AudioHandler::Initialize(); 1814 chromeos::AudioHandler::Initialize();
1802 1815
1803 // Listen for system key events so that the user will be able to adjust the 1816 // Listen for system key events so that the user will be able to adjust the
1804 // volume on the login screen, if Chrome is running on Chrome OS 1817 // volume on the login screen, if Chrome is running on Chrome OS
1805 // (i.e. not Linux desktop), and in non-test mode. 1818 // (i.e. not Linux desktop), and in non-test mode.
1806 if (chromeos::system::runtime_environment::IsRunningOnChromeOS() && 1819 if (chromeos::system::runtime_environment::IsRunningOnChromeOS() &&
1807 !parameters().ui_task) { // ui_task is non-NULL when running tests. 1820 !parameters().ui_task) { // ui_task is non-NULL when running tests.
1808 chromeos::SystemKeyEventListener::Initialize(); 1821 chromeos::SystemKeyEventListener::Initialize();
(...skipping 12 matching lines...) Expand all
1821 return content::RESULT_CODE_NORMAL_EXIT; 1834 return content::RESULT_CODE_NORMAL_EXIT;
1822 return chrome::RESULT_CODE_UNINSTALL_EXTENSION_ERROR; 1835 return chrome::RESULT_CODE_UNINSTALL_EXTENSION_ERROR;
1823 } 1836 }
1824 1837
1825 // Start watching for a hang. 1838 // Start watching for a hang.
1826 MetricsService::LogNeedForCleanShutdown(); 1839 MetricsService::LogNeedForCleanShutdown();
1827 1840
1828 #if defined(OS_WIN) 1841 #if defined(OS_WIN)
1829 // We check this here because if the profile is OTR (chromeos possibility) 1842 // We check this here because if the profile is OTR (chromeos possibility)
1830 // it won't still be accessible after browser is destroyed. 1843 // it won't still be accessible after browser is destroyed.
1831 record_search_engine_ = is_first_run && !profile_->IsOffTheRecord(); 1844 record_search_engine_ = is_first_run_ && !profile_->IsOffTheRecord();
1832 #endif 1845 #endif
1833 1846
1834 // ChildProcess:: is a misnomer unless you consider context. Use 1847 // ChildProcess:: is a misnomer unless you consider context. Use
1835 // of --wait-for-debugger only makes sense when Chrome itself is a 1848 // of --wait-for-debugger only makes sense when Chrome itself is a
1836 // child process (e.g. when launched by PyAuto). 1849 // child process (e.g. when launched by PyAuto).
1837 if (parsed_command_line().HasSwitch(switches::kWaitForDebugger)) { 1850 if (parsed_command_line().HasSwitch(switches::kWaitForDebugger)) {
1838 ChildProcess::WaitForDebugger("Browser"); 1851 ChildProcess::WaitForDebugger("Browser");
1839 } 1852 }
1840 1853
1841 #if defined(OS_CHROMEOS) 1854 #if defined(OS_CHROMEOS)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1880 parameters().ui_task->Run(); 1893 parameters().ui_task->Run();
1881 delete parameters().ui_task; 1894 delete parameters().ui_task;
1882 run_message_loop_ = false; 1895 run_message_loop_ = false;
1883 } else { 1896 } else {
1884 // Most general initialization is behind us, but opening a 1897 // Most general initialization is behind us, but opening a
1885 // tab and/or session restore and such is still to be done. 1898 // tab and/or session restore and such is still to be done.
1886 base::TimeTicks browser_open_start = base::TimeTicks::Now(); 1899 base::TimeTicks browser_open_start = base::TimeTicks::Now();
1887 1900
1888 // We are in regular browser boot sequence. Open initial tabs and enter the 1901 // We are in regular browser boot sequence. Open initial tabs and enter the
1889 // main message loop. 1902 // main message loop.
1903 int result_code;
1890 if (browser_init_->Start(parsed_command_line(), FilePath(), profile_, 1904 if (browser_init_->Start(parsed_command_line(), FilePath(), profile_,
1891 &result_code_)) { 1905 &result_code)) {
1892 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS)) 1906 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS))
1893 // Initialize autoupdate timer. Timer callback costs basically nothing 1907 // Initialize autoupdate timer. Timer callback costs basically nothing
1894 // when browser is not in persistent mode, so it's OK to let it ride on 1908 // when browser is not in persistent mode, so it's OK to let it ride on
1895 // the main thread. This needs to be done here because we don't want 1909 // the main thread. This needs to be done here because we don't want
1896 // to start the timer when Chrome is run inside a test harness. 1910 // to start the timer when Chrome is run inside a test harness.
1897 g_browser_process->StartAutoupdateTimer(); 1911 g_browser_process->StartAutoupdateTimer();
1898 #endif 1912 #endif
1899 1913
1900 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 1914 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1901 // On Linux, the running exe will be updated if an upgrade becomes 1915 // On Linux, the running exe will be updated if an upgrade becomes
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
2048 // The XInput2 event listener needs to be shut down earlier than when 2062 // The XInput2 event listener needs to be shut down earlier than when
2049 // Singletons are finally destroyed in AtExitManager. 2063 // Singletons are finally destroyed in AtExitManager.
2050 chromeos::XInputHierarchyChangedEventListener::GetInstance()->Stop(); 2064 chromeos::XInputHierarchyChangedEventListener::GetInstance()->Stop();
2051 2065
2052 // chromeos::SystemKeyEventListener::Shutdown() is always safe to call, 2066 // chromeos::SystemKeyEventListener::Shutdown() is always safe to call,
2053 // even if Initialize() wasn't called. 2067 // even if Initialize() wasn't called.
2054 chromeos::SystemKeyEventListener::Shutdown(); 2068 chromeos::SystemKeyEventListener::Shutdown();
2055 chromeos::AudioHandler::Shutdown(); 2069 chromeos::AudioHandler::Shutdown();
2056 #endif 2070 #endif
2057 2071
2072 restart_last_session_ = browser_shutdown::ShutdownPreThreadsStop();
2073 browser_process_->StartTearDown();
2074 }
2075
2076 void ChromeBrowserMainParts::PreStopThread(BrowserThread::ID identifier) {
2077 browser_process_->PreStopThread(identifier);
2078 }
2079
2080 void ChromeBrowserMainParts::PostStopThread(BrowserThread::ID identifier) {
2081 browser_process_->PostStopThread(identifier);
2082 }
2083
2084 void ChromeBrowserMainParts::PostDestroyThreads() {
2058 // browser_shutdown takes care of deleting browser_process, so we need to 2085 // browser_shutdown takes care of deleting browser_process, so we need to
2059 // release it. 2086 // release it.
2060 ignore_result(browser_process_.release()); 2087 ignore_result(browser_process_.release());
2061 browser_shutdown::Shutdown(); 2088 browser_shutdown::ShutdownPostThreadsStop(restart_last_session_);
2062 master_prefs_.reset(); 2089 master_prefs_.reset();
2063 process_singleton_.reset(); 2090 process_singleton_.reset();
2064 2091
2065 // We need to do this check as late as possible, but due to modularity, this 2092 // We need to do this check as late as possible, but due to modularity, this
2066 // may be the last point in Chrome. This would be more effective if done at 2093 // may be the last point in Chrome. This would be more effective if done at
2067 // a higher level on the stack, so that it is impossible for an early return 2094 // a higher level on the stack, so that it is impossible for an early return
2068 // to bypass this code. Perhaps we need a *final* hook that is called on all 2095 // to bypass this code. Perhaps we need a *final* hook that is called on all
2069 // paths from content/browser/browser_main. 2096 // paths from content/browser/browser_main.
2070 CHECK(MetricsService::UmaMetricsProperlyShutdown()); 2097 CHECK(MetricsService::UmaMetricsProperlyShutdown());
2071 2098
(...skipping 29 matching lines...) Expand all
2101 if (env->GetVar(chrome::kPreReadEnvironmentVariable, &pre_read) && 2128 if (env->GetVar(chrome::kPreReadEnvironmentVariable, &pre_read) &&
2102 (pre_read == "0" || pre_read == "1")) { 2129 (pre_read == "0" || pre_read == "1")) {
2103 std::string uma_name(name); 2130 std::string uma_name(name);
2104 uma_name += "_PreRead"; 2131 uma_name += "_PreRead";
2105 uma_name += pre_read == "1" ? "Enabled" : "Disabled"; 2132 uma_name += pre_read == "1" ? "Enabled" : "Disabled";
2106 AddPreReadHistogramTime(uma_name.c_str(), time); 2133 AddPreReadHistogramTime(uma_name.c_str(), time);
2107 } 2134 }
2108 #endif 2135 #endif
2109 #endif 2136 #endif
2110 } 2137 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698