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 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 // create a browser window for the corresponding original profile. | 621 // create a browser window for the corresponding original profile. |
622 if (last_opened_profiles.empty()) { | 622 if (last_opened_profiles.empty()) { |
623 // If the last used profile is locked or was a guest, show the user manager. | 623 // If the last used profile is locked or was a guest, show the user manager. |
624 if (switches::IsNewAvatarMenu()) { | 624 if (switches::IsNewAvatarMenu()) { |
625 ProfileInfoCache& profile_info = | 625 ProfileInfoCache& profile_info = |
626 g_browser_process->profile_manager()->GetProfileInfoCache(); | 626 g_browser_process->profile_manager()->GetProfileInfoCache(); |
627 size_t profile_index = profile_info.GetIndexOfProfileWithPath( | 627 size_t profile_index = profile_info.GetIndexOfProfileWithPath( |
628 last_used_profile->GetPath()); | 628 last_used_profile->GetPath()); |
629 bool signin_required = profile_index != std::string::npos && | 629 bool signin_required = profile_index != std::string::npos && |
630 profile_info.ProfileIsSigninRequiredAtIndex(profile_index); | 630 profile_info.ProfileIsSigninRequiredAtIndex(profile_index); |
| 631 |
| 632 // Guest or locked profiles cannot be re-opened on startup. |
631 if (signin_required || last_used_profile->IsGuestSession()) { | 633 if (signin_required || last_used_profile->IsGuestSession()) { |
632 UserManager::Show(base::FilePath(), | 634 UserManager::Show(base::FilePath(), |
633 profiles::USER_MANAGER_NO_TUTORIAL, | 635 profiles::USER_MANAGER_NO_TUTORIAL, |
634 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); | 636 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); |
635 return true; | 637 return true; |
636 } | 638 } |
637 } | 639 } |
638 if (!browser_creator->LaunchBrowser(command_line, last_used_profile, | 640 if (!browser_creator->LaunchBrowser(command_line, last_used_profile, |
639 cur_dir, is_process_startup, | 641 cur_dir, is_process_startup, |
640 is_first_run, return_code)) { | 642 is_first_run, return_code)) { |
641 return false; | 643 return false; |
642 } | 644 } |
643 } else { | 645 } else { |
| 646 // Guest profiles should not be reopened on startup. This can happen if |
| 647 // the last used profile was a Guest, but other profiles were also open |
| 648 // when Chrome was closed. In this case, pick a different open profile |
| 649 // to be the active one, since the Guest profile is never added to the list |
| 650 // of open profiles. |
| 651 if (switches::IsNewAvatarMenu() && last_used_profile->IsGuestSession()) { |
| 652 DCHECK(!last_opened_profiles[0]->IsGuestSession()); |
| 653 last_used_profile = last_opened_profiles[0]; |
| 654 } |
| 655 |
644 // Launch the last used profile with the full command line, and the other | 656 // Launch the last used profile with the full command line, and the other |
645 // opened profiles without the URLs to launch. | 657 // opened profiles without the URLs to launch. |
646 CommandLine command_line_without_urls(command_line.GetProgram()); | 658 CommandLine command_line_without_urls(command_line.GetProgram()); |
647 const CommandLine::SwitchMap& switches = command_line.GetSwitches(); | 659 const CommandLine::SwitchMap& switches = command_line.GetSwitches(); |
648 for (CommandLine::SwitchMap::const_iterator switch_it = switches.begin(); | 660 for (CommandLine::SwitchMap::const_iterator switch_it = switches.begin(); |
649 switch_it != switches.end(); ++switch_it) { | 661 switch_it != switches.end(); ++switch_it) { |
650 command_line_without_urls.AppendSwitchNative(switch_it->first, | 662 command_line_without_urls.AppendSwitchNative(switch_it->first, |
651 switch_it->second); | 663 switch_it->second); |
652 } | 664 } |
653 // Launch the profiles in the order they became active. | 665 // Launch the profiles in the order they became active. |
654 for (Profiles::const_iterator it = last_opened_profiles.begin(); | 666 for (Profiles::const_iterator it = last_opened_profiles.begin(); |
655 it != last_opened_profiles.end(); ++it) { | 667 it != last_opened_profiles.end(); ++it) { |
| 668 DCHECK(!(*it)->IsGuestSession()); |
656 // Don't launch additional profiles which would only open a new tab | 669 // Don't launch additional profiles which would only open a new tab |
657 // page. When restarting after an update, all profiles will reopen last | 670 // page. When restarting after an update, all profiles will reopen last |
658 // open pages. | 671 // open pages. |
659 SessionStartupPref startup_pref = | 672 SessionStartupPref startup_pref = |
660 GetSessionStartupPref(command_line, *it); | 673 GetSessionStartupPref(command_line, *it); |
661 if (*it != last_used_profile && | 674 if (*it != last_used_profile && |
662 startup_pref.type == SessionStartupPref::DEFAULT && | 675 startup_pref.type == SessionStartupPref::DEFAULT && |
663 !HasPendingUncleanExit(*it)) | 676 !HasPendingUncleanExit(*it)) |
664 continue; | 677 continue; |
665 | 678 |
666 // Don't re-open a browser window for the guest profile. | |
667 if (switches::IsNewAvatarMenu() && | |
668 (*it)->IsGuestSession()) | |
669 continue; | |
670 | |
671 if (!browser_creator->LaunchBrowser((*it == last_used_profile) ? | 679 if (!browser_creator->LaunchBrowser((*it == last_used_profile) ? |
672 command_line : command_line_without_urls, *it, cur_dir, | 680 command_line : command_line_without_urls, *it, cur_dir, |
673 is_process_startup, is_first_run, return_code)) | 681 is_process_startup, is_first_run, return_code)) |
674 return false; | 682 return false; |
675 // We've launched at least one browser. | 683 // We've launched at least one browser. |
676 is_process_startup = chrome::startup::IS_NOT_PROCESS_STARTUP; | 684 is_process_startup = chrome::startup::IS_NOT_PROCESS_STARTUP; |
677 } | 685 } |
678 // This must be done after all profiles have been launched so the observer | 686 // This must be done after all profiles have been launched so the observer |
679 // knows about all profiles to wait for before activating this one. | 687 // knows about all profiles to wait for before activating this one. |
680 | 688 profile_launch_observer.Get().set_profile_to_activate(last_used_profile); |
681 // If the last used profile was the guest one, we didn't open it so | |
682 // we don't need to activate it either. | |
683 if (!switches::IsNewAvatarMenu() && | |
684 !last_used_profile->IsGuestSession()) | |
685 profile_launch_observer.Get().set_profile_to_activate(last_used_profile); | |
686 } | 689 } |
687 return true; | 690 return true; |
688 } | 691 } |
689 | 692 |
690 // static | 693 // static |
691 void StartupBrowserCreator::ProcessCommandLineOnProfileCreated( | 694 void StartupBrowserCreator::ProcessCommandLineOnProfileCreated( |
692 const CommandLine& command_line, | 695 const CommandLine& command_line, |
693 const base::FilePath& cur_dir, | 696 const base::FilePath& cur_dir, |
694 Profile* profile, | 697 Profile* profile, |
695 Profile::CreateStatus status) { | 698 Profile::CreateStatus status) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 // If we are showing the app list then chrome isn't shown so load the app | 742 // If we are showing the app list then chrome isn't shown so load the app |
740 // list's profile rather than chrome's. | 743 // list's profile rather than chrome's. |
741 if (command_line.HasSwitch(switches::kShowAppList)) { | 744 if (command_line.HasSwitch(switches::kShowAppList)) { |
742 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)-> | 745 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)-> |
743 GetProfilePath(user_data_dir); | 746 GetProfilePath(user_data_dir); |
744 } | 747 } |
745 | 748 |
746 return g_browser_process->profile_manager()->GetLastUsedProfileDir( | 749 return g_browser_process->profile_manager()->GetLastUsedProfileDir( |
747 user_data_dir); | 750 user_data_dir); |
748 } | 751 } |
OLD | NEW |