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 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 const std::string& extension_app_id) { | 707 const std::string& extension_app_id) { |
707 if (!ShouldTrackChangesToWindow(window_id)) | 708 if (!ShouldTrackChangesToWindow(window_id)) |
708 return; | 709 return; |
709 | 710 |
710 ScheduleCommand(CreateSetTabExtensionAppIDCommand( | 711 ScheduleCommand(CreateSetTabExtensionAppIDCommand( |
711 kCommandSetExtensionAppID, | 712 kCommandSetExtensionAppID, |
712 tab_id.id(), | 713 tab_id.id(), |
713 extension_app_id)); | 714 extension_app_id)); |
714 } | 715 } |
715 | 716 |
| 717 void SessionService::SetTabUserAgentOverride( |
| 718 const SessionID& window_id, |
| 719 const SessionID& tab_id, |
| 720 const std::string& user_agent_override) { |
| 721 if (!ShouldTrackChangesToWindow(window_id)) |
| 722 return; |
| 723 |
| 724 ScheduleCommand(CreateSetTabUserAgentOverrideCommand( |
| 725 kCommandSetTabUserAgentOverride, |
| 726 tab_id.id(), |
| 727 user_agent_override)); |
| 728 } |
| 729 |
716 SessionCommand* SessionService::CreateSetSelectedTabInWindow( | 730 SessionCommand* SessionService::CreateSetSelectedTabInWindow( |
717 const SessionID& window_id, | 731 const SessionID& window_id, |
718 int index) { | 732 int index) { |
719 SelectedTabInIndexPayload payload = { 0 }; | 733 SelectedTabInIndexPayload payload = { 0 }; |
720 payload.id = window_id.id(); | 734 payload.id = window_id.id(); |
721 payload.index = index; | 735 payload.index = index; |
722 SessionCommand* command = new SessionCommand(kCommandSetSelectedTabInIndex, | 736 SessionCommand* command = new SessionCommand(kCommandSetSelectedTabInIndex, |
723 sizeof(payload)); | 737 sizeof(payload)); |
724 memcpy(command->contents(), &payload, sizeof(payload)); | 738 memcpy(command->contents(), &payload, sizeof(payload)); |
725 return command; | 739 return command; |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1177 std::string extension_app_id; | 1191 std::string extension_app_id; |
1178 if (!RestoreSetTabExtensionAppIDCommand( | 1192 if (!RestoreSetTabExtensionAppIDCommand( |
1179 *command, &tab_id, &extension_app_id)) { | 1193 *command, &tab_id, &extension_app_id)) { |
1180 return true; | 1194 return true; |
1181 } | 1195 } |
1182 | 1196 |
1183 GetTab(tab_id, tabs)->extension_app_id.swap(extension_app_id); | 1197 GetTab(tab_id, tabs)->extension_app_id.swap(extension_app_id); |
1184 break; | 1198 break; |
1185 } | 1199 } |
1186 | 1200 |
| 1201 case kCommandSetTabUserAgentOverride: { |
| 1202 SessionID::id_type tab_id; |
| 1203 std::string user_agent_override; |
| 1204 if (!RestoreSetTabUserAgentOverrideCommand( |
| 1205 *command, &tab_id, &user_agent_override)) { |
| 1206 return true; |
| 1207 } |
| 1208 |
| 1209 GetTab(tab_id, tabs)->user_agent_override.swap(user_agent_override); |
| 1210 break; |
| 1211 } |
| 1212 |
1187 default: | 1213 default: |
1188 return true; | 1214 return true; |
1189 } | 1215 } |
1190 } | 1216 } |
1191 return true; | 1217 return true; |
1192 } | 1218 } |
1193 | 1219 |
1194 void SessionService::BuildCommandsForTab( | 1220 void SessionService::BuildCommandsForTab( |
1195 const SessionID& window_id, | 1221 const SessionID& window_id, |
1196 TabContentsWrapper* tab, | 1222 TabContentsWrapper* tab, |
1197 int index_in_window, | 1223 int index_in_window, |
1198 bool is_pinned, | 1224 bool is_pinned, |
1199 std::vector<SessionCommand*>* commands, | 1225 std::vector<SessionCommand*>* commands, |
1200 IdToRange* tab_to_available_range) { | 1226 IdToRange* tab_to_available_range) { |
1201 DCHECK(tab && commands && window_id.id()); | 1227 DCHECK(tab && commands && window_id.id()); |
1202 const SessionID& session_id(tab->restore_tab_helper()->session_id()); | 1228 const SessionID& session_id(tab->restore_tab_helper()->session_id()); |
1203 commands->push_back(CreateSetTabWindowCommand(window_id, session_id)); | 1229 commands->push_back(CreateSetTabWindowCommand(window_id, session_id)); |
| 1230 |
1204 const int current_index = | 1231 const int current_index = |
1205 tab->web_contents()->GetController().GetCurrentEntryIndex(); | 1232 tab->web_contents()->GetController().GetCurrentEntryIndex(); |
1206 const int min_index = std::max(0, | 1233 const int min_index = std::max(0, |
1207 current_index - max_persist_navigation_count); | 1234 current_index - max_persist_navigation_count); |
1208 const int max_index = | 1235 const int max_index = |
1209 std::min(current_index + max_persist_navigation_count, | 1236 std::min(current_index + max_persist_navigation_count, |
1210 tab->web_contents()->GetController().GetEntryCount()); | 1237 tab->web_contents()->GetController().GetEntryCount()); |
1211 const int pending_index = | 1238 const int pending_index = |
1212 tab->web_contents()->GetController().GetPendingEntryIndex(); | 1239 tab->web_contents()->GetController().GetPendingEntryIndex(); |
1213 if (tab_to_available_range) { | 1240 if (tab_to_available_range) { |
1214 (*tab_to_available_range)[session_id.id()] = | 1241 (*tab_to_available_range)[session_id.id()] = |
1215 std::pair<int, int>(min_index, max_index); | 1242 std::pair<int, int>(min_index, max_index); |
1216 } | 1243 } |
| 1244 |
1217 if (is_pinned) { | 1245 if (is_pinned) { |
1218 commands->push_back(CreatePinnedStateCommand(session_id, true)); | 1246 commands->push_back(CreatePinnedStateCommand(session_id, true)); |
1219 } | 1247 } |
| 1248 |
1220 TabContentsWrapper* wrapper = | 1249 TabContentsWrapper* wrapper = |
1221 TabContentsWrapper::GetCurrentWrapperForContents(tab->web_contents()); | 1250 TabContentsWrapper::GetCurrentWrapperForContents(tab->web_contents()); |
1222 if (wrapper->extension_tab_helper()->extension_app()) { | 1251 if (wrapper->extension_tab_helper()->extension_app()) { |
1223 commands->push_back( | 1252 commands->push_back( |
1224 CreateSetTabExtensionAppIDCommand( | 1253 CreateSetTabExtensionAppIDCommand( |
1225 kCommandSetExtensionAppID, session_id.id(), | 1254 kCommandSetExtensionAppID, session_id.id(), |
1226 wrapper->extension_tab_helper()->extension_app()->id())); | 1255 wrapper->extension_tab_helper()->extension_app()->id())); |
1227 } | 1256 } |
| 1257 |
| 1258 const std::string& ua_override = tab->web_contents()->GetUserAgentOverride(); |
| 1259 if (!ua_override.empty()) { |
| 1260 commands->push_back( |
| 1261 CreateSetTabUserAgentOverrideCommand( |
| 1262 kCommandSetTabUserAgentOverride, session_id.id(), ua_override)); |
| 1263 } |
| 1264 |
1228 for (int i = min_index; i < max_index; ++i) { | 1265 for (int i = min_index; i < max_index; ++i) { |
1229 const NavigationEntry* entry = (i == pending_index) ? | 1266 const NavigationEntry* entry = (i == pending_index) ? |
1230 tab->web_contents()->GetController().GetPendingEntry() : | 1267 tab->web_contents()->GetController().GetPendingEntry() : |
1231 tab->web_contents()->GetController().GetEntryAtIndex(i); | 1268 tab->web_contents()->GetController().GetEntryAtIndex(i); |
1232 DCHECK(entry); | 1269 DCHECK(entry); |
1233 if (ShouldTrackEntry(entry->GetVirtualURL())) { | 1270 if (ShouldTrackEntry(entry->GetVirtualURL())) { |
1234 commands->push_back( | 1271 commands->push_back( |
1235 CreateUpdateTabNavigationCommand( | 1272 CreateUpdateTabNavigationCommand( |
1236 kCommandUpdateTabNavigation, session_id.id(), i, *entry)); | 1273 kCommandUpdateTabNavigation, session_id.id(), i, *entry)); |
1237 } | 1274 } |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1618 50); | 1655 50); |
1619 if (use_long_period) { | 1656 if (use_long_period) { |
1620 std::string long_name_("SessionRestore.SaveLongPeriod"); | 1657 std::string long_name_("SessionRestore.SaveLongPeriod"); |
1621 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, | 1658 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, |
1622 delta, | 1659 delta, |
1623 save_delay_in_mins_, | 1660 save_delay_in_mins_, |
1624 save_delay_in_hrs_, | 1661 save_delay_in_hrs_, |
1625 50); | 1662 50); |
1626 } | 1663 } |
1627 } | 1664 } |
OLD | NEW |