| 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/persistent_tab_restore_service.h" | 5 #include "chrome/browser/sessions/persistent_tab_restore_service.h" |
| 6 | 6 |
| 7 #include <cstring> // memcpy | 7 #include <cstring> // memcpy |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 for (size_t i = 0; i < window.tabs.size(); ++i) { | 407 for (size_t i = 0; i < window.tabs.size(); ++i) { |
| 408 int selected_index = GetSelectedNavigationIndexToPersist(window.tabs[i]); | 408 int selected_index = GetSelectedNavigationIndexToPersist(window.tabs[i]); |
| 409 if (selected_index != -1) | 409 if (selected_index != -1) |
| 410 ScheduleCommandsForTab(window.tabs[i], selected_index); | 410 ScheduleCommandsForTab(window.tabs[i], selected_index); |
| 411 } | 411 } |
| 412 } | 412 } |
| 413 | 413 |
| 414 void PersistentTabRestoreService::Delegate::ScheduleCommandsForTab( | 414 void PersistentTabRestoreService::Delegate::ScheduleCommandsForTab( |
| 415 const Tab& tab, | 415 const Tab& tab, |
| 416 int selected_index) { | 416 int selected_index) { |
| 417 const std::vector<TabNavigation>& navigations = tab.navigations; | 417 const std::vector<components::SerializedNavigationEntry>& navigations = |
| 418 tab.navigations; |
| 418 int max_index = static_cast<int>(navigations.size()); | 419 int max_index = static_cast<int>(navigations.size()); |
| 419 | 420 |
| 420 // Determine the first navigation we'll persist. | 421 // Determine the first navigation we'll persist. |
| 421 int valid_count_before_selected = 0; | 422 int valid_count_before_selected = 0; |
| 422 int first_index_to_persist = selected_index; | 423 int first_index_to_persist = selected_index; |
| 423 for (int i = selected_index - 1; i >= 0 && | 424 for (int i = selected_index - 1; i >= 0 && |
| 424 valid_count_before_selected < max_persist_navigation_count; --i) { | 425 valid_count_before_selected < max_persist_navigation_count; --i) { |
| 425 if (ShouldTrackEntry(navigations[i].virtual_url())) { | 426 if (ShouldTrackEntry(navigations[i].virtual_url())) { |
| 426 first_index_to_persist = i; | 427 first_index_to_persist = i; |
| 427 valid_count_before_selected++; | 428 valid_count_before_selected++; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 SessionID::id_type entry_id) { | 509 SessionID::id_type entry_id) { |
| 509 RestoredEntryPayload payload = entry_id; | 510 RestoredEntryPayload payload = entry_id; |
| 510 SessionCommand* command = | 511 SessionCommand* command = |
| 511 new SessionCommand(kCommandRestoredEntry, sizeof(payload)); | 512 new SessionCommand(kCommandRestoredEntry, sizeof(payload)); |
| 512 memcpy(command->contents(), &payload, sizeof(payload)); | 513 memcpy(command->contents(), &payload, sizeof(payload)); |
| 513 return command; | 514 return command; |
| 514 } | 515 } |
| 515 | 516 |
| 516 int PersistentTabRestoreService::Delegate::GetSelectedNavigationIndexToPersist( | 517 int PersistentTabRestoreService::Delegate::GetSelectedNavigationIndexToPersist( |
| 517 const Tab& tab) { | 518 const Tab& tab) { |
| 518 const std::vector<TabNavigation>& navigations = tab.navigations; | 519 const std::vector<components::SerializedNavigationEntry>& navigations = |
| 520 tab.navigations; |
| 519 int selected_index = tab.current_navigation_index; | 521 int selected_index = tab.current_navigation_index; |
| 520 int max_index = static_cast<int>(navigations.size()); | 522 int max_index = static_cast<int>(navigations.size()); |
| 521 | 523 |
| 522 // Find the first navigation to persist. We won't persist the selected | 524 // Find the first navigation to persist. We won't persist the selected |
| 523 // navigation if ShouldTrackEntry returns false. | 525 // navigation if ShouldTrackEntry returns false. |
| 524 while (selected_index >= 0 && | 526 while (selected_index >= 0 && |
| 525 !ShouldTrackEntry(navigations[selected_index].virtual_url())) { | 527 !ShouldTrackEntry(navigations[selected_index].virtual_url())) { |
| 526 selected_index--; | 528 selected_index--; |
| 527 } | 529 } |
| 528 | 530 |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 } | 973 } |
| 972 | 974 |
| 973 void PersistentTabRestoreService::PruneEntries() { | 975 void PersistentTabRestoreService::PruneEntries() { |
| 974 helper_.PruneEntries(); | 976 helper_.PruneEntries(); |
| 975 } | 977 } |
| 976 | 978 |
| 977 ProfileKeyedService* TabRestoreServiceFactory::BuildServiceInstanceFor( | 979 ProfileKeyedService* TabRestoreServiceFactory::BuildServiceInstanceFor( |
| 978 Profile* profile) const { | 980 Profile* profile) const { |
| 979 return new PersistentTabRestoreService(profile, NULL); | 981 return new PersistentTabRestoreService(profile, NULL); |
| 980 } | 982 } |
| OLD | NEW |