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

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: Temporary - look at browser_list, browser_main_loop, content/p/b/browser_shutdown Created 9 years, 1 month 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 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 chrome_extra_parts_[i]->PostMainMessageLoopStart(); 1182 chrome_extra_parts_[i]->PostMainMessageLoopStart();
1196 } 1183 }
1197 1184
1198 void ChromeBrowserMainParts::PreMainMessageLoopRun() { 1185 void ChromeBrowserMainParts::PreMainMessageLoopRun() {
1199 result_code_ = PreMainMessageLoopRunImpl(); 1186 result_code_ = PreMainMessageLoopRunImpl();
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
1192 void ChromeBrowserMainParts::PreMainMessageLoopRunThreadsCreated() {
1193 result_code_ = PreMainMessageLoopRunThreadsCreatedImpl();
1194 }
1195
1205 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { 1196 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
1206 run_message_loop_ = false; 1197 run_message_loop_ = false;
1207 FilePath user_data_dir;
1208 #if defined(OS_WIN) 1198 #if defined(OS_WIN)
1209 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); 1199 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_);
1210 #else 1200 #else
1211 // Getting the user data dir can fail if the directory isn't 1201 // 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 1202 // creatable, for example; on Windows in code below we bring up a
1213 // dialog prompting the user to pick a different directory. 1203 // dialog prompting the user to pick a different directory.
1214 // However, ProcessSingleton needs a real user_data_dir on Mac/Linux, 1204 // However, ProcessSingleton needs a real user_data_dir on Mac/Linux,
1215 // so it's better to fail here than fail mysteriously elsewhere. 1205 // so it's better to fail here than fail mysteriously elsewhere.
1216 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) 1206 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_))
1217 << "Must be able to get user data directory!"; 1207 << "Must be able to get user data directory!";
1218 #endif 1208 #endif
1219 1209
1220 process_singleton_.reset(new ProcessSingleton(user_data_dir)); 1210 process_singleton_.reset(new ProcessSingleton(user_data_dir_));
1221 1211
1222 bool is_first_run = FirstRun::IsChromeFirstRun() || 1212 is_first_run_ = FirstRun::IsChromeFirstRun() ||
1223 parsed_command_line().HasSwitch(switches::kFirstRun); 1213 parsed_command_line().HasSwitch(switches::kFirstRun);
1224 1214
1225 if (parsed_command_line().HasSwitch(switches::kImport) || 1215 if (parsed_command_line().HasSwitch(switches::kImport) ||
1226 parsed_command_line().HasSwitch(switches::kImportFromFile)) { 1216 parsed_command_line().HasSwitch(switches::kImportFromFile)) {
1227 // We use different BrowserProcess when importing so no GoogleURLTracker is 1217 // 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 1218 // instantiated (as it makes a net::URLRequest and we don't have an IO
1229 // thread, see bug #1292702). 1219 // thread, see bug #1292702).
1230 browser_process_.reset(new FirstRunBrowserProcess(parsed_command_line())); 1220 browser_process_.reset(new FirstRunBrowserProcess(parsed_command_line()));
1231 is_first_run = false; 1221 is_first_run_ = false;
1232 } else { 1222 } else {
1233 browser_process_.reset(new BrowserProcessImpl(parsed_command_line())); 1223 browser_process_.reset(new BrowserProcessImpl(parsed_command_line()));
1234 } 1224 }
1235 1225
1236 if (parsed_command_line().HasSwitch(switches::kEnableProfiling)) { 1226 if (parsed_command_line().HasSwitch(switches::kEnableProfiling)) {
1237 // User wants to override default tracking status. 1227 // User wants to override default tracking status.
1238 std::string flag = 1228 std::string flag =
1239 parsed_command_line().GetSwitchValueASCII(switches::kEnableProfiling); 1229 parsed_command_line().GetSwitchValueASCII(switches::kEnableProfiling);
1240 bool enabled = flag.compare("0") != 0; 1230 bool enabled = flag.compare("0") != 0;
1241 tracked_objects::ThreadData::InitializeAndSetTrackingStatus(enabled); 1231 tracked_objects::ThreadData::InitializeAndSetTrackingStatus(enabled);
1242 } 1232 }
1243 1233
1244 // This forces the TabCloseableStateWatcher to be created and, on chromeos, 1234 // This forces the TabCloseableStateWatcher to be created and, on chromeos,
1245 // register for the notifications it needs to track the closeable state of 1235 // register for the notifications it needs to track the closeable state of
1246 // tabs. 1236 // tabs.
1247 g_browser_process->tab_closeable_state_watcher(); 1237 g_browser_process->tab_closeable_state_watcher();
1248 1238
1249 PrefService* local_state = InitializeLocalState(parsed_command_line(), 1239 local_state_ = InitializeLocalState(parsed_command_line(),
1250 is_first_run); 1240 is_first_run_);
1251 1241
1252 #if defined(USE_LINUX_BREAKPAD) 1242 #if defined(USE_LINUX_BREAKPAD)
1253 // Needs to be called after we have chrome::DIR_USER_DATA and 1243 // Needs to be called after we have chrome::DIR_USER_DATA and
1254 // g_browser_process. 1244 // g_browser_process.
1255 g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE, 1245 g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE,
1256 new GetLinuxDistroTask()); 1246 new GetLinuxDistroTask());
1257 1247
1258 if (IsCrashReportingEnabled(local_state)) 1248 if (IsCrashReportingEnabled(local_state_))
1259 InitCrashReporter(); 1249 InitCrashReporter();
1260 #endif 1250 #endif
1261 1251
1262 // If we're running tests (ui_task is non-null), then the ResourceBundle 1252 // If we're running tests (ui_task is non-null), then the ResourceBundle
1263 // has already been initialized. 1253 // has already been initialized.
1264 if (parameters().ui_task) { 1254 if (parameters().ui_task) {
1265 g_browser_process->SetApplicationLocale("en-US"); 1255 g_browser_process->SetApplicationLocale("en-US");
1266 } else { 1256 } else {
1267 // Mac starts it earlier in |PreMainMessageLoopStart()| (because it is 1257 // Mac starts it earlier in |PreMainMessageLoopStart()| (because it is
1268 // needed when loading the MainMenu.nib and the language doesn't depend on 1258 // needed when loading the MainMenu.nib and the language doesn't depend on
1269 // anything since it comes from Cocoa. 1259 // anything since it comes from Cocoa.
1270 #if defined(OS_MACOSX) 1260 #if defined(OS_MACOSX)
1271 g_browser_process->SetApplicationLocale(l10n_util::GetLocaleOverride()); 1261 g_browser_process->SetApplicationLocale(l10n_util::GetLocaleOverride());
1272 #else 1262 #else
1273 const std::string locale = 1263 const std::string locale =
1274 local_state->GetString(prefs::kApplicationLocale); 1264 local_state_->GetString(prefs::kApplicationLocale);
1275 // On a POSIX OS other than ChromeOS, the parameter that is passed to the 1265 // On a POSIX OS other than ChromeOS, the parameter that is passed to the
1276 // method InitSharedInstance is ignored. 1266 // method InitSharedInstance is ignored.
1277 const std::string loaded_locale = 1267 const std::string loaded_locale =
1278 ResourceBundle::InitSharedInstance(locale); 1268 ResourceBundle::InitSharedInstance(locale);
1279 if (loaded_locale.empty() && 1269 if (loaded_locale.empty() &&
1280 !parsed_command_line().HasSwitch(switches::kNoErrorDialogs)) { 1270 !parsed_command_line().HasSwitch(switches::kNoErrorDialogs)) {
1281 ShowMissingLocaleMessageBox(); 1271 ShowMissingLocaleMessageBox();
1282 return chrome::RESULT_CODE_MISSING_DATA; 1272 return chrome::RESULT_CODE_MISSING_DATA;
1283 } 1273 }
1284 CHECK(!loaded_locale.empty()) << "Locale could not be found for " << locale; 1274 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. 1314 // This needs to be called after the locale has been set.
1325 RegisterTranslateableItems(); 1315 RegisterTranslateableItems();
1326 #endif 1316 #endif
1327 1317
1328 browser_init_.reset(new BrowserInit); 1318 browser_init_.reset(new BrowserInit);
1329 1319
1330 // On first run, we need to process the predictor preferences before the 1320 // On first run, we need to process the predictor preferences before the
1331 // browser's profile_manager object is created, but after ResourceBundle 1321 // browser's profile_manager object is created, but after ResourceBundle
1332 // is initialized. 1322 // is initialized.
1333 master_prefs_.reset(new FirstRun::MasterPrefs); 1323 master_prefs_.reset(new FirstRun::MasterPrefs);
1334 bool first_run_ui_bypass = false; // True to skip first run UI. 1324 first_run_ui_bypass_ = false; // True to skip first run UI.
1335 if (is_first_run) { 1325 if (is_first_run_) {
1336 first_run_ui_bypass = 1326 first_run_ui_bypass_ = !FirstRun::ProcessMasterPreferences(
1337 !FirstRun::ProcessMasterPreferences(user_data_dir, master_prefs_.get()); 1327 user_data_dir_, master_prefs_.get());
1338 AddFirstRunNewTabs(browser_init_.get(), master_prefs_->new_tabs); 1328 AddFirstRunNewTabs(browser_init_.get(), master_prefs_->new_tabs);
1339 1329
1340 // If we are running in App mode, we do not want to show the importer 1330 // If we are running in App mode, we do not want to show the importer
1341 // (first run) UI. 1331 // (first run) UI.
1342 if (!first_run_ui_bypass && 1332 if (!first_run_ui_bypass_ &&
1343 (parsed_command_line().HasSwitch(switches::kApp) || 1333 (parsed_command_line().HasSwitch(switches::kApp) ||
1344 parsed_command_line().HasSwitch(switches::kAppId) || 1334 parsed_command_line().HasSwitch(switches::kAppId) ||
1345 parsed_command_line().HasSwitch(switches::kNoFirstRun))) 1335 parsed_command_line().HasSwitch(switches::kNoFirstRun)))
1346 first_run_ui_bypass = true; 1336 first_run_ui_bypass_ = true;
1347 } 1337 }
1348 1338
1349 // TODO(viettrungluu): why don't we run this earlier? 1339 // TODO(viettrungluu): why don't we run this earlier?
1350 if (!parsed_command_line().HasSwitch(switches::kNoErrorDialogs)) 1340 if (!parsed_command_line().HasSwitch(switches::kNoErrorDialogs))
1351 WarnAboutMinimumSystemRequirements(); 1341 WarnAboutMinimumSystemRequirements();
1352 1342
1353 // Enable print preview once for supported platforms. 1343 // Enable print preview once for supported platforms.
1354 #if defined(GOOGLE_CHROME_BUILD) 1344 #if defined(GOOGLE_CHROME_BUILD)
1355 local_state->RegisterBooleanPref(prefs::kPrintingPrintPreviewEnabledOnce, 1345 local_state_->RegisterBooleanPref(prefs::kPrintingPrintPreviewEnabledOnce,
1356 false, 1346 false,
1357 PrefService::UNSYNCABLE_PREF); 1347 PrefService::UNSYNCABLE_PREF);
1358 if (!local_state->GetBoolean(prefs::kPrintingPrintPreviewEnabledOnce)) { 1348 if (!local_state_->GetBoolean(prefs::kPrintingPrintPreviewEnabledOnce)) {
1359 local_state->SetBoolean(prefs::kPrintingPrintPreviewEnabledOnce, true); 1349 local_state_->SetBoolean(prefs::kPrintingPrintPreviewEnabledOnce, true);
1360 about_flags::SetExperimentEnabled(local_state, "print-preview", true); 1350 about_flags::SetExperimentEnabled(local_state_, "print-preview", true);
1361 } 1351 }
1362 #endif 1352 #endif
1363 1353
1364 // Convert active labs into switches. Modifies the current command line. 1354 // Convert active labs into switches. Modifies the current command line.
1365 about_flags::ConvertFlagsToSwitches(local_state, 1355 about_flags::ConvertFlagsToSwitches(local_state_,
1366 CommandLine::ForCurrentProcess()); 1356 CommandLine::ForCurrentProcess());
1367 1357
1368 // Reset the command line in the crash report details, since we may have 1358 // Reset the command line in the crash report details, since we may have
1369 // just changed it to include experiments. 1359 // just changed it to include experiments.
1370 child_process_logging::SetCommandLine(CommandLine::ForCurrentProcess()); 1360 child_process_logging::SetCommandLine(CommandLine::ForCurrentProcess());
1371 1361
1372 InitializeNetworkOptions(parsed_command_line()); 1362 InitializeNetworkOptions(parsed_command_line());
1373 InitializeURLRequestThrottlerManager(browser_process_->net_log()); 1363 InitializeURLRequestThrottlerManager(browser_process_->net_log());
1374 1364
1375 // Initialize histogram synchronizer system. This is a singleton and is used 1365 // Initialize histogram synchronizer system. This is a singleton and is used
1376 // for posting tasks via NewRunnableMethod. Its deleted when it goes out of 1366 // for posting tasks via NewRunnableMethod. Its deleted when it goes out of
1377 // scope. Even though NewRunnableMethod does AddRef and Release, the object 1367 // scope. Even though NewRunnableMethod does AddRef and Release, the object
1378 // will not be deleted after the Task is executed. 1368 // will not be deleted after the Task is executed.
1379 histogram_synchronizer_ = new HistogramSynchronizer(); 1369 histogram_synchronizer_ = new HistogramSynchronizer();
1380 tracking_synchronizer_ = new chrome_browser_metrics::TrackingSynchronizer(); 1370 tracking_synchronizer_ = new chrome_browser_metrics::TrackingSynchronizer();
1381 1371
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) 1372 #if defined(USE_WEBKIT_COMPOSITOR)
1387 // We need to ensure WebKit has been initialized before we start the WebKit 1373 // We need to ensure WebKit has been initialized before we start the WebKit
1388 // compositor. This is done by the ResourceDispatcherHost on creation. 1374 // compositor. This is done by the ResourceDispatcherHost on creation.
1389 g_browser_process->resource_dispatcher_host(); 1375 g_browser_process->resource_dispatcher_host();
1390 #endif 1376 #endif
1391 1377
1392 // Now that all preferences have been registered, set the install date 1378 // 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 1379 // 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. 1380 // gets used if the user has metrics reporting enabled at uninstall time.
1395 int64 install_date = 1381 int64 install_date =
1396 local_state->GetInt64(prefs::kUninstallMetricsInstallDate); 1382 local_state_->GetInt64(prefs::kUninstallMetricsInstallDate);
1397 if (install_date == 0) { 1383 if (install_date == 0) {
1398 local_state->SetInt64(prefs::kUninstallMetricsInstallDate, 1384 local_state_->SetInt64(prefs::kUninstallMetricsInstallDate,
1399 base::Time::Now().ToTimeT()); 1385 base::Time::Now().ToTimeT());
1400 } 1386 }
1401 1387
1402 #if defined(OS_MACOSX) 1388 #if defined(OS_MACOSX)
1403 // Get the Keychain API to register for distributed notifications on the main 1389 // 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, 1390 // 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 1391 // which doesn't. This ensures those notifications will get delivered
1406 // properly. See issue 37766. 1392 // properly. See issue 37766.
1407 // (Note that the callback mask here is empty. I don't want to register for 1393 // (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.) 1394 // any callbacks, I just want to initialize the mechanism.)
1409 SecKeychainAddCallback(&KeychainCallback, 0, NULL); 1395 SecKeychainAddCallback(&KeychainCallback, 0, NULL);
1410 #endif 1396 #endif
1411 1397
1412 CreateChildThreads(browser_process_.get()); 1398 return content::RESULT_CODE_NORMAL_EXIT;
1399 }
1400
1401 int ChromeBrowserMainParts::PreMainMessageLoopRunThreadsCreatedImpl() {
1402 // Create watchdog thread after creating all other threads because it will
1403 // watch the other threads and they must be running.
1404 browser_process_->watchdog_thread();
1405
1406 // Now the command line has been mutated based on about:flags, and
1407 // threads have been started (we need the file thread), we can set
1408 // up metrics and initialize field trials.
1409 metrics_ = SetupMetricsAndFieldTrials(local_state_);
1410
1411 // This initializes the IOThread object. This needs to happen
1412 // before anybody posts tasks to the thread, but must not happen
1413 // before metrics are set up.
1414 browser_process_->CreateIOThreadState();
1413 1415
1414 #if defined(OS_CHROMEOS) 1416 #if defined(OS_CHROMEOS)
1415 // Now that the file thread exists we can record our stats. 1417 // Now that the file thread exists we can record our stats.
1416 chromeos::BootTimesLoader::Get()->RecordChromeMainStats(); 1418 chromeos::BootTimesLoader::Get()->RecordChromeMainStats();
1417 1419
1418 #if defined(TOOLKIT_USES_GTK) 1420 #if defined(TOOLKIT_USES_GTK)
1419 // Read locale-specific GTK resource information. 1421 // Read locale-specific GTK resource information.
1420 std::string gtkrc = l10n_util::GetStringUTF8(IDS_LOCALE_GTKRC); 1422 std::string gtkrc = l10n_util::GetStringUTF8(IDS_LOCALE_GTKRC);
1421 if (!gtkrc.empty()) 1423 if (!gtkrc.empty())
1422 gtk_rc_parse_string(gtkrc.c_str()); 1424 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. 1550 // Redirects Chrome logging to the user data dir.
1549 logging::RedirectChromeLogging(parsed_command_line()); 1551 logging::RedirectChromeLogging(parsed_command_line());
1550 1552
1551 // Initialize user policy before creating the profile so the profile 1553 // Initialize user policy before creating the profile so the profile
1552 // initialization code sees policy settings. 1554 // initialization code sees policy settings.
1553 g_browser_process->browser_policy_connector()->InitializeUserPolicy( 1555 g_browser_process->browser_policy_connector()->InitializeUserPolicy(
1554 username, false /* wait_for_policy_fetch */); 1556 username, false /* wait_for_policy_fetch */);
1555 } 1557 }
1556 #endif 1558 #endif
1557 1559
1558 if (is_first_run) { 1560 if (is_first_run_) {
1559 // Warn the ProfileManager that an import process will run, possibly 1561 // Warn the ProfileManager that an import process will run, possibly
1560 // locking the WebDataService directory of the next Profile created. 1562 // locking the WebDataService directory of the next Profile created.
1561 g_browser_process->profile_manager()->SetWillImport(); 1563 g_browser_process->profile_manager()->SetWillImport();
1562 } 1564 }
1563 1565
1564 profile_ = CreateProfile(parameters(), user_data_dir, parsed_command_line()); 1566 profile_ = CreateProfile(parameters(), user_data_dir_, parsed_command_line());
1565 if (!profile_) 1567 if (!profile_)
1566 return content::RESULT_CODE_NORMAL_EXIT; 1568 return content::RESULT_CODE_NORMAL_EXIT;
1567 1569
1568 // Autoload any profiles which are running background apps. 1570 // Autoload any profiles which are running background apps.
1569 // TODO(rlp): Do this on a separate thread. See http://crbug.com/99075. 1571 // TODO(rlp): Do this on a separate thread. See http://crbug.com/99075.
1570 if (!BackgroundModeManager::IsBackgroundModePermanentlyDisabled( 1572 if (!BackgroundModeManager::IsBackgroundModePermanentlyDisabled(
1571 &parsed_command_line())) { 1573 &parsed_command_line())) {
1572 g_browser_process->profile_manager()->AutoloadProfiles(); 1574 g_browser_process->profile_manager()->AutoloadProfiles();
1573 } 1575 }
1574 // Post-profile init --------------------------------------------------------- 1576 // Post-profile init ---------------------------------------------------------
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1638 // TODO(stevenjb): Move ChromeOS login code into PostProfileInitialized(). 1640 // TODO(stevenjb): Move ChromeOS login code into PostProfileInitialized().
1639 // (Requires making ChromeBrowserMainPartsChromeos a non "main" Parts). 1641 // (Requires making ChromeBrowserMainPartsChromeos a non "main" Parts).
1640 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i) 1642 for (size_t i = 0; i < chrome_extra_parts_.size(); ++i)
1641 chrome_extra_parts_[i]->PostProfileInitialized(); 1643 chrome_extra_parts_[i]->PostProfileInitialized();
1642 1644
1643 // Show the First Run UI if this is the first time Chrome has been run on 1645 // 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. 1646 // 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 1647 // Note that this be done _after_ the PrefService is initialized and all
1646 // preferences are registered, since some of the code that the importer 1648 // preferences are registered, since some of the code that the importer
1647 // touches reads preferences. 1649 // touches reads preferences.
1648 if (is_first_run) { 1650 if (is_first_run_) {
1649 if (!first_run_ui_bypass) { 1651 if (!first_run_ui_bypass_) {
1650 FirstRun::AutoImport(profile_, 1652 FirstRun::AutoImport(profile_,
1651 master_prefs_->homepage_defined, 1653 master_prefs_->homepage_defined,
1652 master_prefs_->do_import_items, 1654 master_prefs_->do_import_items,
1653 master_prefs_->dont_import_items, 1655 master_prefs_->dont_import_items,
1654 master_prefs_->run_search_engine_experiment, 1656 master_prefs_->run_search_engine_experiment,
1655 master_prefs_->randomize_search_engine_experiment, 1657 master_prefs_->randomize_search_engine_experiment,
1656 master_prefs_->make_chrome_default, 1658 master_prefs_->make_chrome_default,
1657 process_singleton_.get()); 1659 process_singleton_.get());
1658 #if defined(OS_POSIX) 1660 #if defined(OS_POSIX)
1659 // On Windows, the download is tagged with enable/disable stats so there 1661 // On Windows, the download is tagged with enable/disable stats so there
1660 // is no need for this code. 1662 // is no need for this code.
1661 1663
1662 // If stats reporting was turned on by the first run dialog then toggle 1664 // If stats reporting was turned on by the first run dialog then toggle
1663 // the pref. 1665 // the pref.
1664 if (GoogleUpdateSettings::GetCollectStatsConsent()) 1666 if (GoogleUpdateSettings::GetCollectStatsConsent())
1665 local_state->SetBoolean(prefs::kMetricsReportingEnabled, true); 1667 local_state_->SetBoolean(prefs::kMetricsReportingEnabled, true);
1666 #endif // OS_POSIX 1668 #endif // OS_POSIX
1667 } // if (!first_run_ui_bypass) 1669 } // if (!first_run_ui_bypass_)
1668 1670
1669 Browser::SetNewHomePagePrefs(profile_->GetPrefs()); 1671 Browser::SetNewHomePagePrefs(profile_->GetPrefs());
1670 g_browser_process->profile_manager()->OnImportFinished(profile_); 1672 g_browser_process->profile_manager()->OnImportFinished(profile_);
1671 } // if (is_first_run) 1673 } // if (is_first_run)
1672 1674
1673 #if defined(OS_WIN) 1675 #if defined(OS_WIN)
1674 // Sets things up so that if we crash from this point on, a dialog will 1676 // 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 1677 // 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. 1678 // testing against a bunch of special cases that are taken care early on.
1677 ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment( 1679 ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment(
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1776 1778
1777 #if defined(OS_WIN) && !defined(GOOGLE_CHROME_BUILD) 1779 #if defined(OS_WIN) && !defined(GOOGLE_CHROME_BUILD)
1778 if (parsed_command_line().HasSwitch(switches::kDebugPrint)) { 1780 if (parsed_command_line().HasSwitch(switches::kDebugPrint)) {
1779 FilePath path = 1781 FilePath path =
1780 parsed_command_line().GetSwitchValuePath(switches::kDebugPrint); 1782 parsed_command_line().GetSwitchValuePath(switches::kDebugPrint);
1781 printing::PrintedDocument::set_debug_dump_path(path); 1783 printing::PrintedDocument::set_debug_dump_path(path);
1782 } 1784 }
1783 #endif 1785 #endif
1784 1786
1785 HandleTestParameters(parsed_command_line()); 1787 HandleTestParameters(parsed_command_line());
1786 RecordBreakpadStatusUMA(metrics); 1788 RecordBreakpadStatusUMA(metrics_);
1787 about_flags::RecordUMAStatistics(local_state); 1789 about_flags::RecordUMAStatistics(local_state_);
1788 LanguageUsageMetrics::RecordAcceptLanguages( 1790 LanguageUsageMetrics::RecordAcceptLanguages(
1789 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); 1791 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
1790 LanguageUsageMetrics::RecordApplicationLanguage( 1792 LanguageUsageMetrics::RecordApplicationLanguage(
1791 g_browser_process->GetApplicationLocale()); 1793 g_browser_process->GetApplicationLocale());
1792 1794
1793 #if defined(OS_WIN) 1795 #if defined(OS_WIN)
1794 fragmentation_checker::RecordFragmentationMetricForCurrentModule(); 1796 fragmentation_checker::RecordFragmentationMetricForCurrentModule();
1795 #endif 1797 #endif
1796 1798
1797 #if defined(OS_CHROMEOS) 1799 #if defined(OS_CHROMEOS)
1798 metrics->StartExternalMetrics(); 1800 metrics_->StartExternalMetrics();
1799 1801
1800 // Initialize the audio handler on ChromeOS. 1802 // Initialize the audio handler on ChromeOS.
1801 chromeos::AudioHandler::Initialize(); 1803 chromeos::AudioHandler::Initialize();
1802 1804
1803 // Listen for system key events so that the user will be able to adjust the 1805 // 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 1806 // volume on the login screen, if Chrome is running on Chrome OS
1805 // (i.e. not Linux desktop), and in non-test mode. 1807 // (i.e. not Linux desktop), and in non-test mode.
1806 if (chromeos::system::runtime_environment::IsRunningOnChromeOS() && 1808 if (chromeos::system::runtime_environment::IsRunningOnChromeOS() &&
1807 !parameters().ui_task) { // ui_task is non-NULL when running tests. 1809 !parameters().ui_task) { // ui_task is non-NULL when running tests.
1808 chromeos::SystemKeyEventListener::Initialize(); 1810 chromeos::SystemKeyEventListener::Initialize();
(...skipping 12 matching lines...) Expand all
1821 return content::RESULT_CODE_NORMAL_EXIT; 1823 return content::RESULT_CODE_NORMAL_EXIT;
1822 return chrome::RESULT_CODE_UNINSTALL_EXTENSION_ERROR; 1824 return chrome::RESULT_CODE_UNINSTALL_EXTENSION_ERROR;
1823 } 1825 }
1824 1826
1825 // Start watching for a hang. 1827 // Start watching for a hang.
1826 MetricsService::LogNeedForCleanShutdown(); 1828 MetricsService::LogNeedForCleanShutdown();
1827 1829
1828 #if defined(OS_WIN) 1830 #if defined(OS_WIN)
1829 // We check this here because if the profile is OTR (chromeos possibility) 1831 // We check this here because if the profile is OTR (chromeos possibility)
1830 // it won't still be accessible after browser is destroyed. 1832 // it won't still be accessible after browser is destroyed.
1831 record_search_engine_ = is_first_run && !profile_->IsOffTheRecord(); 1833 record_search_engine_ = is_first_run_ && !profile_->IsOffTheRecord();
1832 #endif 1834 #endif
1833 1835
1834 // ChildProcess:: is a misnomer unless you consider context. Use 1836 // ChildProcess:: is a misnomer unless you consider context. Use
1835 // of --wait-for-debugger only makes sense when Chrome itself is a 1837 // of --wait-for-debugger only makes sense when Chrome itself is a
1836 // child process (e.g. when launched by PyAuto). 1838 // child process (e.g. when launched by PyAuto).
1837 if (parsed_command_line().HasSwitch(switches::kWaitForDebugger)) { 1839 if (parsed_command_line().HasSwitch(switches::kWaitForDebugger)) {
1838 ChildProcess::WaitForDebugger("Browser"); 1840 ChildProcess::WaitForDebugger("Browser");
1839 } 1841 }
1840 1842
1841 #if defined(OS_CHROMEOS) 1843 #if defined(OS_CHROMEOS)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1880 parameters().ui_task->Run(); 1882 parameters().ui_task->Run();
1881 delete parameters().ui_task; 1883 delete parameters().ui_task;
1882 run_message_loop_ = false; 1884 run_message_loop_ = false;
1883 } else { 1885 } else {
1884 // Most general initialization is behind us, but opening a 1886 // Most general initialization is behind us, but opening a
1885 // tab and/or session restore and such is still to be done. 1887 // tab and/or session restore and such is still to be done.
1886 base::TimeTicks browser_open_start = base::TimeTicks::Now(); 1888 base::TimeTicks browser_open_start = base::TimeTicks::Now();
1887 1889
1888 // We are in regular browser boot sequence. Open initial tabs and enter the 1890 // We are in regular browser boot sequence. Open initial tabs and enter the
1889 // main message loop. 1891 // main message loop.
1892 int result_code;
1890 if (browser_init_->Start(parsed_command_line(), FilePath(), profile_, 1893 if (browser_init_->Start(parsed_command_line(), FilePath(), profile_,
1891 &result_code_)) { 1894 &result_code)) {
1892 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS)) 1895 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS))
1893 // Initialize autoupdate timer. Timer callback costs basically nothing 1896 // 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 1897 // 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 1898 // 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. 1899 // to start the timer when Chrome is run inside a test harness.
1897 g_browser_process->StartAutoupdateTimer(); 1900 g_browser_process->StartAutoupdateTimer();
1898 #endif 1901 #endif
1899 1902
1900 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 1903 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1901 // On Linux, the running exe will be updated if an upgrade becomes 1904 // 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 2051 // The XInput2 event listener needs to be shut down earlier than when
2049 // Singletons are finally destroyed in AtExitManager. 2052 // Singletons are finally destroyed in AtExitManager.
2050 chromeos::XInputHierarchyChangedEventListener::GetInstance()->Stop(); 2053 chromeos::XInputHierarchyChangedEventListener::GetInstance()->Stop();
2051 2054
2052 // chromeos::SystemKeyEventListener::Shutdown() is always safe to call, 2055 // chromeos::SystemKeyEventListener::Shutdown() is always safe to call,
2053 // even if Initialize() wasn't called. 2056 // even if Initialize() wasn't called.
2054 chromeos::SystemKeyEventListener::Shutdown(); 2057 chromeos::SystemKeyEventListener::Shutdown();
2055 chromeos::AudioHandler::Shutdown(); 2058 chromeos::AudioHandler::Shutdown();
2056 #endif 2059 #endif
2057 2060
2061 restart_last_session_ = browser_shutdown::ShutdownPreThreadsStop();
2062 browser_process_->StartTearDown();
2063 }
2064
2065 void ChromeBrowserMainParts::PreStopThread(BrowserThread::ID identifier) {
2066 browser_process_->PreStopThread(identifier);
2067 }
2068
2069 void ChromeBrowserMainParts::PostStopThread(BrowserThread::ID identifier) {
2070 browser_process_->PostStopThread(identifier);
2071 }
2072
2073 void ChromeBrowserMainParts::FinalCleanup() {
2058 // browser_shutdown takes care of deleting browser_process, so we need to 2074 // browser_shutdown takes care of deleting browser_process, so we need to
2059 // release it. 2075 // release it.
2060 ignore_result(browser_process_.release()); 2076 ignore_result(browser_process_.release());
2061 browser_shutdown::Shutdown(); 2077 browser_shutdown::ShutdownPostThreadsStop(restart_last_session_);
2062 master_prefs_.reset(); 2078 master_prefs_.reset();
2063 process_singleton_.reset(); 2079 process_singleton_.reset();
2064 2080
2065 // We need to do this check as late as possible, but due to modularity, this 2081 // 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 2082 // 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 2083 // 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 2084 // to bypass this code. Perhaps we need a *final* hook that is called on all
2069 // paths from content/browser/browser_main. 2085 // paths from content/browser/browser_main.
2070 CHECK(MetricsService::UmaMetricsProperlyShutdown()); 2086 CHECK(MetricsService::UmaMetricsProperlyShutdown());
2071 2087
(...skipping 29 matching lines...) Expand all
2101 if (env->GetVar(chrome::kPreReadEnvironmentVariable, &pre_read) && 2117 if (env->GetVar(chrome::kPreReadEnvironmentVariable, &pre_read) &&
2102 (pre_read == "0" || pre_read == "1")) { 2118 (pre_read == "0" || pre_read == "1")) {
2103 std::string uma_name(name); 2119 std::string uma_name(name);
2104 uma_name += "_PreRead"; 2120 uma_name += "_PreRead";
2105 uma_name += pre_read == "1" ? "Enabled" : "Disabled"; 2121 uma_name += pre_read == "1" ? "Enabled" : "Disabled";
2106 AddPreReadHistogramTime(uma_name.c_str(), time); 2122 AddPreReadHistogramTime(uma_name.c_str(), time);
2107 } 2123 }
2108 #endif 2124 #endif
2109 #endif 2125 #endif
2110 } 2126 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698