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 15 matching lines...) Expand all Loading... | |
26 #include "chrome/browser/sessions/session_command.h" | 26 #include "chrome/browser/sessions/session_command.h" |
27 #include "chrome/browser/sessions/session_restore.h" | 27 #include "chrome/browser/sessions/session_restore.h" |
28 #include "chrome/browser/sessions/session_types.h" | 28 #include "chrome/browser/sessions/session_types.h" |
29 #include "chrome/browser/ui/browser_list.h" | 29 #include "chrome/browser/ui/browser_list.h" |
30 #include "chrome/browser/ui/browser_window.h" | 30 #include "chrome/browser/ui/browser_window.h" |
31 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 31 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
32 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 32 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
33 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 33 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
34 #include "chrome/common/chrome_notification_types.h" | 34 #include "chrome/common/chrome_notification_types.h" |
35 #include "chrome/common/extensions/extension.h" | 35 #include "chrome/common/extensions/extension.h" |
36 #include "content/public/browser/dom_storage_context.h" | |
36 #include "content/public/browser/navigation_details.h" | 37 #include "content/public/browser/navigation_details.h" |
37 #include "content/public/browser/navigation_entry.h" | 38 #include "content/public/browser/navigation_entry.h" |
38 #include "content/public/browser/notification_details.h" | 39 #include "content/public/browser/notification_details.h" |
39 #include "content/public/browser/notification_service.h" | 40 #include "content/public/browser/notification_service.h" |
41 #include "content/public/browser/session_storage_namespace.h" | |
40 #include "content/public/browser/web_contents.h" | 42 #include "content/public/browser/web_contents.h" |
41 | 43 |
42 #if defined(OS_MACOSX) | 44 #if defined(OS_MACOSX) |
43 #include "chrome/browser/app_controller_mac.h" | 45 #include "chrome/browser/app_controller_mac.h" |
44 #endif | 46 #endif |
45 | 47 |
46 using base::Time; | 48 using base::Time; |
47 using content::NavigationEntry; | 49 using content::NavigationEntry; |
48 | 50 |
49 // Identifier for commands written to file. | 51 // Identifier for commands written to file. |
(...skipping 15 matching lines...) Expand all Loading... | |
65 // static const SessionCommand::id_type kCommandSetWindowBounds2 = 10; | 67 // static const SessionCommand::id_type kCommandSetWindowBounds2 = 10; |
66 static const SessionCommand::id_type | 68 static const SessionCommand::id_type |
67 kCommandTabNavigationPathPrunedFromFront = 11; | 69 kCommandTabNavigationPathPrunedFromFront = 11; |
68 static const SessionCommand::id_type kCommandSetPinnedState = 12; | 70 static const SessionCommand::id_type kCommandSetPinnedState = 12; |
69 static const SessionCommand::id_type kCommandSetExtensionAppID = 13; | 71 static const SessionCommand::id_type kCommandSetExtensionAppID = 13; |
70 static const SessionCommand::id_type kCommandSetWindowBounds3 = 14; | 72 static const SessionCommand::id_type kCommandSetWindowBounds3 = 14; |
71 static const SessionCommand::id_type kCommandSetWindowAppName = 15; | 73 static const SessionCommand::id_type kCommandSetWindowAppName = 15; |
72 static const SessionCommand::id_type kCommandTabClosed = 16; | 74 static const SessionCommand::id_type kCommandTabClosed = 16; |
73 static const SessionCommand::id_type kCommandWindowClosed = 17; | 75 static const SessionCommand::id_type kCommandWindowClosed = 17; |
74 static const SessionCommand::id_type kCommandSetTabUserAgentOverride = 18; | 76 static const SessionCommand::id_type kCommandSetTabUserAgentOverride = 18; |
77 static const SessionCommand::id_type kCommandSessionStorageAssociated = 19; | |
75 | 78 |
76 // Every kWritesPerReset commands triggers recreating the file. | 79 // Every kWritesPerReset commands triggers recreating the file. |
77 static const int kWritesPerReset = 250; | 80 static const int kWritesPerReset = 250; |
78 | 81 |
79 namespace { | 82 namespace { |
80 | 83 |
81 // The callback from GetLastSession is internally routed to SessionService | 84 // The callback from GetLastSession is internally routed to SessionService |
82 // first and then the caller. This is done so that the SessionWindows can be | 85 // first and then the caller. This is done so that the SessionWindows can be |
83 // recreated from the SessionCommands and the SessionWindows passed to the | 86 // recreated from the SessionCommands and the SessionWindows passed to the |
84 // caller. The following class is used for this. | 87 // caller. The following class is used for this. |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
593 if (tab->profile() != profile()) | 596 if (tab->profile() != profile()) |
594 return; | 597 return; |
595 SetTabWindow(tab->restore_tab_helper()->window_id(), | 598 SetTabWindow(tab->restore_tab_helper()->window_id(), |
596 tab->restore_tab_helper()->session_id()); | 599 tab->restore_tab_helper()->session_id()); |
597 if (tab->extension_tab_helper()->extension_app()) { | 600 if (tab->extension_tab_helper()->extension_app()) { |
598 SetTabExtensionAppID( | 601 SetTabExtensionAppID( |
599 tab->restore_tab_helper()->window_id(), | 602 tab->restore_tab_helper()->window_id(), |
600 tab->restore_tab_helper()->session_id(), | 603 tab->restore_tab_helper()->session_id(), |
601 tab->extension_tab_helper()->extension_app()->id()); | 604 tab->extension_tab_helper()->extension_app()->id()); |
602 } | 605 } |
606 | |
607 // Record the association between the sessionStorage namespace and the | |
608 // tab. | |
609 content::SessionStorageNamespace* session_storage_namespace = | |
610 tab->web_contents()->GetController().GetSessionStorageNamespace(); | |
611 ScheduleCommand(CreateSessionStorageAssociatedCommand( | |
612 tab->restore_tab_helper()->session_id(), | |
613 session_storage_namespace->persistent_id())); | |
603 break; | 614 break; |
604 } | 615 } |
605 | 616 |
606 case chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED: { | 617 case chrome::NOTIFICATION_TAB_CONTENTS_DESTROYED: { |
607 TabContentsWrapper* tab = | 618 TabContentsWrapper* tab = |
608 content::Source<TabContentsWrapper>(source).ptr(); | 619 content::Source<TabContentsWrapper>(source).ptr(); |
609 if (!tab || tab->profile() != profile()) | 620 if (!tab || tab->profile() != profile()) |
610 return; | 621 return; |
622 // Allow the associated sessionStorage to get deleted; it won't be needed | |
623 // in the session restore. | |
michaeln
2012/06/08 01:04:21
I see that NOTIFICATION_TAB_CONTENTS_DESTROYED hap
marja
2012/06/19 13:17:17
Did the SetShouldPersist change; it's cleaner now.
| |
624 content::SessionStorageNamespace* session_storage_namespace = | |
625 tab->web_contents()->GetController().GetSessionStorageNamespace(); | |
626 content::BrowserContext::GetDOMStorageContext(profile())-> | |
627 DoomSessionStorage(session_storage_namespace->persistent_id()); | |
611 TabClosed(tab->restore_tab_helper()->window_id(), | 628 TabClosed(tab->restore_tab_helper()->window_id(), |
612 tab->restore_tab_helper()->session_id(), | 629 tab->restore_tab_helper()->session_id(), |
613 tab->web_contents()->GetClosedByUserGesture()); | 630 tab->web_contents()->GetClosedByUserGesture()); |
614 RecordSessionUpdateHistogramData(type, &last_updated_tab_closed_time_); | 631 RecordSessionUpdateHistogramData(type, &last_updated_tab_closed_time_); |
615 break; | 632 break; |
616 } | 633 } |
617 | 634 |
618 case content::NOTIFICATION_NAV_LIST_PRUNED: { | 635 case content::NOTIFICATION_NAV_LIST_PRUNED: { |
619 TabContentsWrapper* tab = | 636 TabContentsWrapper* tab = |
620 TabContentsWrapper::GetCurrentWrapperForContents( | 637 TabContentsWrapper::GetCurrentWrapperForContents( |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
836 bool is_pinned) { | 853 bool is_pinned) { |
837 PinnedStatePayload payload = { 0 }; | 854 PinnedStatePayload payload = { 0 }; |
838 payload.tab_id = tab_id.id(); | 855 payload.tab_id = tab_id.id(); |
839 payload.pinned_state = is_pinned; | 856 payload.pinned_state = is_pinned; |
840 SessionCommand* command = | 857 SessionCommand* command = |
841 new SessionCommand(kCommandSetPinnedState, sizeof(payload)); | 858 new SessionCommand(kCommandSetPinnedState, sizeof(payload)); |
842 memcpy(command->contents(), &payload, sizeof(payload)); | 859 memcpy(command->contents(), &payload, sizeof(payload)); |
843 return command; | 860 return command; |
844 } | 861 } |
845 | 862 |
863 SessionCommand* SessionService::CreateSessionStorageAssociatedCommand( | |
864 const SessionID& tab_id, | |
865 const std::string& session_storage_persistent_id) { | |
866 Pickle pickle; | |
867 pickle.WriteInt(tab_id.id()); | |
868 pickle.WriteString(session_storage_persistent_id); | |
869 return new SessionCommand(kCommandSessionStorageAssociated, pickle); | |
870 } | |
871 | |
846 void SessionService::OnGotSessionCommands( | 872 void SessionService::OnGotSessionCommands( |
847 Handle handle, | 873 Handle handle, |
848 scoped_refptr<InternalGetCommandsRequest> request) { | 874 scoped_refptr<InternalGetCommandsRequest> request) { |
849 if (request->canceled()) | 875 if (request->canceled()) |
850 return; | 876 return; |
851 | 877 |
852 ScopedVector<SessionWindow> valid_windows; | 878 ScopedVector<SessionWindow> valid_windows; |
853 RestoreSessionFromCommands( | 879 RestoreSessionFromCommands( |
854 request->commands, &(valid_windows.get())); | 880 request->commands, &(valid_windows.get())); |
855 static_cast<InternalSessionRequest*>(request.get())-> | 881 static_cast<InternalSessionRequest*>(request.get())-> |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1232 std::string user_agent_override; | 1258 std::string user_agent_override; |
1233 if (!RestoreSetTabUserAgentOverrideCommand( | 1259 if (!RestoreSetTabUserAgentOverrideCommand( |
1234 *command, &tab_id, &user_agent_override)) { | 1260 *command, &tab_id, &user_agent_override)) { |
1235 return true; | 1261 return true; |
1236 } | 1262 } |
1237 | 1263 |
1238 GetTab(tab_id, tabs)->user_agent_override.swap(user_agent_override); | 1264 GetTab(tab_id, tabs)->user_agent_override.swap(user_agent_override); |
1239 break; | 1265 break; |
1240 } | 1266 } |
1241 | 1267 |
1268 case kCommandSessionStorageAssociated: { | |
1269 scoped_ptr<Pickle> pickle(command->PayloadAsPickle()); | |
1270 SessionID::id_type tab_id; | |
1271 std::string session_storage_persistent_id; | |
1272 PickleIterator iter(*pickle.get()); | |
1273 pickle->ReadInt(&iter, &tab_id); | |
1274 pickle->ReadString(&iter, &session_storage_persistent_id); | |
1275 // Associate the session storage back. | |
1276 GetTab(tab_id, tabs)->session_storage_persistent_id = | |
1277 session_storage_persistent_id; | |
1278 break; | |
1279 } | |
1280 | |
1242 default: | 1281 default: |
1243 VLOG(1) << "Failed reading an unknown command " << command->id(); | 1282 VLOG(1) << "Failed reading an unknown command " << command->id(); |
1244 return true; | 1283 return true; |
1245 } | 1284 } |
1246 } | 1285 } |
1247 return true; | 1286 return true; |
1248 } | 1287 } |
1249 | 1288 |
1250 void SessionService::BuildCommandsForTab( | 1289 void SessionService::BuildCommandsForTab( |
1251 const SessionID& window_id, | 1290 const SessionID& window_id, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1303 kCommandUpdateTabNavigation, session_id.id(), i, *entry)); | 1342 kCommandUpdateTabNavigation, session_id.id(), i, *entry)); |
1304 } | 1343 } |
1305 } | 1344 } |
1306 commands->push_back( | 1345 commands->push_back( |
1307 CreateSetSelectedNavigationIndexCommand(session_id, current_index)); | 1346 CreateSetSelectedNavigationIndexCommand(session_id, current_index)); |
1308 | 1347 |
1309 if (index_in_window != -1) { | 1348 if (index_in_window != -1) { |
1310 commands->push_back( | 1349 commands->push_back( |
1311 CreateSetTabIndexInWindowCommand(session_id, index_in_window)); | 1350 CreateSetTabIndexInWindowCommand(session_id, index_in_window)); |
1312 } | 1351 } |
1352 | |
1353 // Record the association between the sessionStorage namespace and the tab. | |
1354 content::SessionStorageNamespace* session_storage_namespace = | |
1355 tab->web_contents()->GetController().GetSessionStorageNamespace(); | |
1356 ScheduleCommand(CreateSessionStorageAssociatedCommand( | |
1357 tab->restore_tab_helper()->session_id(), | |
1358 session_storage_namespace->persistent_id())); | |
1313 } | 1359 } |
1314 | 1360 |
1315 void SessionService::BuildCommandsForBrowser( | 1361 void SessionService::BuildCommandsForBrowser( |
1316 Browser* browser, | 1362 Browser* browser, |
1317 std::vector<SessionCommand*>* commands, | 1363 std::vector<SessionCommand*>* commands, |
1318 IdToRange* tab_to_available_range, | 1364 IdToRange* tab_to_available_range, |
1319 std::set<SessionID::id_type>* windows_to_track) { | 1365 std::set<SessionID::id_type>* windows_to_track) { |
1320 DCHECK(browser && commands); | 1366 DCHECK(browser && commands); |
1321 DCHECK(browser->session_id().id()); | 1367 DCHECK(browser->session_id().id()); |
1322 | 1368 |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1685 50); | 1731 50); |
1686 if (use_long_period) { | 1732 if (use_long_period) { |
1687 std::string long_name_("SessionRestore.SaveLongPeriod"); | 1733 std::string long_name_("SessionRestore.SaveLongPeriod"); |
1688 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, | 1734 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, |
1689 delta, | 1735 delta, |
1690 save_delay_in_mins_, | 1736 save_delay_in_mins_, |
1691 save_delay_in_hrs_, | 1737 save_delay_in_hrs_, |
1692 50); | 1738 50); |
1693 } | 1739 } |
1694 } | 1740 } |
OLD | NEW |