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

Side by Side Diff: content/browser/memory/memory_coordinator.cc

Issue 2376233005: [NotForReview] An idea for experimenting purge & suspend (Closed)
Patch Set: Created 4 years, 2 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 #include "content/browser/memory/memory_coordinator.h" 5 #include "content/browser/memory/memory_coordinator.h"
6 6
7 #include "base/memory/memory_coordinator_client_registry.h" 7 #include "base/memory/memory_coordinator_client_registry.h"
8 #include "content/public/common/content_features.h" 8 #include "content/public/common/content_features.h"
9 9
10 namespace content { 10 namespace content {
(...skipping 16 matching lines...) Expand all
27 mojo::Binding<mojom::MemoryCoordinatorHandle>& binding() { return binding_; } 27 mojo::Binding<mojom::MemoryCoordinatorHandle>& binding() { return binding_; }
28 28
29 private: 29 private:
30 mojom::ChildMemoryCoordinatorPtr child_; 30 mojom::ChildMemoryCoordinatorPtr child_;
31 mojo::Binding<mojom::MemoryCoordinatorHandle> binding_; 31 mojo::Binding<mojom::MemoryCoordinatorHandle> binding_;
32 32
33 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorHandleImpl); 33 DISALLOW_COPY_AND_ASSIGN(MemoryCoordinatorHandleImpl);
34 }; 34 };
35 35
36 // static 36 // static
37 bool MemoryCoordinator::IsEnabled() {
38 // TODO(tasak): Remove |kPurgeAndSuspend| when the experiment is done.
39 return base::FeatureList::IsEnabled(features::kMemoryCoordinator) ||
40 base::FeatureList::IsEnabled(features::kPurgeAndSuspend);
41 }
42
43 // static
37 MemoryCoordinator* MemoryCoordinator::GetInstance() { 44 MemoryCoordinator* MemoryCoordinator::GetInstance() {
38 if (!base::FeatureList::IsEnabled(features::kMemoryCoordinator)) 45 if (IsEnabled()) {
39 return nullptr; 46 return base::Singleton<MemoryCoordinator, base::LeakySingletonTraits<
40 return base::Singleton<MemoryCoordinator, 47 MemoryCoordinator>>::get();
41 base::LeakySingletonTraits<MemoryCoordinator>>::get(); 48 }
49 return nullptr;
42 } 50 }
43 51
44 MemoryCoordinator::MemoryCoordinator() {} 52 MemoryCoordinator::MemoryCoordinator() {}
45 53
46 MemoryCoordinator::~MemoryCoordinator() {} 54 MemoryCoordinator::~MemoryCoordinator() {}
47 55
48 void MemoryCoordinator::CreateHandle( 56 void MemoryCoordinator::CreateHandle(
49 int render_process_id, 57 int render_process_id,
50 mojom::MemoryCoordinatorHandleRequest request) { 58 mojom::MemoryCoordinatorHandleRequest request) {
51 std::unique_ptr<MemoryCoordinatorHandleImpl> handle( 59 std::unique_ptr<MemoryCoordinatorHandleImpl> handle(
(...skipping 30 matching lines...) Expand all
82 } 90 }
83 91
84 mojom::MemoryState MemoryCoordinator::GetMemoryState( 92 mojom::MemoryState MemoryCoordinator::GetMemoryState(
85 int render_process_id) const { 93 int render_process_id) const {
86 auto iter = children_.find(render_process_id); 94 auto iter = children_.find(render_process_id);
87 if (iter == children_.end()) 95 if (iter == children_.end())
88 return mojom::MemoryState::UNKNOWN; 96 return mojom::MemoryState::UNKNOWN;
89 return iter->second.memory_state; 97 return iter->second.memory_state;
90 } 98 }
91 99
100 bool MemoryCoordinator::PurgeAndSuspendChild(int render_process_id) {
101 DCHECK(base::FeatureList::IsEnabled(features::kPurgeAndSuspend));
102 return SetMemoryState(render_process_id, mojom::MemoryState::SUSPENDED);
103 }
104
92 void MemoryCoordinator::AddChildForTesting( 105 void MemoryCoordinator::AddChildForTesting(
93 int dummy_render_process_id, mojom::ChildMemoryCoordinatorPtr child) { 106 int dummy_render_process_id, mojom::ChildMemoryCoordinatorPtr child) {
94 mojom::MemoryCoordinatorHandlePtr mch; 107 mojom::MemoryCoordinatorHandlePtr mch;
95 auto request = mojo::GetProxy(&mch); 108 auto request = mojo::GetProxy(&mch);
96 std::unique_ptr<MemoryCoordinatorHandleImpl> handle( 109 std::unique_ptr<MemoryCoordinatorHandleImpl> handle(
97 new MemoryCoordinatorHandleImpl(std::move(request))); 110 new MemoryCoordinatorHandleImpl(std::move(request)));
98 handle->AddChild(std::move(child)); 111 handle->AddChild(std::move(child));
99 CreateChildInfoMapEntry(dummy_render_process_id, std::move(handle)); 112 CreateChildInfoMapEntry(dummy_render_process_id, std::move(handle));
100 } 113 }
101 114
(...skipping 14 matching lines...) Expand all
116 129
117 MemoryCoordinator::ChildInfo::ChildInfo() {} 130 MemoryCoordinator::ChildInfo::ChildInfo() {}
118 131
119 MemoryCoordinator::ChildInfo::ChildInfo(const ChildInfo& rhs) { 132 MemoryCoordinator::ChildInfo::ChildInfo(const ChildInfo& rhs) {
120 // This is a nop, but exists for compatibility with STL containers. 133 // This is a nop, but exists for compatibility with STL containers.
121 } 134 }
122 135
123 MemoryCoordinator::ChildInfo::~ChildInfo() {} 136 MemoryCoordinator::ChildInfo::~ChildInfo() {}
124 137
125 } // namespace content 138 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/memory/memory_coordinator.h ('k') | content/browser/renderer_host/render_process_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698