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.
5 #ifndef COMPONENTS_KEYED_SERVICE_IOS_BROWSER_STATE_CONTEXT_CONVERTER_H_
6 #define COMPONENTS_KEYED_SERVICE_IOS_BROWSER_STATE_CONTEXT_CONVERTER_H_
8 #include "base/macros.h"
11 class SupportsUserData
;
14 // BrowserStateContextConverter does safe conversion of base::SupportsUserData*
15 // to web::BrowserState* or content::BrowserContext*.
17 // iOS code is still using BrowserContextKeyedServiceFactory and until the
18 // conversion is complete — http://crbug.com/478763 — there is need to have
19 // mixed dependency between BCKSF and BSKSF.
21 // The implementation has BrowserStateKeyedServiceFactory supporting a
22 // BrowserContextDependencyManager as DependencyManager. Thus the context
23 // parameter passed to the BrowserStateKeyedServiceFactory can either be
24 // content::BrowserContext if the method is invoked by DependencyManager
25 // or web::BrowserState if the method is invoked via the type-safe public
28 // The public API of BrowserStateKeyedServiceFactory is type-safe (all
29 // public method receive web::BrowserState for context object), so only
30 // methods that take a base::SupportsUserData need to discriminate
31 // between the two objects.
32 class BrowserStateContextConverter
{
34 // Sets/Gets the global BrowserStateContextConverter instance. May return null
35 // when mixed dependencies are disabled.
36 static void SetInstance(BrowserStateContextConverter
* instance
);
37 static BrowserStateContextConverter
* GetInstance();
39 // Converts |context| to a web::BrowserState* and returns it casted as a
40 // base::SupportsUserData*.
41 virtual base::SupportsUserData
* GetBrowserStateForContext(
42 base::SupportsUserData
* context
) = 0;
43 // Converts |context| to a content::BrowserContext* and returns it casted as a
44 // base::SupportsUserData*.
45 virtual base::SupportsUserData
* GetBrowserContextForContext(
46 base::SupportsUserData
* context
) = 0;
49 BrowserStateContextConverter();
50 virtual ~BrowserStateContextConverter();
52 DISALLOW_COPY_AND_ASSIGN(BrowserStateContextConverter
);
55 #endif // COMPONENTS_KEYED_SERVICE_IOS_BROWSER_STATE_CONTEXT_CONVERTER_H_