| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // OBSOLETE Superseded by kCommandSetWindowBounds3. Except for data migration. | 64 // OBSOLETE Superseded by kCommandSetWindowBounds3. Except for data migration. |
| 65 // static const SessionCommand::id_type kCommandSetWindowBounds2 = 10; | 65 // static const SessionCommand::id_type kCommandSetWindowBounds2 = 10; |
| 66 static const SessionCommand::id_type | 66 static const SessionCommand::id_type |
| 67 kCommandTabNavigationPathPrunedFromFront = 11; | 67 kCommandTabNavigationPathPrunedFromFront = 11; |
| 68 static const SessionCommand::id_type kCommandSetPinnedState = 12; | 68 static const SessionCommand::id_type kCommandSetPinnedState = 12; |
| 69 static const SessionCommand::id_type kCommandSetExtensionAppID = 13; | 69 static const SessionCommand::id_type kCommandSetExtensionAppID = 13; |
| 70 static const SessionCommand::id_type kCommandSetWindowBounds3 = 14; | 70 static const SessionCommand::id_type kCommandSetWindowBounds3 = 14; |
| 71 static const SessionCommand::id_type kCommandSetWindowAppName = 15; | 71 static const SessionCommand::id_type kCommandSetWindowAppName = 15; |
| 72 static const SessionCommand::id_type kCommandTabClosed = 16; | 72 static const SessionCommand::id_type kCommandTabClosed = 16; |
| 73 static const SessionCommand::id_type kCommandWindowClosed = 17; | 73 static const SessionCommand::id_type kCommandWindowClosed = 17; |
| 74 static const SessionCommand::id_type kCommandSetTabUserAgentOverride = 18; |
| 74 | 75 |
| 75 // Every kWritesPerReset commands triggers recreating the file. | 76 // Every kWritesPerReset commands triggers recreating the file. |
| 76 static const int kWritesPerReset = 250; | 77 static const int kWritesPerReset = 250; |
| 77 | 78 |
| 78 namespace { | 79 namespace { |
| 79 | 80 |
| 80 // The callback from GetLastSession is internally routed to SessionService | 81 // The callback from GetLastSession is internally routed to SessionService |
| 81 // first and then the caller. This is done so that the SessionWindows can be | 82 // first and then the caller. This is done so that the SessionWindows can be |
| 82 // recreated from the SessionCommands and the SessionWindows passed to the | 83 // recreated from the SessionCommands and the SessionWindows passed to the |
| 83 // caller. The following class is used for this. | 84 // caller. The following class is used for this. |
| (...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 const std::string& extension_app_id) { | 711 const std::string& extension_app_id) { |
| 711 if (!ShouldTrackChangesToWindow(window_id)) | 712 if (!ShouldTrackChangesToWindow(window_id)) |
| 712 return; | 713 return; |
| 713 | 714 |
| 714 ScheduleCommand(CreateSetTabExtensionAppIDCommand( | 715 ScheduleCommand(CreateSetTabExtensionAppIDCommand( |
| 715 kCommandSetExtensionAppID, | 716 kCommandSetExtensionAppID, |
| 716 tab_id.id(), | 717 tab_id.id(), |
| 717 extension_app_id)); | 718 extension_app_id)); |
| 718 } | 719 } |
| 719 | 720 |
| 721 void SessionService::SetTabUserAgentOverride( |
| 722 const SessionID& window_id, |
| 723 const SessionID& tab_id, |
| 724 const std::string& user_agent_override) { |
| 725 if (!ShouldTrackChangesToWindow(window_id)) |
| 726 return; |
| 727 |
| 728 ScheduleCommand(CreateSetTabUserAgentOverrideCommand( |
| 729 kCommandSetTabUserAgentOverride, |
| 730 tab_id.id(), |
| 731 user_agent_override)); |
| 732 } |
| 733 |
| 720 SessionCommand* SessionService::CreateSetSelectedTabInWindow( | 734 SessionCommand* SessionService::CreateSetSelectedTabInWindow( |
| 721 const SessionID& window_id, | 735 const SessionID& window_id, |
| 722 int index) { | 736 int index) { |
| 723 SelectedTabInIndexPayload payload = { 0 }; | 737 SelectedTabInIndexPayload payload = { 0 }; |
| 724 payload.id = window_id.id(); | 738 payload.id = window_id.id(); |
| 725 payload.index = index; | 739 payload.index = index; |
| 726 SessionCommand* command = new SessionCommand(kCommandSetSelectedTabInIndex, | 740 SessionCommand* command = new SessionCommand(kCommandSetSelectedTabInIndex, |
| 727 sizeof(payload)); | 741 sizeof(payload)); |
| 728 memcpy(command->contents(), &payload, sizeof(payload)); | 742 memcpy(command->contents(), &payload, sizeof(payload)); |
| 729 return command; | 743 return command; |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1181 std::string extension_app_id; | 1195 std::string extension_app_id; |
| 1182 if (!RestoreSetTabExtensionAppIDCommand( | 1196 if (!RestoreSetTabExtensionAppIDCommand( |
| 1183 *command, &tab_id, &extension_app_id)) { | 1197 *command, &tab_id, &extension_app_id)) { |
| 1184 return true; | 1198 return true; |
| 1185 } | 1199 } |
| 1186 | 1200 |
| 1187 GetTab(tab_id, tabs)->extension_app_id.swap(extension_app_id); | 1201 GetTab(tab_id, tabs)->extension_app_id.swap(extension_app_id); |
| 1188 break; | 1202 break; |
| 1189 } | 1203 } |
| 1190 | 1204 |
| 1205 case kCommandSetTabUserAgentOverride: { |
| 1206 SessionID::id_type tab_id; |
| 1207 std::string user_agent_override; |
| 1208 if (!RestoreSetTabUserAgentOverrideCommand( |
| 1209 *command, &tab_id, &user_agent_override)) { |
| 1210 return true; |
| 1211 } |
| 1212 |
| 1213 GetTab(tab_id, tabs)->user_agent_override.swap(user_agent_override); |
| 1214 break; |
| 1215 } |
| 1216 |
| 1191 default: | 1217 default: |
| 1192 return true; | 1218 return true; |
| 1193 } | 1219 } |
| 1194 } | 1220 } |
| 1195 return true; | 1221 return true; |
| 1196 } | 1222 } |
| 1197 | 1223 |
| 1198 void SessionService::BuildCommandsForTab( | 1224 void SessionService::BuildCommandsForTab( |
| 1199 const SessionID& window_id, | 1225 const SessionID& window_id, |
| 1200 TabContentsWrapper* tab, | 1226 TabContentsWrapper* tab, |
| 1201 int index_in_window, | 1227 int index_in_window, |
| 1202 bool is_pinned, | 1228 bool is_pinned, |
| 1203 std::vector<SessionCommand*>* commands, | 1229 std::vector<SessionCommand*>* commands, |
| 1204 IdToRange* tab_to_available_range) { | 1230 IdToRange* tab_to_available_range) { |
| 1205 DCHECK(tab && commands && window_id.id()); | 1231 DCHECK(tab && commands && window_id.id()); |
| 1206 const SessionID& session_id(tab->restore_tab_helper()->session_id()); | 1232 const SessionID& session_id(tab->restore_tab_helper()->session_id()); |
| 1207 commands->push_back(CreateSetTabWindowCommand(window_id, session_id)); | 1233 commands->push_back(CreateSetTabWindowCommand(window_id, session_id)); |
| 1234 |
| 1208 const int current_index = | 1235 const int current_index = |
| 1209 tab->web_contents()->GetController().GetCurrentEntryIndex(); | 1236 tab->web_contents()->GetController().GetCurrentEntryIndex(); |
| 1210 const int min_index = std::max(0, | 1237 const int min_index = std::max(0, |
| 1211 current_index - max_persist_navigation_count); | 1238 current_index - max_persist_navigation_count); |
| 1212 const int max_index = | 1239 const int max_index = |
| 1213 std::min(current_index + max_persist_navigation_count, | 1240 std::min(current_index + max_persist_navigation_count, |
| 1214 tab->web_contents()->GetController().GetEntryCount()); | 1241 tab->web_contents()->GetController().GetEntryCount()); |
| 1215 const int pending_index = | 1242 const int pending_index = |
| 1216 tab->web_contents()->GetController().GetPendingEntryIndex(); | 1243 tab->web_contents()->GetController().GetPendingEntryIndex(); |
| 1217 if (tab_to_available_range) { | 1244 if (tab_to_available_range) { |
| 1218 (*tab_to_available_range)[session_id.id()] = | 1245 (*tab_to_available_range)[session_id.id()] = |
| 1219 std::pair<int, int>(min_index, max_index); | 1246 std::pair<int, int>(min_index, max_index); |
| 1220 } | 1247 } |
| 1248 |
| 1221 if (is_pinned) { | 1249 if (is_pinned) { |
| 1222 commands->push_back(CreatePinnedStateCommand(session_id, true)); | 1250 commands->push_back(CreatePinnedStateCommand(session_id, true)); |
| 1223 } | 1251 } |
| 1252 |
| 1224 TabContentsWrapper* wrapper = | 1253 TabContentsWrapper* wrapper = |
| 1225 TabContentsWrapper::GetCurrentWrapperForContents(tab->web_contents()); | 1254 TabContentsWrapper::GetCurrentWrapperForContents(tab->web_contents()); |
| 1226 if (wrapper->extension_tab_helper()->extension_app()) { | 1255 if (wrapper->extension_tab_helper()->extension_app()) { |
| 1227 commands->push_back( | 1256 commands->push_back( |
| 1228 CreateSetTabExtensionAppIDCommand( | 1257 CreateSetTabExtensionAppIDCommand( |
| 1229 kCommandSetExtensionAppID, session_id.id(), | 1258 kCommandSetExtensionAppID, session_id.id(), |
| 1230 wrapper->extension_tab_helper()->extension_app()->id())); | 1259 wrapper->extension_tab_helper()->extension_app()->id())); |
| 1231 } | 1260 } |
| 1261 |
| 1262 const std::string& ua_override = tab->web_contents()->GetUserAgentOverride(); |
| 1263 if (!ua_override.empty()) { |
| 1264 commands->push_back( |
| 1265 CreateSetTabUserAgentOverrideCommand( |
| 1266 kCommandSetTabUserAgentOverride, session_id.id(), ua_override)); |
| 1267 } |
| 1268 |
| 1232 for (int i = min_index; i < max_index; ++i) { | 1269 for (int i = min_index; i < max_index; ++i) { |
| 1233 const NavigationEntry* entry = (i == pending_index) ? | 1270 const NavigationEntry* entry = (i == pending_index) ? |
| 1234 tab->web_contents()->GetController().GetPendingEntry() : | 1271 tab->web_contents()->GetController().GetPendingEntry() : |
| 1235 tab->web_contents()->GetController().GetEntryAtIndex(i); | 1272 tab->web_contents()->GetController().GetEntryAtIndex(i); |
| 1236 DCHECK(entry); | 1273 DCHECK(entry); |
| 1237 if (ShouldTrackEntry(entry->GetVirtualURL())) { | 1274 if (ShouldTrackEntry(entry->GetVirtualURL())) { |
| 1238 commands->push_back( | 1275 commands->push_back( |
| 1239 CreateUpdateTabNavigationCommand( | 1276 CreateUpdateTabNavigationCommand( |
| 1240 kCommandUpdateTabNavigation, session_id.id(), i, *entry)); | 1277 kCommandUpdateTabNavigation, session_id.id(), i, *entry)); |
| 1241 } | 1278 } |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1622 50); | 1659 50); |
| 1623 if (use_long_period) { | 1660 if (use_long_period) { |
| 1624 std::string long_name_("SessionRestore.SaveLongPeriod"); | 1661 std::string long_name_("SessionRestore.SaveLongPeriod"); |
| 1625 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, | 1662 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, |
| 1626 delta, | 1663 delta, |
| 1627 save_delay_in_mins_, | 1664 save_delay_in_mins_, |
| 1628 save_delay_in_hrs_, | 1665 save_delay_in_hrs_, |
| 1629 50); | 1666 50); |
| 1630 } | 1667 } |
| 1631 } | 1668 } |
| OLD | NEW |