| OLD | NEW | 
|    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/run_loop.h" |    8 #include "base/run_loop.h" | 
|    9 #include "base/synchronization/waitable_event.h" |    9 #include "base/synchronization/waitable_event.h" | 
|   10 #include "base/threading/thread.h" |   10 #include "base/threading/thread.h" | 
|   11 #include "testing/gtest/include/gtest/gtest.h" |   11 #include "testing/gtest/include/gtest/gtest.h" | 
|   12  |   12  | 
|   13 namespace base { |   13 namespace base { | 
|   14 namespace { |   14 namespace { | 
|   15  |   15  | 
|   16 class TestAllocationImpl : public internal::DiscardableMemoryManagerAllocation { |   16 class TestAllocationImpl : public internal::DiscardableMemoryManagerAllocation { | 
|   17  public: |   17  public: | 
|   18   TestAllocationImpl() : is_allocated_(false), is_locked_(false) {} |   18   TestAllocationImpl() : is_allocated_(false), is_locked_(false) {} | 
|   19   virtual ~TestAllocationImpl() { DCHECK(!is_locked_); } |   19   virtual ~TestAllocationImpl() { DCHECK(!is_locked_); } | 
|   20  |   20  | 
|   21   // Overridden from internal::DiscardableMemoryManagerAllocation: |   21   // Overridden from internal::DiscardableMemoryManagerAllocation: | 
|   22   virtual bool AllocateAndAcquireLock() OVERRIDE { |   22   virtual bool AllocateAndAcquireLock(size_t bytes) OVERRIDE { | 
|   23     bool was_allocated = is_allocated_; |   23     bool was_allocated = is_allocated_; | 
|   24     is_allocated_ = true; |   24     is_allocated_ = true; | 
|   25     DCHECK(!is_locked_); |   25     DCHECK(!is_locked_); | 
|   26     is_locked_ = true; |   26     is_locked_ = true; | 
|   27     return was_allocated; |   27     return was_allocated; | 
|   28   } |   28   } | 
|   29   virtual void ReleaseLock() OVERRIDE { |   29   virtual void ReleaseLock() OVERRIDE { | 
|   30     DCHECK(is_locked_); |   30     DCHECK(is_locked_); | 
|   31     is_locked_ = false; |   31     is_locked_ = false; | 
|   32   } |   32   } | 
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  417            Unretained(this))); |  417            Unretained(this))); | 
|  418   memory_usage_thread_.message_loop()->PostTask( |  418   memory_usage_thread_.message_loop()->PostTask( | 
|  419       FROM_HERE, |  419       FROM_HERE, | 
|  420       Bind(&ThreadedDiscardableMemoryManagerTest::SignalHelper, |  420       Bind(&ThreadedDiscardableMemoryManagerTest::SignalHelper, | 
|  421            Unretained(this))); |  421            Unretained(this))); | 
|  422   thread_sync_.Wait(); |  422   thread_sync_.Wait(); | 
|  423 } |  423 } | 
|  424  |  424  | 
|  425 }  // namespace |  425 }  // namespace | 
|  426 }  // namespace base |  426 }  // namespace base | 
| OLD | NEW |