Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ios/web/navigation/serialized_user_data_manager_impl.h" | |
| 6 | |
| 7 #include "base/memory/scoped_ptr.h" | |
| 8 #include "ios/web/public/navigation_manager.h" | |
| 9 | |
| 10 namespace { | |
| 11 | |
| 12 // Private key used to store BrowserContextUserDataWrappers in a | |
| 13 // NavigationManager's user data. | |
| 14 const void* const kSerializedUserDataManagerWrapperKey = | |
| 15 &kSerializedUserDataManagerWrapperKey; | |
| 16 | |
| 17 // Wraps a SerializedUserDataManagerImpl in a SupportsUserData::Data. | |
| 18 class SerializedUserDataManagerWrapper : public base::SupportsUserData::Data { | |
| 19 public: | |
| 20 // Returns the SerializedUserDataManagerWrapper for |manager|, lazily creating | |
| 21 // one if necessary. | |
| 22 static SerializedUserDataManagerWrapper* FromNavigationManager( | |
| 23 web::NavigationManager* manager) { | |
| 24 DCHECK(manager); | |
| 25 SerializedUserDataManagerWrapper* user_data_manager_wrapper = | |
| 26 static_cast<SerializedUserDataManagerWrapper*>( | |
| 27 manager->GetUserData(kSerializedUserDataManagerWrapperKey)); | |
| 28 if (!user_data_manager_wrapper) | |
| 29 user_data_manager_wrapper = new SerializedUserDataManagerWrapper(manager); | |
| 30 return user_data_manager_wrapper; | |
| 31 } | |
| 32 | |
| 33 // Returns the SerializedUserDataManager for this wrapper. | |
| 34 web::SerializedUserDataManager* GetUserDataManager() const { | |
| 35 return user_data_manager_.get(); | |
| 36 } | |
| 37 | |
| 38 private: | |
| 39 DISALLOW_COPY_AND_ASSIGN(SerializedUserDataManagerWrapper); | |
| 40 | |
| 41 // The SerializedUserDataManager owned by the wrapper. | |
| 42 scoped_ptr<web::SerializedUserDataManagerImpl> user_data_manager_; | |
| 43 | |
| 44 // Private constructor used to create a new wrapper for |manager|. | |
| 45 explicit SerializedUserDataManagerWrapper(web::NavigationManager* manager) | |
| 46 : user_data_manager_(new web::SerializedUserDataManagerImpl()) { | |
| 47 DCHECK(manager); | |
| 48 manager->SetUserData(kSerializedUserDataManagerWrapperKey, this); | |
| 49 } | |
| 50 }; | |
| 51 | |
| 52 } // namespace | |
| 53 | |
| 54 namespace web { | |
| 55 | |
| 56 // static | |
| 57 SerializedUserDataManager* SerializedUserDataManager::FromNavigationManager( | |
| 58 NavigationManager* manager) { | |
| 59 return SerializedUserDataManagerWrapper::FromNavigationManager(manager) | |
| 60 ->GetUserDataManager(); | |
| 61 } | |
| 62 | |
| 63 SerializedUserDataManagerImpl::SerializedUserDataManagerImpl() | |
| 64 : dictionary_([[NSMutableDictionary alloc] init]) {} | |
| 65 | |
| 66 SerializedUserDataManagerImpl::~SerializedUserDataManagerImpl() {} | |
| 67 | |
| 68 void SerializedUserDataManagerImpl::SetValueForSerializationKey( | |
| 69 SerializedUserDataType data, | |
| 70 NSString* serialization_key) { | |
| 71 DCHECK(serialization_key.length); | |
| 72 if (data) | |
| 73 [dictionary_ setObject:data forKey:serialization_key]; | |
| 74 else | |
| 75 [dictionary_ removeObjectForKey:serialization_key]; | |
| 76 } | |
| 77 | |
| 78 SerializedUserDataType | |
| 79 SerializedUserDataManagerImpl::GetValueForSerializationKey( | |
| 80 NSString* serialization_key) const { | |
| 81 return [dictionary_ objectForKey:serialization_key]; | |
|
Eugene But (OOO till 7-30)
2015/09/24 17:05:07
DCHECK(serialization_key.length)
kkhorimoto
2015/09/24 21:24:29
Done.
| |
| 82 } | |
| 83 | |
| 84 NSDictionary* SerializedUserDataManagerImpl::GetSerializationDictionary() | |
| 85 const { | |
| 86 return dictionary_; | |
|
Eugene But (OOO till 7-30)
2015/09/24 17:05:07
I would return an autoreleased copy of this dict t
kkhorimoto
2015/09/24 21:24:29
Done.
| |
| 87 } | |
| 88 | |
| 89 void SerializedUserDataManagerImpl::AddValuesFromDictionary( | |
| 90 NSDictionary* dictionary) { | |
| 91 [dictionary_ addEntriesFromDictionary:dictionary]; | |
|
Eugene But (OOO till 7-30)
2015/09/24 17:05:07
DCHECK(dictionary)
kkhorimoto
2015/09/24 21:24:29
Done.
| |
| 92 } | |
| 93 } | |
| OLD | NEW |