| 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/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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 // TabRestoreService ---------------------------------------------------------- | 61 // TabRestoreService ---------------------------------------------------------- |
| 62 | 62 |
| 63 // static | 63 // static |
| 64 const size_t TabRestoreService::kMaxEntries = 25; | 64 const size_t TabRestoreService::kMaxEntries = 25; |
| 65 | 65 |
| 66 // Identifier for commands written to file. | 66 // Identifier for commands written to file. |
| 67 // The ordering in the file is as follows: | 67 // The ordering in the file is as follows: |
| 68 // . When the user closes a tab a command of type | 68 // . When the user closes a tab a command of type |
| 69 // kCommandSelectedNavigationInTab is written identifying the tab and | 69 // kCommandSelectedNavigationInTab is written identifying the tab and |
| 70 // the selected index, then a kCommandPinnedState command if the tab was | 70 // the selected index, then a kCommandPinnedState command if the tab was |
| 71 // pinned and kCommandSetExtensionAppID if the tab has an app id. This is | 71 // pinned and kCommandSetExtensionAppID if the tab has an app id and |
| 72 // the user agent override if it was using one. This is |
| 72 // followed by any number of kCommandUpdateTabNavigation commands (1 per | 73 // followed by any number of kCommandUpdateTabNavigation commands (1 per |
| 73 // navigation entry). | 74 // navigation entry). |
| 74 // . When the user closes a window a kCommandSelectedNavigationInTab command | 75 // . When the user closes a window a kCommandSelectedNavigationInTab command |
| 75 // is written out and followed by n tab closed sequences (as previoulsy | 76 // is written out and followed by n tab closed sequences (as previoulsy |
| 76 // described). | 77 // described). |
| 77 // . When the user restores an entry a command of type kCommandRestoredEntry | 78 // . When the user restores an entry a command of type kCommandRestoredEntry |
| 78 // is written. | 79 // is written. |
| 79 static const SessionCommand::id_type kCommandUpdateTabNavigation = 1; | 80 static const SessionCommand::id_type kCommandUpdateTabNavigation = 1; |
| 80 static const SessionCommand::id_type kCommandRestoredEntry = 2; | 81 static const SessionCommand::id_type kCommandRestoredEntry = 2; |
| 81 static const SessionCommand::id_type kCommandWindow = 3; | 82 static const SessionCommand::id_type kCommandWindow = 3; |
| 82 static const SessionCommand::id_type kCommandSelectedNavigationInTab = 4; | 83 static const SessionCommand::id_type kCommandSelectedNavigationInTab = 4; |
| 83 static const SessionCommand::id_type kCommandPinnedState = 5; | 84 static const SessionCommand::id_type kCommandPinnedState = 5; |
| 84 static const SessionCommand::id_type kCommandSetExtensionAppID = 6; | 85 static const SessionCommand::id_type kCommandSetExtensionAppID = 6; |
| 85 static const SessionCommand::id_type kCommandSetWindowAppName = 7; | 86 static const SessionCommand::id_type kCommandSetWindowAppName = 7; |
| 87 static const SessionCommand::id_type kCommandSetTabUserAgentOverride = 8; |
| 86 | 88 |
| 87 // Number of entries (not commands) before we clobber the file and write | 89 // Number of entries (not commands) before we clobber the file and write |
| 88 // everything. | 90 // everything. |
| 89 static const int kEntriesPerReset = 40; | 91 static const int kEntriesPerReset = 40; |
| 90 | 92 |
| 91 namespace { | 93 namespace { |
| 92 | 94 |
| 93 // Payload structures. | 95 // Payload structures. |
| 94 | 96 |
| 95 typedef int32 RestoredEntryPayload; | 97 typedef int32 RestoredEntryPayload; |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 memcpy(command->contents(), &payload, sizeof(payload)); | 681 memcpy(command->contents(), &payload, sizeof(payload)); |
| 680 ScheduleCommand(command); | 682 ScheduleCommand(command); |
| 681 } | 683 } |
| 682 | 684 |
| 683 if (!tab.extension_app_id.empty()) { | 685 if (!tab.extension_app_id.empty()) { |
| 684 ScheduleCommand( | 686 ScheduleCommand( |
| 685 CreateSetTabExtensionAppIDCommand(kCommandSetExtensionAppID, tab.id, | 687 CreateSetTabExtensionAppIDCommand(kCommandSetExtensionAppID, tab.id, |
| 686 tab.extension_app_id)); | 688 tab.extension_app_id)); |
| 687 } | 689 } |
| 688 | 690 |
| 691 if (!tab.user_agent_override.empty()) { |
| 692 ScheduleCommand( |
| 693 CreateSetTabUserAgentOverrideCommand(kCommandSetTabUserAgentOverride, |
| 694 tab.id, tab.user_agent_override)); |
| 695 } |
| 696 |
| 689 // Then write the navigations. | 697 // Then write the navigations. |
| 690 for (int i = first_index_to_persist, wrote_count = 0; | 698 for (int i = first_index_to_persist, wrote_count = 0; |
| 691 i < max_index && wrote_count < 2 * max_persist_navigation_count; ++i) { | 699 i < max_index && wrote_count < 2 * max_persist_navigation_count; ++i) { |
| 692 if (ShouldTrackEntry(navigations[i].virtual_url())) { | 700 if (ShouldTrackEntry(navigations[i].virtual_url())) { |
| 693 // Creating a NavigationEntry isn't the most efficient way to go about | 701 // Creating a NavigationEntry isn't the most efficient way to go about |
| 694 // this, but it simplifies the code and makes it less error prone as we | 702 // this, but it simplifies the code and makes it less error prone as we |
| 695 // add new data to NavigationEntry. | 703 // add new data to NavigationEntry. |
| 696 scoped_ptr<NavigationEntry> entry( | 704 scoped_ptr<NavigationEntry> entry( |
| 697 navigations[i].ToNavigationEntry(wrote_count, profile())); | 705 navigations[i].ToNavigationEntry(wrote_count, profile())); |
| 698 ScheduleCommand( | 706 ScheduleCommand( |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 SessionID::id_type tab_id; | 949 SessionID::id_type tab_id; |
| 942 std::string extension_app_id; | 950 std::string extension_app_id; |
| 943 if (!RestoreSetTabExtensionAppIDCommand(command, &tab_id, | 951 if (!RestoreSetTabExtensionAppIDCommand(command, &tab_id, |
| 944 &extension_app_id)) { | 952 &extension_app_id)) { |
| 945 return; | 953 return; |
| 946 } | 954 } |
| 947 current_tab->extension_app_id.swap(extension_app_id); | 955 current_tab->extension_app_id.swap(extension_app_id); |
| 948 break; | 956 break; |
| 949 } | 957 } |
| 950 | 958 |
| 959 case kCommandSetTabUserAgentOverride: { |
| 960 if (!current_tab) { |
| 961 // Should be in a tab when we get this. |
| 962 return; |
| 963 } |
| 964 SessionID::id_type tab_id; |
| 965 std::string user_agent_override; |
| 966 if (!RestoreSetTabUserAgentOverrideCommand(command, &tab_id, |
| 967 &user_agent_override)) { |
| 968 return; |
| 969 } |
| 970 current_tab->user_agent_override.swap(user_agent_override); |
| 971 break; |
| 972 } |
| 973 |
| 951 default: | 974 default: |
| 952 // Unknown type, usually indicates corruption of file. Ignore it. | 975 // Unknown type, usually indicates corruption of file. Ignore it. |
| 953 return; | 976 return; |
| 954 } | 977 } |
| 955 } | 978 } |
| 956 | 979 |
| 957 // If there was corruption some of the entries won't be valid. | 980 // If there was corruption some of the entries won't be valid. |
| 958 ValidateAndDeleteEmptyEntries(&(entries.get())); | 981 ValidateAndDeleteEmptyEntries(&(entries.get())); |
| 959 | 982 |
| 960 loaded_entries->swap(entries.get()); | 983 loaded_entries->swap(entries.get()); |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1218 // the front, not the end and we just added the entries to the end). | 1241 // the front, not the end and we just added the entries to the end). |
| 1219 entries_to_write_ = staging_entries_.size(); | 1242 entries_to_write_ = staging_entries_.size(); |
| 1220 | 1243 |
| 1221 PruneEntries(); | 1244 PruneEntries(); |
| 1222 NotifyTabsChanged(); | 1245 NotifyTabsChanged(); |
| 1223 } | 1246 } |
| 1224 | 1247 |
| 1225 Time TabRestoreService::TimeNow() const { | 1248 Time TabRestoreService::TimeNow() const { |
| 1226 return time_factory_ ? time_factory_->TimeNow() : Time::Now(); | 1249 return time_factory_ ? time_factory_->TimeNow() : Time::Now(); |
| 1227 } | 1250 } |
| OLD | NEW |