Commit f6812b62 authored by Sylvain Defresne's avatar Sylvain Defresne Committed by Commit Bot

Remove obsolete code in WebStateList deserialization

The properties used to serialize the WebStateList opener-opened
relationship was changed in M-59, so the support for the legacy
format can be dropped now that M-69 has been branched.

Bug: 704941
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I63180a9be5d47a507ddcb5c1c37f6b3512cbfa94
Reviewed-on: https://chromium-review.googlesource.com/1158696
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580147}
parent 0bddcf50
......@@ -27,110 +27,6 @@ namespace {
// the WebStates stored in the WebStateList.
NSString* const kOpenerIndexKey = @"OpenerIndex";
NSString* const kOpenerNavigationIndexKey = @"OpenerNavigationIndex";
// Legacy keys used to store information about the opener-opener relationship
// before the M-60 release. Remove once M-70 has shipped.
NSString* const kObjectIDKey = @"TabID";
NSString* const kOpenerIDKey = @"OpenerID";
// Returns whether the opener-opener relationship is encoded with legacy format.
// The legacy format (pre M-59) references the opener by id while the new format
// references it by index.
// TODO(crbug.com/704941): remove once no sessions uses the old format.
bool IsSessionUsingLegacyFormat(WebStateList* web_state_list, int old_count) {
for (int index = old_count; index < web_state_list->count(); ++index) {
web::WebState* web_state = web_state_list->GetWebStateAt(index);
web::SerializableUserDataManager* user_data_manager =
web::SerializableUserDataManager::FromWebState(web_state);
if (!user_data_manager->GetValueForSerializationKey(kOpenerIndexKey))
return true;
}
return false;
}
// Restores the WebStates opener-opened relationship. The relationship is
// encoded using legacy format.
// TODO(crbug.com/704941): remove once no sessions uses the old format.
void RestoreRelationshipLegacy(WebStateList* web_state_list, int old_count) {
NSMutableDictionary<NSString*, NSValue*>* id_to_web_state =
[NSMutableDictionary dictionary];
for (int index = old_count; index < web_state_list->count(); ++index) {
web::WebState* web_state = web_state_list->GetWebStateAt(index);
web::SerializableUserDataManager* user_data_manager =
web::SerializableUserDataManager::FromWebState(web_state);
NSString* object_id = base::mac::ObjCCast<NSString>(
user_data_manager->GetValueForSerializationKey(kObjectIDKey));
if (!object_id || ![object_id length])
continue;
if (id_to_web_state[object_id] != nil)
continue;
id_to_web_state[object_id] = [NSValue valueWithPointer:web_state];
}
for (int index = old_count; index < web_state_list->count(); ++index) {
web::WebState* web_state = web_state_list->GetWebStateAt(index);
web::SerializableUserDataManager* user_data_manager =
web::SerializableUserDataManager::FromWebState(web_state);
NSString* opener_id = base::mac::ObjCCast<NSString>(
user_data_manager->GetValueForSerializationKey(kOpenerIDKey));
NSNumber* boxed_opener_navigation_index = base::mac::ObjCCast<NSNumber>(
user_data_manager->GetValueForSerializationKey(
kOpenerNavigationIndexKey));
if (!opener_id || !boxed_opener_navigation_index || ![opener_id length])
continue;
if (id_to_web_state[opener_id] == nil)
continue;
web::WebState* opener_web_state =
static_cast<web::WebState*>(id_to_web_state[opener_id].pointerValue);
web_state_list->SetOpenerOfWebStateAt(
index, WebStateOpener(opener_web_state,
[boxed_opener_navigation_index intValue]));
}
}
// Restores the WebStates opener-opened relationship.
void RestoreRelationship(WebStateList* web_state_list, int old_count) {
if (IsSessionUsingLegacyFormat(web_state_list, old_count))
return RestoreRelationshipLegacy(web_state_list, old_count);
for (int index = old_count; index < web_state_list->count(); ++index) {
web::WebState* web_state = web_state_list->GetWebStateAt(index);
web::SerializableUserDataManager* user_data_manager =
web::SerializableUserDataManager::FromWebState(web_state);
NSNumber* boxed_opener_index = base::mac::ObjCCast<NSNumber>(
user_data_manager->GetValueForSerializationKey(kOpenerIndexKey));
NSNumber* boxed_opener_navigation_index = base::mac::ObjCCast<NSNumber>(
user_data_manager->GetValueForSerializationKey(
kOpenerNavigationIndexKey));
if (!boxed_opener_index || !boxed_opener_navigation_index)
continue;
// If opener index is out of bound then assume there is no opener.
int opener_index = [boxed_opener_index intValue] + old_count;
if (opener_index < old_count || opener_index >= web_state_list->count())
continue;
web::WebState* opener = web_state_list->GetWebStateAt(opener_index);
web_state_list->SetOpenerOfWebStateAt(
index,
WebStateOpener(opener, [boxed_opener_navigation_index intValue]));
}
}
} // namespace
SessionWindowIOS* SerializeWebStateList(WebStateList* web_state_list) {
......@@ -172,7 +68,7 @@ SessionWindowIOS* SerializeWebStateList(WebStateList* web_state_list) {
void DeserializeWebStateList(WebStateList* web_state_list,
SessionWindowIOS* session_window,
const WebStateFactory& web_state_factory) {
int old_count = web_state_list->count();
const int old_count = web_state_list->count();
for (CRWSessionStorage* session in session_window.sessions) {
std::unique_ptr<web::WebState> web_state = web_state_factory.Run(session);
web_state_list->InsertWebState(
......@@ -180,7 +76,32 @@ void DeserializeWebStateList(WebStateList* web_state_list,
WebStateList::INSERT_FORCE_INDEX, WebStateOpener());
}
RestoreRelationship(web_state_list, old_count);
// Restore the WebStates opener-opened relationship.
for (int index = old_count; index < web_state_list->count(); ++index) {
web::WebState* web_state = web_state_list->GetWebStateAt(index);
web::SerializableUserDataManager* user_data_manager =
web::SerializableUserDataManager::FromWebState(web_state);
NSNumber* boxed_opener_index = base::mac::ObjCCast<NSNumber>(
user_data_manager->GetValueForSerializationKey(kOpenerIndexKey));
NSNumber* boxed_opener_navigation_index = base::mac::ObjCCast<NSNumber>(
user_data_manager->GetValueForSerializationKey(
kOpenerNavigationIndexKey));
if (!boxed_opener_index || !boxed_opener_navigation_index)
continue;
// If opener index is out of bound then assume there is no opener.
const int opener_index = [boxed_opener_index intValue] + old_count;
if (opener_index < old_count || opener_index >= web_state_list->count())
continue;
web::WebState* opener = web_state_list->GetWebStateAt(opener_index);
web_state_list->SetOpenerOfWebStateAt(
index,
WebStateOpener(opener, [boxed_opener_navigation_index intValue]));
}
if (session_window.selectedIndex != NSNotFound) {
DCHECK_LT(session_window.selectedIndex, session_window.sessions.count);
......
......@@ -91,8 +91,6 @@ SerializableUserDataImpl::GetLegacyKeyConversion() {
// TODO(crbug.com/661633): those mappings where introduced between M57 and
// M58, so remove them after M67 has shipped to stable.
return @{
@"tabId" : @"TabID",
@"openerId" : @"OpenerID",
@"openerNavigationIndex" : @"OpenerNavigationIndex",
};
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment