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

Side by Side Diff: trunk/src/base/memory/discardable_memory_emulated.cc

Issue 257383004: Revert 267170 "Use DiscardableMemoryManager on Android." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/memory/discardable_memory_emulated.h" 5 #include "base/memory/discardable_memory_emulated.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/memory/discardable_memory_manager.h" 8 #include "base/memory/discardable_memory_manager.h"
9 9
10 namespace base { 10 namespace base {
11 namespace { 11 namespace {
12 12
13 base::LazyInstance<internal::DiscardableMemoryManager>::Leaky g_manager = 13 base::LazyInstance<internal::DiscardableMemoryManager>::Leaky g_manager =
14 LAZY_INSTANCE_INITIALIZER; 14 LAZY_INSTANCE_INITIALIZER;
15 15
16 } // namespace 16 } // namespace
17 17
18 namespace internal { 18 namespace internal {
19 19
20 DiscardableMemoryEmulated::DiscardableMemoryEmulated(size_t bytes) 20 DiscardableMemoryEmulated::DiscardableMemoryEmulated(size_t size)
21 : bytes_(bytes), 21 : is_locked_(false) {
22 is_locked_(false) { 22 g_manager.Pointer()->Register(this, size);
23 g_manager.Pointer()->Register(this, bytes);
24 } 23 }
25 24
26 DiscardableMemoryEmulated::~DiscardableMemoryEmulated() { 25 DiscardableMemoryEmulated::~DiscardableMemoryEmulated() {
27 if (is_locked_) 26 if (is_locked_)
28 Unlock(); 27 Unlock();
29 g_manager.Pointer()->Unregister(this); 28 g_manager.Pointer()->Unregister(this);
30 } 29 }
31 30
32 // static 31 // static
33 void DiscardableMemoryEmulated::RegisterMemoryPressureListeners() { 32 void DiscardableMemoryEmulated::RegisterMemoryPressureListeners() {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 g_manager.Pointer()->ReleaseLock(this); 64 g_manager.Pointer()->ReleaseLock(this);
66 is_locked_ = false; 65 is_locked_ = false;
67 } 66 }
68 67
69 void* DiscardableMemoryEmulated::Memory() const { 68 void* DiscardableMemoryEmulated::Memory() const {
70 DCHECK(is_locked_); 69 DCHECK(is_locked_);
71 DCHECK(memory_); 70 DCHECK(memory_);
72 return memory_.get(); 71 return memory_.get();
73 } 72 }
74 73
75 bool DiscardableMemoryEmulated::AllocateAndAcquireLock() { 74 bool DiscardableMemoryEmulated::AllocateAndAcquireLock(size_t bytes) {
76 if (memory_) 75 if (memory_)
77 return true; 76 return true;
78 77
79 memory_.reset(new uint8[bytes_]); 78 memory_.reset(new uint8[bytes]);
80 return false; 79 return false;
81 } 80 }
82 81
83 void DiscardableMemoryEmulated::Purge() { 82 void DiscardableMemoryEmulated::Purge() {
84 memory_.reset(); 83 memory_.reset();
85 } 84 }
86 85
87 } // namespace internal 86 } // namespace internal
88 } // namespace base 87 } // namespace base
OLDNEW
« no previous file with comments | « trunk/src/base/memory/discardable_memory_emulated.h ('k') | trunk/src/base/memory/discardable_memory_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698