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

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

Issue 10850010: Make session restore understand that tabs have multiple SessionStorageNamespaces. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased, with test robustified. 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
« no previous file with comments | « chrome/browser/sessions/session_service.h ('k') | chrome/browser/sessions/session_types.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_service.h" 5 #include "chrome/browser/sessions/session_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 return; 596 return;
597 SetTabWindow(tab->restore_tab_helper()->window_id(), 597 SetTabWindow(tab->restore_tab_helper()->window_id(),
598 tab->restore_tab_helper()->session_id()); 598 tab->restore_tab_helper()->session_id());
599 if (tab->extension_tab_helper()->extension_app()) { 599 if (tab->extension_tab_helper()->extension_app()) {
600 SetTabExtensionAppID( 600 SetTabExtensionAppID(
601 tab->restore_tab_helper()->window_id(), 601 tab->restore_tab_helper()->window_id(),
602 tab->restore_tab_helper()->session_id(), 602 tab->restore_tab_helper()->session_id(),
603 tab->extension_tab_helper()->extension_app()->id()); 603 tab->extension_tab_helper()->extension_app()->id());
604 } 604 }
605 605
606 // Record the association between the SessionStorageNamespace and the 606 // Record the association between all the SessionStorageNamespaces and
607 // tab. 607 // their containing tab.
608 content::SessionStorageNamespace* session_storage_namespace = 608 const content::SessionStorageNamespaceMap& session_storage_namespace_map =
609 tab->web_contents()->GetController().GetSessionStorageNamespaceMap() 609 tab->web_contents()->GetController().GetSessionStorageNamespaceMap();
michaeln 2012/08/08 22:29:30 Looks like namespaces for isolated-apps can be add
610 .find("")->second; 610 for (content::SessionStorageNamespaceMap::const_iterator it =
611 ScheduleCommand(CreateSessionStorageAssociatedCommand( 611 session_storage_namespace_map.begin();
612 tab->restore_tab_helper()->session_id(), 612 it != session_storage_namespace_map.end();
613 session_storage_namespace->persistent_id())); 613 ++it) {
614 session_storage_namespace->SetShouldPersist(true); 614 ScheduleCommand(CreateSessionStorageAssociatedCommand(
615 tab->restore_tab_helper()->session_id(),
616 it->second->persistent_id(), it->first));
617 it->second->SetShouldPersist(true);
618 }
615 break; 619 break;
616 } 620 }
617 621
618 case chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED: { 622 case chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED: {
619 TabContents* tab = content::Source<TabContents>(source).ptr(); 623 TabContents* tab = content::Source<TabContents>(source).ptr();
620 if (!tab || tab->profile() != profile()) 624 if (!tab || tab->profile() != profile())
621 return; 625 return;
622 // Allow the associated sessionStorage to get deleted; it won't be needed 626 // Allow the associated SessionStorageNamespaces to be deleted; they won't
623 // in the session restore. 627 // be needed in the session restore.
624 content::SessionStorageNamespace* session_storage_namespace = 628 const content::SessionStorageNamespaceMap& session_storage_namespace_map =
625 tab->web_contents()->GetController().GetSessionStorageNamespaceMap() 629 tab->web_contents()->GetController().GetSessionStorageNamespaceMap();
626 .find("")->second; 630 for (content::SessionStorageNamespaceMap::const_iterator it =
627 session_storage_namespace->SetShouldPersist(false); 631 session_storage_namespace_map.begin();
632 it != session_storage_namespace_map.end();
633 ++it) {
634 it->second->SetShouldPersist(false);
635 }
628 TabClosed(tab->restore_tab_helper()->window_id(), 636 TabClosed(tab->restore_tab_helper()->window_id(),
629 tab->restore_tab_helper()->session_id(), 637 tab->restore_tab_helper()->session_id(),
630 tab->web_contents()->GetClosedByUserGesture()); 638 tab->web_contents()->GetClosedByUserGesture());
631 RecordSessionUpdateHistogramData(type, &last_updated_tab_closed_time_); 639 RecordSessionUpdateHistogramData(type, &last_updated_tab_closed_time_);
632 break; 640 break;
633 } 641 }
634 642
635 case content::NOTIFICATION_NAV_LIST_PRUNED: { 643 case content::NOTIFICATION_NAV_LIST_PRUNED: {
636 TabContents* tab = TabContents::FromWebContents( 644 TabContents* tab = TabContents::FromWebContents(
637 content::Source<content::NavigationController>(source).ptr()-> 645 content::Source<content::NavigationController>(source).ptr()->
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 payload.tab_id = tab_id.id(); 860 payload.tab_id = tab_id.id();
853 payload.pinned_state = is_pinned; 861 payload.pinned_state = is_pinned;
854 SessionCommand* command = 862 SessionCommand* command =
855 new SessionCommand(kCommandSetPinnedState, sizeof(payload)); 863 new SessionCommand(kCommandSetPinnedState, sizeof(payload));
856 memcpy(command->contents(), &payload, sizeof(payload)); 864 memcpy(command->contents(), &payload, sizeof(payload));
857 return command; 865 return command;
858 } 866 }
859 867
860 SessionCommand* SessionService::CreateSessionStorageAssociatedCommand( 868 SessionCommand* SessionService::CreateSessionStorageAssociatedCommand(
861 const SessionID& tab_id, 869 const SessionID& tab_id,
862 const std::string& session_storage_persistent_id) { 870 const std::string& session_storage_persistent_id,
871 const std::string& partition_id) {
863 Pickle pickle; 872 Pickle pickle;
864 pickle.WriteInt(tab_id.id()); 873 pickle.WriteInt(tab_id.id());
865 pickle.WriteString(session_storage_persistent_id); 874 pickle.WriteString(session_storage_persistent_id);
875 pickle.WriteString(partition_id);
866 return new SessionCommand(kCommandSessionStorageAssociated, pickle); 876 return new SessionCommand(kCommandSessionStorageAssociated, pickle);
867 } 877 }
868 878
869 void SessionService::OnGotSessionCommands( 879 void SessionService::OnGotSessionCommands(
870 Handle handle, 880 Handle handle,
871 scoped_refptr<InternalGetCommandsRequest> request) { 881 scoped_refptr<InternalGetCommandsRequest> request) {
872 if (request->canceled()) 882 if (request->canceled())
873 return; 883 return;
874 884
875 ScopedVector<SessionWindow> valid_windows; 885 ScopedVector<SessionWindow> valid_windows;
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 } 1269 }
1260 1270
1261 GetTab(tab_id, tabs)->user_agent_override.swap(user_agent_override); 1271 GetTab(tab_id, tabs)->user_agent_override.swap(user_agent_override);
1262 break; 1272 break;
1263 } 1273 }
1264 1274
1265 case kCommandSessionStorageAssociated: { 1275 case kCommandSessionStorageAssociated: {
1266 scoped_ptr<Pickle> command_pickle(command->PayloadAsPickle()); 1276 scoped_ptr<Pickle> command_pickle(command->PayloadAsPickle());
1267 SessionID::id_type command_tab_id; 1277 SessionID::id_type command_tab_id;
1268 std::string session_storage_persistent_id; 1278 std::string session_storage_persistent_id;
1279 std::string partition_id;
1269 PickleIterator iter(*command_pickle.get()); 1280 PickleIterator iter(*command_pickle.get());
1281 // TODO(ajwong): Is it okay to just skip this command and proceed with
1282 // the rest of session restore?
1270 if (!command_pickle->ReadInt(&iter, &command_tab_id) || 1283 if (!command_pickle->ReadInt(&iter, &command_tab_id) ||
1271 !command_pickle->ReadString(&iter, &session_storage_persistent_id)) 1284 !command_pickle->ReadString(&iter,
1272 return true; 1285 &session_storage_persistent_id) ||
1286 !command_pickle->ReadString(&iter, &partition_id))
1287 continue; // If the storage is corrupt, just ignore it.
1273 // Associate the session storage back. 1288 // Associate the session storage back.
1274 GetTab(command_tab_id, tabs)->session_storage_persistent_id = 1289 GetTab(command_tab_id, tabs)->
1275 session_storage_persistent_id; 1290 session_storage_persistent_id_map[partition_id] =
1291 session_storage_persistent_id;
1276 break; 1292 break;
1277 } 1293 }
1278 1294
1279 default: 1295 default:
1280 VLOG(1) << "Failed reading an unknown command " << command->id(); 1296 VLOG(1) << "Failed reading an unknown command " << command->id();
1281 return true; 1297 return true;
1282 } 1298 }
1283 } 1299 }
1284 return true; 1300 return true;
1285 } 1301 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1339 } 1355 }
1340 } 1356 }
1341 commands->push_back( 1357 commands->push_back(
1342 CreateSetSelectedNavigationIndexCommand(session_id, current_index)); 1358 CreateSetSelectedNavigationIndexCommand(session_id, current_index));
1343 1359
1344 if (index_in_window != -1) { 1360 if (index_in_window != -1) {
1345 commands->push_back( 1361 commands->push_back(
1346 CreateSetTabIndexInWindowCommand(session_id, index_in_window)); 1362 CreateSetTabIndexInWindowCommand(session_id, index_in_window));
1347 } 1363 }
1348 1364
1349 // Record the association between the sessionStorage namespace and the tab. 1365 // Record the association between the SessionStorageNamespaces and the tab.
1350 content::SessionStorageNamespace* session_storage_namespace = 1366 const content::SessionStorageNamespaceMap& session_storage_namespace_map =
1351 tab->web_contents()->GetController().GetSessionStorageNamespaceMap() 1367 tab->web_contents()->GetController().GetSessionStorageNamespaceMap();
1352 .find("")->second; 1368 for (content::SessionStorageNamespaceMap::const_iterator it =
1353 ScheduleCommand(CreateSessionStorageAssociatedCommand( 1369 session_storage_namespace_map.begin();
1354 tab->restore_tab_helper()->session_id(), 1370 it != session_storage_namespace_map.end();
1355 session_storage_namespace->persistent_id())); 1371 ++it) {
1372 it->second->SetShouldPersist(true);
1373 ScheduleCommand(CreateSessionStorageAssociatedCommand(
1374 tab->restore_tab_helper()->session_id(),
1375 it->second->persistent_id(), it->first));
1376 }
1356 } 1377 }
1357 1378
1358 void SessionService::BuildCommandsForBrowser( 1379 void SessionService::BuildCommandsForBrowser(
1359 Browser* browser, 1380 Browser* browser,
1360 std::vector<SessionCommand*>* commands, 1381 std::vector<SessionCommand*>* commands,
1361 IdToRange* tab_to_available_range, 1382 IdToRange* tab_to_available_range,
1362 std::set<SessionID::id_type>* windows_to_track) { 1383 std::set<SessionID::id_type>* windows_to_track) {
1363 DCHECK(browser && commands); 1384 DCHECK(browser && commands);
1364 DCHECK(browser->session_id().id()); 1385 DCHECK(browser->session_id().id());
1365 1386
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
1728 50); 1749 50);
1729 if (use_long_period) { 1750 if (use_long_period) {
1730 std::string long_name_("SessionRestore.SaveLongPeriod"); 1751 std::string long_name_("SessionRestore.SaveLongPeriod");
1731 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, 1752 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_,
1732 delta, 1753 delta,
1733 save_delay_in_mins_, 1754 save_delay_in_mins_,
1734 save_delay_in_hrs_, 1755 save_delay_in_hrs_,
1735 50); 1756 50);
1736 } 1757 }
1737 } 1758 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/session_service.h ('k') | chrome/browser/sessions/session_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698