Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: components/keyed_service/ios/browser_state_helper.cc

Issue 1090373003: Allow cross dependencies between BCKSF and BSKSF (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove wrapper methods Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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.
4
5 #include "components/keyed_service/ios/browser_state_helper.h"
6
7 #include "base/logging.h"
8 #include "base/supports_user_data.h"
9 #include "ios/web/public/browser_state.h"
10
11 // iOS code is still using BrowserContextKeyedServiceFactory and until the
12 // upstreaming is complete (http://crbug.com/419366) there is need to have
13 // mixed dependency between BCKSF and BSKSF.
14 //
15 // The implementation has BrowserStateKeyedServiceFactory supporting a
16 // BrowserContextDependencyManager as DependencyManager. Thus the context
17 // parameter passed to the BrowserStateKeyedServiceFactory can either be
18 // content::BrowserContext if the method is invoked by DependencyManager
19 // or web::BrowserState if the method is invoked via the type-safe public
20 // API.
21 //
22 // The public API of BrowserStateKeyedServiceFactory is type-safe (all
23 // public method receive web::BrowserState for context object), so only
24 // methods that take a base::SupportsUserData need to discriminate
25 // between the two objects.
26 //
27 // If the base::SupportsUserData is a web::BrowserState then the public
28 // method web::BrowserState::FromSupportsUserData can do the conversion
29 // safely. If this method fails then context is content::BrowserContext
30 // and the methods defined below allow the embedder to provides helper
31 // to find the associated web::BrowserState (there is a 1:1 mapping).
32
33 namespace {
34 BrowserStateFromContextFn g_browser_state_from_context = nullptr;
35 } // namespace
36
37 void SetBrowserStateFromContextHelper(BrowserStateFromContextFn helper) {
38 g_browser_state_from_context = helper;
39 }
40
41 web::BrowserState* BrowserStateFromContext(base::SupportsUserData* context) {
42 web::BrowserState* state = nullptr;
43 if (context) {
44 state = web::BrowserState::FromSupportsUserData(context);
45 if (!state && g_browser_state_from_context)
46 state = g_browser_state_from_context(context);
47 DCHECK(state) << "cannot convert context to web::BrowserState";
48 }
49 return state;
50 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698