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/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 Loading... |
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 overwritten if it exists. This function should only be called in |
| 234 // the blocking pool. |
| 235 void DumpBrowserHistograms(const base::FilePath& output_file) { |
| 236 base::ThreadRestrictions::AssertIOAllowed(); |
| 237 |
| 238 std::string output_string(base::StatisticsRecorder::ToJSON(std::string())); |
| 239 file_util::WriteFile(output_file, output_string.data(), |
| 240 static_cast<int>(output_string.size())); |
| 241 } |
| 242 |
230 } // namespace | 243 } // namespace |
231 | 244 |
232 StartupBrowserCreator::StartupBrowserCreator() | 245 StartupBrowserCreator::StartupBrowserCreator() |
233 : is_default_browser_dialog_suppressed_(false), | 246 : is_default_browser_dialog_suppressed_(false), |
234 show_main_browser_window_(true) { | 247 show_main_browser_window_(true) { |
235 } | 248 } |
236 | 249 |
237 StartupBrowserCreator::~StartupBrowserCreator() {} | 250 StartupBrowserCreator::~StartupBrowserCreator() {} |
238 | 251 |
239 // static | 252 // static |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 | 608 |
596 // Skip browser launch since app mode launches its app window. | 609 // Skip browser launch since app mode launches its app window. |
597 silent_launch = true; | 610 silent_launch = true; |
598 } | 611 } |
599 #endif | 612 #endif |
600 | 613 |
601 #if defined(TOOLKIT_VIEWS) && defined(USE_X11) | 614 #if defined(TOOLKIT_VIEWS) && defined(USE_X11) |
602 ui::TouchFactory::SetTouchDeviceListFromCommandLine(); | 615 ui::TouchFactory::SetTouchDeviceListFromCommandLine(); |
603 #endif | 616 #endif |
604 | 617 |
| 618 if (!process_startup && |
| 619 command_line.HasSwitch(switches::kDumpBrowserHistograms)) { |
| 620 // Only handle --dump-browser-histograms from a rendezvous. In this case, do |
| 621 // not open a new browser window even if no output file was given. |
| 622 base::FilePath output_file( |
| 623 command_line.GetSwitchValuePath(switches::kDumpBrowserHistograms)); |
| 624 if (!output_file.empty()) { |
| 625 BrowserThread::PostBlockingPoolTask( |
| 626 FROM_HERE, |
| 627 base::Bind(&DumpBrowserHistograms, output_file)); |
| 628 } |
| 629 silent_launch = true; |
| 630 } |
| 631 |
605 // If we don't want to launch a new browser window or tab (in the case | 632 // 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. | 633 // of an automation request), we are done here. |
607 if (silent_launch) | 634 if (silent_launch) |
608 return true; | 635 return true; |
609 | 636 |
610 // Check for --load-and-launch-app. | 637 // Check for --load-and-launch-app. |
611 if (command_line.HasSwitch(apps::kLoadAndLaunchApp) && | 638 if (command_line.HasSwitch(apps::kLoadAndLaunchApp) && |
612 !IncognitoModePrefs::ShouldLaunchIncognito( | 639 !IncognitoModePrefs::ShouldLaunchIncognito( |
613 command_line, last_used_profile->GetPrefs())) { | 640 command_line, last_used_profile->GetPrefs())) { |
614 CommandLine::StringType path = command_line.GetSwitchValueNative( | 641 CommandLine::StringType path = command_line.GetSwitchValueNative( |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 | 781 |
755 // static | 782 // static |
756 bool StartupBrowserCreator::ActivatedProfile() { | 783 bool StartupBrowserCreator::ActivatedProfile() { |
757 return profile_launch_observer.Get().activated_profile(); | 784 return profile_launch_observer.Get().activated_profile(); |
758 } | 785 } |
759 | 786 |
760 bool HasPendingUncleanExit(Profile* profile) { | 787 bool HasPendingUncleanExit(Profile* profile) { |
761 return profile->GetLastSessionExitType() == Profile::EXIT_CRASHED && | 788 return profile->GetLastSessionExitType() == Profile::EXIT_CRASHED && |
762 !profile_launch_observer.Get().HasBeenLaunched(profile); | 789 !profile_launch_observer.Get().HasBeenLaunched(profile); |
763 } | 790 } |
OLD | NEW |