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/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 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 tab->restore_tab_helper()->session_id()); | 611 tab->restore_tab_helper()->session_id()); |
612 if (tab->extension_tab_helper()->extension_app()) { | 612 if (tab->extension_tab_helper()->extension_app()) { |
613 SetTabExtensionAppID( | 613 SetTabExtensionAppID( |
614 tab->restore_tab_helper()->window_id(), | 614 tab->restore_tab_helper()->window_id(), |
615 tab->restore_tab_helper()->session_id(), | 615 tab->restore_tab_helper()->session_id(), |
616 tab->extension_tab_helper()->extension_app()->id()); | 616 tab->extension_tab_helper()->extension_app()->id()); |
617 } | 617 } |
618 | 618 |
619 // Record the association between the SessionStorageNamespace and the | 619 // Record the association between the SessionStorageNamespace and the |
620 // tab. | 620 // tab. |
621 // | 621 // Record the association between all the SessionStorageNamespaces and |
622 // TODO(ajwong): This should be processing the whole map rather than | 622 // their containing tab. |
623 // just the default. This in particular will not work for tabs with only | 623 const content::SessionStorageNamespaceMap& session_storage_namespace_map = |
624 // isolated apps which won't have a default partition. | 624 tab->web_contents()->GetController().GetSessionStorageNamespaceMap(); |
625 content::SessionStorageNamespace* session_storage_namespace = | 625 LOG(ERROR) << "Associating map of size " << session_storage_namespace_map.
size(); |
626 tab->web_contents()->GetController(). | 626 for (content::SessionStorageNamespaceMap::const_iterator it = |
627 GetDefaultSessionStorageNamespace(); | 627 session_storage_namespace_map.begin(); |
628 ScheduleCommand(CreateSessionStorageAssociatedCommand( | 628 it != session_storage_namespace_map.end(); |
629 tab->restore_tab_helper()->session_id(), | 629 ++it) { |
630 session_storage_namespace->persistent_id())); | 630 LOG(ERROR) << "Associating --" << it->first << "++ with --" << it->secon
d->persistent_id(); |
631 session_storage_namespace->SetShouldPersist(true); | 631 ScheduleCommand(CreateSessionStorageAssociatedCommand( |
| 632 tab->restore_tab_helper()->session_id(), |
| 633 it->second->persistent_id(), |
| 634 it->first)); |
| 635 it->second->SetShouldPersist(true); |
| 636 } |
632 break; | 637 break; |
633 } | 638 } |
634 | 639 |
635 case chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED: { | 640 case chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED: { |
636 TabContents* tab = content::Source<TabContents>(source).ptr(); | 641 TabContents* tab = content::Source<TabContents>(source).ptr(); |
637 if (!tab || tab->profile() != profile()) | 642 if (!tab || tab->profile() != profile()) |
638 return; | 643 return; |
639 // Allow the associated sessionStorage to get deleted; it won't be needed | 644 // Allow the associated sessionStorage to get deleted; it won't be needed |
640 // in the session restore. | 645 // in the session restore. |
641 content::SessionStorageNamespace* session_storage_namespace = | 646 const content::SessionStorageNamespaceMap& session_storage_namespace_map = |
642 tab->web_contents()->GetController(). | 647 tab->web_contents()->GetController().GetSessionStorageNamespaceMap(); |
643 GetDefaultSessionStorageNamespace(); | 648 for (content::SessionStorageNamespaceMap::const_iterator it = |
644 session_storage_namespace->SetShouldPersist(false); | 649 session_storage_namespace_map.begin(); |
| 650 it != session_storage_namespace_map.end(); |
| 651 ++it) { |
| 652 it->second->SetShouldPersist(false); |
| 653 } |
645 TabClosed(tab->restore_tab_helper()->window_id(), | 654 TabClosed(tab->restore_tab_helper()->window_id(), |
646 tab->restore_tab_helper()->session_id(), | 655 tab->restore_tab_helper()->session_id(), |
647 tab->web_contents()->GetClosedByUserGesture()); | 656 tab->web_contents()->GetClosedByUserGesture()); |
648 RecordSessionUpdateHistogramData(type, &last_updated_tab_closed_time_); | 657 RecordSessionUpdateHistogramData(type, &last_updated_tab_closed_time_); |
649 break; | 658 break; |
650 } | 659 } |
651 | 660 |
652 case content::NOTIFICATION_NAV_LIST_PRUNED: { | 661 case content::NOTIFICATION_NAV_LIST_PRUNED: { |
653 TabContents* tab = TabContents::FromWebContents( | 662 TabContents* tab = TabContents::FromWebContents( |
654 content::Source<content::NavigationController>(source).ptr()-> | 663 content::Source<content::NavigationController>(source).ptr()-> |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 payload.tab_id = tab_id.id(); | 865 payload.tab_id = tab_id.id(); |
857 payload.pinned_state = is_pinned; | 866 payload.pinned_state = is_pinned; |
858 SessionCommand* command = | 867 SessionCommand* command = |
859 new SessionCommand(kCommandSetPinnedState, sizeof(payload)); | 868 new SessionCommand(kCommandSetPinnedState, sizeof(payload)); |
860 memcpy(command->contents(), &payload, sizeof(payload)); | 869 memcpy(command->contents(), &payload, sizeof(payload)); |
861 return command; | 870 return command; |
862 } | 871 } |
863 | 872 |
864 SessionCommand* SessionService::CreateSessionStorageAssociatedCommand( | 873 SessionCommand* SessionService::CreateSessionStorageAssociatedCommand( |
865 const SessionID& tab_id, | 874 const SessionID& tab_id, |
866 const std::string& session_storage_persistent_id) { | 875 const std::string& session_storage_persistent_id, |
| 876 const std::string& partiton_id) { |
867 Pickle pickle; | 877 Pickle pickle; |
868 pickle.WriteInt(tab_id.id()); | 878 pickle.WriteInt(tab_id.id()); |
869 pickle.WriteString(session_storage_persistent_id); | 879 pickle.WriteString(session_storage_persistent_id); |
| 880 pickle.WriteString(partiton_id); |
870 return new SessionCommand(kCommandSessionStorageAssociated, pickle); | 881 return new SessionCommand(kCommandSessionStorageAssociated, pickle); |
871 } | 882 } |
872 | 883 |
873 void SessionService::OnGotSessionCommands( | 884 void SessionService::OnGotSessionCommands( |
874 Handle handle, | 885 Handle handle, |
875 scoped_refptr<InternalGetCommandsRequest> request) { | 886 scoped_refptr<InternalGetCommandsRequest> request) { |
876 if (request->canceled()) | 887 if (request->canceled()) |
877 return; | 888 return; |
878 | 889 |
879 ScopedVector<SessionWindow> valid_windows; | 890 ScopedVector<SessionWindow> valid_windows; |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1263 } | 1274 } |
1264 | 1275 |
1265 GetTab(tab_id, tabs)->user_agent_override.swap(user_agent_override); | 1276 GetTab(tab_id, tabs)->user_agent_override.swap(user_agent_override); |
1266 break; | 1277 break; |
1267 } | 1278 } |
1268 | 1279 |
1269 case kCommandSessionStorageAssociated: { | 1280 case kCommandSessionStorageAssociated: { |
1270 scoped_ptr<Pickle> command_pickle(command->PayloadAsPickle()); | 1281 scoped_ptr<Pickle> command_pickle(command->PayloadAsPickle()); |
1271 SessionID::id_type command_tab_id; | 1282 SessionID::id_type command_tab_id; |
1272 std::string session_storage_persistent_id; | 1283 std::string session_storage_persistent_id; |
| 1284 std::string partition_id; |
1273 PickleIterator iter(*command_pickle.get()); | 1285 PickleIterator iter(*command_pickle.get()); |
1274 if (!command_pickle->ReadInt(&iter, &command_tab_id) || | 1286 if (!command_pickle->ReadInt(&iter, &command_tab_id) || |
1275 !command_pickle->ReadString(&iter, &session_storage_persistent_id)) | 1287 !command_pickle->ReadString(&iter, &session_storage_persistent_id) |
| |
1276 return true; | 1288 !command_pickle->ReadString(&iter, &partition_id)) |
| 1289 continue; // We can safely just lose SessionStorage on a restore. |
1277 // Associate the session storage back. | 1290 // Associate the session storage back. |
1278 GetTab(command_tab_id, tabs)->session_storage_persistent_id = | 1291 GetTab(command_tab_id, tabs)-> |
1279 session_storage_persistent_id; | 1292 session_storage_persistent_id_map[partition_id] = |
| 1293 session_storage_persistent_id; |
1280 break; | 1294 break; |
1281 } | 1295 } |
1282 | 1296 |
1283 default: | 1297 default: |
1284 VLOG(1) << "Failed reading an unknown command " << command->id(); | 1298 VLOG(1) << "Failed reading an unknown command " << command->id(); |
1285 return true; | 1299 return true; |
1286 } | 1300 } |
1287 } | 1301 } |
1288 return true; | 1302 return true; |
1289 } | 1303 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1343 } | 1357 } |
1344 } | 1358 } |
1345 commands->push_back( | 1359 commands->push_back( |
1346 CreateSetSelectedNavigationIndexCommand(session_id, current_index)); | 1360 CreateSetSelectedNavigationIndexCommand(session_id, current_index)); |
1347 | 1361 |
1348 if (index_in_window != -1) { | 1362 if (index_in_window != -1) { |
1349 commands->push_back( | 1363 commands->push_back( |
1350 CreateSetTabIndexInWindowCommand(session_id, index_in_window)); | 1364 CreateSetTabIndexInWindowCommand(session_id, index_in_window)); |
1351 } | 1365 } |
1352 | 1366 |
1353 // Record the association between the sessionStorage namespace and the tab. | 1367 // Record the association between the SessionStorageNamespaces and the tab. |
1354 content::SessionStorageNamespace* session_storage_namespace = | 1368 const content::SessionStorageNamespaceMap& session_storage_namespace_map = |
1355 tab->web_contents()->GetController().GetDefaultSessionStorageNamespace(); | 1369 tab->web_contents()->GetController().GetSessionStorageNamespaceMap(); |
1356 ScheduleCommand(CreateSessionStorageAssociatedCommand( | 1370 for (content::SessionStorageNamespaceMap::const_iterator it = |
1357 tab->restore_tab_helper()->session_id(), | 1371 session_storage_namespace_map.begin(); |
1358 session_storage_namespace->persistent_id())); | 1372 it != session_storage_namespace_map.end(); |
| 1373 ++it) { |
| 1374 // TODO(ajwong): Again I wonder if we should do this? |
| 1375 it->second->SetShouldPersist(true); |
| 1376 ScheduleCommand(CreateSessionStorageAssociatedCommand( |
| 1377 tab->restore_tab_helper()->session_id(), |
| 1378 it->second->persistent_id(), it->first)); |
| 1379 } |
1359 } | 1380 } |
1360 | 1381 |
1361 void SessionService::BuildCommandsForBrowser( | 1382 void SessionService::BuildCommandsForBrowser( |
1362 Browser* browser, | 1383 Browser* browser, |
1363 std::vector<SessionCommand*>* commands, | 1384 std::vector<SessionCommand*>* commands, |
1364 IdToRange* tab_to_available_range, | 1385 IdToRange* tab_to_available_range, |
1365 std::set<SessionID::id_type>* windows_to_track) { | 1386 std::set<SessionID::id_type>* windows_to_track) { |
1366 DCHECK(browser && commands); | 1387 DCHECK(browser && commands); |
1367 DCHECK(browser->session_id().id()); | 1388 DCHECK(browser->session_id().id()); |
1368 | 1389 |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1731 50); | 1752 50); |
1732 if (use_long_period) { | 1753 if (use_long_period) { |
1733 std::string long_name_("SessionRestore.SaveLongPeriod"); | 1754 std::string long_name_("SessionRestore.SaveLongPeriod"); |
1734 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, | 1755 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, |
1735 delta, | 1756 delta, |
1736 save_delay_in_mins_, | 1757 save_delay_in_mins_, |
1737 save_delay_in_hrs_, | 1758 save_delay_in_hrs_, |
1738 50); | 1759 50); |
1739 } | 1760 } |
1740 } | 1761 } |
OLD | NEW |