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

Side by Side Diff: content/child/memory/child_memory_coordinator_impl.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/child/memory/child_memory_coordinator_impl.h" 5 #include "content/child/memory/child_memory_coordinator_impl.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/memory/memory_coordinator_client_registry.h" 8 #include "base/memory/memory_coordinator_client_registry.h"
9 #include "base/synchronization/lock.h" 9 #include "base/synchronization/lock.h"
10 #include "content/public/common/content_features.h"
10 11
11 namespace content { 12 namespace content {
12 13
13 namespace { 14 namespace {
14 15
15 base::LazyInstance<base::Lock>::Leaky g_lock = LAZY_INSTANCE_INITIALIZER; 16 base::LazyInstance<base::Lock>::Leaky g_lock = LAZY_INSTANCE_INITIALIZER;
16 ChildMemoryCoordinatorImpl* g_child_memory_coordinator = nullptr; 17 ChildMemoryCoordinatorImpl* g_child_memory_coordinator = nullptr;
17 18
18 base::MemoryState ToBaseMemoryState(mojom::MemoryState state) { 19 base::MemoryState ToBaseMemoryState(mojom::MemoryState state) {
19 switch (state) { 20 switch (state) {
20 case mojom::MemoryState::UNKNOWN: 21 case mojom::MemoryState::UNKNOWN:
21 return base::MemoryState::UNKNOWN; 22 return base::MemoryState::UNKNOWN;
22 case mojom::MemoryState::NORMAL: 23 case mojom::MemoryState::NORMAL:
23 return base::MemoryState::NORMAL; 24 return base::MemoryState::NORMAL;
24 case mojom::MemoryState::THROTTLED: 25 case mojom::MemoryState::THROTTLED:
25 return base::MemoryState::THROTTLED; 26 return base::MemoryState::THROTTLED;
26 case mojom::MemoryState::SUSPENDED: 27 case mojom::MemoryState::SUSPENDED:
27 return base::MemoryState::SUSPENDED; 28 return base::MemoryState::SUSPENDED;
28 default: 29 default:
29 NOTREACHED(); 30 NOTREACHED();
30 return base::MemoryState::UNKNOWN; 31 return base::MemoryState::UNKNOWN;
31 } 32 }
32 } 33 }
33 34
34 } // namespace 35 } // namespace
35 36
36 // static 37 // static
38 bool ChildMemoryCoordinatorImpl::IsEnabled() {
39 // TODO(tasak): Remove |kPurgeAndSuspend| when the experiment is done.
40 return base::FeatureList::IsEnabled(features::kMemoryCoordinator) ||
41 base::FeatureList::IsEnabled(features::kPurgeAndSuspend);
42 }
43
44 // static
37 ChildMemoryCoordinatorImpl* ChildMemoryCoordinatorImpl::GetInstance() { 45 ChildMemoryCoordinatorImpl* ChildMemoryCoordinatorImpl::GetInstance() {
38 base::AutoLock lock(*g_lock.Pointer()); 46 base::AutoLock lock(*g_lock.Pointer());
39 return g_child_memory_coordinator; 47 return g_child_memory_coordinator;
40 } 48 }
41 49
42 ChildMemoryCoordinatorImpl::ChildMemoryCoordinatorImpl( 50 ChildMemoryCoordinatorImpl::ChildMemoryCoordinatorImpl(
43 mojom::MemoryCoordinatorHandlePtr parent, 51 mojom::MemoryCoordinatorHandlePtr parent,
44 ChildMemoryCoordinatorDelegate* delegate) 52 ChildMemoryCoordinatorDelegate* delegate)
45 : binding_(this), parent_(std::move(parent)), delegate_(delegate) { 53 : binding_(this), parent_(std::move(parent)), delegate_(delegate) {
46 base::AutoLock lock(*g_lock.Pointer()); 54 base::AutoLock lock(*g_lock.Pointer());
(...skipping 18 matching lines...) Expand all
65 #if !defined(OS_ANDROID) 73 #if !defined(OS_ANDROID)
66 std::unique_ptr<ChildMemoryCoordinatorImpl> CreateChildMemoryCoordinator( 74 std::unique_ptr<ChildMemoryCoordinatorImpl> CreateChildMemoryCoordinator(
67 mojom::MemoryCoordinatorHandlePtr parent, 75 mojom::MemoryCoordinatorHandlePtr parent,
68 ChildMemoryCoordinatorDelegate* delegate) { 76 ChildMemoryCoordinatorDelegate* delegate) {
69 return base::WrapUnique( 77 return base::WrapUnique(
70 new ChildMemoryCoordinatorImpl(std::move(parent), delegate)); 78 new ChildMemoryCoordinatorImpl(std::move(parent), delegate));
71 } 79 }
72 #endif 80 #endif
73 81
74 } // namespace content 82 } // namespace content
OLDNEW
« no previous file with comments | « content/child/memory/child_memory_coordinator_impl.h ('k') | content/public/common/content_features.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698