| Index: components/keyed_service/ios/browser_state_helper.cc
|
| diff --git a/components/keyed_service/ios/browser_state_helper.cc b/components/keyed_service/ios/browser_state_helper.cc
|
| index c8e39f8e2257163deeae4b43e5eb1b910fbdf05c..a155b2a26ef07e0ee1a8da763e1727cd8c460f3d 100644
|
| --- a/components/keyed_service/ios/browser_state_helper.cc
|
| +++ b/components/keyed_service/ios/browser_state_helper.cc
|
| @@ -9,7 +9,7 @@
|
| #include "ios/web/public/browser_state.h"
|
|
|
| // iOS code is still using BrowserContextKeyedServiceFactory and until the
|
| -// upstreaming is complete (http://crbug.com/419366) there is need to have
|
| +// conversion is complete (http://crbug.com/478763) there is need to have
|
| // mixed dependency between BCKSF and BSKSF.
|
| //
|
| // The implementation has BrowserStateKeyedServiceFactory supporting a
|
| @@ -31,20 +31,40 @@
|
| // to find the associated web::BrowserState (there is a 1:1 mapping).
|
|
|
| namespace {
|
| -BrowserStateFromContextFn g_browser_state_from_context = nullptr;
|
| +UnderlyingContextFromContextFn g_underlying_context_from_context = nullptr;
|
| +OriginalContextFromContextFn g_original_context_from_context = nullptr;
|
| } // namespace
|
|
|
| -void SetBrowserStateFromContextHelper(BrowserStateFromContextFn helper) {
|
| - g_browser_state_from_context = helper;
|
| +void SetUnderlyingContextFromContextHelper(
|
| + UnderlyingContextFromContextFn helper) {
|
| + DCHECK_NE(UnderlyingContextFromContext, helper);
|
| + g_underlying_context_from_context = helper;
|
| }
|
|
|
| -web::BrowserState* BrowserStateFromContext(base::SupportsUserData* context) {
|
| - web::BrowserState* state = nullptr;
|
| +web::BrowserState* UnderlyingContextFromContext(
|
| + base::SupportsUserData* context) {
|
| + web::BrowserState* underlying_context = nullptr;
|
| if (context) {
|
| - state = web::BrowserState::FromSupportsUserData(context);
|
| - if (!state && g_browser_state_from_context)
|
| - state = g_browser_state_from_context(context);
|
| - DCHECK(state) << "cannot convert context to web::BrowserState";
|
| + underlying_context = web::BrowserState::FromSupportsUserData(context);
|
| + if (!underlying_context && g_underlying_context_from_context)
|
| + underlying_context = g_underlying_context_from_context(context);
|
| + DCHECK(underlying_context) << "cannot resolve underlying context";
|
| }
|
| - return state;
|
| + return underlying_context;
|
| +}
|
| +
|
| +void SetOriginalContextFromContextHelper(OriginalContextFromContextFn helper) {
|
| + g_original_context_from_context = helper;
|
| +}
|
| +
|
| +base::SupportsUserData* OriginalContextFromContext(
|
| + base::SupportsUserData* context) {
|
| + base::SupportsUserData* original_context = context;
|
| + if (context) {
|
| + web::BrowserState* browser_state =
|
| + web::BrowserState::FromSupportsUserData(context);
|
| + if (browser_state && g_original_context_from_context)
|
| + original_context = g_original_context_from_context(browser_state);
|
| + }
|
| + return original_context;
|
| }
|
|
|