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

Side by Side Diff: base/test/test_discardable_memory_allocator.cc

Issue 1787973002: Replace blink::WebDiscardableMemory with base::DiscardableMemory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use StringPiece::as_string Created 4 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
« no previous file with comments | « no previous file | content/child/blink_platform_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/test/test_discardable_memory_allocator.h" 5 #include "base/test/test_discardable_memory_allocator.h"
6 6
7 #include <stdint.h> 7 #include <cstdint>
8 #include <cstring>
8 9
9 #include "base/memory/discardable_memory.h" 10 #include "base/memory/discardable_memory.h"
10 11
11 namespace base { 12 namespace base {
12 namespace { 13 namespace {
13 14
14 class DiscardableMemoryImpl : public DiscardableMemory { 15 class DiscardableMemoryImpl : public DiscardableMemory {
15 public: 16 public:
16 explicit DiscardableMemoryImpl(size_t size) : data_(new uint8_t[size]) {} 17 explicit DiscardableMemoryImpl(size_t size)
18 : data_(new uint8_t[size]), size_(size) {}
17 19
18 // Overridden from DiscardableMemory: 20 // Overridden from DiscardableMemory:
19 bool Lock() override { return false; } 21 bool Lock() override {
20 void Unlock() override {} 22 DCHECK(!is_locked_);
21 void* data() const override { return data_.get(); } 23 is_locked_ = true;
24 return false;
25 }
26
27 void Unlock() override {
28 DCHECK(is_locked_);
29 is_locked_ = false;
30 // Force eviction to catch clients not correctly checking the return value
31 // of Lock().
32 memset(data_.get(), 0, size_);
33 }
34
35 void* data() const override {
36 DCHECK(is_locked_);
37 return data_.get();
38 }
22 39
23 trace_event::MemoryAllocatorDump* CreateMemoryAllocatorDump( 40 trace_event::MemoryAllocatorDump* CreateMemoryAllocatorDump(
24 const char* name, 41 const char* name,
25 trace_event::ProcessMemoryDump* pmd) const override { 42 trace_event::ProcessMemoryDump* pmd) const override {
26 return nullptr; 43 return nullptr;
27 } 44 }
28 45
29 private: 46 private:
47 bool is_locked_ = true;
30 scoped_ptr<uint8_t[]> data_; 48 scoped_ptr<uint8_t[]> data_;
49 size_t size_;
31 }; 50 };
32 51
33 } // namespace 52 } // namespace
34 53
35 TestDiscardableMemoryAllocator::TestDiscardableMemoryAllocator() { 54 TestDiscardableMemoryAllocator::TestDiscardableMemoryAllocator() {
36 } 55 }
37 56
38 TestDiscardableMemoryAllocator::~TestDiscardableMemoryAllocator() { 57 TestDiscardableMemoryAllocator::~TestDiscardableMemoryAllocator() {
39 } 58 }
40 59
41 scoped_ptr<DiscardableMemory> 60 scoped_ptr<DiscardableMemory>
42 TestDiscardableMemoryAllocator::AllocateLockedDiscardableMemory(size_t size) { 61 TestDiscardableMemoryAllocator::AllocateLockedDiscardableMemory(size_t size) {
43 return make_scoped_ptr(new DiscardableMemoryImpl(size)); 62 return make_scoped_ptr(new DiscardableMemoryImpl(size));
44 } 63 }
45 64
46 } // namespace base 65 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | content/child/blink_platform_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698