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

Unified Diff: ios/web/navigation/serialized_user_data_manager_impl.mm

Issue 1361173005: Created SerializedUserDataManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@serialized_navigation_manager
Patch Set: Eugene's comments Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: ios/web/navigation/serialized_user_data_manager_impl.mm
diff --git a/ios/web/navigation/serialized_user_data_manager_impl.mm b/ios/web/navigation/serialized_user_data_manager_impl.mm
new file mode 100644
index 0000000000000000000000000000000000000000..a0cc3a62e1c50aa0ee8649c995dcd0f78310e858
--- /dev/null
+++ b/ios/web/navigation/serialized_user_data_manager_impl.mm
@@ -0,0 +1,97 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ios/web/navigation/serialized_user_data_manager_impl.h"
+
+#include "base/memory/scoped_ptr.h"
+#include "ios/web/public/web_state/web_state.h"
+
+namespace {
+
+// Private key used to store BrowserContextUserDataWrappers in a
+// NavigationManager's user data.
+const void* const kSerializedUserDataManagerWrapperKey =
+ &kSerializedUserDataManagerWrapperKey;
+
+// Wraps a SerializedUserDataManagerImpl in a SupportsUserData::Data.
+class SerializedUserDataManagerWrapper : public base::SupportsUserData::Data {
+ public:
+ // Returns the SerializedUserDataManagerWrapper for |web_state|, lazily
+ // creating one if necessary.
+ static SerializedUserDataManagerWrapper* FromWebState(
+ web::WebState* web_state) {
+ DCHECK(web_state);
+ SerializedUserDataManagerWrapper* user_data_manager_wrapper =
+ static_cast<SerializedUserDataManagerWrapper*>(
+ web_state->GetUserData(kSerializedUserDataManagerWrapperKey));
+ if (!user_data_manager_wrapper) {
+ user_data_manager_wrapper =
+ new SerializedUserDataManagerWrapper(web_state);
+ }
+ return user_data_manager_wrapper;
+ }
+
+ // Returns the SerializedUserDataManager for this wrapper.
+ web::SerializedUserDataManager* GetUserDataManager() const {
+ return user_data_manager_.get();
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SerializedUserDataManagerWrapper);
+
+ // The SerializedUserDataManager owned by the wrapper.
+ scoped_ptr<web::SerializedUserDataManagerImpl> user_data_manager_;
+
+ // Private constructor used to create a new wrapper for |manager|.
+ explicit SerializedUserDataManagerWrapper(web::WebState* web_state)
+ : user_data_manager_(new web::SerializedUserDataManagerImpl()) {
+ DCHECK(web_state);
+ web_state->SetUserData(kSerializedUserDataManagerWrapperKey, this);
+ }
+};
+
+} // namespace
+
+namespace web {
+
+// static
+SerializedUserDataManager* SerializedUserDataManager::FromWebState(
+ WebState* web_state) {
+ return SerializedUserDataManagerWrapper::FromWebState(web_state)
+ ->GetUserDataManager();
+}
+
+SerializedUserDataManagerImpl::SerializedUserDataManagerImpl()
+ : user_data_([[NSMutableDictionary alloc] init]) {}
+
+SerializedUserDataManagerImpl::~SerializedUserDataManagerImpl() {}
+
+void SerializedUserDataManagerImpl::SetValueForSerializationKey(
+ SerializedUserDataType data,
+ NSString* serialization_key) {
+ DCHECK(serialization_key.length);
+ if (data)
+ [user_data_ setObject:data forKey:serialization_key];
+ else
+ [user_data_ removeObjectForKey:serialization_key];
+}
+
+SerializedUserDataType
+SerializedUserDataManagerImpl::GetValueForSerializationKey(
+ NSString* serialization_key) const {
+ DCHECK(serialization_key.length);
+ return [user_data_ objectForKey:serialization_key];
+}
+
+NSDictionary* SerializedUserDataManagerImpl::GetSerializationDictionary()
+ const {
+ return [NSDictionary dictionaryWithDictionary:user_data_];
+}
+
+void SerializedUserDataManagerImpl::AddValuesFromDictionary(
+ NSDictionary* dictionary) {
+ DCHECK(user_data_);
+ [user_data_ addEntriesFromDictionary:dictionary];
+}
+}

Powered by Google App Engine
This is Rietveld 408576698