1 // Copyright 2013 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.
5 #include "ios/web/public/browser_state.h"
9 // Private key used for safe conversion of base::SupportsUserData to
10 // web::BrowserState in web::BrowserState::FromSupportsUserData.
11 const char kBrowserStateIdentifierKey
[] = "BrowserStateIdentifierKey";
14 BrowserState::BrowserState() {
15 // (Refcounted)?BrowserStateKeyedServiceFactories needs to be able to convert
16 // a base::SupportsUserData to a BrowserState. Moreover, since the factories
17 // may be passed a content::BrowserContext instead of a BrowserState, attach
18 // an empty object to this via a private key.
19 SetUserData(kBrowserStateIdentifierKey
, new SupportsUserData::Data
);
22 BrowserState::~BrowserState() {
26 BrowserState
* BrowserState::FromSupportsUserData(
27 base::SupportsUserData
* supports_user_data
) {
28 if (!supports_user_data
||
29 !supports_user_data
->GetUserData(kBrowserStateIdentifierKey
)) {
32 return static_cast<BrowserState
*>(supports_user_data
);