Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: chrome/browser/sessions/session_service.cc

Issue 9447084: Refactor Pickle Read methods to use higher performance PickleIterator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: jar feedback Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 1245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 } 1256 }
1257 StartSaveTimer(); 1257 StartSaveTimer();
1258 } 1258 }
1259 1259
1260 bool SessionService::ReplacePendingCommand(SessionCommand* command) { 1260 bool SessionService::ReplacePendingCommand(SessionCommand* command) {
1261 // We only optimize page navigations, which can happen quite frequently and 1261 // We only optimize page navigations, which can happen quite frequently and
1262 // are expensive. If necessary, other commands could be searched for as 1262 // are expensive. If necessary, other commands could be searched for as
1263 // well. 1263 // well.
1264 if (command->id() != kCommandUpdateTabNavigation) 1264 if (command->id() != kCommandUpdateTabNavigation)
1265 return false; 1265 return false;
1266 void* iterator = NULL;
1267 scoped_ptr<Pickle> command_pickle(command->PayloadAsPickle()); 1266 scoped_ptr<Pickle> command_pickle(command->PayloadAsPickle());
1267 PickleReader iterator(*command_pickle);
1268 SessionID::id_type command_tab_id; 1268 SessionID::id_type command_tab_id;
1269 int command_nav_index; 1269 int command_nav_index;
1270 if (!command_pickle->ReadInt(&iterator, &command_tab_id) || 1270 if (!command_pickle->ReadInt(&iterator, &command_tab_id) ||
1271 !command_pickle->ReadInt(&iterator, &command_nav_index)) { 1271 !command_pickle->ReadInt(&iterator, &command_nav_index)) {
1272 return false; 1272 return false;
1273 } 1273 }
1274 for (std::vector<SessionCommand*>::reverse_iterator i = 1274 for (std::vector<SessionCommand*>::reverse_iterator i =
1275 pending_commands().rbegin(); i != pending_commands().rend(); ++i) { 1275 pending_commands().rbegin(); i != pending_commands().rend(); ++i) {
1276 SessionCommand* existing_command = *i; 1276 SessionCommand* existing_command = *i;
1277 if (existing_command->id() == kCommandUpdateTabNavigation) { 1277 if (existing_command->id() == kCommandUpdateTabNavigation) {
1278 SessionID::id_type existing_tab_id; 1278 SessionID::id_type existing_tab_id;
1279 int existing_nav_index; 1279 int existing_nav_index;
1280 { 1280 {
1281 // Creating a pickle like this means the Pickle references the data from 1281 // Creating a pickle like this means the Pickle references the data from
1282 // the command. Make sure we delete the pickle before the command, else 1282 // the command. Make sure we delete the pickle before the command, else
1283 // the pickle references deleted memory. 1283 // the pickle references deleted memory.
1284 scoped_ptr<Pickle> existing_pickle(existing_command->PayloadAsPickle()); 1284 scoped_ptr<Pickle> existing_pickle(existing_command->PayloadAsPickle());
1285 iterator = NULL; 1285 iterator = PickleReader(*existing_pickle);
1286 if (!existing_pickle->ReadInt(&iterator, &existing_tab_id) || 1286 if (!existing_pickle->ReadInt(&iterator, &existing_tab_id) ||
1287 !existing_pickle->ReadInt(&iterator, &existing_nav_index)) { 1287 !existing_pickle->ReadInt(&iterator, &existing_nav_index)) {
1288 return false; 1288 return false;
1289 } 1289 }
1290 } 1290 }
1291 if (existing_tab_id == command_tab_id && 1291 if (existing_tab_id == command_tab_id &&
1292 existing_nav_index == command_nav_index) { 1292 existing_nav_index == command_nav_index) {
1293 // existing_command is an update for the same tab/index pair. Replace 1293 // existing_command is an update for the same tab/index pair. Replace
1294 // it with the new one. We need to add to the end of the list just in 1294 // it with the new one. We need to add to the end of the list just in
1295 // case there is a prune command after the update command. 1295 // case there is a prune command after the update command.
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1532 50); 1532 50);
1533 if (use_long_period) { 1533 if (use_long_period) {
1534 std::string long_name_("SessionRestore.SaveLongPeriod"); 1534 std::string long_name_("SessionRestore.SaveLongPeriod");
1535 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_, 1535 UMA_HISTOGRAM_CUSTOM_TIMES(long_name_,
1536 delta, 1536 delta,
1537 save_delay_in_mins_, 1537 save_delay_in_mins_,
1538 save_delay_in_hrs_, 1538 save_delay_in_hrs_,
1539 50); 1539 50);
1540 } 1540 }
1541 } 1541 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698