QUIC - Browser shutdown crash fix. Accessing disk_cache's backend after
[chromium-blink-merge.git] / ios / web / browser_state.cc
blob5a8c03270ef169aadb6ede59f61341ee33c24d2c
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"
7 namespace web {
8 namespace {
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() {
25 // static
26 BrowserState* BrowserState::FromSupportsUserData(
27 base::SupportsUserData* supports_user_data) {
28 if (!supports_user_data ||
29 !supports_user_data->GetUserData(kBrowserStateIdentifierKey)) {
30 return nullptr;
32 return static_cast<BrowserState*>(supports_user_data);
34 } // namespace web