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

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

Issue 2413643002: Add MemoryCoordinator::SetClientMemoryState and GetClientMemoryState (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
« no previous file with comments | « content/browser/memory/memory_coordinator.h ('k') | no next file » | 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 #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 23 matching lines...) Expand all
34 }; 34 };
35 35
36 // static 36 // static
37 MemoryCoordinator* MemoryCoordinator::GetInstance() { 37 MemoryCoordinator* MemoryCoordinator::GetInstance() {
38 if (!base::FeatureList::IsEnabled(features::kMemoryCoordinator)) 38 if (!base::FeatureList::IsEnabled(features::kMemoryCoordinator))
39 return nullptr; 39 return nullptr;
40 return base::Singleton<MemoryCoordinator, 40 return base::Singleton<MemoryCoordinator,
41 base::LeakySingletonTraits<MemoryCoordinator>>::get(); 41 base::LeakySingletonTraits<MemoryCoordinator>>::get();
42 } 42 }
43 43
44 MemoryCoordinator::MemoryCoordinator() {} 44 MemoryCoordinator::MemoryCoordinator()
45 : client_memory_state_(base::MemoryState::NORMAL) {}
45 46
46 MemoryCoordinator::~MemoryCoordinator() {} 47 MemoryCoordinator::~MemoryCoordinator() {}
47 48
48 void MemoryCoordinator::CreateHandle( 49 void MemoryCoordinator::CreateHandle(
49 int render_process_id, 50 int render_process_id,
50 mojom::MemoryCoordinatorHandleRequest request) { 51 mojom::MemoryCoordinatorHandleRequest request) {
51 std::unique_ptr<MemoryCoordinatorHandleImpl> handle( 52 std::unique_ptr<MemoryCoordinatorHandleImpl> handle(
52 new MemoryCoordinatorHandleImpl(std::move(request))); 53 new MemoryCoordinatorHandleImpl(std::move(request)));
53 handle->binding().set_connection_error_handler( 54 handle->binding().set_connection_error_handler(
54 base::Bind(&MemoryCoordinator::OnConnectionError, base::Unretained(this), 55 base::Bind(&MemoryCoordinator::OnConnectionError, base::Unretained(this),
(...skipping 19 matching lines...) Expand all
74 // A nop doesn't need to be sent, but is considered successful. 75 // A nop doesn't need to be sent, but is considered successful.
75 if (iter->second.memory_state == memory_state) 76 if (iter->second.memory_state == memory_state)
76 return true; 77 return true;
77 78
78 // Update the internal state and send the message. 79 // Update the internal state and send the message.
79 iter->second.memory_state = memory_state; 80 iter->second.memory_state = memory_state;
80 iter->second.handle->child()->OnStateChange(memory_state); 81 iter->second.handle->child()->OnStateChange(memory_state);
81 return true; 82 return true;
82 } 83 }
83 84
85 void MemoryCoordinator::SetClientMemoryState(base::MemoryState memory_state) {
haraken 2016/10/12 08:11:45 Who are you assuming calls this method? Also Chri
86 client_memory_state_ = memory_state;
87 base::MemoryCoordinatorClientRegistry::GetInstance()->Notify(memory_state);
88 }
89
84 mojom::MemoryState MemoryCoordinator::GetMemoryState( 90 mojom::MemoryState MemoryCoordinator::GetMemoryState(
85 int render_process_id) const { 91 int render_process_id) const {
86 auto iter = children_.find(render_process_id); 92 auto iter = children_.find(render_process_id);
87 if (iter == children_.end()) 93 if (iter == children_.end())
88 return mojom::MemoryState::UNKNOWN; 94 return mojom::MemoryState::UNKNOWN;
89 return iter->second.memory_state; 95 return iter->second.memory_state;
90 } 96 }
91 97
98 base::MemoryState MemoryCoordinator::GetClientMemoryState() const {
99 return client_memory_state_;
100 }
101
92 void MemoryCoordinator::AddChildForTesting( 102 void MemoryCoordinator::AddChildForTesting(
93 int dummy_render_process_id, mojom::ChildMemoryCoordinatorPtr child) { 103 int dummy_render_process_id, mojom::ChildMemoryCoordinatorPtr child) {
94 mojom::MemoryCoordinatorHandlePtr mch; 104 mojom::MemoryCoordinatorHandlePtr mch;
95 auto request = mojo::GetProxy(&mch); 105 auto request = mojo::GetProxy(&mch);
96 std::unique_ptr<MemoryCoordinatorHandleImpl> handle( 106 std::unique_ptr<MemoryCoordinatorHandleImpl> handle(
97 new MemoryCoordinatorHandleImpl(std::move(request))); 107 new MemoryCoordinatorHandleImpl(std::move(request)));
98 handle->AddChild(std::move(child)); 108 handle->AddChild(std::move(child));
99 CreateChildInfoMapEntry(dummy_render_process_id, std::move(handle)); 109 CreateChildInfoMapEntry(dummy_render_process_id, std::move(handle));
100 } 110 }
101 111
(...skipping 14 matching lines...) Expand all
116 126
117 MemoryCoordinator::ChildInfo::ChildInfo() {} 127 MemoryCoordinator::ChildInfo::ChildInfo() {}
118 128
119 MemoryCoordinator::ChildInfo::ChildInfo(const ChildInfo& rhs) { 129 MemoryCoordinator::ChildInfo::ChildInfo(const ChildInfo& rhs) {
120 // This is a nop, but exists for compatibility with STL containers. 130 // This is a nop, but exists for compatibility with STL containers.
121 } 131 }
122 132
123 MemoryCoordinator::ChildInfo::~ChildInfo() {} 133 MemoryCoordinator::ChildInfo::~ChildInfo() {}
124 134
125 } // namespace content 135 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/memory/memory_coordinator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698