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 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]; | |
|
sky
2014/10/16 19:51:12
How do you know last_opened_profiles isn't a guest
noms (inactive)
2014/10/16 19:57:05
Only non-off-the-record profiles are added to the
| |
| 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) { |
| 656 // Don't launch additional profiles which would only open a new tab | 668 // Don't launch additional profiles which would only open a new tab |
| 657 // page. When restarting after an update, all profiles will reopen last | 669 // page. When restarting after an update, all profiles will reopen last |
| 658 // open pages. | 670 // open pages. |
| 659 SessionStartupPref startup_pref = | 671 SessionStartupPref startup_pref = |
| 660 GetSessionStartupPref(command_line, *it); | 672 GetSessionStartupPref(command_line, *it); |
| 661 if (*it != last_used_profile && | 673 if (*it != last_used_profile && |
| 662 startup_pref.type == SessionStartupPref::DEFAULT && | 674 startup_pref.type == SessionStartupPref::DEFAULT && |
| 663 !HasPendingUncleanExit(*it)) | 675 !HasPendingUncleanExit(*it)) |
| 664 continue; | 676 continue; |
| 665 | 677 |
| 666 // Don't re-open a browser window for the guest profile. | |
| 667 if (switches::IsNewAvatarMenu() && | |
|
sky
2014/10/16 19:51:12
Can't this still happen?
noms (inactive)
2014/10/16 19:57:05
No, since none of the profiles in last_opened_prof
| |
| 668 (*it)->IsGuestSession()) | |
| 669 continue; | |
| 670 | |
| 671 if (!browser_creator->LaunchBrowser((*it == last_used_profile) ? | 678 if (!browser_creator->LaunchBrowser((*it == last_used_profile) ? |
| 672 command_line : command_line_without_urls, *it, cur_dir, | 679 command_line : command_line_without_urls, *it, cur_dir, |
| 673 is_process_startup, is_first_run, return_code)) | 680 is_process_startup, is_first_run, return_code)) |
| 674 return false; | 681 return false; |
| 675 // We've launched at least one browser. | 682 // We've launched at least one browser. |
| 676 is_process_startup = chrome::startup::IS_NOT_PROCESS_STARTUP; | 683 is_process_startup = chrome::startup::IS_NOT_PROCESS_STARTUP; |
| 677 } | 684 } |
| 678 // This must be done after all profiles have been launched so the observer | 685 // 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. | 686 // knows about all profiles to wait for before activating this one. |
| 680 | 687 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 } | 688 } |
| 687 return true; | 689 return true; |
| 688 } | 690 } |
| 689 | 691 |
| 690 // static | 692 // static |
| 691 void StartupBrowserCreator::ProcessCommandLineOnProfileCreated( | 693 void StartupBrowserCreator::ProcessCommandLineOnProfileCreated( |
| 692 const CommandLine& command_line, | 694 const CommandLine& command_line, |
| 693 const base::FilePath& cur_dir, | 695 const base::FilePath& cur_dir, |
| 694 Profile* profile, | 696 Profile* profile, |
| 695 Profile::CreateStatus status) { | 697 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 | 741 // If we are showing the app list then chrome isn't shown so load the app |
| 740 // list's profile rather than chrome's. | 742 // list's profile rather than chrome's. |
| 741 if (command_line.HasSwitch(switches::kShowAppList)) { | 743 if (command_line.HasSwitch(switches::kShowAppList)) { |
| 742 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)-> | 744 return AppListService::Get(chrome::HOST_DESKTOP_TYPE_NATIVE)-> |
| 743 GetProfilePath(user_data_dir); | 745 GetProfilePath(user_data_dir); |
| 744 } | 746 } |
| 745 | 747 |
| 746 return g_browser_process->profile_manager()->GetLastUsedProfileDir( | 748 return g_browser_process->profile_manager()->GetLastUsedProfileDir( |
| 747 user_data_dir); | 749 user_data_dir); |
| 748 } | 750 } |
| OLD | NEW |