Chromium Code Reviews| Index: ios/chrome/browser/web/tab_id_tab_helper.mm |
| diff --git a/ios/chrome/browser/web/tab_id_tab_helper.mm b/ios/chrome/browser/web/tab_id_tab_helper.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ad2d40ce17730d9dec238a217c71ffedaa4a289a |
| --- /dev/null |
| +++ b/ios/chrome/browser/web/tab_id_tab_helper.mm |
| @@ -0,0 +1,35 @@ |
| +// Copyright 2017 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. |
| + |
| +#import "ios/chrome/browser/web/tab_id_tab_helper.h" |
| + |
| +#include "base/mac/foundation_util.h" |
| +#include "base/strings/sys_string_conversions.h" |
| +#import "ios/web/public/serializable_user_data_manager.h" |
| + |
| +#if !defined(__has_feature) || !__has_feature(objc_arc) |
| +#error "This file requires ARC support." |
| +#endif |
| + |
| +DEFINE_WEB_STATE_USER_DATA_KEY(TabIDTabHelper); |
| + |
| +namespace { |
| +// The key under which the TabID is stored in the WebState's serializable user |
| +// data. |
| +NSString* const kTabIDKey = @"TabID"; |
| +} |
| + |
| +TabIDTabHelper::TabIDTabHelper(web::WebState* web_state) { |
| + web::SerializableUserDataManager* user_data_manager = |
| + web::SerializableUserDataManager::FromWebState(web_state); |
| + NSString* unique_id = base::mac::ObjCCast<NSString>( |
| + user_data_manager->GetValueForSerializationKey(kTabIDKey)); |
| + if (!unique_id || ![unique_id length]) { |
|
Eugene But (OOO till 7-30)
2017/06/23 22:44:56
No need for |!unique_id || | check. |[unique_id le
edchin
2017/06/26 16:20:57
Done.
|
| + unique_id = [[NSUUID UUID] UUIDString]; |
| + user_data_manager->AddSerializableData(unique_id, kTabIDKey); |
| + } |
| + tab_id_ = [unique_id copy]; |
| +} |
| + |
| +TabIDTabHelper::~TabIDTabHelper() = default; |