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..8fe8aa2cc92cc9c93f29623235df349f74d3a92c |
| --- /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); |
|
rohitrao (ping after 24h)
2017/06/23 11:10:27
Is this guaranteed to exist before the TabIDTabHel
edchin
2017/06/23 16:24:21
The class comment says this:
"// Returns the Seria
|
| + NSString* unique_id = base::mac::ObjCCast<NSString>( |
| + user_data_manager->GetValueForSerializationKey(kTabIDKey)); |
| + if (!unique_id || ![unique_id length]) { |
| + unique_id = [[NSUUID UUID] UUIDString]; |
| + user_data_manager->AddSerializableData(unique_id, kTabIDKey); |
| + } |
| + tab_id_ = base::SysNSStringToUTF8(unique_id); |
| +} |
| + |
| +TabIDTabHelper::~TabIDTabHelper() = default; |