| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.impl; | 5 package org.chromium.net.impl; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.os.Handler; | 8 import android.os.Handler; |
| 9 import android.os.Looper; | 9 import android.os.Looper; |
| 10 | 10 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 public void run() { | 62 public void run() { |
| 63 ensureInitializedOnMainThread(applicationContext); | 63 ensureInitializedOnMainThread(applicationContext); |
| 64 } | 64 } |
| 65 }; | 65 }; |
| 66 // Run task immediately or post it to the UI thread. | 66 // Run task immediately or post it to the UI thread. |
| 67 if (Looper.getMainLooper() == Looper.myLooper()) { | 67 if (Looper.getMainLooper() == Looper.myLooper()) { |
| 68 task.run(); | 68 task.run(); |
| 69 } else { | 69 } else { |
| 70 // The initOnMainThread will complete on the main thread pri
or | 70 // The initOnMainThread will complete on the main thread pri
or |
| 71 // to other tasks posted to the main thread. | 71 // to other tasks posted to the main thread. |
| 72 new Handler(Looper.getMainLooper()).post(task); | 72 if (builder.uiExecutor() != null) { |
| 73 builder.uiExecutor().execute(task); |
| 74 } else { |
| 75 new Handler(Looper.getMainLooper()).post(task); |
| 76 } |
| 73 } | 77 } |
| 74 } | 78 } |
| 75 } | 79 } |
| 76 } | 80 } |
| 77 | 81 |
| 78 /** | 82 /** |
| 79 * Ensure that the main thread initialization has completed. Can only be cal
led from | 83 * Ensure that the main thread initialization has completed. Can only be cal
led from |
| 80 * the main thread. Ensures that the NetworkChangeNotifier is initialzied an
d the | 84 * the main thread. Ensures that the NetworkChangeNotifier is initialzied an
d the |
| 81 * main thread native MessageLoop is initialized. | 85 * main thread native MessageLoop is initialized. |
| 82 */ | 86 */ |
| (...skipping 15 matching lines...) Expand all Loading... |
| 98 // the undesired initial network change observer notification, which | 102 // the undesired initial network change observer notification, which |
| 99 // will cause active requests to fail with ERR_NETWORK_CHANGED. | 103 // will cause active requests to fail with ERR_NETWORK_CHANGED. |
| 100 nativeCronetInitOnMainThread(); | 104 nativeCronetInitOnMainThread(); |
| 101 sMainThreadInitDone = true; | 105 sMainThreadInitDone = true; |
| 102 } | 106 } |
| 103 | 107 |
| 104 // Native methods are implemented in cronet_library_loader.cc. | 108 // Native methods are implemented in cronet_library_loader.cc. |
| 105 private static native void nativeCronetInitOnMainThread(); | 109 private static native void nativeCronetInitOnMainThread(); |
| 106 private static native String nativeGetCronetVersion(); | 110 private static native String nativeGetCronetVersion(); |
| 107 } | 111 } |
| OLD | NEW |