Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: chrome/browser/sessions/session_restore.cc

Issue 2493573002: Make sure that the browser will always restore settings page instead of sign out page after user si… (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/sessions/session_restore.h" 5 #include "chrome/browser/sessions/session_restore.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <list> 10 #include <list>
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 base::TimeDelta delta = highest_time - tab.last_active_time; 568 base::TimeDelta delta = highest_time - tab.last_active_time;
569 contents->SetLastActiveTime(now - delta); 569 contents->SetLastActiveTime(now - delta);
570 RestoredTab restored_tab(contents, false, 570 RestoredTab restored_tab(contents, false,
571 tab.extension_app_id.empty(), tab.pinned); 571 tab.extension_app_id.empty(), tab.pinned);
572 created_contents->push_back(restored_tab); 572 created_contents->push_back(restored_tab);
573 } 573 }
574 } 574 }
575 } 575 }
576 } 576 }
577 577
578 int GetSelectedIndex(const sessions::SessionTab& tab) {
sky 2016/11/09 22:24:04 I have a mild preference for moving this to Sessio
sky 2016/11/09 22:24:04 This only effects session restore, what about tab
zmin 2016/11/10 22:36:07 I want to scope the affect of this change as littl
zmin 2016/11/10 22:36:07 OnGotSessionCommands is a simple function. Moving
579 int selected_index = tab.current_navigation_index;
580 selected_index = std::max(
581 0,
582 std::min(selected_index, static_cast<int>(tab.navigations.size() - 1)));
583
584 // After user sign out, Chrome may navigate to the setting page from the
585 // sign out page asynchronously. The browser may be closed before the
586 // navigation callback finished.
587 std::string setting_page_url = std::string(chrome::kChromeUISettingsURL);
588 std::string sign_out_page_url =
589 setting_page_url + std::string(chrome::kSignOutSubPage);
sky 2016/11/09 22:24:04 Is there a reason you care about this case, and sa
zmin 2016/11/10 22:36:07 There're some edge cases I'm thinking about. For e
590 if (selected_index > 0 &&
591 tab.navigations.at(selected_index).virtual_url().spec() ==
sky 2016/11/09 22:24:04 at() -> [] (same comment below).
zmin 2016/11/10 22:36:07 Done.
592 sign_out_page_url &&
593 tab.navigations.at(selected_index - 1).virtual_url().spec() ==
594 setting_page_url) {
595 selected_index -= 1;
596 }
597
598 return selected_index;
599 }
600
578 // |tab_index| is ignored for pinned tabs which will always be pushed behind 601 // |tab_index| is ignored for pinned tabs which will always be pushed behind
579 // the last existing pinned tab. 602 // the last existing pinned tab.
580 // |tab_loader_| will schedule this tab for loading if |is_selected_tab| is 603 // |tab_loader_| will schedule this tab for loading if |is_selected_tab| is
581 // false. 604 // false.
582 WebContents* RestoreTab(const sessions::SessionTab& tab, 605 WebContents* RestoreTab(const sessions::SessionTab& tab,
583 const int tab_index, 606 const int tab_index,
584 Browser* browser, 607 Browser* browser,
585 bool is_selected_tab) { 608 bool is_selected_tab) {
586 // It's possible (particularly for foreign sessions) to receive a tab 609 // It's possible (particularly for foreign sessions) to receive a tab
587 // without valid navigations. In that case, just skip it. 610 // without valid navigations. In that case, just skip it.
588 // See crbug.com/154129. 611 // See crbug.com/154129.
589 if (tab.navigations.empty()) 612 if (tab.navigations.empty())
590 return nullptr; 613 return nullptr;
591 int selected_index = tab.current_navigation_index; 614 int selected_index = GetSelectedIndex(tab);
592 selected_index = std::max(
593 0,
594 std::min(selected_index, static_cast<int>(tab.navigations.size() - 1)));
595 615
596 RecordAppLaunchForTab(browser, tab, selected_index); 616 RecordAppLaunchForTab(browser, tab, selected_index);
597 617
598 // Associate sessionStorage (if any) to the restored tab. 618 // Associate sessionStorage (if any) to the restored tab.
599 scoped_refptr<content::SessionStorageNamespace> session_storage_namespace; 619 scoped_refptr<content::SessionStorageNamespace> session_storage_namespace;
600 if (!tab.session_storage_persistent_id.empty()) { 620 if (!tab.session_storage_persistent_id.empty()) {
601 session_storage_namespace = 621 session_storage_namespace =
602 content::BrowserContext::GetDefaultStoragePartition(profile_) 622 content::BrowserContext::GetDefaultStoragePartition(profile_)
603 ->GetDOMStorageContext() 623 ->GetDOMStorageContext()
604 ->RecreateSessionStorage(tab.session_storage_persistent_id); 624 ->RecreateSessionStorage(tab.session_storage_persistent_id);
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 // static 856 // static
837 SessionRestore::CallbackSubscription 857 SessionRestore::CallbackSubscription
838 SessionRestore::RegisterOnSessionRestoredCallback( 858 SessionRestore::RegisterOnSessionRestoredCallback(
839 const base::Callback<void(int)>& callback) { 859 const base::Callback<void(int)>& callback) {
840 return on_session_restored_callbacks()->Add(callback); 860 return on_session_restored_callbacks()->Add(callback);
841 } 861 }
842 862
843 // static 863 // static
844 base::CallbackList<void(int)>* 864 base::CallbackList<void(int)>*
845 SessionRestore::on_session_restored_callbacks_ = nullptr; 865 SessionRestore::on_session_restored_callbacks_ = nullptr;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698