Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #import "ios/web/navigation/serializable_user_data_manager_impl.h" | 5 #import "ios/web/navigation/serializable_user_data_manager_impl.h" |
| 6 | 6 |
| 7 #import "base/mac/foundation_util.h" | 7 #import "base/mac/foundation_util.h" |
| 8 #import "ios/web/public/web_state/web_state.h" | 8 #import "ios/web/public/web_state/web_state.h" |
| 9 | 9 |
| 10 #if !defined(__has_feature) || !__has_feature(objc_arc) | 10 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 } | 52 } |
| 53 }; | 53 }; |
| 54 } // namespace | 54 } // namespace |
| 55 | 55 |
| 56 // static | 56 // static |
| 57 std::unique_ptr<SerializableUserData> SerializableUserData::Create() { | 57 std::unique_ptr<SerializableUserData> SerializableUserData::Create() { |
| 58 return std::unique_ptr<SerializableUserData>(new SerializableUserDataImpl()); | 58 return std::unique_ptr<SerializableUserData>(new SerializableUserDataImpl()); |
| 59 } | 59 } |
| 60 | 60 |
| 61 SerializableUserDataImpl::SerializableUserDataImpl() | 61 SerializableUserDataImpl::SerializableUserDataImpl() |
| 62 : data_([[NSDictionary alloc] init]) {} | 62 : data_([[NSDictionary alloc] init]), |
| 63 legacy_key_conversions_(@{@"tabId" : @"TabID"}) {} | |
|
Eugene But (OOO till 7-30)
2017/02/13 17:37:57
Should we keep the old tabId name to avoid extra c
kkhorimoto
2017/02/13 23:41:18
Since we've set a milestone to remove the legacy c
| |
| 63 | 64 |
| 64 SerializableUserDataImpl::~SerializableUserDataImpl() {} | 65 SerializableUserDataImpl::~SerializableUserDataImpl() {} |
| 65 | 66 |
| 66 SerializableUserDataImpl::SerializableUserDataImpl(NSDictionary* data) | 67 SerializableUserDataImpl::SerializableUserDataImpl(NSDictionary* data) |
| 67 : data_([data copy]) {} | 68 : data_([data copy]) {} |
| 68 | 69 |
| 69 void SerializableUserDataImpl::Encode(NSCoder* coder) { | 70 void SerializableUserDataImpl::Encode(NSCoder* coder) { |
| 70 [coder encodeObject:data_ forKey:kSerializedUserDataKey]; | 71 [coder encodeObject:data_ forKey:kSerializedUserDataKey]; |
| 71 } | 72 } |
| 72 | 73 |
| 73 void SerializableUserDataImpl::Decode(NSCoder* coder) { | 74 void SerializableUserDataImpl::Decode(NSCoder* coder) { |
| 74 NSDictionary* data = base::mac::ObjCCastStrict<NSDictionary>( | 75 NSMutableDictionary* data = |
| 75 [coder decodeObjectForKey:kSerializedUserDataKey]); | 76 [[coder decodeObjectForKey:kSerializedUserDataKey] mutableCopy]; |
| 76 data_.reset([data mutableCopy]); | 77 [data addEntriesFromDictionary:GetDecodedLegacyValues(coder)]; |
| 78 data_.reset([data copy]); | |
| 79 } | |
| 80 | |
| 81 NSDictionary* SerializableUserDataImpl::GetDecodedLegacyValues(NSCoder* coder) { | |
| 82 NSMutableDictionary* legacy_values = [[NSMutableDictionary alloc] init]; | |
| 83 for (NSString* legacy_key in [legacy_key_conversions_ allKeys]) { | |
| 84 id<NSCoding> value = [coder decodeObjectForKey:legacy_key]; | |
| 85 NSString* new_key = [legacy_key_conversions_ objectForKey:legacy_key]; | |
| 86 legacy_values[new_key] = value; | |
| 87 } | |
| 88 return legacy_values; | |
| 77 } | 89 } |
| 78 | 90 |
| 79 // static | 91 // static |
| 80 SerializableUserDataManager* SerializableUserDataManager::FromWebState( | 92 SerializableUserDataManager* SerializableUserDataManager::FromWebState( |
| 81 web::WebState* web_state) { | 93 web::WebState* web_state) { |
| 82 DCHECK(web_state); | 94 DCHECK(web_state); |
| 83 return SerializableUserDataManagerWrapper::FromWebState(web_state)->manager(); | 95 return SerializableUserDataManagerWrapper::FromWebState(web_state)->manager(); |
| 84 } | 96 } |
| 85 | 97 |
| 86 SerializableUserDataManagerImpl::SerializableUserDataManagerImpl() | 98 SerializableUserDataManagerImpl::SerializableUserDataManagerImpl() |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 108 | 120 |
| 109 void SerializableUserDataManagerImpl::AddSerializableUserData( | 121 void SerializableUserDataManagerImpl::AddSerializableUserData( |
| 110 SerializableUserData* data) { | 122 SerializableUserData* data) { |
| 111 DCHECK(data); | 123 DCHECK(data); |
| 112 SerializableUserDataImpl* data_impl = | 124 SerializableUserDataImpl* data_impl = |
| 113 static_cast<SerializableUserDataImpl*>(data); | 125 static_cast<SerializableUserDataImpl*>(data); |
| 114 data_.reset([data_impl->data() mutableCopy]); | 126 data_.reset([data_impl->data() mutableCopy]); |
| 115 } | 127 } |
| 116 | 128 |
| 117 } // namespace web | 129 } // namespace web |
| OLD | NEW |