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

Side by Side Diff: base/memory/discardable_memory_manager_unittest.cc

Issue 668783004: Standardize usage of virtual/override/final in base/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Formatted Created 6 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 | « base/memory/discardable_memory_mach.h ('k') | base/memory/linked_ptr_unittest.cc » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_manager.h" 5 #include "base/memory/discardable_memory_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/synchronization/waitable_event.h" 8 #include "base/synchronization/waitable_event.h"
9 #include "base/threading/thread.h" 9 #include "base/threading/thread.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 namespace base { 12 namespace base {
13 namespace { 13 namespace {
14 14
15 class TestAllocationImpl : public internal::DiscardableMemoryManagerAllocation { 15 class TestAllocationImpl : public internal::DiscardableMemoryManagerAllocation {
16 public: 16 public:
17 TestAllocationImpl() : is_allocated_(false), is_locked_(false) {} 17 TestAllocationImpl() : is_allocated_(false), is_locked_(false) {}
18 virtual ~TestAllocationImpl() { DCHECK(!is_locked_); } 18 ~TestAllocationImpl() override { DCHECK(!is_locked_); }
19 19
20 // Overridden from internal::DiscardableMemoryManagerAllocation: 20 // Overridden from internal::DiscardableMemoryManagerAllocation:
21 virtual bool AllocateAndAcquireLock() override { 21 bool AllocateAndAcquireLock() override {
22 bool was_allocated = is_allocated_; 22 bool was_allocated = is_allocated_;
23 is_allocated_ = true; 23 is_allocated_ = true;
24 DCHECK(!is_locked_); 24 DCHECK(!is_locked_);
25 is_locked_ = true; 25 is_locked_ = true;
26 return was_allocated; 26 return was_allocated;
27 } 27 }
28 virtual void ReleaseLock() override { 28 void ReleaseLock() override {
29 DCHECK(is_locked_); 29 DCHECK(is_locked_);
30 is_locked_ = false; 30 is_locked_ = false;
31 } 31 }
32 virtual void Purge() override { 32 void Purge() override {
33 DCHECK(is_allocated_); 33 DCHECK(is_allocated_);
34 is_allocated_ = false; 34 is_allocated_ = false;
35 } 35 }
36 36
37 bool is_locked() const { return is_locked_; } 37 bool is_locked() const { return is_locked_; }
38 38
39 private: 39 private:
40 bool is_allocated_; 40 bool is_allocated_;
41 bool is_locked_; 41 bool is_locked_;
42 }; 42 };
43 43
44 // Tests can assume that the default limit is at least 1024. Tests that rely on 44 // Tests can assume that the default limit is at least 1024. Tests that rely on
45 // something else needs to explicit set the limit. 45 // something else needs to explicit set the limit.
46 const size_t kDefaultMemoryLimit = 1024; 46 const size_t kDefaultMemoryLimit = 1024;
47 const size_t kDefaultSoftMemoryLimit = kDefaultMemoryLimit; 47 const size_t kDefaultSoftMemoryLimit = kDefaultMemoryLimit;
48 48
49 class TestDiscardableMemoryManagerImpl 49 class TestDiscardableMemoryManagerImpl
50 : public internal::DiscardableMemoryManager { 50 : public internal::DiscardableMemoryManager {
51 public: 51 public:
52 TestDiscardableMemoryManagerImpl() 52 TestDiscardableMemoryManagerImpl()
53 : DiscardableMemoryManager(kDefaultMemoryLimit, 53 : DiscardableMemoryManager(kDefaultMemoryLimit,
54 kDefaultSoftMemoryLimit, 54 kDefaultSoftMemoryLimit,
55 TimeDelta::Max()) {} 55 TimeDelta::Max()) {}
56 56
57 void SetNow(TimeTicks now) { now_ = now; } 57 void SetNow(TimeTicks now) { now_ = now; }
58 58
59 private: 59 private:
60 // Overriden from internal::DiscardableMemoryManager: 60 // Overriden from internal::DiscardableMemoryManager:
61 virtual TimeTicks Now() const override { return now_; } 61 TimeTicks Now() const override { return now_; }
62 62
63 TimeTicks now_; 63 TimeTicks now_;
64 }; 64 };
65 65
66 class DiscardableMemoryManagerTestBase { 66 class DiscardableMemoryManagerTestBase {
67 public: 67 public:
68 DiscardableMemoryManagerTestBase() {} 68 DiscardableMemoryManagerTestBase() {}
69 69
70 protected: 70 protected:
71 enum LockStatus { 71 enum LockStatus {
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 Unretained(this))); 481 Unretained(this)));
482 memory_usage_thread_.message_loop()->PostTask( 482 memory_usage_thread_.message_loop()->PostTask(
483 FROM_HERE, 483 FROM_HERE,
484 Bind(&ThreadedDiscardableMemoryManagerTest::SignalHelper, 484 Bind(&ThreadedDiscardableMemoryManagerTest::SignalHelper,
485 Unretained(this))); 485 Unretained(this)));
486 thread_sync_.Wait(); 486 thread_sync_.Wait();
487 } 487 }
488 488
489 } // namespace 489 } // namespace
490 } // namespace base 490 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/discardable_memory_mach.h ('k') | base/memory/linked_ptr_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698