Chromium Code Reviews| Index: chrome/browser/ui/startup/startup_browser_creator.cc |
| diff --git a/chrome/browser/ui/startup/startup_browser_creator.cc b/chrome/browser/ui/startup/startup_browser_creator.cc |
| index 202f9f8f2c473aeddd0aa22a1a0214921d1e298b..727ae6305f3ef88ddd76b05de46a85fbfe53abc1 100644 |
| --- a/chrome/browser/ui/startup/startup_browser_creator.cc |
| +++ b/chrome/browser/ui/startup/startup_browser_creator.cc |
| @@ -14,11 +14,13 @@ |
| #include "base/command_line.h" |
| #include "base/compiler_specific.h" |
| #include "base/environment.h" |
| +#include "base/file_util.h" |
| #include "base/files/file_path.h" |
| #include "base/lazy_instance.h" |
| #include "base/logging.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/metrics/histogram.h" |
| +#include "base/metrics/statistics_recorder.h" |
| #include "base/path_service.h" |
| #include "base/prefs/pref_service.h" |
| #include "base/strings/string_number_conversions.h" |
| @@ -227,6 +229,20 @@ class ProfileLaunchObserver : public content::NotificationObserver { |
| base::LazyInstance<ProfileLaunchObserver> profile_launch_observer = |
| LAZY_INSTANCE_INITIALIZER; |
| +// Dumps the current set of the browser process's histograms to |output_file|. |
| +// The file is not overwritten or modified if it exists. This function should |
| +// only be called in the blocking pool. |
| +void DumpBrowserHistograms(const base::FilePath& output_file) { |
| + base::ThreadRestrictions::AssertIOAllowed(); |
| + |
| + if (base::PathExists(output_file)) |
|
marja
2013/11/14 08:33:10
I think this is confusing and error prone for the
grt (UTC plus 2)
2013/11/14 14:44:12
After more consideration, I think you're right. My
|
| + return; |
| + |
| + std::string output_string(base::StatisticsRecorder::ToJSON(std::string())); |
| + file_util::WriteFile(output_file, output_string.data(), |
| + static_cast<int>(output_string.size())); |
| +} |
| + |
| } // namespace |
| StartupBrowserCreator::StartupBrowserCreator() |
| @@ -602,6 +618,20 @@ bool StartupBrowserCreator::ProcessCmdLineImpl( |
| ui::TouchFactory::SetTouchDeviceListFromCommandLine(); |
| #endif |
| + if (!process_startup && |
| + command_line.HasSwitch(switches::kDumpBrowserHistograms)) { |
| + // Only handle --dump-browser-histograms from a rendezvous. In this case, do |
| + // not open a new browser window even if no output file was given. |
| + base::FilePath output_file( |
| + command_line.GetSwitchValuePath(switches::kDumpBrowserHistograms)); |
| + if (!output_file.empty()) { |
| + BrowserThread::PostBlockingPoolTask( |
| + FROM_HERE, |
| + base::Bind(&DumpBrowserHistograms, output_file)); |
| + } |
| + silent_launch = true; |
| + } |
| + |
| // If we don't want to launch a new browser window or tab (in the case |
| // of an automation request), we are done here. |
| if (silent_launch) |