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

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

Issue 10850010: Make session restore understand that tabs have multiple SessionStorageNamespaces. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: attempt to fix unittsets. Created 8 years, 4 months 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 | Annotate | Revision Log
OLDNEW
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/sessions/session_restore.h" 5 #include "chrome/browser/sessions/session_restore.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <list> 8 #include <list>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 namespace { 60 namespace {
61 61
62 class SessionRestoreImpl; 62 class SessionRestoreImpl;
63 class TabLoader; 63 class TabLoader;
64 64
65 TabLoader* shared_tab_loader = NULL; 65 TabLoader* shared_tab_loader = NULL;
66 66
67 // Pointers to SessionRestoreImpls which are currently restoring the session. 67 // Pointers to SessionRestoreImpls which are currently restoring the session.
68 std::set<SessionRestoreImpl*>* active_session_restorers = NULL; 68 std::set<SessionRestoreImpl*>* active_session_restorers = NULL;
69 69
70 // Helper to use with BrowserContext::ForEachStoragePartition().
71 void StartScavengingUnusedSessionStorage(const std::string& id,
72 content::StoragePartition* storage_part ition) {
73 storage_partition->GetDOMStorageContext()->
74 StartScavengingUnusedSessionStorage();
75 }
76
70 // TabLoader ------------------------------------------------------------------ 77 // TabLoader ------------------------------------------------------------------
71 78
72 // Initial delay (see class decription for details). 79 // Initial delay (see class decription for details).
73 static const int kInitialDelayTimerMS = 100; 80 static const int kInitialDelayTimerMS = 100;
74 81
75 // TabLoader is responsible for loading tabs after session restore creates 82 // TabLoader is responsible for loading tabs after session restore creates
76 // tabs. New tabs are loaded after the current tab finishes loading, or a delay 83 // tabs. New tabs are loaded after the current tab finishes loading, or a delay
77 // is reached (initially kInitialDelayTimerMS). If the delay is reached before 84 // is reached (initially kInitialDelayTimerMS). If the delay is reached before
78 // a tab finishes loading a new tab is loaded and the time of the delay 85 // a tab finishes loading a new tab is loaded and the time of the delay
79 // doubled. 86 // doubled.
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 594
588 RecordAppLaunchForTab(browser, tab, selected_index); 595 RecordAppLaunchForTab(browser, tab, selected_index);
589 596
590 if (disposition == CURRENT_TAB) { 597 if (disposition == CURRENT_TAB) {
591 DCHECK(!use_new_window); 598 DCHECK(!use_new_window);
592 chrome::ReplaceRestoredTab(browser, 599 chrome::ReplaceRestoredTab(browser,
593 tab.navigations, 600 tab.navigations,
594 selected_index, 601 selected_index,
595 true, 602 true,
596 tab.extension_app_id, 603 tab.extension_app_id,
597 NULL, 604 content::SessionStorageNamespaceMap(),
598 tab.user_agent_override); 605 tab.user_agent_override);
599 } else { 606 } else {
600 int tab_index = use_new_window ? 0 : browser->active_index() + 1; 607 int tab_index = use_new_window ? 0 : browser->active_index() + 1;
601 WebContents* web_contents = chrome::AddRestoredTab( 608 WebContents* web_contents = chrome::AddRestoredTab(
602 browser, 609 browser,
603 tab.navigations, 610 tab.navigations,
604 tab_index, 611 tab_index,
605 selected_index, 612 selected_index,
606 tab.extension_app_id, 613 tab.extension_app_id,
607 false, // selected 614 false, // selected
608 tab.pinned, 615 tab.pinned,
609 true, 616 true,
610 NULL, 617 content::SessionStorageNamespaceMap(),
611 tab.user_agent_override); 618 tab.user_agent_override);
612 // Start loading the tab immediately. 619 // Start loading the tab immediately.
613 web_contents->GetController().LoadIfNecessary(); 620 web_contents->GetController().LoadIfNecessary();
614 } 621 }
615 622
616 if (use_new_window) { 623 if (use_new_window) {
617 chrome::ActivateTabAt(browser, 0, true); 624 chrome::ActivateTabAt(browser, 0, true);
618 browser->window()->Show(); 625 browser->window()->Show();
619 } 626 }
620 NotifySessionServiceOfRestoredTabs(browser, browser->tab_count()); 627 NotifySessionServiceOfRestoredTabs(browser, browser->tab_count());
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 UMA_HISTOGRAM_CUSTOM_TIMES( 741 UMA_HISTOGRAM_CUSTOM_TIMES(
735 "SessionRestore.TimeToProcessSessions", 742 "SessionRestore.TimeToProcessSessions",
736 time_to_process_sessions, 743 time_to_process_sessions,
737 base::TimeDelta::FromMilliseconds(10), 744 base::TimeDelta::FromMilliseconds(10),
738 base::TimeDelta::FromSeconds(1000), 745 base::TimeDelta::FromSeconds(1000),
739 100); 746 100);
740 747
741 if (windows->empty()) { 748 if (windows->empty()) {
742 // Restore was unsuccessful. The DOM storage system can also delete its 749 // Restore was unsuccessful. The DOM storage system can also delete its
743 // data, since no session restore will happen at a later point in time. 750 // data, since no session restore will happen at a later point in time.
744 content::BrowserContext::GetDefaultStoragePartition(profile_)-> 751 content::BrowserContext::ForEachStoragePartition(
745 GetDOMStorageContext()->StartScavengingUnusedSessionStorage(); 752 profile_,
753 base::Bind(&StartScavengingUnusedSessionStorage));
746 return FinishedTabCreation(false, false); 754 return FinishedTabCreation(false, false);
747 } 755 }
748 756
749 #if defined(OS_CHROMEOS) 757 #if defined(OS_CHROMEOS)
750 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker( 758 chromeos::BootTimesLoader::Get()->AddLoginTimeMarker(
751 "SessionRestore-CreatingTabs-Start", false); 759 "SessionRestore-CreatingTabs-Start", false);
752 #endif 760 #endif
753 StartTabCreation(); 761 StartTabCreation();
754 762
755 // After the for loop this contains the last TABBED_BROWSER. Is null if no 763 // After the for loop this contains the last TABBED_BROWSER. Is null if no
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 // If last_browser is NULL and urls_to_open_ is non-empty, 836 // If last_browser is NULL and urls_to_open_ is non-empty,
829 // FinishedTabCreation will create a new TabbedBrowser and add the urls to 837 // FinishedTabCreation will create a new TabbedBrowser and add the urls to
830 // it. 838 // it.
831 Browser* finished_browser = FinishedTabCreation(true, has_tabbed_browser); 839 Browser* finished_browser = FinishedTabCreation(true, has_tabbed_browser);
832 if (finished_browser) 840 if (finished_browser)
833 last_browser = finished_browser; 841 last_browser = finished_browser;
834 842
835 // sessionStorages needed for the session restore have now been recreated 843 // sessionStorages needed for the session restore have now been recreated
836 // by RestoreTab. Now it's safe for the DOM storage system to start 844 // by RestoreTab. Now it's safe for the DOM storage system to start
837 // deleting leftover data. 845 // deleting leftover data.
838 content::BrowserContext::GetDefaultStoragePartition(profile_)-> 846 content::BrowserContext::ForEachStoragePartition(
839 GetDOMStorageContext()->StartScavengingUnusedSessionStorage(); 847 profile_,
848 base::Bind(&StartScavengingUnusedSessionStorage));
840 return last_browser; 849 return last_browser;
841 } 850 }
842 851
843 // Record an app launch event (if appropriate) for a tab which is about to 852 // Record an app launch event (if appropriate) for a tab which is about to
844 // be restored. Callers should ensure that selected_index is within the 853 // be restored. Callers should ensure that selected_index is within the
845 // bounds of tab.navigations before calling. 854 // bounds of tab.navigations before calling.
846 void RecordAppLaunchForTab(Browser* browser, 855 void RecordAppLaunchForTab(Browser* browser,
847 const SessionTab& tab, 856 const SessionTab& tab,
848 int selected_index) { 857 int selected_index) {
849 DCHECK(selected_index >= 0 && 858 DCHECK(selected_index >= 0 &&
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 DCHECK(!tab.navigations.empty()); 893 DCHECK(!tab.navigations.empty());
885 int selected_index = tab.current_navigation_index; 894 int selected_index = tab.current_navigation_index;
886 selected_index = std::max( 895 selected_index = std::max(
887 0, 896 0,
888 std::min(selected_index, 897 std::min(selected_index,
889 static_cast<int>(tab.navigations.size() - 1))); 898 static_cast<int>(tab.navigations.size() - 1)));
890 899
891 RecordAppLaunchForTab(browser, tab, selected_index); 900 RecordAppLaunchForTab(browser, tab, selected_index);
892 901
893 // Associate sessionStorage (if any) to the restored tab. 902 // Associate sessionStorage (if any) to the restored tab.
894 scoped_refptr<content::SessionStorageNamespace> session_storage_namespace; 903 content::SessionStorageNamespaceMap restored_session_storage_namespaces;
895 if (!tab.session_storage_persistent_id.empty()) { 904 for (std::map<std::string, std::string>::const_iterator it =
896 session_storage_namespace = 905 tab.session_storage_persistent_id_map.begin();
897 content::BrowserContext::GetDefaultStoragePartition(profile_)-> 906 it != tab.session_storage_persistent_id_map.end();
898 GetDOMStorageContext()->RecreateSessionStorage( 907 ++it) {
899 tab.session_storage_persistent_id); 908 using content::BrowserContext;
909 if (BrowserContext::IsValidPartitionId(profile_, it->first)) {
910 content::StoragePartition* partition =
911 BrowserContext::GetStoragePartitionById(profile_, it->first);
912 restored_session_storage_namespaces[it->first] =
913 partition->GetDOMStorageContext()->
914 RecreateSessionStorage(it->second);
915 }
900 } 916 }
901 917
902 WebContents* web_contents = 918 WebContents* web_contents =
903 chrome::AddRestoredTab(browser, 919 chrome::AddRestoredTab(browser,
904 tab.navigations, 920 tab.navigations,
905 tab_index, 921 tab_index,
906 selected_index, 922 selected_index,
907 tab.extension_app_id, 923 tab.extension_app_id,
908 false, // select 924 false, // select
909 tab.pinned, 925 tab.pinned,
910 true, 926 true,
911 session_storage_namespace.get(), 927 restored_session_storage_namespaces,
912 tab.user_agent_override); 928 tab.user_agent_override);
913 // Regression check: check that the tab didn't start loading right away. The 929 // Regression check: check that the tab didn't start loading right away. The
914 // focused tab will be loaded by Browser, and TabLoader will load the rest. 930 // focused tab will be loaded by Browser, and TabLoader will load the rest.
915 DCHECK(web_contents->GetController().NeedsReload()); 931 DCHECK(web_contents->GetController().NeedsReload());
916 932
917 // Set up the file access rights for the selected navigation entry. 933 // Set up the file access rights for the selected navigation entry.
918 const int id = web_contents->GetRenderProcessHost()->GetID(); 934 const int id = web_contents->GetRenderProcessHost()->GetID();
919 const int read_file_permissions = 935 const int read_file_permissions =
920 base::PLATFORM_FILE_OPEN | 936 base::PLATFORM_FILE_OPEN |
921 base::PLATFORM_FILE_READ | 937 base::PLATFORM_FILE_READ |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 if (active_session_restorers == NULL) 1123 if (active_session_restorers == NULL)
1108 return false; 1124 return false;
1109 for (std::set<SessionRestoreImpl*>::const_iterator it = 1125 for (std::set<SessionRestoreImpl*>::const_iterator it =
1110 active_session_restorers->begin(); 1126 active_session_restorers->begin();
1111 it != active_session_restorers->end(); ++it) { 1127 it != active_session_restorers->end(); ++it) {
1112 if ((*it)->profile() == profile) 1128 if ((*it)->profile() == profile)
1113 return true; 1129 return true;
1114 } 1130 }
1115 return false; 1131 return false;
1116 } 1132 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/isolated_app_browsertest.cc ('k') | chrome/browser/sessions/session_restore_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698