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

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: More IWYU, missing link-time dependency for Chrome Frame. 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 #include "chrome/browser/profiles/profile.h" 65 #include "chrome/browser/profiles/profile.h"
66 #include "chrome/browser/profiles/profile_manager.h" 66 #include "chrome/browser/profiles/profile_manager.h"
67 #include "chrome/browser/search_engines/search_engine_type.h" 67 #include "chrome/browser/search_engines/search_engine_type.h"
68 #include "chrome/browser/search_engines/template_url.h" 68 #include "chrome/browser/search_engines/template_url.h"
69 #include "chrome/browser/search_engines/template_url_service.h" 69 #include "chrome/browser/search_engines/template_url_service.h"
70 #include "chrome/browser/search_engines/template_url_service_factory.h" 70 #include "chrome/browser/search_engines/template_url_service_factory.h"
71 #include "chrome/browser/service/service_process_control.h" 71 #include "chrome/browser/service/service_process_control.h"
72 #include "chrome/browser/shell_integration.h" 72 #include "chrome/browser/shell_integration.h"
73 #include "chrome/browser/translate/translate_manager.h" 73 #include "chrome/browser/translate/translate_manager.h"
74 #include "chrome/browser/ui/browser.h" 74 #include "chrome/browser/ui/browser.h"
75 #include "chrome/browser/ui/browser_init.h"
76 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" 75 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h"
77 #include "chrome/browser/web_resource/gpu_blacklist_updater.h" 76 #include "chrome/browser/web_resource/gpu_blacklist_updater.h"
78 #include "chrome/common/child_process_logging.h" 77 #include "chrome/common/child_process_logging.h"
79 #include "chrome/common/chrome_constants.h" 78 #include "chrome/common/chrome_constants.h"
80 #include "chrome/common/chrome_paths.h" 79 #include "chrome/common/chrome_paths.h"
81 #include "chrome/common/chrome_result_codes.h" 80 #include "chrome/common/chrome_result_codes.h"
82 #include "chrome/common/chrome_switches.h" 81 #include "chrome/common/chrome_switches.h"
83 #include "chrome/common/chrome_version_info.h" 82 #include "chrome/common/chrome_version_info.h"
84 #include "chrome/common/env_vars.h" 83 #include "chrome/common/env_vars.h"
85 #include "chrome/common/json_pref_store.h" 84 #include "chrome/common/json_pref_store.h"
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 net::URLRequestThrottlerManager::GetInstance()->set_enable_thread_checks( 307 net::URLRequestThrottlerManager::GetInstance()->set_enable_thread_checks(
309 true); 308 true);
310 309
311 // TODO(joi): Passing the NetLog here is temporary; once I switch the 310 // TODO(joi): Passing the NetLog here is temporary; once I switch the
312 // URLRequestThrottlerManager to be part of the URLRequestContext it will 311 // URLRequestThrottlerManager to be part of the URLRequestContext it will
313 // come from there. Doing it this way for now (2011/5/12) to try to fail 312 // come from there. Doing it this way for now (2011/5/12) to try to fail
314 // fast in case A/B experiment gives unexpected results. 313 // fast in case A/B experiment gives unexpected results.
315 net::URLRequestThrottlerManager::GetInstance()->set_net_log(net_log); 314 net::URLRequestThrottlerManager::GetInstance()->set_net_log(net_log);
316 } 315 }
317 316
318 // Creates key child threads. We need to do this explicitly since
319 // BrowserThread::PostTask silently deletes a posted task if the target message
320 // loop isn't created.
321 void CreateChildThreads(BrowserProcessImpl* process) {
322 process->db_thread();
323 process->file_thread();
324 process->process_launcher_thread();
325 process->cache_thread();
326 process->io_thread();
327 #if defined(OS_CHROMEOS)
328 process->web_socket_proxy_thread();
329 #endif
330 // Create watchdog thread after creating all other threads because it will
331 // watch the other threads and they must be running.
332 process->watchdog_thread();
333 }
334
335 // Returns the new local state object, guaranteed non-NULL. 317 // Returns the new local state object, guaranteed non-NULL.
336 PrefService* InitializeLocalState(const CommandLine& parsed_command_line, 318 PrefService* InitializeLocalState(const CommandLine& parsed_command_line,
337 bool is_first_run) { 319 bool is_first_run) {
338 FilePath local_state_path; 320 FilePath local_state_path;
339 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path); 321 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path);
340 bool local_state_file_exists = file_util::PathExists(local_state_path); 322 bool local_state_file_exists = file_util::PathExists(local_state_path);
341 323
342 // Load local state. This includes the application locale so we know which 324 // Load local state. This includes the application locale so we know which
343 // locale dll to load. 325 // locale dll to load.
344 PrefService* local_state = g_browser_process->local_state(); 326 PrefService* local_state = g_browser_process->local_state();
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 ChromeBrowserMainParts::ChromeBrowserMainParts( 673 ChromeBrowserMainParts::ChromeBrowserMainParts(
692 const content::MainFunctionParams& parameters) 674 const content::MainFunctionParams& parameters)
693 : parameters_(parameters), 675 : parameters_(parameters),
694 parsed_command_line_(parameters.command_line), 676 parsed_command_line_(parameters.command_line),
695 result_code_(content::RESULT_CODE_NORMAL_EXIT), 677 result_code_(content::RESULT_CODE_NORMAL_EXIT),
696 shutdown_watcher_(new ShutdownWatcherHelper()), 678 shutdown_watcher_(new ShutdownWatcherHelper()),
697 record_search_engine_(false), 679 record_search_engine_(false),
698 translate_manager_(NULL), 680 translate_manager_(NULL),
699 profile_(NULL), 681 profile_(NULL),
700 run_message_loop_(true), 682 run_message_loop_(true),
701 notify_result_(ProcessSingleton::PROCESS_NONE) { 683 notify_result_(ProcessSingleton::PROCESS_NONE),
684 is_first_run_(false),
685 first_run_ui_bypass_(false),
686 metrics_(NULL),
687 local_state_(NULL) {
702 // If we're running tests (ui_task is non-null). 688 // If we're running tests (ui_task is non-null).
703 if (parameters.ui_task) 689 if (parameters.ui_task)
704 browser_defaults::enable_help_app = false; 690 browser_defaults::enable_help_app = false;
705 } 691 }
706 692
707 ChromeBrowserMainParts::~ChromeBrowserMainParts() { 693 ChromeBrowserMainParts::~ChromeBrowserMainParts() {
708 } 694 }
709 695
710 // This will be called after the command-line has been mutated by about:flags 696 // This will be called after the command-line has been mutated by about:flags
711 MetricsService* ChromeBrowserMainParts::SetupMetricsAndFieldTrials( 697 MetricsService* ChromeBrowserMainParts::SetupMetricsAndFieldTrials(
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 // in ChromeMain() got destructed when the function returned. 1169 // in ChromeMain() got destructed when the function returned.
1184 base::AtExitManager exit_manager; 1170 base::AtExitManager exit_manager;
1185 upgrade_util::RelaunchChromeBrowserWithNewCommandLineIfNeeded(); 1171 upgrade_util::RelaunchChromeBrowserWithNewCommandLineIfNeeded();
1186 } 1172 }
1187 #endif 1173 #endif
1188 1174
1189 void ChromeBrowserMainParts::PreMainMessageLoopRun() { 1175 void ChromeBrowserMainParts::PreMainMessageLoopRun() {
1190 result_code_ = PreMainMessageLoopRunImpl(); 1176 result_code_ = PreMainMessageLoopRunImpl();
1191 } 1177 }
1192 1178
1179 void ChromeBrowserMainParts::PreMainMessageLoopRunThreadsCreated() {
1180 result_code_ = PreMainMessageLoopRunThreadsCreatedImpl();
1181 }
1182
1193 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() { 1183 int ChromeBrowserMainParts::PreMainMessageLoopRunImpl() {
1194 run_message_loop_ = false; 1184 run_message_loop_ = false;
1195 FilePath user_data_dir;
1196 #if defined(OS_WIN) 1185 #if defined(OS_WIN)
1197 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); 1186 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_);
1198 #else 1187 #else
1199 // Getting the user data dir can fail if the directory isn't 1188 // Getting the user data dir can fail if the directory isn't
1200 // creatable, for example; on Windows in code below we bring up a 1189 // creatable, for example; on Windows in code below we bring up a
1201 // dialog prompting the user to pick a different directory. 1190 // dialog prompting the user to pick a different directory.
1202 // However, ProcessSingleton needs a real user_data_dir on Mac/Linux, 1191 // However, ProcessSingleton needs a real user_data_dir on Mac/Linux,
1203 // so it's better to fail here than fail mysteriously elsewhere. 1192 // so it's better to fail here than fail mysteriously elsewhere.
1204 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) 1193 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir_))
1205 << "Must be able to get user data directory!"; 1194 << "Must be able to get user data directory!";
1206 #endif 1195 #endif
1207 1196
1208 process_singleton_.reset(new ProcessSingleton(user_data_dir)); 1197 process_singleton_.reset(new ProcessSingleton(user_data_dir_));
1209 1198
1210 bool is_first_run = FirstRun::IsChromeFirstRun() || 1199 is_first_run_ = FirstRun::IsChromeFirstRun() ||
1211 parsed_command_line().HasSwitch(switches::kFirstRun); 1200 parsed_command_line().HasSwitch(switches::kFirstRun);
1212 1201
1213 #if defined(USE_AURA) 1202 #if defined(USE_AURA)
1214 // No first run on Aura. See crbug.com/99439. 1203 // No first run on Aura. See crbug.com/99439.
1215 is_first_run = false; 1204 is_first_run_ = false;
1216 #endif 1205 #endif
1217 1206
1218 if (parsed_command_line().HasSwitch(switches::kImport) || 1207 if (parsed_command_line().HasSwitch(switches::kImport) ||
1219 parsed_command_line().HasSwitch(switches::kImportFromFile)) { 1208 parsed_command_line().HasSwitch(switches::kImportFromFile)) {
1220 // We use different BrowserProcess when importing so no GoogleURLTracker is 1209 // We use different BrowserProcess when importing so no GoogleURLTracker is
1221 // instantiated (as it makes a net::URLRequest and we don't have an IO 1210 // instantiated (as it makes a net::URLRequest and we don't have an IO
1222 // thread, see bug #1292702). 1211 // thread, see bug #1292702).
1223 browser_process_.reset(new FirstRunBrowserProcess(parsed_command_line())); 1212 browser_process_.reset(new FirstRunBrowserProcess(parsed_command_line()));
1224 is_first_run = false; 1213 is_first_run_ = false;
1225 } else { 1214 } else {
1226 browser_process_.reset(new BrowserProcessImpl(parsed_command_line())); 1215 browser_process_.reset(new BrowserProcessImpl(parsed_command_line()));
1227 } 1216 }
1228 1217
1229 if (parsed_command_line().HasSwitch(switches::kEnableTracking)) { 1218 if (parsed_command_line().HasSwitch(switches::kEnableTracking)) {
1230 // User wants to override default tracking status. 1219 // User wants to override default tracking status.
1231 std::string flag = 1220 std::string flag =
1232 parsed_command_line().GetSwitchValueASCII(switches::kEnableTracking); 1221 parsed_command_line().GetSwitchValueASCII(switches::kEnableTracking);
1233 bool enabled = flag.compare("0") != 0; 1222 bool enabled = flag.compare("0") != 0;
1234 tracked_objects::ThreadData::InitializeAndSetTrackingStatus(enabled); 1223 tracked_objects::ThreadData::InitializeAndSetTrackingStatus(enabled);
1235 } 1224 }
1236 1225
1237 // This forces the TabCloseableStateWatcher to be created and, on chromeos, 1226 // This forces the TabCloseableStateWatcher to be created and, on chromeos,
1238 // register for the notifications it needs to track the closeable state of 1227 // register for the notifications it needs to track the closeable state of
1239 // tabs. 1228 // tabs.
1240 g_browser_process->tab_closeable_state_watcher(); 1229 g_browser_process->tab_closeable_state_watcher();
1241 1230
1242 PrefService* local_state = InitializeLocalState(parsed_command_line(), 1231 local_state_ = InitializeLocalState(parsed_command_line(),
1243 is_first_run); 1232 is_first_run_);
1244 1233
1245 #if defined(USE_LINUX_BREAKPAD) 1234 #if defined(USE_LINUX_BREAKPAD)
1246 // Needs to be called after we have chrome::DIR_USER_DATA and 1235 // Needs to be called after we have chrome::DIR_USER_DATA and
1247 // g_browser_process. 1236 // g_browser_process.
1248 g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE, 1237 g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE,
1249 new GetLinuxDistroTask()); 1238 new GetLinuxDistroTask());
1250 1239
1251 if (IsCrashReportingEnabled(local_state)) 1240 if (IsCrashReportingEnabled(local_state_))
1252 InitCrashReporter(); 1241 InitCrashReporter();
1253 #endif 1242 #endif
1254 1243
1255 // If we're running tests (ui_task is non-null), then the ResourceBundle 1244 // If we're running tests (ui_task is non-null), then the ResourceBundle
1256 // has already been initialized. 1245 // has already been initialized.
1257 if (parameters().ui_task) { 1246 if (parameters().ui_task) {
1258 g_browser_process->SetApplicationLocale("en-US"); 1247 g_browser_process->SetApplicationLocale("en-US");
1259 } else { 1248 } else {
1260 // Mac starts it earlier in |PreMainMessageLoopStart()| (because it is 1249 // Mac starts it earlier in |PreMainMessageLoopStart()| (because it is
1261 // needed when loading the MainMenu.nib and the language doesn't depend on 1250 // needed when loading the MainMenu.nib and the language doesn't depend on
1262 // anything since it comes from Cocoa. 1251 // anything since it comes from Cocoa.
1263 #if defined(OS_MACOSX) 1252 #if defined(OS_MACOSX)
1264 g_browser_process->SetApplicationLocale(l10n_util::GetLocaleOverride()); 1253 g_browser_process->SetApplicationLocale(l10n_util::GetLocaleOverride());
1265 #else 1254 #else
1266 const std::string locale = 1255 const std::string locale =
1267 local_state->GetString(prefs::kApplicationLocale); 1256 local_state_->GetString(prefs::kApplicationLocale);
1268 // On a POSIX OS other than ChromeOS, the parameter that is passed to the 1257 // On a POSIX OS other than ChromeOS, the parameter that is passed to the
1269 // method InitSharedInstance is ignored. 1258 // method InitSharedInstance is ignored.
1270 const std::string loaded_locale = 1259 const std::string loaded_locale =
1271 ResourceBundle::InitSharedInstance(locale); 1260 ResourceBundle::InitSharedInstance(locale);
1272 if (loaded_locale.empty() && 1261 if (loaded_locale.empty() &&
1273 !parsed_command_line().HasSwitch(switches::kNoErrorDialogs)) { 1262 !parsed_command_line().HasSwitch(switches::kNoErrorDialogs)) {
1274 ShowMissingLocaleMessageBox(); 1263 ShowMissingLocaleMessageBox();
1275 return chrome::RESULT_CODE_MISSING_DATA; 1264 return chrome::RESULT_CODE_MISSING_DATA;
1276 } 1265 }
1277 CHECK(!loaded_locale.empty()) << "Locale could not be found for " << locale; 1266 CHECK(!loaded_locale.empty()) << "Locale could not be found for " << locale;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1311 // We don't support retention experiments on Mac or Linux. 1300 // We don't support retention experiments on Mac or Linux.
1312 return content::RESULT_CODE_NORMAL_EXIT; 1301 return content::RESULT_CODE_NORMAL_EXIT;
1313 #endif // defined(OS_WIN) 1302 #endif // defined(OS_WIN)
1314 } 1303 }
1315 1304
1316 #if defined(OS_CHROMEOS) && defined(TOOLKIT_USES_GTK) 1305 #if defined(OS_CHROMEOS) && defined(TOOLKIT_USES_GTK)
1317 // This needs to be called after the locale has been set. 1306 // This needs to be called after the locale has been set.
1318 RegisterTranslateableItems(); 1307 RegisterTranslateableItems();
1319 #endif 1308 #endif
1320 1309
1321 BrowserInit browser_init;
1322
1323 // On first run, we need to process the predictor preferences before the 1310 // On first run, we need to process the predictor preferences before the
1324 // browser's profile_manager object is created, but after ResourceBundle 1311 // browser's profile_manager object is created, but after ResourceBundle
1325 // is initialized. 1312 // is initialized.
1326 master_prefs_.reset(new FirstRun::MasterPrefs); 1313 master_prefs_.reset(new FirstRun::MasterPrefs);
1327 bool first_run_ui_bypass = false; // True to skip first run UI. 1314 first_run_ui_bypass_ = false; // True to skip first run UI.
1328 if (is_first_run) { 1315 if (is_first_run_) {
1329 first_run_ui_bypass = 1316 first_run_ui_bypass_ = !FirstRun::ProcessMasterPreferences(
1330 !FirstRun::ProcessMasterPreferences(user_data_dir, master_prefs_.get()); 1317 user_data_dir_, master_prefs_.get());
1331 AddFirstRunNewTabs(&browser_init, master_prefs_->new_tabs); 1318 AddFirstRunNewTabs(&browser_init_, master_prefs_->new_tabs);
1332 1319
1333 // If we are running in App mode, we do not want to show the importer 1320 // If we are running in App mode, we do not want to show the importer
1334 // (first run) UI. 1321 // (first run) UI.
1335 if (!first_run_ui_bypass && 1322 if (!first_run_ui_bypass_ &&
1336 (parsed_command_line().HasSwitch(switches::kApp) || 1323 (parsed_command_line().HasSwitch(switches::kApp) ||
1337 parsed_command_line().HasSwitch(switches::kAppId) || 1324 parsed_command_line().HasSwitch(switches::kAppId) ||
1338 parsed_command_line().HasSwitch(switches::kNoFirstRun))) 1325 parsed_command_line().HasSwitch(switches::kNoFirstRun)))
1339 first_run_ui_bypass = true; 1326 first_run_ui_bypass_ = true;
1340 } 1327 }
1341 1328
1342 // TODO(viettrungluu): why don't we run this earlier? 1329 // TODO(viettrungluu): why don't we run this earlier?
1343 if (!parsed_command_line().HasSwitch(switches::kNoErrorDialogs)) 1330 if (!parsed_command_line().HasSwitch(switches::kNoErrorDialogs))
1344 WarnAboutMinimumSystemRequirements(); 1331 WarnAboutMinimumSystemRequirements();
1345 1332
1346 // Enable print preview once for supported platforms. 1333 // Enable print preview once for supported platforms.
1347 #if defined(GOOGLE_CHROME_BUILD) 1334 #if defined(GOOGLE_CHROME_BUILD)
1348 local_state->RegisterBooleanPref(prefs::kPrintingPrintPreviewEnabledOnce, 1335 local_state_->RegisterBooleanPref(prefs::kPrintingPrintPreviewEnabledOnce,
1349 false, 1336 false,
1350 PrefService::UNSYNCABLE_PREF); 1337 PrefService::UNSYNCABLE_PREF);
1351 if (!local_state->GetBoolean(prefs::kPrintingPrintPreviewEnabledOnce)) { 1338 if (!local_state_->GetBoolean(prefs::kPrintingPrintPreviewEnabledOnce)) {
1352 local_state->SetBoolean(prefs::kPrintingPrintPreviewEnabledOnce, true); 1339 local_state_->SetBoolean(prefs::kPrintingPrintPreviewEnabledOnce, true);
1353 about_flags::SetExperimentEnabled(local_state, "print-preview", true); 1340 about_flags::SetExperimentEnabled(local_state_, "print-preview", true);
1354 } 1341 }
1355 #endif 1342 #endif
1356 1343
1357 #if defined(TOUCH_UI) 1344 #if defined(TOUCH_UI)
1358 // Always add the --views-desktop flag, if not already set. 1345 // Always add the --views-desktop flag, if not already set.
1359 // If the user disabled the flag from about:flags, it will get unset by the 1346 // If the user disabled the flag from about:flags, it will get unset by the
1360 // call to ConvertFlagsToSwitches in the following line. 1347 // call to ConvertFlagsToSwitches in the following line.
1361 if (!parsed_command_line().HasSwitch(switches::kViewsDesktop)) 1348 if (!parsed_command_line().HasSwitch(switches::kViewsDesktop))
1362 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kViewsDesktop, 1349 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kViewsDesktop,
1363 "other"); 1350 "other");
(...skipping 12 matching lines...) Expand all
1376 // set. We'll leave this on for a bit to determine if we Break The Web for 1363 // set. We'll leave this on for a bit to determine if we Break The Web for
1377 // Canary users. 1364 // Canary users.
1378 // 1365 //
1379 // TODO(mkwst): Remove this once impact is clear (http://crbug.com/98241). 1366 // TODO(mkwst): Remove this once impact is clear (http://crbug.com/98241).
1380 if (!parsed_command_line().HasSwitch( 1367 if (!parsed_command_line().HasSwitch(
1381 switches::kBlockReadingThirdPartyCookies)) 1368 switches::kBlockReadingThirdPartyCookies))
1382 CommandLine::ForCurrentProcess()->AppendSwitch( 1369 CommandLine::ForCurrentProcess()->AppendSwitch(
1383 switches::kBlockReadingThirdPartyCookies); 1370 switches::kBlockReadingThirdPartyCookies);
1384 1371
1385 // Convert active labs into switches. Modifies the current command line. 1372 // Convert active labs into switches. Modifies the current command line.
1386 about_flags::ConvertFlagsToSwitches(local_state, 1373 about_flags::ConvertFlagsToSwitches(local_state_,
1387 CommandLine::ForCurrentProcess()); 1374 CommandLine::ForCurrentProcess());
1388 1375
1389 // Reset the command line in the crash report details, since we may have 1376 // Reset the command line in the crash report details, since we may have
1390 // just changed it to include experiments. 1377 // just changed it to include experiments.
1391 child_process_logging::SetCommandLine(CommandLine::ForCurrentProcess()); 1378 child_process_logging::SetCommandLine(CommandLine::ForCurrentProcess());
1392 1379
1393 InitializeNetworkOptions(parsed_command_line()); 1380 InitializeNetworkOptions(parsed_command_line());
1394 InitializeURLRequestThrottlerManager(browser_process_->net_log()); 1381 InitializeURLRequestThrottlerManager(browser_process_->net_log());
1395 1382
1396 // Initialize histogram synchronizer system. This is a singleton and is used 1383 // Initialize histogram synchronizer system. This is a singleton and is used
1397 // for posting tasks via NewRunnableMethod. Its deleted when it goes out of 1384 // for posting tasks via NewRunnableMethod. Its deleted when it goes out of
1398 // scope. Even though NewRunnableMethod does AddRef and Release, the object 1385 // scope. Even though NewRunnableMethod does AddRef and Release, the object
1399 // will not be deleted after the Task is executed. 1386 // will not be deleted after the Task is executed.
1400 histogram_synchronizer_ = new HistogramSynchronizer(); 1387 histogram_synchronizer_ = new HistogramSynchronizer();
1401 tracking_synchronizer_ = new chrome_browser_metrics::TrackingSynchronizer(); 1388 tracking_synchronizer_ = new chrome_browser_metrics::TrackingSynchronizer();
1402 1389
1403 // Now the command line has been mutated based on about:flags, we can 1390 // Now the command line has been mutated based on about:flags, we can
1404 // set up metrics and initialize field trials. 1391 // set up metrics and initialize field trials.
1405 MetricsService* metrics = SetupMetricsAndFieldTrials(local_state); 1392 metrics_ = SetupMetricsAndFieldTrials(local_state_);
1406 1393
1407 #if defined(USE_WEBKIT_COMPOSITOR) 1394 #if defined(USE_WEBKIT_COMPOSITOR)
1408 // We need to ensure WebKit has been initialized before we start the WebKit 1395 // We need to ensure WebKit has been initialized before we start the WebKit
1409 // compositor. This is done by the ResourceDispatcherHost on creation. 1396 // compositor. This is done by the ResourceDispatcherHost on creation.
1410 g_browser_process->resource_dispatcher_host(); 1397 g_browser_process->resource_dispatcher_host();
1411 #endif 1398 #endif
1412 #if defined(USE_AURA) 1399 #if defined(USE_AURA)
1413 // Shell takes ownership of ChromeShellDelegate. 1400 // Shell takes ownership of ChromeShellDelegate.
1414 aura_shell::Shell::GetInstance()->SetDelegate(new ChromeShellDelegate); 1401 aura_shell::Shell::GetInstance()->SetDelegate(new ChromeShellDelegate);
1415 #elif defined(TOOLKIT_VIEWS) 1402 #elif defined(TOOLKIT_VIEWS)
(...skipping 18 matching lines...) Expand all
1434 chrome_views_delegate->default_parent_view = 1421 chrome_views_delegate->default_parent_view =
1435 views::desktop::DesktopWindowView::desktop_window_view; 1422 views::desktop::DesktopWindowView::desktop_window_view;
1436 } 1423 }
1437 } 1424 }
1438 #endif 1425 #endif
1439 1426
1440 // Now that all preferences have been registered, set the install date 1427 // Now that all preferences have been registered, set the install date
1441 // for the uninstall metrics if this is our first run. This only actually 1428 // for the uninstall metrics if this is our first run. This only actually
1442 // gets used if the user has metrics reporting enabled at uninstall time. 1429 // gets used if the user has metrics reporting enabled at uninstall time.
1443 int64 install_date = 1430 int64 install_date =
1444 local_state->GetInt64(prefs::kUninstallMetricsInstallDate); 1431 local_state_->GetInt64(prefs::kUninstallMetricsInstallDate);
1445 if (install_date == 0) { 1432 if (install_date == 0) {
1446 local_state->SetInt64(prefs::kUninstallMetricsInstallDate, 1433 local_state_->SetInt64(prefs::kUninstallMetricsInstallDate,
1447 base::Time::Now().ToTimeT()); 1434 base::Time::Now().ToTimeT());
1448 } 1435 }
1449 1436
1450 #if defined(OS_MACOSX) 1437 #if defined(OS_MACOSX)
1451 // Get the Keychain API to register for distributed notifications on the main 1438 // Get the Keychain API to register for distributed notifications on the main
1452 // thread, which has a proper CFRunloop, instead of later on the I/O thread, 1439 // thread, which has a proper CFRunloop, instead of later on the I/O thread,
1453 // which doesn't. This ensures those notifications will get delivered 1440 // which doesn't. This ensures those notifications will get delivered
1454 // properly. See issue 37766. 1441 // properly. See issue 37766.
1455 // (Note that the callback mask here is empty. I don't want to register for 1442 // (Note that the callback mask here is empty. I don't want to register for
1456 // any callbacks, I just want to initialize the mechanism.) 1443 // any callbacks, I just want to initialize the mechanism.)
1457 SecKeychainAddCallback(&KeychainCallback, 0, NULL); 1444 SecKeychainAddCallback(&KeychainCallback, 0, NULL);
1458 #endif 1445 #endif
1459 1446
1460 CreateChildThreads(browser_process_.get()); 1447 // This initializes the IOThread object. This needs to happen
1448 // before the thread itself is created.
1449 browser_process_->CreateIOThreadState();
1450
1451 return content::RESULT_CODE_NORMAL_EXIT;
1452 }
1453
1454 int ChromeBrowserMainParts::PreMainMessageLoopRunThreadsCreatedImpl() {
1455 // Create watchdog thread after creating all other threads because it will
1456 // watch the other threads and they must be running.
1457 browser_process_->watchdog_thread();
1461 1458
1462 #if defined(OS_CHROMEOS) 1459 #if defined(OS_CHROMEOS)
1463 // Now that the file thread exists we can record our stats. 1460 // Now that the file thread exists we can record our stats.
1464 chromeos::BootTimesLoader::Get()->RecordChromeMainStats(); 1461 chromeos::BootTimesLoader::Get()->RecordChromeMainStats();
1465 1462
1466 #if defined(TOOLKIT_USES_GTK) 1463 #if defined(TOOLKIT_USES_GTK)
1467 // Read locale-specific GTK resource information. 1464 // Read locale-specific GTK resource information.
1468 std::string gtkrc = l10n_util::GetStringUTF8(IDS_LOCALE_GTKRC); 1465 std::string gtkrc = l10n_util::GetStringUTF8(IDS_LOCALE_GTKRC);
1469 if (!gtkrc.empty()) 1466 if (!gtkrc.empty())
1470 gtk_rc_parse_string(gtkrc.c_str()); 1467 gtk_rc_parse_string(gtkrc.c_str());
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
1592 // Redirects Chrome logging to the user data dir. 1589 // Redirects Chrome logging to the user data dir.
1593 logging::RedirectChromeLogging(parsed_command_line()); 1590 logging::RedirectChromeLogging(parsed_command_line());
1594 1591
1595 // Initialize user policy before creating the profile so the profile 1592 // Initialize user policy before creating the profile so the profile
1596 // initialization code sees policy settings. 1593 // initialization code sees policy settings.
1597 g_browser_process->browser_policy_connector()->InitializeUserPolicy( 1594 g_browser_process->browser_policy_connector()->InitializeUserPolicy(
1598 username); 1595 username);
1599 } 1596 }
1600 #endif 1597 #endif
1601 1598
1602 if (is_first_run) { 1599 if (is_first_run_) {
1603 // Warn the ProfileManager that an import process will run, possibly 1600 // Warn the ProfileManager that an import process will run, possibly
1604 // locking the WebDataService directory of the next Profile created. 1601 // locking the WebDataService directory of the next Profile created.
1605 g_browser_process->profile_manager()->SetWillImport(); 1602 g_browser_process->profile_manager()->SetWillImport();
1606 } 1603 }
1607 1604
1608 profile_ = CreateProfile(parameters(), user_data_dir, parsed_command_line()); 1605 profile_ = CreateProfile(parameters(), user_data_dir_, parsed_command_line());
1609 if (!profile_) 1606 if (!profile_)
1610 return content::RESULT_CODE_NORMAL_EXIT; 1607 return content::RESULT_CODE_NORMAL_EXIT;
1611 1608
1612 // Autoload any profiles which are running background apps. 1609 // Autoload any profiles which are running background apps.
1613 // TODO(rlp): Do this on a separate thread. See http://crbug.com/99075. 1610 // TODO(rlp): Do this on a separate thread. See http://crbug.com/99075.
1614 if (!BackgroundModeManager::IsBackgroundModePermanentlyDisabled( 1611 if (!BackgroundModeManager::IsBackgroundModePermanentlyDisabled(
1615 &parsed_command_line())) { 1612 &parsed_command_line())) {
1616 g_browser_process->profile_manager()->AutoloadProfiles(); 1613 g_browser_process->profile_manager()->AutoloadProfiles();
1617 } 1614 }
1618 // Post-profile init --------------------------------------------------------- 1615 // Post-profile init ---------------------------------------------------------
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1681 } 1678 }
1682 } 1679 }
1683 base::mac::ScopedNSAutoreleasePool* pool = parameters().autorelease_pool; 1680 base::mac::ScopedNSAutoreleasePool* pool = parameters().autorelease_pool;
1684 #endif 1681 #endif
1685 1682
1686 // Show the First Run UI if this is the first time Chrome has been run on 1683 // Show the First Run UI if this is the first time Chrome has been run on
1687 // this computer, or we're being compelled to do so by a command line flag. 1684 // this computer, or we're being compelled to do so by a command line flag.
1688 // Note that this be done _after_ the PrefService is initialized and all 1685 // Note that this be done _after_ the PrefService is initialized and all
1689 // preferences are registered, since some of the code that the importer 1686 // preferences are registered, since some of the code that the importer
1690 // touches reads preferences. 1687 // touches reads preferences.
1691 if (is_first_run) { 1688 if (is_first_run_) {
1692 if (!first_run_ui_bypass) { 1689 if (!first_run_ui_bypass_) {
1693 FirstRun::AutoImport(profile_, 1690 FirstRun::AutoImport(profile_,
1694 master_prefs_->homepage_defined, 1691 master_prefs_->homepage_defined,
1695 master_prefs_->do_import_items, 1692 master_prefs_->do_import_items,
1696 master_prefs_->dont_import_items, 1693 master_prefs_->dont_import_items,
1697 master_prefs_->run_search_engine_experiment, 1694 master_prefs_->run_search_engine_experiment,
1698 master_prefs_->randomize_search_engine_experiment, 1695 master_prefs_->randomize_search_engine_experiment,
1699 master_prefs_->make_chrome_default, 1696 master_prefs_->make_chrome_default,
1700 process_singleton_.get()); 1697 process_singleton_.get());
1701 #if defined(OS_POSIX) 1698 #if defined(OS_POSIX)
1702 // On Windows, the download is tagged with enable/disable stats so there 1699 // On Windows, the download is tagged with enable/disable stats so there
1703 // is no need for this code. 1700 // is no need for this code.
1704 1701
1705 // If stats reporting was turned on by the first run dialog then toggle 1702 // If stats reporting was turned on by the first run dialog then toggle
1706 // the pref. 1703 // the pref.
1707 if (GoogleUpdateSettings::GetCollectStatsConsent()) 1704 if (GoogleUpdateSettings::GetCollectStatsConsent())
1708 local_state->SetBoolean(prefs::kMetricsReportingEnabled, true); 1705 local_state_->SetBoolean(prefs::kMetricsReportingEnabled, true);
1709 #endif // OS_POSIX 1706 #endif // OS_POSIX
1710 } // if (!first_run_ui_bypass) 1707 } // if (!first_run_ui_bypass_)
1711 1708
1712 Browser::SetNewHomePagePrefs(user_prefs); 1709 Browser::SetNewHomePagePrefs(user_prefs);
1713 g_browser_process->profile_manager()->OnImportFinished(profile_); 1710 g_browser_process->profile_manager()->OnImportFinished(profile_);
1714 } // if (is_first_run) 1711 } // if (is_first_run)
1715 1712
1716 #if defined(OS_WIN) 1713 #if defined(OS_WIN)
1717 // Sets things up so that if we crash from this point on, a dialog will 1714 // Sets things up so that if we crash from this point on, a dialog will
1718 // popup asking the user to restart chrome. It is done this late to avoid 1715 // popup asking the user to restart chrome. It is done this late to avoid
1719 // testing against a bunch of special cases that are taken care early on. 1716 // testing against a bunch of special cases that are taken care early on.
1720 ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment( 1717 ChromeBrowserMainPartsWin::PrepareRestartOnCrashEnviroment(
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1819 1816
1820 #if defined(OS_WIN) && !defined(GOOGLE_CHROME_BUILD) 1817 #if defined(OS_WIN) && !defined(GOOGLE_CHROME_BUILD)
1821 if (parsed_command_line().HasSwitch(switches::kDebugPrint)) { 1818 if (parsed_command_line().HasSwitch(switches::kDebugPrint)) {
1822 FilePath path = 1819 FilePath path =
1823 parsed_command_line().GetSwitchValuePath(switches::kDebugPrint); 1820 parsed_command_line().GetSwitchValuePath(switches::kDebugPrint);
1824 printing::PrintedDocument::set_debug_dump_path(path); 1821 printing::PrintedDocument::set_debug_dump_path(path);
1825 } 1822 }
1826 #endif 1823 #endif
1827 1824
1828 HandleTestParameters(parsed_command_line()); 1825 HandleTestParameters(parsed_command_line());
1829 RecordBreakpadStatusUMA(metrics); 1826 RecordBreakpadStatusUMA(metrics_);
1830 about_flags::RecordUMAStatistics(local_state); 1827 about_flags::RecordUMAStatistics(local_state_);
1831 LanguageUsageMetrics::RecordAcceptLanguages( 1828 LanguageUsageMetrics::RecordAcceptLanguages(
1832 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); 1829 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
1833 LanguageUsageMetrics::RecordApplicationLanguage( 1830 LanguageUsageMetrics::RecordApplicationLanguage(
1834 g_browser_process->GetApplicationLocale()); 1831 g_browser_process->GetApplicationLocale());
1835 1832
1836 #if defined(OS_WIN) 1833 #if defined(OS_WIN)
1837 fragmentation_checker::RecordFragmentationMetricForCurrentModule(); 1834 fragmentation_checker::RecordFragmentationMetricForCurrentModule();
1838 #endif 1835 #endif
1839 1836
1840 #if defined(OS_CHROMEOS) 1837 #if defined(OS_CHROMEOS)
1841 metrics->StartExternalMetrics(); 1838 metrics_->StartExternalMetrics();
1842 1839
1843 // Initialize the audio handler on ChromeOS. 1840 // Initialize the audio handler on ChromeOS.
1844 chromeos::AudioHandler::Initialize(); 1841 chromeos::AudioHandler::Initialize();
1845 1842
1846 // Listen for system key events so that the user will be able to adjust the 1843 // Listen for system key events so that the user will be able to adjust the
1847 // volume on the login screen, if Chrome is running on Chrome OS 1844 // volume on the login screen, if Chrome is running on Chrome OS
1848 // (i.e. not Linux desktop), and in non-test mode. 1845 // (i.e. not Linux desktop), and in non-test mode.
1849 if (chromeos::system::runtime_environment::IsRunningOnChromeOS() && 1846 if (chromeos::system::runtime_environment::IsRunningOnChromeOS() &&
1850 !parameters().ui_task) { // ui_task is non-NULL when running tests. 1847 !parameters().ui_task) { // ui_task is non-NULL when running tests.
1851 chromeos::SystemKeyEventListener::Initialize(); 1848 chromeos::SystemKeyEventListener::Initialize();
(...skipping 12 matching lines...) Expand all
1864 return content::RESULT_CODE_NORMAL_EXIT; 1861 return content::RESULT_CODE_NORMAL_EXIT;
1865 return chrome::RESULT_CODE_UNINSTALL_EXTENSION_ERROR; 1862 return chrome::RESULT_CODE_UNINSTALL_EXTENSION_ERROR;
1866 } 1863 }
1867 1864
1868 // Start watching for a hang. 1865 // Start watching for a hang.
1869 MetricsService::LogNeedForCleanShutdown(); 1866 MetricsService::LogNeedForCleanShutdown();
1870 1867
1871 #if defined(OS_WIN) 1868 #if defined(OS_WIN)
1872 // We check this here because if the profile is OTR (chromeos possibility) 1869 // We check this here because if the profile is OTR (chromeos possibility)
1873 // it won't still be accessible after browser is destroyed. 1870 // it won't still be accessible after browser is destroyed.
1874 record_search_engine_ = is_first_run && !profile_->IsOffTheRecord(); 1871 record_search_engine_ = is_first_run_ && !profile_->IsOffTheRecord();
1875 #endif 1872 #endif
1876 1873
1877 // ChildProcess:: is a misnomer unless you consider context. Use 1874 // ChildProcess:: is a misnomer unless you consider context. Use
1878 // of --wait-for-debugger only makes sense when Chrome itself is a 1875 // of --wait-for-debugger only makes sense when Chrome itself is a
1879 // child process (e.g. when launched by PyAuto). 1876 // child process (e.g. when launched by PyAuto).
1880 if (parsed_command_line().HasSwitch(switches::kWaitForDebugger)) { 1877 if (parsed_command_line().HasSwitch(switches::kWaitForDebugger)) {
1881 ChildProcess::WaitForDebugger("Browser"); 1878 ChildProcess::WaitForDebugger("Browser");
1882 } 1879 }
1883 1880
1884 #if defined(OS_CHROMEOS) 1881 #if defined(OS_CHROMEOS)
(...skipping 28 matching lines...) Expand all
1913 #endif 1910 #endif
1914 parameters().ui_task->Run(); 1911 parameters().ui_task->Run();
1915 delete parameters().ui_task; 1912 delete parameters().ui_task;
1916 } else { 1913 } else {
1917 // Most general initialization is behind us, but opening a 1914 // Most general initialization is behind us, but opening a
1918 // tab and/or session restore and such is still to be done. 1915 // tab and/or session restore and such is still to be done.
1919 base::TimeTicks browser_open_start = base::TimeTicks::Now(); 1916 base::TimeTicks browser_open_start = base::TimeTicks::Now();
1920 1917
1921 // We are in regular browser boot sequence. Open initial tabs and enter the 1918 // We are in regular browser boot sequence. Open initial tabs and enter the
1922 // main message loop. 1919 // main message loop.
1923 if (browser_init.Start(parsed_command_line(), FilePath(), profile_, 1920 if (browser_init_.Start(parsed_command_line(), FilePath(), profile_,
1924 &result_code)) { 1921 &result_code)) {
1925 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) 1922 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
1926 // Initialize autoupdate timer. Timer callback costs basically nothing 1923 // Initialize autoupdate timer. Timer callback costs basically nothing
1927 // when browser is not in persistent mode, so it's OK to let it ride on 1924 // when browser is not in persistent mode, so it's OK to let it ride on
1928 // the main thread. This needs to be done here because we don't want 1925 // the main thread. This needs to be done here because we don't want
1929 // to start the timer when Chrome is run inside a test harness. 1926 // to start the timer when Chrome is run inside a test harness.
1930 g_browser_process->StartAutoupdateTimer(); 1927 g_browser_process->StartAutoupdateTimer();
1931 #endif 1928 #endif
1932 1929
1933 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 1930 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
1934 // On Linux, the running exe will be updated if an upgrade becomes 1931 // On Linux, the running exe will be updated if an upgrade becomes
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
2078 // The XInput2 event listener needs to be shut down earlier than when 2075 // The XInput2 event listener needs to be shut down earlier than when
2079 // Singletons are finally destroyed in AtExitManager. 2076 // Singletons are finally destroyed in AtExitManager.
2080 chromeos::XInputHierarchyChangedEventListener::GetInstance()->Stop(); 2077 chromeos::XInputHierarchyChangedEventListener::GetInstance()->Stop();
2081 2078
2082 // chromeos::SystemKeyEventListener::Shutdown() is always safe to call, 2079 // chromeos::SystemKeyEventListener::Shutdown() is always safe to call,
2083 // even if Initialize() wasn't called. 2080 // even if Initialize() wasn't called.
2084 chromeos::SystemKeyEventListener::Shutdown(); 2081 chromeos::SystemKeyEventListener::Shutdown();
2085 chromeos::AudioHandler::Shutdown(); 2082 chromeos::AudioHandler::Shutdown();
2086 #endif 2083 #endif
2087 2084
2085 browser_process_->StartTearDown();
2086 }
2087
2088 void ChromeBrowserMainParts::PreStopThread(BrowserThread::ID identifier) {
2089 browser_process_->PreStopThread(identifier);
2090 }
2091
2092 void ChromeBrowserMainParts::PostStopThread(BrowserThread::ID identifier) {
2093 browser_process_->PostStopThread(identifier);
2094 }
2095
2096 void ChromeBrowserMainParts::FinalCleanup() {
2088 // browser_shutdown takes care of deleting browser_process, so we need to 2097 // browser_shutdown takes care of deleting browser_process, so we need to
2089 // release it. 2098 // release it.
2090 ignore_result(browser_process_.release()); 2099 ignore_result(browser_process_.release());
2091 browser_shutdown::Shutdown(); 2100 browser_shutdown::Shutdown();
2092 master_prefs_.reset(); 2101 master_prefs_.reset();
2093 process_singleton_.reset(); 2102 process_singleton_.reset();
2094 2103
2095 // We need to do this check as late as possible, but due to modularity, this 2104 // We need to do this check as late as possible, but due to modularity, this
2096 // may be the last point in Chrome. This would be more effective if done at 2105 // may be the last point in Chrome. This would be more effective if done at
2097 // a higher level on the stack, so that it is impossible for an early return 2106 // a higher level on the stack, so that it is impossible for an early return
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2138 if (env->GetVar(chrome::kPreReadEnvironmentVariable, &pre_read) && 2147 if (env->GetVar(chrome::kPreReadEnvironmentVariable, &pre_read) &&
2139 (pre_read == "0" || pre_read == "1")) { 2148 (pre_read == "0" || pre_read == "1")) {
2140 std::string uma_name(name); 2149 std::string uma_name(name);
2141 uma_name += "_PreRead"; 2150 uma_name += "_PreRead";
2142 uma_name += pre_read == "1" ? "Enabled" : "Disabled"; 2151 uma_name += pre_read == "1" ? "Enabled" : "Disabled";
2143 AddPreReadHistogramTime(uma_name.c_str(), time); 2152 AddPreReadHistogramTime(uma_name.c_str(), time);
2144 } 2153 }
2145 #endif 2154 #endif
2146 #endif 2155 #endif
2147 } 2156 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698