Commit ca5efa8e authored by Rohit Agarwal's avatar Rohit Agarwal Committed by Commit Bot

Restart in the profile type that invoked it.

If the user started the browser in incognito mode and
triggered a restart in regular mode, the browser was started
in the incognito mode. Similarly, if the user started in the
regular mode and triggered a restart in the incognito mode,
the browser was started in the regular mode.

The fix is to find the profile type that invoked the restart.
Then use this type to modify old switch arguments which are used
to create the new cmd line arguments for restart.

Bug: 999085
Change-Id: Ide6e86aabb90b5a333ec10ea23e3add62a3d0e34
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1789582Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Reviewed-by: default avatarRamin Halavati <rhalavati@chromium.org>
Commit-Queue: Rohit Agarwal <roagarwal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#694717}
parent e66296d5
......@@ -28,6 +28,7 @@
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/buildflags.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "components/keep_alive_registry/keep_alive_registry.h"
#include "components/language/core/browser/pref_names.h"
......@@ -246,10 +247,32 @@ void AttemptRestart() {
}
#endif // defined(OS_WIN)
auto* browser_list = BrowserList::GetInstance();
// TODO(beng): Can this use ProfileManager::GetLoadedProfiles instead?
for (auto* browser : *BrowserList::GetInstance())
for (auto* browser : *browser_list)
content::BrowserContext::SaveSessionState(browser->profile());
Browser* last_active_browser = browser_list->GetLastActive();
if (last_active_browser) {
Profile* last_profile = last_active_browser->profile();
if (last_profile) {
// We remove profile type decorators from the current run arguments and
// then append the last profile type that invoked the restart, in the old
// switch arguments. The old switch arguments are later used to create a
// new command line for restart phase.
base::CommandLine& old_cl(*base::CommandLine::ForCurrentProcess());
old_cl.RemoveSwitch(switches::kGuest);
old_cl.RemoveSwitch(switches::kIncognito);
if (last_profile->IsIncognitoProfile())
old_cl.AppendSwitch(switches::kIncognito);
else if (last_profile->IsGuestSession())
old_cl.AppendSwitch(switches::kGuest);
}
}
PrefService* pref_service = g_browser_process->local_state();
pref_service->SetBoolean(prefs::kWasRestarted, true);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment