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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 // . When the user restores an entry a command of type kCommandRestoredEntry | 95 // . When the user restores an entry a command of type kCommandRestoredEntry |
96 // is written. | 96 // is written. |
97 const SessionCommand::id_type kCommandUpdateTabNavigation = 1; | 97 const SessionCommand::id_type kCommandUpdateTabNavigation = 1; |
98 const SessionCommand::id_type kCommandRestoredEntry = 2; | 98 const SessionCommand::id_type kCommandRestoredEntry = 2; |
99 const SessionCommand::id_type kCommandWindow = 3; | 99 const SessionCommand::id_type kCommandWindow = 3; |
100 const SessionCommand::id_type kCommandSelectedNavigationInTab = 4; | 100 const SessionCommand::id_type kCommandSelectedNavigationInTab = 4; |
101 const SessionCommand::id_type kCommandPinnedState = 5; | 101 const SessionCommand::id_type kCommandPinnedState = 5; |
102 const SessionCommand::id_type kCommandSetExtensionAppID = 6; | 102 const SessionCommand::id_type kCommandSetExtensionAppID = 6; |
103 const SessionCommand::id_type kCommandSetWindowAppName = 7; | 103 const SessionCommand::id_type kCommandSetWindowAppName = 7; |
104 const SessionCommand::id_type kCommandSetTabUserAgentOverride = 8; | 104 const SessionCommand::id_type kCommandSetTabUserAgentOverride = 8; |
| 105 const SessionCommand::id_type kCommandSetTabSessionSyncId = 9; |
105 | 106 |
106 // Number of entries (not commands) before we clobber the file and write | 107 // Number of entries (not commands) before we clobber the file and write |
107 // everything. | 108 // everything. |
108 const int kEntriesPerReset = 40; | 109 const int kEntriesPerReset = 40; |
109 | 110 |
110 const size_t kMaxEntries = TabRestoreServiceHelper::kMaxEntries; | 111 const size_t kMaxEntries = TabRestoreServiceHelper::kMaxEntries; |
111 | 112 |
112 } // namespace | 113 } // namespace |
113 | 114 |
114 // PersistentTabRestoreService::Delegate --------------------------------------- | 115 // PersistentTabRestoreService::Delegate --------------------------------------- |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 CreateSetTabExtensionAppIDCommand(kCommandSetExtensionAppID, tab.id, | 449 CreateSetTabExtensionAppIDCommand(kCommandSetExtensionAppID, tab.id, |
449 tab.extension_app_id)); | 450 tab.extension_app_id)); |
450 } | 451 } |
451 | 452 |
452 if (!tab.user_agent_override.empty()) { | 453 if (!tab.user_agent_override.empty()) { |
453 ScheduleCommand( | 454 ScheduleCommand( |
454 CreateSetTabUserAgentOverrideCommand(kCommandSetTabUserAgentOverride, | 455 CreateSetTabUserAgentOverrideCommand(kCommandSetTabUserAgentOverride, |
455 tab.id, tab.user_agent_override)); | 456 tab.id, tab.user_agent_override)); |
456 } | 457 } |
457 | 458 |
| 459 if (tab.sync_session_id != -1) { |
| 460 ScheduleCommand(CreateSetTabSessionSyncIdCommand( |
| 461 kCommandSetTabSessionSyncId, tab.id, tab.sync_session_id)); |
| 462 } |
| 463 |
458 // Then write the navigations. | 464 // Then write the navigations. |
459 for (int i = first_index_to_persist, wrote_count = 0; | 465 for (int i = first_index_to_persist, wrote_count = 0; |
460 i < max_index && wrote_count < 2 * max_persist_navigation_count; ++i) { | 466 i < max_index && wrote_count < 2 * max_persist_navigation_count; ++i) { |
461 if (ShouldTrackEntry(navigations[i].virtual_url())) { | 467 if (ShouldTrackEntry(navigations[i].virtual_url())) { |
462 ScheduleCommand( | 468 ScheduleCommand( |
463 CreateUpdateTabNavigationCommand(kCommandUpdateTabNavigation, tab.id, | 469 CreateUpdateTabNavigationCommand(kCommandUpdateTabNavigation, tab.id, |
464 navigations[i])); | 470 navigations[i])); |
465 } | 471 } |
466 } | 472 } |
467 } | 473 } |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 SessionID::id_type tab_id; | 734 SessionID::id_type tab_id; |
729 std::string user_agent_override; | 735 std::string user_agent_override; |
730 if (!RestoreSetTabUserAgentOverrideCommand(command, &tab_id, | 736 if (!RestoreSetTabUserAgentOverrideCommand(command, &tab_id, |
731 &user_agent_override)) { | 737 &user_agent_override)) { |
732 return; | 738 return; |
733 } | 739 } |
734 current_tab->user_agent_override.swap(user_agent_override); | 740 current_tab->user_agent_override.swap(user_agent_override); |
735 break; | 741 break; |
736 } | 742 } |
737 | 743 |
| 744 case kCommandSetTabSessionSyncId: { |
| 745 if (!current_tab) { |
| 746 // Should be in a tab when we get this. |
| 747 return; |
| 748 } |
| 749 SessionID::id_type tab_id; |
| 750 int64 sync_id; |
| 751 if (!RestoreSetTabSessionSyncIdCommand(command, &tab_id, &sync_id)) { |
| 752 current_tab->sync_session_id = sync_id; |
| 753 return; |
| 754 } |
| 755 current_tab->sync_session_id = sync_id; |
| 756 break; |
| 757 } |
| 758 |
738 default: | 759 default: |
739 // Unknown type, usually indicates corruption of file. Ignore it. | 760 // Unknown type, usually indicates corruption of file. Ignore it. |
740 return; | 761 return; |
741 } | 762 } |
742 } | 763 } |
743 | 764 |
744 // If there was corruption some of the entries won't be valid. | 765 // If there was corruption some of the entries won't be valid. |
745 ValidateAndDeleteEmptyEntries(&(entries.get())); | 766 ValidateAndDeleteEmptyEntries(&(entries.get())); |
746 | 767 |
747 loaded_entries->swap(entries.get()); | 768 loaded_entries->swap(entries.get()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 Window* window) { | 806 Window* window) { |
786 for (size_t i = 0; i < session_window->tabs.size(); ++i) { | 807 for (size_t i = 0; i < session_window->tabs.size(); ++i) { |
787 if (!session_window->tabs[i]->navigations.empty()) { | 808 if (!session_window->tabs[i]->navigations.empty()) { |
788 window->tabs.resize(window->tabs.size() + 1); | 809 window->tabs.resize(window->tabs.size() + 1); |
789 Tab& tab = window->tabs.back(); | 810 Tab& tab = window->tabs.back(); |
790 tab.pinned = session_window->tabs[i]->pinned; | 811 tab.pinned = session_window->tabs[i]->pinned; |
791 tab.navigations.swap(session_window->tabs[i]->navigations); | 812 tab.navigations.swap(session_window->tabs[i]->navigations); |
792 tab.current_navigation_index = | 813 tab.current_navigation_index = |
793 session_window->tabs[i]->current_navigation_index; | 814 session_window->tabs[i]->current_navigation_index; |
794 tab.extension_app_id = session_window->tabs[i]->extension_app_id; | 815 tab.extension_app_id = session_window->tabs[i]->extension_app_id; |
| 816 tab.sync_session_id = session_window->tabs[i]->sync_session_id; |
795 tab.timestamp = base::Time(); | 817 tab.timestamp = base::Time(); |
796 } | 818 } |
797 } | 819 } |
798 if (window->tabs.empty()) | 820 if (window->tabs.empty()) |
799 return false; | 821 return false; |
800 | 822 |
801 window->selected_tab_index = | 823 window->selected_tab_index = |
802 std::min(session_window->selected_tab_index, | 824 std::min(session_window->selected_tab_index, |
803 static_cast<int>(window->tabs.size() - 1)); | 825 static_cast<int>(window->tabs.size() - 1)); |
804 window->timestamp = base::Time(); | 826 window->timestamp = base::Time(); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 } | 994 } |
973 | 995 |
974 void PersistentTabRestoreService::PruneEntries() { | 996 void PersistentTabRestoreService::PruneEntries() { |
975 helper_.PruneEntries(); | 997 helper_.PruneEntries(); |
976 } | 998 } |
977 | 999 |
978 ProfileKeyedService* TabRestoreServiceFactory::BuildServiceInstanceFor( | 1000 ProfileKeyedService* TabRestoreServiceFactory::BuildServiceInstanceFor( |
979 content::BrowserContext* profile) const { | 1001 content::BrowserContext* profile) const { |
980 return new PersistentTabRestoreService(static_cast<Profile*>(profile), NULL); | 1002 return new PersistentTabRestoreService(static_cast<Profile*>(profile), NULL); |
981 } | 1003 } |
OLD | NEW |