Linux: Depend on liberation-fonts package for RPMs.
[chromium-blink-merge.git] / components / keyed_service / ios / browser_state_dependency_manager.h
blob649f16f2376a26df82090b05fceedc679ebf4ac9
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_DEPENDENCY_MANAGER_H_
6 #define COMPONENTS_KEYED_SERVICE_IOS_BROWSER_STATE_DEPENDENCY_MANAGER_H_
8 #include "base/callback_forward.h"
9 #include "base/callback_list.h"
10 #include "base/macros.h"
11 #include "components/keyed_service/core/dependency_manager.h"
12 #include "components/keyed_service/core/keyed_service_export.h"
14 namespace base {
15 template <typename T>
16 struct DefaultSingletonTraits;
17 } // namespace base
19 namespace web {
20 class BrowserState;
23 namespace user_prefs {
24 class PrefRegistrySyncable;
27 // A singleton that listens for context destruction notifications and
28 // rebroadcasts them to each KeyedServiceBaseFactory in a safe order
29 // based on the stated dependencies by each service.
30 class KEYED_SERVICE_EXPORT BrowserStateDependencyManager
31 : public DependencyManager {
32 public:
33 static BrowserStateDependencyManager* GetInstance();
35 // Registers context-specific preferences for all services via |registry|.
36 // |context| should be the BrowserState containing |registry| and is used as
37 // a key to prevent multiple registrations on the same BrowserState in
38 // tests.
39 void RegisterBrowserStatePrefsForServices(
40 web::BrowserState* context,
41 user_prefs::PrefRegistrySyncable* registry);
43 // Called by each BrowserState to alert us of its creation. Service that
44 // want to be started when BrowserState is created should override the
45 // ServiceIsCreatedWithBrowserState() method in their factory. Preferences
46 // registration also happens during that method call.
47 void CreateBrowserStateServices(web::BrowserState* context);
49 // Similar to CreateBrowserStateServices(), except this is used for creating
50 // test BrowserStates - these contexts will not create services for any
51 // BrowserStateKeyedBaseFactories that return true from
52 // ServiceIsNULLWhileTesting().
53 void CreateBrowserStateServicesForTest(web::BrowserState* context);
55 // Called by each BrowserState to alert us that we should destroy services
56 // associated with it.
57 void DestroyBrowserStateServices(web::BrowserState* context);
59 #ifndef NDEBUG
60 // Debugging assertion called as part of GetServiceForBrowserState in debug
61 // mode. This will NOTREACHED() whenever the user is trying to access a stale
62 // BrowserState*.
63 void AssertBrowserStateWasntDestroyed(web::BrowserState* context);
65 // Marks |context| as live (i.e., not stale). This method can be called as a
66 // safeguard against |AssertBrowserStateWasntDestroyed()| checks going off
67 // due to |context| aliasing a BrowserState instance from a prior test
68 // (i.e., 0xWhatever might be created, be destroyed, and then a new
69 // BrowserState object might be created at 0xWhatever).
70 void MarkBrowserStateLiveForTesting(web::BrowserState* context);
71 #endif // NDEBUG
73 private:
74 friend struct base::DefaultSingletonTraits<BrowserStateDependencyManager>;
76 BrowserStateDependencyManager();
77 ~BrowserStateDependencyManager() override;
79 // Helper function used by CreateBrowserStateServices[ForTest].
80 void DoCreateBrowserStateServices(web::BrowserState* context,
81 bool is_testing_context);
83 #ifndef NDEBUG
84 // DependencyManager:
85 void DumpContextDependencies(base::SupportsUserData* context) const final;
86 #endif // NDEBUG
88 DISALLOW_COPY_AND_ASSIGN(BrowserStateDependencyManager);
91 #endif // COMPONENTS_KEYED_SERVICE_IOS_BROWSER_STATE_DEPENDENCY_MANAGER_H_