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

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

Issue 8776018: fix tab restore service crash (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: always prune Created 9 years 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/tab_restore_service.h" 5 #include "chrome/browser/sessions/tab_restore_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <map> 9 #include <map>
10 10
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 if (!FilterEntry(entry) || (entries_.size() >= kMaxEntries && !to_front)) { 530 if (!FilterEntry(entry) || (entries_.size() >= kMaxEntries && !to_front)) {
531 delete entry; 531 delete entry;
532 return; 532 return;
533 } 533 }
534 534
535 if (to_front) 535 if (to_front)
536 entries_.push_front(entry); 536 entries_.push_front(entry);
537 else 537 else
538 entries_.push_back(entry); 538 entries_.push_back(entry);
539 539
540 PruneEntries();
541
540 if (notify) 542 if (notify)
541 NotifyTabsChanged(); 543 NotifyTabsChanged();
542 544
543 // Start the save timer, when it fires we'll generate the commands. 545 // Start the save timer, when it fires we'll generate the commands.
544 StartSaveTimer(); 546 StartSaveTimer();
545 entries_to_write_++; 547 entries_to_write_++;
546 } 548 }
547 549
548 void TabRestoreService::PruneEntries() { 550 void TabRestoreService::PruneEntries() {
549 Entries new_entries; 551 Entries new_entries;
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
1114 void TabRestoreService::LoadStateChanged() { 1116 void TabRestoreService::LoadStateChanged() {
1115 if ((load_state_ & (LOADED_LAST_TABS | LOADED_LAST_SESSION)) != 1117 if ((load_state_ & (LOADED_LAST_TABS | LOADED_LAST_SESSION)) !=
1116 (LOADED_LAST_TABS | LOADED_LAST_SESSION)) { 1118 (LOADED_LAST_TABS | LOADED_LAST_SESSION)) {
1117 // Still waiting on previous session or previous tabs. 1119 // Still waiting on previous session or previous tabs.
1118 return; 1120 return;
1119 } 1121 }
1120 1122
1121 // We're done loading. 1123 // We're done loading.
1122 load_state_ ^= LOADING; 1124 load_state_ ^= LOADING;
1123 1125
1124 if (entries_.size() == kMaxEntries) { 1126 if (staging_entries_.empty() || entries_.size() >= kMaxEntries) {
1125 STLDeleteElements(&staging_entries_); 1127 STLDeleteElements(&staging_entries_);
1126 return; 1128 return;
1127 } 1129 }
1128 1130
1129 if (staging_entries_.size() + entries_.size() > kMaxEntries) { 1131 if (staging_entries_.size() + entries_.size() > kMaxEntries) {
1130 // If we add all the staged entries we'll end up with more than 1132 // If we add all the staged entries we'll end up with more than
1131 // kMaxEntries. Delete entries such that we only end up with 1133 // kMaxEntries. Delete entries such that we only end up with
1132 // at most kMaxEntries. 1134 // at most kMaxEntries.
1133 DCHECK(entries_.size() < kMaxEntries); 1135 int surplus = kMaxEntries - entries_.size();
1136 CHECK_LE(0, surplus);
1137 CHECK_GE(static_cast<int>(staging_entries_.size()), surplus);
1134 STLDeleteContainerPointers( 1138 STLDeleteContainerPointers(
1135 staging_entries_.begin() + (kMaxEntries - entries_.size()), 1139 staging_entries_.begin() + (kMaxEntries - entries_.size()),
1136 staging_entries_.end()); 1140 staging_entries_.end());
1137 staging_entries_.erase( 1141 staging_entries_.erase(
1138 staging_entries_.begin() + (kMaxEntries - entries_.size()), 1142 staging_entries_.begin() + (kMaxEntries - entries_.size()),
1139 staging_entries_.end()); 1143 staging_entries_.end());
1140 } 1144 }
1141 1145
1142 // And add them. 1146 // And add them.
1143 for (size_t i = 0; i < staging_entries_.size(); ++i) { 1147 for (size_t i = 0; i < staging_entries_.size(); ++i) {
(...skipping 10 matching lines...) Expand all
1154 // the front, not the end and we just added the entries to the end). 1158 // the front, not the end and we just added the entries to the end).
1155 entries_to_write_ = staging_entries_.size(); 1159 entries_to_write_ = staging_entries_.size();
1156 1160
1157 PruneEntries(); 1161 PruneEntries();
1158 NotifyTabsChanged(); 1162 NotifyTabsChanged();
1159 } 1163 }
1160 1164
1161 Time TabRestoreService::TimeNow() const { 1165 Time TabRestoreService::TimeNow() const {
1162 return time_factory_ ? time_factory_->TimeNow() : Time::Now(); 1166 return time_factory_ ? time_factory_->TimeNow() : Time::Now();
1163 } 1167 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/tab_restore_service.h ('k') | chrome/browser/sessions/tab_restore_service_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698