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

Side by Side Diff: chrome/browser/ui/startup/startup_browser_creator.cc

Issue 61983003: Add a switch to emit browser histograms. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more review comments Created 7 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) 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/ui/startup/startup_browser_creator.h" 5 #include "chrome/browser/ui/startup/startup_browser_creator.h"
6 6
7 #include <algorithm> // For max(). 7 #include <algorithm> // For max().
8 #include <set> 8 #include <set>
9 9
10 #include "apps/app_load_service.h" 10 #include "apps/app_load_service.h"
11 #include "apps/switches.h" 11 #include "apps/switches.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
16 #include "base/environment.h" 16 #include "base/environment.h"
17 #include "base/file_util.h"
17 #include "base/files/file_path.h" 18 #include "base/files/file_path.h"
18 #include "base/lazy_instance.h" 19 #include "base/lazy_instance.h"
19 #include "base/logging.h" 20 #include "base/logging.h"
20 #include "base/memory/scoped_ptr.h" 21 #include "base/memory/scoped_ptr.h"
21 #include "base/metrics/histogram.h" 22 #include "base/metrics/histogram.h"
23 #include "base/metrics/statistics_recorder.h"
22 #include "base/path_service.h" 24 #include "base/path_service.h"
23 #include "base/prefs/pref_service.h" 25 #include "base/prefs/pref_service.h"
24 #include "base/strings/string_number_conversions.h" 26 #include "base/strings/string_number_conversions.h"
25 #include "base/strings/string_split.h" 27 #include "base/strings/string_split.h"
26 #include "base/strings/utf_string_conversions.h" 28 #include "base/strings/utf_string_conversions.h"
27 #include "base/threading/thread_restrictions.h" 29 #include "base/threading/thread_restrictions.h"
28 #include "chrome/browser/app_mode/app_mode_utils.h" 30 #include "chrome/browser/app_mode/app_mode_utils.h"
29 #include "chrome/browser/auto_launch_trial.h" 31 #include "chrome/browser/auto_launch_trial.h"
30 #include "chrome/browser/automation/automation_provider.h" 32 #include "chrome/browser/automation/automation_provider.h"
31 #include "chrome/browser/automation/automation_provider_list.h" 33 #include "chrome/browser/automation/automation_provider_list.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 Profile* profile_to_activate_; 222 Profile* profile_to_activate_;
221 // Set once we attempted to activate a profile. We only get one shot at this. 223 // Set once we attempted to activate a profile. We only get one shot at this.
222 bool activated_profile_; 224 bool activated_profile_;
223 225
224 DISALLOW_COPY_AND_ASSIGN(ProfileLaunchObserver); 226 DISALLOW_COPY_AND_ASSIGN(ProfileLaunchObserver);
225 }; 227 };
226 228
227 base::LazyInstance<ProfileLaunchObserver> profile_launch_observer = 229 base::LazyInstance<ProfileLaunchObserver> profile_launch_observer =
228 LAZY_INSTANCE_INITIALIZER; 230 LAZY_INSTANCE_INITIALIZER;
229 231
232 // Dumps the current set of the browser process's histograms to |output_file|.
233 // The file is not overwritten or modified if it exists. This function should
234 // only be called in the blocking pool.
235 void DumpBrowserHistograms(const base::FilePath& output_file) {
236 base::ThreadRestrictions::AssertIOAllowed();
237
238 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
239 return;
240
241 std::string output_string(base::StatisticsRecorder::ToJSON(std::string()));
242 file_util::WriteFile(output_file, output_string.data(),
243 static_cast<int>(output_string.size()));
244 }
245
230 } // namespace 246 } // namespace
231 247
232 StartupBrowserCreator::StartupBrowserCreator() 248 StartupBrowserCreator::StartupBrowserCreator()
233 : is_default_browser_dialog_suppressed_(false), 249 : is_default_browser_dialog_suppressed_(false),
234 show_main_browser_window_(true) { 250 show_main_browser_window_(true) {
235 } 251 }
236 252
237 StartupBrowserCreator::~StartupBrowserCreator() {} 253 StartupBrowserCreator::~StartupBrowserCreator() {}
238 254
239 // static 255 // static
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 611
596 // Skip browser launch since app mode launches its app window. 612 // Skip browser launch since app mode launches its app window.
597 silent_launch = true; 613 silent_launch = true;
598 } 614 }
599 #endif 615 #endif
600 616
601 #if defined(TOOLKIT_VIEWS) && defined(USE_X11) 617 #if defined(TOOLKIT_VIEWS) && defined(USE_X11)
602 ui::TouchFactory::SetTouchDeviceListFromCommandLine(); 618 ui::TouchFactory::SetTouchDeviceListFromCommandLine();
603 #endif 619 #endif
604 620
621 if (!process_startup &&
622 command_line.HasSwitch(switches::kDumpBrowserHistograms)) {
623 // Only handle --dump-browser-histograms from a rendezvous. In this case, do
624 // not open a new browser window even if no output file was given.
625 base::FilePath output_file(
626 command_line.GetSwitchValuePath(switches::kDumpBrowserHistograms));
627 if (!output_file.empty()) {
628 BrowserThread::PostBlockingPoolTask(
629 FROM_HERE,
630 base::Bind(&DumpBrowserHistograms, output_file));
631 }
632 silent_launch = true;
633 }
634
605 // If we don't want to launch a new browser window or tab (in the case 635 // If we don't want to launch a new browser window or tab (in the case
606 // of an automation request), we are done here. 636 // of an automation request), we are done here.
607 if (silent_launch) 637 if (silent_launch)
608 return true; 638 return true;
609 639
610 // Check for --load-and-launch-app. 640 // Check for --load-and-launch-app.
611 if (command_line.HasSwitch(apps::kLoadAndLaunchApp) && 641 if (command_line.HasSwitch(apps::kLoadAndLaunchApp) &&
612 !IncognitoModePrefs::ShouldLaunchIncognito( 642 !IncognitoModePrefs::ShouldLaunchIncognito(
613 command_line, last_used_profile->GetPrefs())) { 643 command_line, last_used_profile->GetPrefs())) {
614 CommandLine::StringType path = command_line.GetSwitchValueNative( 644 CommandLine::StringType path = command_line.GetSwitchValueNative(
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 784
755 // static 785 // static
756 bool StartupBrowserCreator::ActivatedProfile() { 786 bool StartupBrowserCreator::ActivatedProfile() {
757 return profile_launch_observer.Get().activated_profile(); 787 return profile_launch_observer.Get().activated_profile();
758 } 788 }
759 789
760 bool HasPendingUncleanExit(Profile* profile) { 790 bool HasPendingUncleanExit(Profile* profile) {
761 return profile->GetLastSessionExitType() == Profile::EXIT_CRASHED && 791 return profile->GetLastSessionExitType() == Profile::EXIT_CRASHED &&
762 !profile_launch_observer.Get().HasBeenLaunched(profile); 792 !profile_launch_observer.Get().HasBeenLaunched(profile);
763 } 793 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698