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

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

Issue 2731913002: NotForReview: Expose the global memory budget (chromium side)
Patch Set: Add --simulate-memory-pressure 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
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 "base/memory/memory_coordinator_proxy.h"
11 #include "content/common/child_memory_coordinator.mojom.h" 11 #include "content/common/child_memory_coordinator.mojom.h"
12 #include "content/common/content_export.h" 12 #include "content/common/content_export.h"
13 #include "content/common/memory_coordinator.mojom.h" 13 #include "content/common/memory_coordinator.mojom.h"
14 #include "mojo/public/cpp/bindings/binding.h" 14 #include "mojo/public/cpp/bindings/binding.h"
15 #include "mojo/public/cpp/system/buffer.h"
15 16
16 namespace content { 17 namespace content {
17 18
18 class CONTENT_EXPORT ChildMemoryCoordinatorDelegate { 19 class CONTENT_EXPORT ChildMemoryCoordinatorDelegate {
19 public: 20 public:
20 virtual ~ChildMemoryCoordinatorDelegate() {} 21 virtual ~ChildMemoryCoordinatorDelegate() {}
21 22
22 // Called when the system requests immediate actions to free memory. 23 // Called when the system requests immediate actions to free memory.
23 virtual void OnTrimMemoryImmediately() = 0; 24 virtual void OnTrimMemoryImmediately() = 0;
24 }; 25 };
25 26
26 // ChildMemoryCoordinatorImpl is the implementation of ChildMemoryCoordinator. 27 // ChildMemoryCoordinatorImpl is the implementation of ChildMemoryCoordinator.
27 // It lives in child processes and is responsible for dispatching memory events 28 // It lives in child processes and is responsible for dispatching memory events
28 // to its clients. 29 // to its clients.
29 class CONTENT_EXPORT ChildMemoryCoordinatorImpl 30 class CONTENT_EXPORT ChildMemoryCoordinatorImpl
30 : base::MemoryCoordinator, 31 : base::MemoryCoordinator,
31 NON_EXPORTED_BASE(public mojom::ChildMemoryCoordinator) { 32 NON_EXPORTED_BASE(public mojom::ChildMemoryCoordinator) {
32 public: 33 public:
33 // Returns the instance of ChildMemoryCoordinatorImpl. Could be nullptr. 34 // Returns the instance of ChildMemoryCoordinatorImpl. Could be nullptr.
34 static ChildMemoryCoordinatorImpl* GetInstance(); 35 static ChildMemoryCoordinatorImpl* GetInstance();
35 36
36 ChildMemoryCoordinatorImpl(mojom::MemoryCoordinatorHandlePtr parent, 37 ChildMemoryCoordinatorImpl(mojom::MemoryCoordinatorHandlePtr parent,
37 ChildMemoryCoordinatorDelegate* delegate); 38 ChildMemoryCoordinatorDelegate* delegate);
38 ~ChildMemoryCoordinatorImpl() override; 39 ~ChildMemoryCoordinatorImpl() override;
39 40
40 // base::MemoryCoordinator implementations: 41 // base::MemoryCoordinator implementations:
41 base::MemoryState GetCurrentMemoryState() const override; 42 base::MemoryState GetCurrentMemoryState() const override;
43 int64_t GetGlobalBudget() override;
44 void SetGlobalBudgetUpdateInterval(uint32_t interval_ms) override;
42 45
43 // mojom::ChildMemoryCoordinator implementations: 46 // mojom::ChildMemoryCoordinator implementations:
44 void OnStateChange(mojom::MemoryState state) override; 47 void OnStateChange(mojom::MemoryState state) override;
45 void PurgeMemory() override; 48 void PurgeMemory() override;
46 49
47 protected: 50 protected:
48 ChildMemoryCoordinatorDelegate* delegate() { return delegate_; } 51 ChildMemoryCoordinatorDelegate* delegate() { return delegate_; }
49 52
50 private: 53 private:
51 friend class ChildMemoryCoordinatorImplTest; 54 friend class ChildMemoryCoordinatorImplTest;
52 55
56 void OnGetGlobalBudgetHandle(mojo::ScopedSharedBufferHandle handle);
57
53 mojo::Binding<mojom::ChildMemoryCoordinator> binding_; 58 mojo::Binding<mojom::ChildMemoryCoordinator> binding_;
54 base::MemoryState current_state_ = base::MemoryState::NORMAL; 59 base::MemoryState current_state_ = base::MemoryState::NORMAL;
55 mojom::MemoryCoordinatorHandlePtr parent_; 60 mojom::MemoryCoordinatorHandlePtr parent_;
56 ChildMemoryCoordinatorDelegate* delegate_; 61 ChildMemoryCoordinatorDelegate* delegate_;
62 mojo::ScopedSharedBufferHandle global_budget_handle_;
63 mojo::ScopedSharedBufferMapping global_budget_mapping_;
57 64
58 DISALLOW_COPY_AND_ASSIGN(ChildMemoryCoordinatorImpl); 65 DISALLOW_COPY_AND_ASSIGN(ChildMemoryCoordinatorImpl);
59 }; 66 };
60 67
61 // Factory function for creating a ChildMemoryCoordinator for the current 68 // Factory function for creating a ChildMemoryCoordinator for the current
62 // platform. Doesn't take the ownership of |delegate|. 69 // platform. Doesn't take the ownership of |delegate|.
63 CONTENT_EXPORT std::unique_ptr<ChildMemoryCoordinatorImpl> 70 CONTENT_EXPORT std::unique_ptr<ChildMemoryCoordinatorImpl>
64 CreateChildMemoryCoordinator(mojom::MemoryCoordinatorHandlePtr parent, 71 CreateChildMemoryCoordinator(mojom::MemoryCoordinatorHandlePtr parent,
65 ChildMemoryCoordinatorDelegate* delegate); 72 ChildMemoryCoordinatorDelegate* delegate);
66 73
67 } // namespace content 74 } // namespace content
68 75
69 #endif // CONTENT_CHILD_MEMORY_CHILD_MEMORY_COORDINATOR_IMPL_H_ 76 #endif // CONTENT_CHILD_MEMORY_CHILD_MEMORY_COORDINATOR_IMPL_H_
OLDNEW
« no previous file with comments | « content/browser/memory/memory_coordinator_impl.cc ('k') | content/child/memory/child_memory_coordinator_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698