Only send _NET_ACTIVE_WINDOW hint if the chromium window is not already active.
[chromium-blink-merge.git] / components / keyed_service / ios / browser_state_dependency_manager.h
blobc13f4a8a4c9e565d76a3f574dea72d466048b0df
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 template <typename T>
15 struct DefaultSingletonTraits;
17 namespace web {
18 class BrowserState;
21 namespace user_prefs {
22 class PrefRegistrySyncable;
25 // A singleton that listens for context destruction notifications and
26 // rebroadcasts them to each KeyedServiceBaseFactory in a safe order
27 // based on the stated dependencies by each service.
28 class KEYED_SERVICE_EXPORT BrowserStateDependencyManager
29 : public DependencyManager {
30 public:
31 static BrowserStateDependencyManager* GetInstance();
33 // Registers context-specific preferences for all services via |registry|.
34 // |context| should be the BrowserState containing |registry| and is used as
35 // a key to prevent multiple registrations on the same BrowserState in
36 // tests.
37 void RegisterBrowserStatePrefsForServices(
38 web::BrowserState* context,
39 user_prefs::PrefRegistrySyncable* registry);
41 // Called by each BrowserState to alert us of its creation. Service that
42 // want to be started when BrowserState is created should override the
43 // ServiceIsCreatedWithBrowserState() method in their factory. Preferences
44 // registration also happens during that method call.
45 void CreateBrowserStateServices(web::BrowserState* context);
47 // Similar to CreateBrowserStateServices(), except this is used for creating
48 // test BrowserStates - these contexts will not create services for any
49 // BrowserStateKeyedBaseFactories that return true from
50 // ServiceIsNULLWhileTesting().
51 void CreateBrowserStateServicesForTest(web::BrowserState* context);
53 // Called by each BrowserState to alert us that we should destroy services
54 // associated with it.
55 void DestroyBrowserStateServices(web::BrowserState* context);
57 #ifndef NDEBUG
58 // Debugging assertion called as part of GetServiceForBrowserState in debug
59 // mode. This will NOTREACHED() whenever the user is trying to access a stale
60 // BrowserState*.
61 void AssertBrowserStateWasntDestroyed(web::BrowserState* context);
63 // Marks |context| as live (i.e., not stale). This method can be called as a
64 // safeguard against |AssertBrowserStateWasntDestroyed()| checks going off
65 // due to |context| aliasing a BrowserState instance from a prior test
66 // (i.e., 0xWhatever might be created, be destroyed, and then a new
67 // BrowserState object might be created at 0xWhatever).
68 void MarkBrowserStateLiveForTesting(web::BrowserState* context);
69 #endif // NDEBUG
71 private:
72 friend struct DefaultSingletonTraits<BrowserStateDependencyManager>;
74 BrowserStateDependencyManager();
75 ~BrowserStateDependencyManager() override;
77 // Helper function used by CreateBrowserStateServices[ForTest].
78 void DoCreateBrowserStateServices(web::BrowserState* context,
79 bool is_testing_context);
81 #ifndef NDEBUG
82 // DependencyManager:
83 void DumpContextDependencies(base::SupportsUserData* context) const final;
84 #endif // NDEBUG
86 DISALLOW_COPY_AND_ASSIGN(BrowserStateDependencyManager);
89 #endif // COMPONENTS_KEYED_SERVICE_IOS_BROWSER_STATE_DEPENDENCY_MANAGER_H_