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 package org.chromium.net; | 5 package org.chromium.net; |
6 | 6 |
7 import android.os.ConditionVariable; | 7 import android.os.ConditionVariable; |
8 import android.os.StrictMode; | 8 import android.os.StrictMode; |
9 | 9 |
10 import static junit.framework.Assert.assertEquals; | 10 import static junit.framework.Assert.assertEquals; |
11 import static junit.framework.Assert.assertFalse; | 11 import static junit.framework.Assert.assertFalse; |
12 import static junit.framework.Assert.assertNotNull; | 12 import static junit.framework.Assert.assertNotNull; |
13 import static junit.framework.Assert.assertNull; | 13 import static junit.framework.Assert.assertNull; |
14 import static junit.framework.Assert.assertTrue; | 14 import static junit.framework.Assert.assertTrue; |
15 | 15 |
16 import java.nio.ByteBuffer; | 16 import java.nio.ByteBuffer; |
17 import java.util.ArrayList; | 17 import java.util.ArrayList; |
18 import java.util.concurrent.Executor; | |
19 import java.util.concurrent.ExecutorService; | 18 import java.util.concurrent.ExecutorService; |
20 import java.util.concurrent.Executors; | 19 import java.util.concurrent.Executors; |
21 import java.util.concurrent.ThreadFactory; | 20 import java.util.concurrent.ThreadFactory; |
22 import java.util.concurrent.TimeUnit; | 21 import java.util.concurrent.TimeUnit; |
23 | 22 |
24 /** | 23 /** |
25 * Callback that tracks information from different callbacks and and has a | 24 * Callback that tracks information from different callbacks and and has a |
26 * method to block thread until the request completes on another thread. | 25 * method to block thread until the request completes on another thread. |
27 * Allows to cancel, block request or throw an exception from an arbitrary step. | 26 * Allows to cancel, block request or throw an exception from an arbitrary step. |
28 */ | 27 */ |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 126 |
128 public void blockForDone() { | 127 public void blockForDone() { |
129 mDone.block(); | 128 mDone.block(); |
130 } | 129 } |
131 | 130 |
132 public void waitForNextStep() { | 131 public void waitForNextStep() { |
133 mStepBlock.block(); | 132 mStepBlock.block(); |
134 mStepBlock.close(); | 133 mStepBlock.close(); |
135 } | 134 } |
136 | 135 |
137 public Executor getExecutor() { | 136 public ExecutorService getExecutor() { |
138 return mExecutorService; | 137 return mExecutorService; |
139 } | 138 } |
140 | 139 |
141 public void shutdownExecutor() { | 140 public void shutdownExecutor() { |
142 mExecutorService.shutdown(); | 141 mExecutorService.shutdown(); |
143 } | 142 } |
144 | 143 |
145 /** | 144 /** |
146 * Shuts down the ExecutorService and waits until it executes all posted | 145 * Shuts down the ExecutorService and waits until it executes all posted |
147 * tasks. | 146 * tasks. |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 }; | 333 }; |
335 if (mFailureType == FailureType.CANCEL_ASYNC | 334 if (mFailureType == FailureType.CANCEL_ASYNC |
336 || mFailureType == FailureType.CANCEL_ASYNC_WITHOUT_PAUSE) { | 335 || mFailureType == FailureType.CANCEL_ASYNC_WITHOUT_PAUSE) { |
337 getExecutor().execute(task); | 336 getExecutor().execute(task); |
338 } else { | 337 } else { |
339 task.run(); | 338 task.run(); |
340 } | 339 } |
341 return mFailureType != FailureType.CANCEL_ASYNC_WITHOUT_PAUSE; | 340 return mFailureType != FailureType.CANCEL_ASYNC_WITHOUT_PAUSE; |
342 } | 341 } |
343 } | 342 } |
OLD | NEW |