| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "net/disk_cache/disk_cache_test_util.h" | 5 #include "net/disk_cache/disk_cache_test_util.h" |
| 6 | 6 |
| 7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/run_loop.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
| 11 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
| 12 #include "net/disk_cache/blockfile/backend_impl.h" | 13 #include "net/disk_cache/blockfile/backend_impl.h" |
| 13 #include "net/disk_cache/blockfile/file.h" | 14 #include "net/disk_cache/blockfile/file.h" |
| 14 #include "net/disk_cache/cache_util.h" | 15 #include "net/disk_cache/cache_util.h" |
| 15 | 16 |
| 16 using base::Time; | 17 using base::Time; |
| 17 using base::TimeDelta; | 18 using base::TimeDelta; |
| 18 | 19 |
| 19 std::string GenerateKey(bool same_length) { | 20 std::string GenerateKey(bool same_length) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 90 |
| 90 bool MessageLoopHelper::WaitUntilCacheIoFinished(int num_callbacks) { | 91 bool MessageLoopHelper::WaitUntilCacheIoFinished(int num_callbacks) { |
| 91 if (num_callbacks == callbacks_called_) | 92 if (num_callbacks == callbacks_called_) |
| 92 return true; | 93 return true; |
| 93 | 94 |
| 94 ExpectCallbacks(num_callbacks); | 95 ExpectCallbacks(num_callbacks); |
| 95 // Create a recurrent timer of 50 mS. | 96 // Create a recurrent timer of 50 mS. |
| 96 if (!timer_.IsRunning()) | 97 if (!timer_.IsRunning()) |
| 97 timer_.Start(FROM_HERE, TimeDelta::FromMilliseconds(50), this, | 98 timer_.Start(FROM_HERE, TimeDelta::FromMilliseconds(50), this, |
| 98 &MessageLoopHelper::TimerExpired); | 99 &MessageLoopHelper::TimerExpired); |
| 99 base::MessageLoop::current()->Run(); | 100 base::RunLoop().Run(); |
| 100 return completed_; | 101 return completed_; |
| 101 } | 102 } |
| 102 | 103 |
| 103 // Quits the message loop when all callbacks are called or we've been waiting | 104 // Quits the message loop when all callbacks are called or we've been waiting |
| 104 // too long for them (2 secs without a callback). | 105 // too long for them (2 secs without a callback). |
| 105 void MessageLoopHelper::TimerExpired() { | 106 void MessageLoopHelper::TimerExpired() { |
| 106 CHECK_LE(callbacks_called_, num_callbacks_); | 107 CHECK_LE(callbacks_called_, num_callbacks_); |
| 107 if (callbacks_called_ == num_callbacks_) { | 108 if (callbacks_called_ == num_callbacks_) { |
| 108 completed_ = true; | 109 completed_ = true; |
| 109 base::MessageLoop::current()->QuitWhenIdle(); | 110 base::MessageLoop::current()->QuitWhenIdle(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 136 | 137 |
| 137 if (reuse_) { | 138 if (reuse_) { |
| 138 DCHECK_EQ(1, reuse_); | 139 DCHECK_EQ(1, reuse_); |
| 139 if (2 == reuse_) | 140 if (2 == reuse_) |
| 140 helper_->set_callback_reused_error(true); | 141 helper_->set_callback_reused_error(true); |
| 141 reuse_++; | 142 reuse_++; |
| 142 } | 143 } |
| 143 | 144 |
| 144 helper_->CallbackWasCalled(); | 145 helper_->CallbackWasCalled(); |
| 145 } | 146 } |
| OLD | NEW |