Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(353)

Side by Side Diff: ios/web/navigation/serializable_user_data_manager_impl.mm

Issue 2732063003: Add unittests checking that old saved session can be restored. (Closed)
Patch Set: Rebase and document -performSaveToDirectoryInBackground:. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/chrome/test/data/sessions/session_m58.plist ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #import "ios/web/public/web_state/web_state.h" 9 #import "ios/web/public/web_state/web_state.h"
10 10
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 web_state->GetUserData(kSerializableUserDataManagerKey)); 43 web_state->GetUserData(kSerializableUserDataManagerKey));
44 } 44 }
45 45
46 // Returns the manager owned by this wrapper. 46 // Returns the manager owned by this wrapper.
47 SerializableUserDataManagerImpl* manager() { return &manager_; } 47 SerializableUserDataManagerImpl* manager() { return &manager_; }
48 48
49 private: 49 private:
50 // The SerializableUserDataManagerWrapper owned by this object. 50 // The SerializableUserDataManagerWrapper owned by this object.
51 SerializableUserDataManagerImpl manager_; 51 SerializableUserDataManagerImpl manager_;
52 }; 52 };
53
54 // Returns a dictionary mapping old CRWSessionStorage serialised properties to
55 // the corresponding key in the serialised user data. When adding a mapping to
56 // this dictionary, create a new crbug to track its removal and mark it with a
57 // release at least one year after the introduction of the mapping.
58 NSDictionary* GetLegacyKeyConversion() {
59 NSMutableDictionary* legacy_key_conversion = [NSMutableDictionary dictionary];
60 // TODO(crbug.com/661633): those mappings where introduced between M57 and
61 // M58, so remove them after M67 has shipped to stable.
62 [legacy_key_conversion addEntriesFromDictionary:@{
63 @"tabId" : @"TabID",
64 @"openerId" : @"OpenerID",
65 @"openerNavigationIndex" : @"OpenerNavigationIndex",
66 @"lastVisitedTimestamp" : @"LastVisitedTimestamp",
67 }];
68 return [legacy_key_conversion copy];
69 }
53 } // namespace 70 } // namespace
54 71
55 // static 72 // static
56 std::unique_ptr<SerializableUserData> SerializableUserData::Create() { 73 std::unique_ptr<SerializableUserData> SerializableUserData::Create() {
57 return base::MakeUnique<SerializableUserDataImpl>(); 74 return base::MakeUnique<SerializableUserDataImpl>();
58 } 75 }
59 76
60 SerializableUserDataImpl::SerializableUserDataImpl() 77 SerializableUserDataImpl::SerializableUserDataImpl()
61 : data_(@{}), legacy_key_conversions_(@{ 78 : data_(@{}), legacy_key_conversions_(GetLegacyKeyConversion()) {}
62 @"tabId" : @"TabID",
63 @"openerId" : @"OpenerID",
64 @"openerNavigationIndex" : @"OpenerNavigationIndex",
65 @"lastVisitedTimestamp" : @"LastVisitedTimestamp",
66 }) {}
67 79
68 SerializableUserDataImpl::~SerializableUserDataImpl() {} 80 SerializableUserDataImpl::~SerializableUserDataImpl() {}
69 81
70 SerializableUserDataImpl::SerializableUserDataImpl(NSDictionary* data) 82 SerializableUserDataImpl::SerializableUserDataImpl(NSDictionary* data)
71 : data_([data copy]) {} 83 : data_([data copy]) {}
72 84
73 void SerializableUserDataImpl::Encode(NSCoder* coder) { 85 void SerializableUserDataImpl::Encode(NSCoder* coder) {
74 [coder encodeObject:data_ forKey:kSerializedUserDataKey]; 86 [coder encodeObject:data_ forKey:kSerializedUserDataKey];
75 } 87 }
76 88
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 void SerializableUserDataManagerImpl::AddSerializableUserData( 135 void SerializableUserDataManagerImpl::AddSerializableUserData(
124 SerializableUserData* data) { 136 SerializableUserData* data) {
125 if (data) { 137 if (data) {
126 SerializableUserDataImpl* data_impl = 138 SerializableUserDataImpl* data_impl =
127 static_cast<SerializableUserDataImpl*>(data); 139 static_cast<SerializableUserDataImpl*>(data);
128 data_.reset([data_impl->data() mutableCopy]); 140 data_.reset([data_impl->data() mutableCopy]);
129 } 141 }
130 } 142 }
131 143
132 } // namespace web 144 } // namespace web
OLDNEW
« no previous file with comments | « ios/chrome/test/data/sessions/session_m58.plist ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698