OLD | NEW |
(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 #ifndef COMPONENTS_KEYED_SERVICE_IOS_BROWSER_STATE_CONTEXT_CONVERTER_H_ |
| 6 #define COMPONENTS_KEYED_SERVICE_IOS_BROWSER_STATE_CONTEXT_CONVERTER_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 |
| 10 namespace base { |
| 11 class SupportsUserData; |
| 12 } |
| 13 |
| 14 // BrowserStateContextConverter does safe conversion of base::SupportsUserData* |
| 15 // to web::BrowserState* or content::BrowserContext*. |
| 16 // |
| 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. |
| 20 // |
| 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 |
| 26 // API. |
| 27 // |
| 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 { |
| 33 public: |
| 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(); |
| 38 |
| 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; |
| 47 |
| 48 protected: |
| 49 BrowserStateContextConverter(); |
| 50 virtual ~BrowserStateContextConverter(); |
| 51 |
| 52 DISALLOW_COPY_AND_ASSIGN(BrowserStateContextConverter); |
| 53 }; |
| 54 |
| 55 #endif // COMPONENTS_KEYED_SERVICE_IOS_BROWSER_STATE_CONTEXT_CONVERTER_H_ |
OLD | NEW |