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

Side by Side Diff: components/cronet/android/test/javatests/src/org/chromium/net/TestUrlRequestCallback.java

Issue 1619923004: Fix doing network operations on wrong executor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix doing network operations on wrong executor Created 4 years, 11 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 | « components/cronet/android/api/src/org/chromium/net/JavaUrlRequest.java ('k') | no next file » | 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 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 9
9 import static junit.framework.Assert.assertEquals; 10 import static junit.framework.Assert.assertEquals;
10 import static junit.framework.Assert.assertFalse; 11 import static junit.framework.Assert.assertFalse;
11 import static junit.framework.Assert.assertNull; 12 import static junit.framework.Assert.assertNull;
12 import static junit.framework.Assert.assertTrue; 13 import static junit.framework.Assert.assertTrue;
13 14
14 import java.nio.ByteBuffer; 15 import java.nio.ByteBuffer;
15 import java.util.ArrayList; 16 import java.util.ArrayList;
16 import java.util.concurrent.Executor; 17 import java.util.concurrent.Executor;
17 import java.util.concurrent.ExecutorService; 18 import java.util.concurrent.ExecutorService;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 62
62 // Executor Service for Cronet callbacks. 63 // Executor Service for Cronet callbacks.
63 private final ExecutorService mExecutorService = 64 private final ExecutorService mExecutorService =
64 Executors.newSingleThreadExecutor(new ExecutorThreadFactory()); 65 Executors.newSingleThreadExecutor(new ExecutorThreadFactory());
65 private Thread mExecutorThread; 66 private Thread mExecutorThread;
66 67
67 // position() of ByteBuffer prior to readNew() call. 68 // position() of ByteBuffer prior to readNew() call.
68 private int mBufferPositionBeforeRead; 69 private int mBufferPositionBeforeRead;
69 70
70 private class ExecutorThreadFactory implements ThreadFactory { 71 private class ExecutorThreadFactory implements ThreadFactory {
71 public Thread newThread(Runnable r) { 72 public Thread newThread(final Runnable r) {
72 mExecutorThread = new Thread(r); 73 mExecutorThread = new Thread(new Runnable() {
74 @Override
75 public void run() {
76 StrictMode.ThreadPolicy threadPolicy = StrictMode.getThreadP olicy();
77 try {
78 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.B uilder()
79 .detectNetwork()
80 .penaltyLog()
81 .penaltyDeath()
82 .build());
83 r.run();
84 } finally {
85 StrictMode.setThreadPolicy(threadPolicy);
86 }
87 }
88 });
73 return mExecutorThread; 89 return mExecutorThread;
74 } 90 }
75 } 91 }
76 92
77 public enum ResponseStep { 93 public enum ResponseStep {
78 NOTHING, 94 NOTHING,
79 ON_RECEIVED_REDIRECT, 95 ON_RECEIVED_REDIRECT,
80 ON_RESPONSE_STARTED, 96 ON_RESPONSE_STARTED,
81 ON_READ_COMPLETED, 97 ON_READ_COMPLETED,
82 ON_SUCCEEDED 98 ON_SUCCEEDED
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 }; 295 };
280 if (mFailureType == FailureType.CANCEL_ASYNC 296 if (mFailureType == FailureType.CANCEL_ASYNC
281 || mFailureType == FailureType.CANCEL_ASYNC_WITHOUT_PAUSE) { 297 || mFailureType == FailureType.CANCEL_ASYNC_WITHOUT_PAUSE) {
282 getExecutor().execute(task); 298 getExecutor().execute(task);
283 } else { 299 } else {
284 task.run(); 300 task.run();
285 } 301 }
286 return mFailureType != FailureType.CANCEL_ASYNC_WITHOUT_PAUSE; 302 return mFailureType != FailureType.CANCEL_ASYNC_WITHOUT_PAUSE;
287 } 303 }
288 } 304 }
OLDNEW
« no previous file with comments | « components/cronet/android/api/src/org/chromium/net/JavaUrlRequest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698