OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chrome_browser_main.h" | 5 #include "chrome/browser/chrome_browser_main.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/debug/trace_event.h" | 14 #include "base/debug/trace_event.h" |
15 #include "base/file_path.h" | 15 #include "base/file_path.h" |
16 #include "base/file_util.h" | 16 #include "base/file_util.h" |
17 #include "base/metrics/field_trial.h" | 17 #include "base/metrics/field_trial.h" |
18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
19 #include "base/path_service.h" | 19 #include "base/path_service.h" |
20 #include "base/process_info.h" | 20 #include "base/process_info.h" |
21 #include "base/process_util.h" | 21 #include "base/process_util.h" |
22 #include "base/run_loop.h" | 22 #include "base/run_loop.h" |
23 #include "base/string_number_conversions.h" | 23 #include "base/string_number_conversions.h" |
24 #include "base/string_piece.h" | 24 #include "base/string_piece.h" |
25 #include "base/string_split.h" | 25 #include "base/string_split.h" |
26 #include "base/sys_string_conversions.h" | 26 #include "base/sys_string_conversions.h" |
27 #include "base/threading/platform_thread.h" | 27 #include "base/threading/platform_thread.h" |
28 #include "base/threading/sequenced_worker_pool.h" | |
akalin
2012/10/19 02:00:51
not needed anymore (if you use GetTaskRunnerForFil
zel
2012/10/19 18:45:07
Done.
| |
28 #include "base/time.h" | 29 #include "base/time.h" |
29 #include "base/utf_string_conversions.h" | 30 #include "base/utf_string_conversions.h" |
30 #include "base/values.h" | 31 #include "base/values.h" |
31 #include "build/build_config.h" | 32 #include "build/build_config.h" |
32 #include "chrome/browser/about_flags.h" | 33 #include "chrome/browser/about_flags.h" |
33 #include "chrome/browser/browser_process.h" | 34 #include "chrome/browser/browser_process.h" |
34 #include "chrome/browser/browser_process_impl.h" | 35 #include "chrome/browser/browser_process_impl.h" |
35 #include "chrome/browser/browser_shutdown.h" | 36 #include "chrome/browser/browser_shutdown.h" |
36 #include "chrome/browser/chrome_browser_main_extra_parts.h" | 37 #include "chrome/browser/chrome_browser_main_extra_parts.h" |
37 #include "chrome/browser/chrome_gpu_util.h" | 38 #include "chrome/browser/chrome_gpu_util.h" |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 } else if (parsed_command_line.HasSwitch(switches::kEnableNpnHttpOnly)) { | 262 } else if (parsed_command_line.HasSwitch(switches::kEnableNpnHttpOnly)) { |
262 net::HttpStreamFactory::EnableNpnHttpOnly(); | 263 net::HttpStreamFactory::EnableNpnHttpOnly(); |
263 used_spdy_switch = true; | 264 used_spdy_switch = true; |
264 } | 265 } |
265 if (!used_spdy_switch) { | 266 if (!used_spdy_switch) { |
266 net::HttpStreamFactory::EnableNpnSpdy3(); | 267 net::HttpStreamFactory::EnableNpnSpdy3(); |
267 } | 268 } |
268 } | 269 } |
269 | 270 |
270 // Returns the new local state object, guaranteed non-NULL. | 271 // Returns the new local state object, guaranteed non-NULL. |
271 PrefService* InitializeLocalState(const CommandLine& parsed_command_line, | 272 // |local_state_task_runner| must be a shutdown-blocking task runner. |
272 bool is_first_run) { | 273 PrefService* InitializeLocalState( |
274 base::SequencedTaskRunner* local_state_task_runner, | |
275 const CommandLine& parsed_command_line, | |
276 bool is_first_run) { | |
273 FilePath local_state_path; | 277 FilePath local_state_path; |
274 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path); | 278 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path); |
275 bool local_state_file_exists = file_util::PathExists(local_state_path); | 279 bool local_state_file_exists = file_util::PathExists(local_state_path); |
276 | 280 |
277 // Load local state. This includes the application locale so we know which | 281 // Load local state. This includes the application locale so we know which |
278 // locale dll to load. | 282 // locale dll to load. |
279 PrefService* local_state = g_browser_process->local_state(); | 283 PrefService* local_state = g_browser_process->local_state(); |
280 DCHECK(local_state); | 284 DCHECK(local_state); |
281 | 285 |
282 // TODO(brettw,*): this comment about ResourceBundle was here since | 286 // TODO(brettw,*): this comment about ResourceBundle was here since |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
318 // since the parent profile command line flag can be present even when the | 322 // since the parent profile command line flag can be present even when the |
319 // current profile is not a new one, and in that case we do not want to | 323 // current profile is not a new one, and in that case we do not want to |
320 // inherit and reset the user's setting. | 324 // inherit and reset the user's setting. |
321 if (!local_state_file_exists && | 325 if (!local_state_file_exists && |
322 parsed_command_line.HasSwitch(switches::kParentProfile)) { | 326 parsed_command_line.HasSwitch(switches::kParentProfile)) { |
323 FilePath parent_profile = | 327 FilePath parent_profile = |
324 parsed_command_line.GetSwitchValuePath(switches::kParentProfile); | 328 parsed_command_line.GetSwitchValuePath(switches::kParentProfile); |
325 scoped_ptr<PrefService> parent_local_state( | 329 scoped_ptr<PrefService> parent_local_state( |
326 PrefService::CreatePrefService(parent_profile, | 330 PrefService::CreatePrefService(parent_profile, |
327 g_browser_process->policy_service(), | 331 g_browser_process->policy_service(), |
328 NULL, false)); | 332 NULL, false, local_state_task_runner)); |
329 parent_local_state->RegisterStringPref(prefs::kApplicationLocale, | 333 parent_local_state->RegisterStringPref(prefs::kApplicationLocale, |
330 std::string()); | 334 std::string()); |
331 // Right now, we only inherit the locale setting from the parent profile. | 335 // Right now, we only inherit the locale setting from the parent profile. |
332 local_state->SetString( | 336 local_state->SetString( |
333 prefs::kApplicationLocale, | 337 prefs::kApplicationLocale, |
334 parent_local_state->GetString(prefs::kApplicationLocale)); | 338 parent_local_state->GetString(prefs::kApplicationLocale)); |
335 } | 339 } |
336 | 340 |
337 #if defined(OS_CHROMEOS) | 341 #if defined(OS_CHROMEOS) |
338 if (parsed_command_line.HasSwitch(switches::kLoginManager)) { | 342 if (parsed_command_line.HasSwitch(switches::kLoginManager)) { |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
697 process_singleton_.reset(new ProcessSingleton(user_data_dir_)); | 701 process_singleton_.reset(new ProcessSingleton(user_data_dir_)); |
698 // Ensure ProcessSingleton won't process messages too early. It will be | 702 // Ensure ProcessSingleton won't process messages too early. It will be |
699 // unlocked in PostBrowserStart(). | 703 // unlocked in PostBrowserStart(). |
700 process_singleton_->Lock(NULL); | 704 process_singleton_->Lock(NULL); |
701 | 705 |
702 is_first_run_ = | 706 is_first_run_ = |
703 (first_run::IsChromeFirstRun() || | 707 (first_run::IsChromeFirstRun() || |
704 parsed_command_line().HasSwitch(switches::kFirstRun)) && | 708 parsed_command_line().HasSwitch(switches::kFirstRun)) && |
705 !HasImportSwitch(parsed_command_line()); | 709 !HasImportSwitch(parsed_command_line()); |
706 #endif | 710 #endif |
707 browser_process_.reset(new BrowserProcessImpl(parsed_command_line())); | 711 |
712 | |
713 FilePath local_state_path; | |
714 PathService::Get(chrome::FILE_LOCAL_STATE, &local_state_path); | |
715 scoped_refptr<base::SequencedTaskRunner> local_state_task_runner = | |
akalin
2012/10/19 02:00:51
did you forget to use JsonPrefStore::GetTaskRunner
zel
2012/10/19 18:45:07
Done.
| |
716 BrowserThread::GetBlockingPool()-> | |
717 GetSequencedTaskRunnerWithShutdownBehavior( | |
718 BrowserThread::GetBlockingPool()->GetNamedSequenceToken( | |
719 local_state_path.AsUTF8Unsafe()), | |
720 base::SequencedWorkerPool::BLOCK_SHUTDOWN); | |
721 | |
722 browser_process_.reset(new BrowserProcessImpl(local_state_task_runner, | |
723 parsed_command_line())); | |
708 | 724 |
709 if (parsed_command_line().HasSwitch(switches::kEnableProfiling)) { | 725 if (parsed_command_line().HasSwitch(switches::kEnableProfiling)) { |
710 // User wants to override default tracking status. | 726 // User wants to override default tracking status. |
711 std::string flag = | 727 std::string flag = |
712 parsed_command_line().GetSwitchValueASCII(switches::kEnableProfiling); | 728 parsed_command_line().GetSwitchValueASCII(switches::kEnableProfiling); |
713 // Default to basic profiling (no parent child support). | 729 // Default to basic profiling (no parent child support). |
714 tracked_objects::ThreadData::Status status = | 730 tracked_objects::ThreadData::Status status = |
715 tracked_objects::ThreadData::PROFILING_ACTIVE; | 731 tracked_objects::ThreadData::PROFILING_ACTIVE; |
716 if (flag.compare("0") != 0) | 732 if (flag.compare("0") != 0) |
717 status = tracked_objects::ThreadData::DEACTIVATED; | 733 status = tracked_objects::ThreadData::DEACTIVATED; |
718 else if (flag.compare("child") != 0) | 734 else if (flag.compare("child") != 0) |
719 status = tracked_objects::ThreadData::PROFILING_CHILDREN_ACTIVE; | 735 status = tracked_objects::ThreadData::PROFILING_CHILDREN_ACTIVE; |
720 tracked_objects::ThreadData::InitializeAndSetTrackingStatus(status); | 736 tracked_objects::ThreadData::InitializeAndSetTrackingStatus(status); |
721 } | 737 } |
722 | 738 |
723 if (parsed_command_line().HasSwitch(switches::kProfilingOutputFile)) { | 739 if (parsed_command_line().HasSwitch(switches::kProfilingOutputFile)) { |
724 tracking_objects_.set_output_file_path( | 740 tracking_objects_.set_output_file_path( |
725 parsed_command_line().GetSwitchValuePath( | 741 parsed_command_line().GetSwitchValuePath( |
726 switches::kProfilingOutputFile)); | 742 switches::kProfilingOutputFile)); |
727 } | 743 } |
728 | 744 |
729 local_state_ = InitializeLocalState(parsed_command_line(), is_first_run_); | 745 local_state_ = InitializeLocalState(local_state_task_runner, |
746 parsed_command_line(), | |
747 is_first_run_); | |
730 | 748 |
731 // These members must be initialized before returning from this function. | 749 // These members must be initialized before returning from this function. |
732 master_prefs_.reset(new first_run::MasterPrefs); | 750 master_prefs_.reset(new first_run::MasterPrefs); |
733 | 751 |
734 #if !defined(OS_ANDROID) | 752 #if !defined(OS_ANDROID) |
735 // Android doesn't use StartupBrowserCreator. | 753 // Android doesn't use StartupBrowserCreator. |
736 browser_creator_.reset(new StartupBrowserCreator); | 754 browser_creator_.reset(new StartupBrowserCreator); |
737 // TODO(yfriedman): Refactor Android to re-use UMABrowsingActivityObserver | 755 // TODO(yfriedman): Refactor Android to re-use UMABrowsingActivityObserver |
738 chrome::UMABrowsingActivityObserver::Init(); | 756 chrome::UMABrowsingActivityObserver::Init(); |
739 #endif | 757 #endif |
(...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1641 if (base::win::GetVersion() <= base::win::VERSION_XP) | 1659 if (base::win::GetVersion() <= base::win::VERSION_XP) |
1642 uma_name += "_XP"; | 1660 uma_name += "_XP"; |
1643 | 1661 |
1644 uma_name += "_PreRead_"; | 1662 uma_name += "_PreRead_"; |
1645 uma_name += pre_read_percentage; | 1663 uma_name += pre_read_percentage; |
1646 AddPreReadHistogramTime(uma_name.c_str(), time); | 1664 AddPreReadHistogramTime(uma_name.c_str(), time); |
1647 } | 1665 } |
1648 #endif | 1666 #endif |
1649 #endif | 1667 #endif |
1650 } | 1668 } |
OLD | NEW |