Chromium Code Reviews| 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" |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 // The file is overwritten if it exists. This function should only be called in | 243 // The file is overwritten if it exists. This function should only be called in |
| 244 // the blocking pool. | 244 // the blocking pool. |
| 245 void DumpBrowserHistograms(const base::FilePath& output_file) { | 245 void DumpBrowserHistograms(const base::FilePath& output_file) { |
| 246 base::ThreadRestrictions::AssertIOAllowed(); | 246 base::ThreadRestrictions::AssertIOAllowed(); |
| 247 | 247 |
| 248 std::string output_string(base::StatisticsRecorder::ToJSON(std::string())); | 248 std::string output_string(base::StatisticsRecorder::ToJSON(std::string())); |
| 249 base::WriteFile(output_file, output_string.data(), | 249 base::WriteFile(output_file, output_string.data(), |
| 250 static_cast<int>(output_string.size())); | 250 static_cast<int>(output_string.size())); |
| 251 } | 251 } |
| 252 | 252 |
| 253 // Shows the User Manager on startup if the last used profile must sign in or | |
| 254 // if the last used profile was the guest or system profile. | |
| 255 // Returns true if the User Manager was shown, false otherwise. | |
| 256 bool ShowUserManagerOnStartupIfNeeded( | |
| 257 Profile* last_used_profile, const base::CommandLine& command_line) { | |
| 258 #if defined(OS_CHROMEOS) | |
| 259 // ChromeOS never shows the User Manager on startup. | |
| 260 return false; | |
| 261 #endif | |
|
Peter Kasting
2015/09/25 23:42:52
This can trigger an unreachable code warning. Ins
anthonyvd
2015/09/29 20:23:15
Done.
| |
| 262 | |
| 263 ProfileInfoCache& profile_info = | |
| 264 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
| 265 size_t profile_index = profile_info.GetIndexOfProfileWithPath( | |
| 266 last_used_profile->GetPath()); | |
| 267 bool signin_required = profile_index != std::string::npos && | |
| 268 profile_info.ProfileIsSigninRequiredAtIndex(profile_index); | |
| 269 | |
| 270 // Guest, system or locked profiles cannot be re-opened on startup. The | |
| 271 // only exception is if there's already a Guest window open in a separate | |
| 272 // process (for example, launching a new browser after clicking on a | |
| 273 // downloaded file in Guest mode). | |
| 274 bool guest_or_system = last_used_profile->IsGuestSession() || | |
| 275 last_used_profile->IsSystemProfile(); | |
| 276 bool has_guest_browsers = guest_or_system && | |
| 277 chrome::GetTotalBrowserCountForProfile( | |
| 278 last_used_profile->GetOffTheRecordProfile()) > 0; | |
| 279 if (signin_required || (guest_or_system && !has_guest_browsers)) { | |
| 280 profiles::UserManagerProfileSelected action = | |
| 281 command_line.HasSwitch(switches::kShowAppList) ? | |
| 282 profiles::USER_MANAGER_SELECT_PROFILE_APP_LAUNCHER : | |
| 283 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION; | |
| 284 UserManager::Show( | |
| 285 base::FilePath(), profiles::USER_MANAGER_NO_TUTORIAL, action); | |
| 286 return true; | |
| 287 } | |
| 288 | |
| 289 return false; | |
| 290 } | |
|
Peter Kasting
2015/09/25 23:42:52
Nit: Compared to the implementation above, this is
anthonyvd
2015/09/29 20:23:15
I feel like your version is a little easier to fol
| |
| 291 | |
| 253 } // namespace | 292 } // namespace |
| 254 | 293 |
| 255 StartupBrowserCreator::StartupBrowserCreator() | 294 StartupBrowserCreator::StartupBrowserCreator() |
| 256 : is_default_browser_dialog_suppressed_(false), | 295 : is_default_browser_dialog_suppressed_(false), |
| 257 show_main_browser_window_(true) { | 296 show_main_browser_window_(true) { |
| 258 } | 297 } |
| 259 | 298 |
| 260 StartupBrowserCreator::~StartupBrowserCreator() {} | 299 StartupBrowserCreator::~StartupBrowserCreator() {} |
| 261 | 300 |
| 262 // static | 301 // static |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 664 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; | 703 chrome::startup::IS_FIRST_RUN : chrome::startup::IS_NOT_FIRST_RUN; |
| 665 // |last_opened_profiles| will be empty in the following circumstances: | 704 // |last_opened_profiles| will be empty in the following circumstances: |
| 666 // - This is the first launch. |last_used_profile| is the initial profile. | 705 // - This is the first launch. |last_used_profile| is the initial profile. |
| 667 // - The user exited the browser by closing all windows for all | 706 // - The user exited the browser by closing all windows for all |
| 668 // profiles. |last_used_profile| is the profile which owned the last open | 707 // profiles. |last_used_profile| is the profile which owned the last open |
| 669 // window. | 708 // window. |
| 670 // - Only incognito windows were open when the browser exited. | 709 // - Only incognito windows were open when the browser exited. |
| 671 // |last_used_profile| is the last used incognito profile. Restoring it will | 710 // |last_used_profile| is the last used incognito profile. Restoring it will |
| 672 // create a browser window for the corresponding original profile. | 711 // create a browser window for the corresponding original profile. |
| 673 if (last_opened_profiles.empty()) { | 712 if (last_opened_profiles.empty()) { |
| 674 // If the last used profile is locked or was a guest, show the user manager. | 713 if (ShowUserManagerOnStartupIfNeeded(last_used_profile, command_line)) { |
|
Peter Kasting
2015/09/25 23:42:52
Nit: Or just:
if (last_opened_profiles.empty()
anthonyvd
2015/09/29 20:23:15
I'm not sure that's equivalent, the rest of the bl
Peter Kasting
2015/09/29 20:34:16
You're right, my suggestion is wrong. Sorry!
I s
anthonyvd
2015/09/30 18:34:03
Done.
| |
| 675 if (switches::IsNewAvatarMenu()) { | 714 return true; |
| 676 ProfileInfoCache& profile_info = | |
| 677 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
| 678 size_t profile_index = profile_info.GetIndexOfProfileWithPath( | |
| 679 last_used_profile->GetPath()); | |
| 680 bool signin_required = profile_index != std::string::npos && | |
| 681 profile_info.ProfileIsSigninRequiredAtIndex(profile_index); | |
| 682 | |
| 683 // Guest, system or locked profiles cannot be re-opened on startup. The | |
| 684 // only exception is if there's already a Guest window open in a separate | |
| 685 // process (for example, launching a new browser after clicking on a | |
| 686 // downloaded file in Guest mode). | |
| 687 bool guest_or_system = last_used_profile->IsGuestSession() || | |
| 688 last_used_profile->IsSystemProfile(); | |
| 689 bool has_guest_browsers = guest_or_system && | |
| 690 chrome::GetTotalBrowserCountForProfile( | |
| 691 last_used_profile->GetOffTheRecordProfile()) > 0; | |
| 692 if (signin_required || (guest_or_system && !has_guest_browsers)) { | |
| 693 profiles::UserManagerProfileSelected action = | |
| 694 command_line.HasSwitch(switches::kShowAppList) ? | |
| 695 profiles::USER_MANAGER_SELECT_PROFILE_APP_LAUNCHER : | |
| 696 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION; | |
| 697 UserManager::Show( | |
| 698 base::FilePath(), profiles::USER_MANAGER_NO_TUTORIAL, action); | |
| 699 return true; | |
| 700 } | |
| 701 } | 715 } |
| 702 | 716 |
| 703 Profile* profile_to_open = last_used_profile->IsGuestSession() ? | 717 Profile* profile_to_open = last_used_profile->IsGuestSession() ? |
| 704 last_used_profile->GetOffTheRecordProfile() : last_used_profile; | 718 last_used_profile->GetOffTheRecordProfile() : last_used_profile; |
| 705 | 719 |
| 706 if (!browser_creator->LaunchBrowser(command_line, profile_to_open, | 720 if (!browser_creator->LaunchBrowser(command_line, profile_to_open, |
| 707 cur_dir, is_process_startup, | 721 cur_dir, is_process_startup, |
| 708 is_first_run)) { | 722 is_first_run)) { |
| 709 return false; | 723 return false; |
| 710 } | 724 } |
| 711 } else { | 725 } else { |
| 726 #if !defined(OS_CHROMEOS) | |
| 712 // Guest profiles should not be reopened on startup. This can happen if | 727 // Guest profiles should not be reopened on startup. This can happen if |
| 713 // the last used profile was a Guest, but other profiles were also open | 728 // the last used profile was a Guest, but other profiles were also open |
| 714 // when Chrome was closed. In this case, pick a different open profile | 729 // when Chrome was closed. In this case, pick a different open profile |
| 715 // to be the active one, since the Guest profile is never added to the list | 730 // to be the active one, since the Guest profile is never added to the list |
| 716 // of open profiles. | 731 // of open profiles. |
| 717 if (switches::IsNewAvatarMenu() && last_used_profile->IsGuestSession()) { | 732 if (last_used_profile->IsGuestSession()) { |
| 718 DCHECK(!last_opened_profiles[0]->IsGuestSession()); | 733 DCHECK(!last_opened_profiles[0]->IsGuestSession()); |
| 719 last_used_profile = last_opened_profiles[0]; | 734 last_used_profile = last_opened_profiles[0]; |
| 720 } | 735 } |
| 736 #endif | |
| 721 | 737 |
| 722 // Launch the last used profile with the full command line, and the other | 738 // Launch the last used profile with the full command line, and the other |
| 723 // opened profiles without the URLs to launch. | 739 // opened profiles without the URLs to launch. |
| 724 base::CommandLine command_line_without_urls(command_line.GetProgram()); | 740 base::CommandLine command_line_without_urls(command_line.GetProgram()); |
| 725 const base::CommandLine::SwitchMap& switches = command_line.GetSwitches(); | 741 const base::CommandLine::SwitchMap& switches = command_line.GetSwitches(); |
| 726 for (base::CommandLine::SwitchMap::const_iterator switch_it = | 742 for (base::CommandLine::SwitchMap::const_iterator switch_it = |
| 727 switches.begin(); | 743 switches.begin(); |
| 728 switch_it != switches.end(); ++switch_it) { | 744 switch_it != switches.end(); ++switch_it) { |
| 729 command_line_without_urls.AppendSwitchNative(switch_it->first, | 745 command_line_without_urls.AppendSwitchNative(switch_it->first, |
| 730 switch_it->second); | 746 switch_it->second); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 842 // If we are showing the app list then chrome isn't shown so load the app | 858 // If we are showing the app list then chrome isn't shown so load the app |
| 843 // list's profile rather than chrome's. | 859 // list's profile rather than chrome's. |
| 844 if (command_line.HasSwitch(switches::kShowAppList)) { | 860 if (command_line.HasSwitch(switches::kShowAppList)) { |
| 845 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)-> | 861 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)-> |
| 846 GetProfilePath(user_data_dir); | 862 GetProfilePath(user_data_dir); |
| 847 } | 863 } |
| 848 | 864 |
| 849 return g_browser_process->profile_manager()->GetLastUsedProfileDir( | 865 return g_browser_process->profile_manager()->GetLastUsedProfileDir( |
| 850 user_data_dir); | 866 user_data_dir); |
| 851 } | 867 } |
| OLD | NEW |