| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/web_state/ui/wk_back_forward_list_item_holder.h" | 5 #import "ios/web/web_state/ui/wk_back_forward_list_item_holder.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" |
| 7 #import "ios/web/public/navigation_item.h" | 8 #import "ios/web/public/navigation_item.h" |
| 8 | 9 |
| 9 namespace web { | 10 namespace web { |
| 10 | 11 |
| 11 namespace { | 12 namespace { |
| 12 // Private key used for safe conversion of base::SupportsUserData to | 13 // Private key used for safe conversion of base::SupportsUserData to |
| 13 // web::WKBackForwardListItemHolder in | 14 // web::WKBackForwardListItemHolder in |
| 14 // web::WKBackForwardListItemHolder::FromNavigationItem. | 15 // web::WKBackForwardListItemHolder::FromNavigationItem. |
| 15 const char kBackForwardListItemIdentifierKey[] = | 16 const char kBackForwardListItemIdentifierKey[] = |
| 16 "BackForwardListItemIdentifierKey"; | 17 "BackForwardListItemIdentifierKey"; |
| 17 } | 18 } |
| 18 | 19 |
| 19 WKBackForwardListItemHolder::WKBackForwardListItemHolder() | 20 WKBackForwardListItemHolder::WKBackForwardListItemHolder() |
| 20 : navigation_type_(WKNavigationTypeOther) {} | 21 : navigation_type_(WKNavigationTypeOther) {} |
| 21 | 22 |
| 22 WKBackForwardListItemHolder::~WKBackForwardListItemHolder() {} | 23 WKBackForwardListItemHolder::~WKBackForwardListItemHolder() {} |
| 23 | 24 |
| 24 // static | 25 // static |
| 25 WKBackForwardListItemHolder* WKBackForwardListItemHolder::FromNavigationItem( | 26 WKBackForwardListItemHolder* WKBackForwardListItemHolder::FromNavigationItem( |
| 26 web::NavigationItem* item) { | 27 web::NavigationItem* item) { |
| 27 DCHECK(item); | 28 DCHECK(item); |
| 28 base::SupportsUserData::Data* user_data = | 29 base::SupportsUserData::Data* user_data = |
| 29 item->GetUserData(kBackForwardListItemIdentifierKey); | 30 item->GetUserData(kBackForwardListItemIdentifierKey); |
| 30 if (!user_data) { | 31 if (!user_data) { |
| 31 user_data = new WKBackForwardListItemHolder(); | 32 user_data = new WKBackForwardListItemHolder(); |
| 32 item->SetUserData(kBackForwardListItemIdentifierKey, user_data); | 33 item->SetUserData(kBackForwardListItemIdentifierKey, |
| 34 base::WrapUnique(user_data)); |
| 33 } | 35 } |
| 34 return static_cast<WKBackForwardListItemHolder*>(user_data); | 36 return static_cast<WKBackForwardListItemHolder*>(user_data); |
| 35 } | 37 } |
| 36 | 38 |
| 37 } // namespace web | 39 } // namespace web |
| OLD | NEW |