1 // Copyright 2017 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 CHROMECAST_BROWSER_MEMORY_PRESSURE_CONTROLLER_IMPL_H_
6 #define CHROMECAST_BROWSER_MEMORY_PRESSURE_CONTROLLER_IMPL_H_
7 
8 #include "base/macros.h"
9 #include "base/memory/memory_pressure_listener.h"
10 #include "chromecast/common/mojom/memory_pressure.mojom.h"
11 #include "mojo/public/cpp/bindings/pending_remote.h"
12 #include "mojo/public/cpp/bindings/receiver_set.h"
13 #include "mojo/public/cpp/bindings/remote_set.h"
14 
15 namespace chromecast {
16 
17 class MemoryPressureControllerImpl : public mojom::MemoryPressureController {
18  public:
19   MemoryPressureControllerImpl();
20   ~MemoryPressureControllerImpl() override;
21 
22   void AddReceiver(
23       mojo::PendingReceiver<mojom::MemoryPressureController> receiver);
24 
25  private:
26   // chromecast::mojom::MemoryPressure implementation.
27   void AddObserver(
28       mojo::PendingRemote<mojom::MemoryPressureObserver> observer) override;
29 
30   void OnMemoryPressure(
31       base::MemoryPressureListener::MemoryPressureLevel level);
32 
33   mojo::RemoteSet<mojom::MemoryPressureObserver> observers_;
34   mojo::ReceiverSet<mojom::MemoryPressureController> receivers_;
35 
36   std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_;
37 
38   DISALLOW_COPY_AND_ASSIGN(MemoryPressureControllerImpl);
39 };
40 
41 }  // namespace chromecast
42 
43 #endif  // CHROMECAST_BROWSER_MEMORY_PRESSURE_CONTROLLER_IMPL_H_
44