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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 ScheduleCommand(CreateRestoredEntryCommand(id)); | 311 ScheduleCommand(CreateRestoredEntryCommand(id)); |
312 } | 312 } |
313 | 313 |
314 void PersistentTabRestoreService::Delegate::OnAddEntry() { | 314 void PersistentTabRestoreService::Delegate::OnAddEntry() { |
315 // Start the save timer, when it fires we'll generate the commands. | 315 // Start the save timer, when it fires we'll generate the commands. |
316 StartSaveTimer(); | 316 StartSaveTimer(); |
317 entries_to_write_++; | 317 entries_to_write_++; |
318 } | 318 } |
319 | 319 |
320 void PersistentTabRestoreService::Delegate::LoadTabsFromLastSession() { | 320 void PersistentTabRestoreService::Delegate::LoadTabsFromLastSession() { |
321 if (load_state_ != NOT_LOADED || | 321 if (load_state_ != NOT_LOADED) |
322 tab_restore_service_helper_->entries().size() == kMaxEntries) | |
323 return; | 322 return; |
324 | 323 |
| 324 if (tab_restore_service_helper_->entries().size() == kMaxEntries) { |
| 325 // We already have the max number of entries we can take. There is no point |
| 326 // in attempting to load since we'll just drop the results. Skip to loaded. |
| 327 load_state_ = (LOADING | LOADED_LAST_SESSION | LOADED_LAST_TABS); |
| 328 LoadStateChanged(); |
| 329 return; |
| 330 } |
| 331 |
325 #if !defined(ENABLE_SESSION_SERVICE) | 332 #if !defined(ENABLE_SESSION_SERVICE) |
326 // If sessions are not stored in the SessionService, default to | 333 // If sessions are not stored in the SessionService, default to |
327 // |LOADED_LAST_SESSION| state. | 334 // |LOADED_LAST_SESSION| state. |
328 load_state_ = LOADING | LOADED_LAST_SESSION; | 335 load_state_ = LOADING | LOADED_LAST_SESSION; |
329 #else | 336 #else |
330 load_state_ = LOADING; | 337 load_state_ = LOADING; |
331 | 338 |
332 SessionService* session_service = | 339 SessionService* session_service = |
333 SessionServiceFactory::GetForProfile(profile()); | 340 SessionServiceFactory::GetForProfile(profile()); |
334 Profile::ExitType exit_type = profile()->GetLastSessionExitType(); | 341 Profile::ExitType exit_type = profile()->GetLastSessionExitType(); |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 // Still waiting on previous session or previous tabs. | 818 // Still waiting on previous session or previous tabs. |
812 return; | 819 return; |
813 } | 820 } |
814 | 821 |
815 // We're done loading. | 822 // We're done loading. |
816 load_state_ ^= LOADING; | 823 load_state_ ^= LOADING; |
817 | 824 |
818 const Entries& entries = tab_restore_service_helper_->entries(); | 825 const Entries& entries = tab_restore_service_helper_->entries(); |
819 if (staging_entries_.empty() || entries.size() >= kMaxEntries) { | 826 if (staging_entries_.empty() || entries.size() >= kMaxEntries) { |
820 staging_entries_.clear(); | 827 staging_entries_.clear(); |
| 828 tab_restore_service_helper_->NotifyLoaded(); |
821 return; | 829 return; |
822 } | 830 } |
823 | 831 |
824 if (staging_entries_.size() + entries.size() > kMaxEntries) { | 832 if (staging_entries_.size() + entries.size() > kMaxEntries) { |
825 // If we add all the staged entries we'll end up with more than | 833 // If we add all the staged entries we'll end up with more than |
826 // kMaxEntries. Delete entries such that we only end up with at most | 834 // kMaxEntries. Delete entries such that we only end up with at most |
827 // kMaxEntries. | 835 // kMaxEntries. |
828 int surplus = kMaxEntries - entries.size(); | 836 int surplus = kMaxEntries - entries.size(); |
829 CHECK_LE(0, surplus); | 837 CHECK_LE(0, surplus); |
830 CHECK_GE(static_cast<int>(staging_entries_.size()), surplus); | 838 CHECK_GE(static_cast<int>(staging_entries_.size()), surplus); |
(...skipping 12 matching lines...) Expand all Loading... |
843 // it doesn't delete them. | 851 // it doesn't delete them. |
844 staging_entries_.weak_clear(); | 852 staging_entries_.weak_clear(); |
845 | 853 |
846 // Make it so we rewrite all the tabs. We need to do this otherwise we won't | 854 // Make it so we rewrite all the tabs. We need to do this otherwise we won't |
847 // correctly write out the entries when Save is invoked (Save starts from | 855 // correctly write out the entries when Save is invoked (Save starts from |
848 // the front, not the end and we just added the entries to the end). | 856 // the front, not the end and we just added the entries to the end). |
849 entries_to_write_ = staging_entries_.size(); | 857 entries_to_write_ = staging_entries_.size(); |
850 | 858 |
851 tab_restore_service_helper_->PruneEntries(); | 859 tab_restore_service_helper_->PruneEntries(); |
852 tab_restore_service_helper_->NotifyTabsChanged(); | 860 tab_restore_service_helper_->NotifyTabsChanged(); |
| 861 |
| 862 tab_restore_service_helper_->NotifyLoaded(); |
853 } | 863 } |
854 | 864 |
855 void PersistentTabRestoreService::Delegate::RemoveEntryByID( | 865 void PersistentTabRestoreService::Delegate::RemoveEntryByID( |
856 SessionID::id_type id, | 866 SessionID::id_type id, |
857 IDToEntry* id_to_entry, | 867 IDToEntry* id_to_entry, |
858 std::vector<TabRestoreService::Entry*>* entries) { | 868 std::vector<TabRestoreService::Entry*>* entries) { |
859 // Look for the entry in the map. If it is present, erase it from both | 869 // Look for the entry in the map. If it is present, erase it from both |
860 // collections and return. | 870 // collections and return. |
861 IDToEntry::iterator i = id_to_entry->find(id); | 871 IDToEntry::iterator i = id_to_entry->find(id); |
862 if (i != id_to_entry->end()) { | 872 if (i != id_to_entry->end()) { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 } | 982 } |
973 | 983 |
974 void PersistentTabRestoreService::PruneEntries() { | 984 void PersistentTabRestoreService::PruneEntries() { |
975 helper_.PruneEntries(); | 985 helper_.PruneEntries(); |
976 } | 986 } |
977 | 987 |
978 ProfileKeyedService* TabRestoreServiceFactory::BuildServiceInstanceFor( | 988 ProfileKeyedService* TabRestoreServiceFactory::BuildServiceInstanceFor( |
979 content::BrowserContext* profile) const { | 989 content::BrowserContext* profile) const { |
980 return new PersistentTabRestoreService(static_cast<Profile*>(profile), NULL); | 990 return new PersistentTabRestoreService(static_cast<Profile*>(profile), NULL); |
981 } | 991 } |
OLD | NEW |