Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: content/child/memory/child_memory_coordinator_impl.h

Issue 2739363002: Implement base::MemoryCoordinator for ChildMemoryCoordinatorImpl (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/child/memory/child_memory_coordinator_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 CONTENT_CHILD_MEMORY_CHILD_MEMORY_COORDINATOR_IMPL_H_ 5 #ifndef CONTENT_CHILD_MEMORY_CHILD_MEMORY_COORDINATOR_IMPL_H_
6 #define CONTENT_CHILD_MEMORY_CHILD_MEMORY_COORDINATOR_IMPL_H_ 6 #define CONTENT_CHILD_MEMORY_CHILD_MEMORY_COORDINATOR_IMPL_H_
7 7
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/memory/memory_coordinator_client.h" 9 #include "base/memory/memory_coordinator_client.h"
10 #include "base/memory/memory_coordinator_proxy.h"
10 #include "content/common/child_memory_coordinator.mojom.h" 11 #include "content/common/child_memory_coordinator.mojom.h"
11 #include "content/common/content_export.h" 12 #include "content/common/content_export.h"
12 #include "content/common/memory_coordinator.mojom.h" 13 #include "content/common/memory_coordinator.mojom.h"
13 #include "mojo/public/cpp/bindings/binding.h" 14 #include "mojo/public/cpp/bindings/binding.h"
14 15
15 namespace content { 16 namespace content {
16 17
17 class CONTENT_EXPORT ChildMemoryCoordinatorDelegate { 18 class CONTENT_EXPORT ChildMemoryCoordinatorDelegate {
18 public: 19 public:
19 virtual ~ChildMemoryCoordinatorDelegate() {} 20 virtual ~ChildMemoryCoordinatorDelegate() {}
20 21
21 // Called when the system requests immediate actions to free memory. 22 // Called when the system requests immediate actions to free memory.
22 virtual void OnTrimMemoryImmediately() = 0; 23 virtual void OnTrimMemoryImmediately() = 0;
23 }; 24 };
24 25
25 // ChildMemoryCoordinatorImpl is the implementation of ChildMemoryCoordinator. 26 // ChildMemoryCoordinatorImpl is the implementation of ChildMemoryCoordinator.
26 // It lives in child processes and is responsible for dispatching memory events 27 // It lives in child processes and is responsible for dispatching memory events
27 // to its clients. 28 // to its clients.
28 class CONTENT_EXPORT ChildMemoryCoordinatorImpl 29 class CONTENT_EXPORT ChildMemoryCoordinatorImpl
29 : NON_EXPORTED_BASE(public mojom::ChildMemoryCoordinator) { 30 : base::MemoryCoordinator,
31 NON_EXPORTED_BASE(public mojom::ChildMemoryCoordinator) {
30 public: 32 public:
31 // Returns the instance of ChildMemoryCoordinatorImpl. Could be nullptr. 33 // Returns the instance of ChildMemoryCoordinatorImpl. Could be nullptr.
32 static ChildMemoryCoordinatorImpl* GetInstance(); 34 static ChildMemoryCoordinatorImpl* GetInstance();
33 35
34 ChildMemoryCoordinatorImpl(mojom::MemoryCoordinatorHandlePtr parent, 36 ChildMemoryCoordinatorImpl(mojom::MemoryCoordinatorHandlePtr parent,
35 ChildMemoryCoordinatorDelegate* delegate); 37 ChildMemoryCoordinatorDelegate* delegate);
36 ~ChildMemoryCoordinatorImpl() override; 38 ~ChildMemoryCoordinatorImpl() override;
37 39
40 // base::MemoryCoordinator implementations:
41 base::MemoryState GetCurrentMemoryState() const override;
42
38 // mojom::ChildMemoryCoordinator implementations: 43 // mojom::ChildMemoryCoordinator implementations:
39 void OnStateChange(mojom::MemoryState state) override; 44 void OnStateChange(mojom::MemoryState state) override;
40 void PurgeMemory() override; 45 void PurgeMemory() override;
41 46
42 protected: 47 protected:
43 ChildMemoryCoordinatorDelegate* delegate() { return delegate_; } 48 ChildMemoryCoordinatorDelegate* delegate() { return delegate_; }
44 49
45 private: 50 private:
46 friend class ChildMemoryCoordinatorImplTest; 51 friend class ChildMemoryCoordinatorImplTest;
47 52
48 mojo::Binding<mojom::ChildMemoryCoordinator> binding_; 53 mojo::Binding<mojom::ChildMemoryCoordinator> binding_;
54 base::MemoryState current_state_ = base::MemoryState::NORMAL;
49 mojom::MemoryCoordinatorHandlePtr parent_; 55 mojom::MemoryCoordinatorHandlePtr parent_;
50 ChildMemoryCoordinatorDelegate* delegate_; 56 ChildMemoryCoordinatorDelegate* delegate_;
51 57
52 DISALLOW_COPY_AND_ASSIGN(ChildMemoryCoordinatorImpl); 58 DISALLOW_COPY_AND_ASSIGN(ChildMemoryCoordinatorImpl);
53 }; 59 };
54 60
55 // Factory function for creating a ChildMemoryCoordinator for the current 61 // Factory function for creating a ChildMemoryCoordinator for the current
56 // platform. Doesn't take the ownership of |delegate|. 62 // platform. Doesn't take the ownership of |delegate|.
57 CONTENT_EXPORT std::unique_ptr<ChildMemoryCoordinatorImpl> 63 CONTENT_EXPORT std::unique_ptr<ChildMemoryCoordinatorImpl>
58 CreateChildMemoryCoordinator(mojom::MemoryCoordinatorHandlePtr parent, 64 CreateChildMemoryCoordinator(mojom::MemoryCoordinatorHandlePtr parent,
59 ChildMemoryCoordinatorDelegate* delegate); 65 ChildMemoryCoordinatorDelegate* delegate);
60 66
61 } // namespace content 67 } // namespace content
62 68
63 #endif // CONTENT_CHILD_MEMORY_CHILD_MEMORY_COORDINATOR_IMPL_H_ 69 #endif // CONTENT_CHILD_MEMORY_CHILD_MEMORY_COORDINATOR_IMPL_H_
OLDNEW
« no previous file with comments | « no previous file | content/child/memory/child_memory_coordinator_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698