OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/keyed_service/ios/browser_state_helper.h" | 5 #include "components/keyed_service/ios/browser_state_helper.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/supports_user_data.h" | 8 #include "base/supports_user_data.h" |
9 #include "ios/web/public/browser_state.h" | 9 #include "ios/web/public/browser_state.h" |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 // methods that take a base::SupportsUserData need to discriminate | 24 // methods that take a base::SupportsUserData need to discriminate |
25 // between the two objects. | 25 // between the two objects. |
26 // | 26 // |
27 // If the base::SupportsUserData is a web::BrowserState then the public | 27 // If the base::SupportsUserData is a web::BrowserState then the public |
28 // method web::BrowserState::FromSupportsUserData can do the conversion | 28 // method web::BrowserState::FromSupportsUserData can do the conversion |
29 // safely. If this method fails then context is content::BrowserContext | 29 // safely. If this method fails then context is content::BrowserContext |
30 // and the methods defined below allow the embedder to provides helper | 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). | 31 // to find the associated web::BrowserState (there is a 1:1 mapping). |
32 | 32 |
33 namespace { | 33 namespace { |
34 BrowserStateFromContextFn gBrowserStateFromContext = nullptr; | 34 BrowserStateFromContextFn g_browser_state_from_context = nullptr; |
35 } // namespace | 35 } // namespace |
36 | 36 |
37 void SetBrowserStateFromContextHelper(BrowserStateFromContextFn helper) { | 37 void SetBrowserStateFromContextHelper(BrowserStateFromContextFn helper) { |
38 gBrowserStateFromContext = helper; | 38 g_browser_state_from_context = helper; |
39 } | 39 } |
40 | 40 |
41 web::BrowserState* BrowserStateFromContext(base::SupportsUserData* context) { | 41 web::BrowserState* BrowserStateFromContext(base::SupportsUserData* context) { |
42 web::BrowserState* state = nullptr; | 42 web::BrowserState* state = nullptr; |
43 if (context) { | 43 if (context) { |
44 state = web::BrowserState::FromSupportsUserData(context); | 44 state = web::BrowserState::FromSupportsUserData(context); |
45 if (!state && gBrowserStateFromContext) | 45 if (!state && g_browser_state_from_context) |
46 state = gBrowserStateFromContext(context); | 46 state = g_browser_state_from_context(context); |
47 DCHECK(state) << "cannot convert context to web::BrowserState"; | 47 DCHECK(state) << "cannot convert context to web::BrowserState"; |
48 } | 48 } |
49 return state; | 49 return state; |
50 } | 50 } |
OLD | NEW |