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

Side by Side Diff: components/sessions/core/persistent_tab_restore_service.cc

Issue 2600583002: Remove ScopedVector from components/sessions. (Closed)
Patch Set: include Created 3 years, 11 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "components/sessions/core/persistent_tab_restore_service.h" 5 #include "components/sessions/core/persistent_tab_restore_service.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <string.h> 9 #include <string.h>
10 #include <utility> 10 #include <utility>
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 204
205 // Returns the index to persist as the selected index. This is the same as 205 // Returns the index to persist as the selected index. This is the same as
206 // |tab.current_navigation_index| unless the entry at 206 // |tab.current_navigation_index| unless the entry at
207 // |tab.current_navigation_index| shouldn't be persisted. Returns -1 if no 207 // |tab.current_navigation_index| shouldn't be persisted. Returns -1 if no
208 // valid navigation to persist. 208 // valid navigation to persist.
209 int GetSelectedNavigationIndexToPersist(const Tab& tab); 209 int GetSelectedNavigationIndexToPersist(const Tab& tab);
210 210
211 // Invoked when we've loaded the session commands that identify the previously 211 // Invoked when we've loaded the session commands that identify the previously
212 // closed tabs. This creates entries, adds them to staging_entries_, and 212 // closed tabs. This creates entries, adds them to staging_entries_, and
213 // invokes LoadState. 213 // invokes LoadState.
214 void OnGotLastSessionCommands(ScopedVector<SessionCommand> commands); 214 void OnGotLastSessionCommands(
215 std::vector<std::unique_ptr<SessionCommand>> commands);
215 216
216 // Populates |loaded_entries| with Entries from |commands|. 217 // Populates |loaded_entries| with Entries from |commands|.
217 void CreateEntriesFromCommands( 218 void CreateEntriesFromCommands(
218 const std::vector<SessionCommand*>& commands, 219 const std::vector<std::unique_ptr<SessionCommand>>& commands,
219 std::vector<std::unique_ptr<Entry>>* loaded_entries); 220 std::vector<std::unique_ptr<Entry>>* loaded_entries);
220 221
221 // Validates all entries in |entries|, deleting any with no navigations. This 222 // Validates all entries in |entries|, deleting any with no navigations. This
222 // also deletes any entries beyond the max number of entries we can hold. 223 // also deletes any entries beyond the max number of entries we can hold.
223 static void ValidateAndDeleteEmptyEntries( 224 static void ValidateAndDeleteEmptyEntries(
224 std::vector<std::unique_ptr<Entry>>* entries); 225 std::vector<std::unique_ptr<Entry>>* entries);
225 226
226 // Callback from BaseSessionService when we've received the windows from the 227 // Callback from BaseSessionService when we've received the windows from the
227 // previous session. This creates and add entries to |staging_entries_| and 228 // previous session. This creates and add entries to |staging_entries_| and
228 // invokes LoadStateChanged. |ignored_active_window| is ignored because we 229 // invokes LoadStateChanged. |ignored_active_window| is ignored because we
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 while (selected_index < max_index && 572 while (selected_index < max_index &&
572 !client_->ShouldTrackURLForRestore( 573 !client_->ShouldTrackURLForRestore(
573 navigations[selected_index].virtual_url())) { 574 navigations[selected_index].virtual_url())) {
574 selected_index++; 575 selected_index++;
575 } 576 }
576 577
577 return (selected_index == max_index) ? -1 : selected_index; 578 return (selected_index == max_index) ? -1 : selected_index;
578 } 579 }
579 580
580 void PersistentTabRestoreService::Delegate::OnGotLastSessionCommands( 581 void PersistentTabRestoreService::Delegate::OnGotLastSessionCommands(
581 ScopedVector<SessionCommand> commands) { 582 std::vector<std::unique_ptr<SessionCommand>> commands) {
582 std::vector<std::unique_ptr<TabRestoreService::Entry>> entries; 583 std::vector<std::unique_ptr<TabRestoreService::Entry>> entries;
583 CreateEntriesFromCommands(commands.get(), &entries); 584 CreateEntriesFromCommands(commands, &entries);
584 // Closed tabs always go to the end. 585 // Closed tabs always go to the end.
585 staging_entries_.insert(staging_entries_.end(), 586 staging_entries_.insert(staging_entries_.end(),
586 make_move_iterator(entries.begin()), 587 make_move_iterator(entries.begin()),
587 make_move_iterator(entries.end())); 588 make_move_iterator(entries.end()));
588 load_state_ |= LOADED_LAST_TABS; 589 load_state_ |= LOADED_LAST_TABS;
589 LoadStateChanged(); 590 LoadStateChanged();
590 } 591 }
591 592
592 void PersistentTabRestoreService::Delegate::CreateEntriesFromCommands( 593 void PersistentTabRestoreService::Delegate::CreateEntriesFromCommands(
593 const std::vector<SessionCommand*>& commands, 594 const std::vector<std::unique_ptr<SessionCommand>>& commands,
594 std::vector<std::unique_ptr<Entry>>* loaded_entries) { 595 std::vector<std::unique_ptr<Entry>>* loaded_entries) {
595 if (tab_restore_service_helper_->entries().size() == kMaxEntries) 596 if (tab_restore_service_helper_->entries().size() == kMaxEntries)
596 return; 597 return;
597 598
598 // Iterate through the commands, populating |entries|. 599 // Iterate through the commands, populating |entries|.
599 std::vector<std::unique_ptr<Entry>> entries; 600 std::vector<std::unique_ptr<Entry>> entries;
600 // If non-null we're processing the navigations of this tab. 601 // If non-null we're processing the navigations of this tab.
601 Tab* current_tab = nullptr; 602 Tab* current_tab = nullptr;
602 // If non-null we're processing the tabs of this window. 603 // If non-null we're processing the tabs of this window.
603 Window* current_window = nullptr; 604 Window* current_window = nullptr;
604 // If > 0, we've gotten a window command but not all the tabs yet. 605 // If > 0, we've gotten a window command but not all the tabs yet.
605 int pending_window_tabs = 0; 606 int pending_window_tabs = 0;
606 for (std::vector<SessionCommand*>::const_iterator i = commands.begin(); 607 for (auto i = commands.begin(); i != commands.end(); ++i) {
607 i != commands.end(); ++i) {
608 const SessionCommand& command = *(*i); 608 const SessionCommand& command = *(*i);
609 switch (command.id()) { 609 switch (command.id()) {
610 case kCommandRestoredEntry: { 610 case kCommandRestoredEntry: {
611 if (pending_window_tabs > 0) { 611 if (pending_window_tabs > 0) {
612 // Should never receive a restored command while waiting for all the 612 // Should never receive a restored command while waiting for all the
613 // tabs in a window. 613 // tabs in a window.
614 return; 614 return;
615 } 615 }
616 616
617 current_tab = nullptr; 617 current_tab = nullptr;
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 964
965 TabRestoreService::Entries* PersistentTabRestoreService::mutable_entries() { 965 TabRestoreService::Entries* PersistentTabRestoreService::mutable_entries() {
966 return &helper_.entries_; 966 return &helper_.entries_;
967 } 967 }
968 968
969 void PersistentTabRestoreService::PruneEntries() { 969 void PersistentTabRestoreService::PruneEntries() {
970 helper_.PruneEntries(); 970 helper_.PruneEntries();
971 } 971 }
972 972
973 } // namespace sessions 973 } // namespace sessions
OLDNEW
« no previous file with comments | « components/sessions/core/base_session_service_test_helper.cc ('k') | components/sessions/core/session_backend.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698