OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef COMPONENTS_MEMORY_COORDINATOR_COMMON_CLIENT_REGISTRY_H_ | 5 #ifndef COMPONENTS_MEMORY_COORDINATOR_COMMON_CLIENT_REGISTRY_H_ |
6 #define COMPONENTS_MEMORY_COORDINATOR_COMMON_CLIENT_REGISTRY_H_ | 6 #define COMPONENTS_MEMORY_COORDINATOR_COMMON_CLIENT_REGISTRY_H_ |
7 | 7 |
8 #include "base/observer_list_threadsafe.h" | 8 #include "base/observer_list_threadsafe.h" |
9 #include "components/memory_coordinator/common/memory_coordinator_client.h" | 9 #include "components/memory_coordinator/common/memory_coordinator_client.h" |
10 #include "components/memory_coordinator/common/memory_coordinator_export.h" | 10 #include "components/memory_coordinator/common/memory_coordinator_export.h" |
11 | 11 |
12 namespace memory_coordinator { | 12 namespace memory_coordinator { |
13 | 13 |
14 // ClientRegistry is a base class of process-specific memory coordinator | 14 // ClientRegistry is a base class of process-specific memory coordinator |
15 // and provides ways to register/unregister MemoryCoordinatorClients. | 15 // and provides ways to register/unregister MemoryCoordinatorClients. |
16 class MEMORY_COORDINATOR_EXPORT ClientRegistry { | 16 class MEMORY_COORDINATOR_EXPORT ClientRegistry { |
17 public: | 17 public: |
18 ClientRegistry(); | 18 ClientRegistry(); |
19 virtual ~ClientRegistry(); | 19 virtual ~ClientRegistry(); |
20 | 20 |
| 21 static ClientRegistry* GetInstance(); |
| 22 |
21 // Registers/unregisters a client. Does not take ownership of client. | 23 // Registers/unregisters a client. Does not take ownership of client. |
22 void RegisterClient(MemoryCoordinatorClient* client); | 24 void RegisterClient(MemoryCoordinatorClient* client); |
23 void UnregisterClient(MemoryCoordinatorClient* client); | 25 void UnregisterClient(MemoryCoordinatorClient* client); |
24 | 26 |
25 protected: | 27 protected: |
| 28 static void SetInstance(ClientRegistry*); |
| 29 |
26 using ClientList = base::ObserverListThreadSafe<MemoryCoordinatorClient>; | 30 using ClientList = base::ObserverListThreadSafe<MemoryCoordinatorClient>; |
27 ClientList* clients() { return clients_.get(); } | 31 ClientList* clients() { return clients_.get(); } |
28 | 32 |
29 private: | 33 private: |
30 scoped_refptr<ClientList> clients_; | 34 scoped_refptr<ClientList> clients_; |
| 35 static ClientRegistry* instance_; |
31 }; | 36 }; |
32 | 37 |
33 } // namespace memory_coordinator | 38 } // namespace memory_coordinator |
34 | 39 |
35 #endif // COMPONENTS_MEMORY_COORDINATOR_COMMON_CLIENT_REGISTRY_H_ | 40 #endif // COMPONENTS_MEMORY_COORDINATOR_COMMON_CLIENT_REGISTRY_H_ |
OLD | NEW |