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 1286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1297 } | 1297 } |
1298 StartSaveTimer(); | 1298 StartSaveTimer(); |
1299 } | 1299 } |
1300 | 1300 |
1301 bool SessionService::ReplacePendingCommand(SessionCommand* command) { | 1301 bool SessionService::ReplacePendingCommand(SessionCommand* command) { |
1302 // We only optimize page navigations, which can happen quite frequently and | 1302 // We only optimize page navigations, which can happen quite frequently and |
1303 // are expensive. If necessary, other commands could be searched for as | 1303 // are expensive. If necessary, other commands could be searched for as |
1304 // well. | 1304 // well. |
1305 if (command->id() != kCommandUpdateTabNavigation) | 1305 if (command->id() != kCommandUpdateTabNavigation) |
1306 return false; | 1306 return false; |
1307 void* iterator = NULL; | |
1308 scoped_ptr<Pickle> command_pickle(command->PayloadAsPickle()); | 1307 scoped_ptr<Pickle> command_pickle(command->PayloadAsPickle()); |
| 1308 PickleIterator iterator(*command_pickle); |
1309 SessionID::id_type command_tab_id; | 1309 SessionID::id_type command_tab_id; |
1310 int command_nav_index; | 1310 int command_nav_index; |
1311 if (!command_pickle->ReadInt(&iterator, &command_tab_id) || | 1311 if (!command_pickle->ReadInt(&iterator, &command_tab_id) || |
1312 !command_pickle->ReadInt(&iterator, &command_nav_index)) { | 1312 !command_pickle->ReadInt(&iterator, &command_nav_index)) { |
1313 return false; | 1313 return false; |
1314 } | 1314 } |
1315 for (std::vector<SessionCommand*>::reverse_iterator i = | 1315 for (std::vector<SessionCommand*>::reverse_iterator i = |
1316 pending_commands().rbegin(); i != pending_commands().rend(); ++i) { | 1316 pending_commands().rbegin(); i != pending_commands().rend(); ++i) { |
1317 SessionCommand* existing_command = *i; | 1317 SessionCommand* existing_command = *i; |
1318 if (existing_command->id() == kCommandUpdateTabNavigation) { | 1318 if (existing_command->id() == kCommandUpdateTabNavigation) { |
1319 SessionID::id_type existing_tab_id; | 1319 SessionID::id_type existing_tab_id; |
1320 int existing_nav_index; | 1320 int existing_nav_index; |
1321 { | 1321 { |
1322 // Creating a pickle like this means the Pickle references the data from | 1322 // Creating a pickle like this means the Pickle references the data from |
1323 // the command. Make sure we delete the pickle before the command, else | 1323 // the command. Make sure we delete the pickle before the command, else |
1324 // the pickle references deleted memory. | 1324 // the pickle references deleted memory. |
1325 scoped_ptr<Pickle> existing_pickle(existing_command->PayloadAsPickle()); | 1325 scoped_ptr<Pickle> existing_pickle(existing_command->PayloadAsPickle()); |
1326 iterator = NULL; | 1326 iterator = PickleIterator(*existing_pickle); |
1327 if (!existing_pickle->ReadInt(&iterator, &existing_tab_id) || | 1327 if (!existing_pickle->ReadInt(&iterator, &existing_tab_id) || |
1328 !existing_pickle->ReadInt(&iterator, &existing_nav_index)) { | 1328 !existing_pickle->ReadInt(&iterator, &existing_nav_index)) { |
1329 return false; | 1329 return false; |
1330 } | 1330 } |
1331 } | 1331 } |
1332 if (existing_tab_id == command_tab_id && | 1332 if (existing_tab_id == command_tab_id && |
1333 existing_nav_index == command_nav_index) { | 1333 existing_nav_index == command_nav_index) { |
1334 // existing_command is an update for the same tab/index pair. Replace | 1334 // existing_command is an update for the same tab/index pair. Replace |
1335 // it with the new one. We need to add to the end of the list just in | 1335 // it with the new one. We need to add to the end of the list just in |
1336 // case there is a prune command after the update command. | 1336 // case there is a prune command after the update command. |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1583 50); | 1583 50); |
1584 if (use_long_period) { | 1584 if (use_long_period) { |
1585 std::string long_name_("SessionRestore.SaveLongPeriod"); | 1585 std::string long_name_("SessionRestore.SaveLongPeriod"); |
1586 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, | 1586 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, |
1587 delta, | 1587 delta, |
1588 save_delay_in_mins_, | 1588 save_delay_in_mins_, |
1589 save_delay_in_hrs_, | 1589 save_delay_in_hrs_, |
1590 50); | 1590 50); |
1591 } | 1591 } |
1592 } | 1592 } |
OLD | NEW |