| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 package org.chromium.base.test.util; | 5 package org.chromium.base.test.util; |
| 6 | 6 |
| 7 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; | 7 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; |
| 8 | 8 |
| 9 import java.util.concurrent.TimeUnit; | 9 import java.util.concurrent.TimeUnit; |
| 10 import java.util.concurrent.TimeoutException; | 10 import java.util.concurrent.TimeoutException; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 * }); | 120 * }); |
| 121 * operationHelper.waitForCallback(callCount); | 121 * operationHelper.waitForCallback(callCount); |
| 122 * } | 122 * } |
| 123 * | 123 * |
| 124 */ | 124 */ |
| 125 public class CallbackHelper { | 125 public class CallbackHelper { |
| 126 /** The default timeout (in seconds) for a callback to wait. */ | 126 /** The default timeout (in seconds) for a callback to wait. */ |
| 127 public static final long WAIT_TIMEOUT_SECONDS = scaleTimeout(5); | 127 public static final long WAIT_TIMEOUT_SECONDS = scaleTimeout(5); |
| 128 | 128 |
| 129 private final Object mLock = new Object(); | 129 private final Object mLock = new Object(); |
| 130 private int mCallCount = 0; | 130 private int mCallCount; |
| 131 | 131 |
| 132 /** | 132 /** |
| 133 * Gets the number of times the callback has been called. | 133 * Gets the number of times the callback has been called. |
| 134 * | 134 * |
| 135 * The call count can be used with the waitForCallback() method, indicating
a point | 135 * The call count can be used with the waitForCallback() method, indicating
a point |
| 136 * in time after which the caller wishes to record calls to the callback. | 136 * in time after which the caller wishes to record calls to the callback. |
| 137 * | 137 * |
| 138 * In order to wait for a callback caused by X, the call count should be obt
ained | 138 * In order to wait for a callback caused by X, the call count should be obt
ained |
| 139 * before X occurs. | 139 * before X occurs. |
| 140 * | 140 * |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 /** | 222 /** |
| 223 * Should be called when the callback associated with this helper object is
called. | 223 * Should be called when the callback associated with this helper object is
called. |
| 224 */ | 224 */ |
| 225 public void notifyCalled() { | 225 public void notifyCalled() { |
| 226 synchronized (mLock) { | 226 synchronized (mLock) { |
| 227 mCallCount++; | 227 mCallCount++; |
| 228 mLock.notifyAll(); | 228 mLock.notifyAll(); |
| 229 } | 229 } |
| 230 } | 230 } |
| 231 } | 231 } |
| OLD | NEW |