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

Side by Side Diff: components/cronet/android/java/src/org/chromium/net/CronetUploadDataStream.java

Issue 1124333003: Rename CronetUploadDataStreamAdapter to CronetUploadDataStream. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
OLDNEW
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; 5 package org.chromium.net;
6 6
7 import org.chromium.base.CalledByNative; 7 import org.chromium.base.CalledByNative;
8 import org.chromium.base.JNINamespace; 8 import org.chromium.base.JNINamespace;
9 import org.chromium.base.NativeClassQualifiedName; 9 import org.chromium.base.NativeClassQualifiedName;
10 10
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } catch (Exception exception) { 109 } catch (Exception exception) {
110 onError(exception); 110 onError(exception);
111 } 111 }
112 } 112 }
113 }; 113 };
114 mExecutor.execute(task); 114 mExecutor.execute(task);
115 } 115 }
116 116
117 /** 117 /**
118 * Called by native code to destroy the native adapter delegate, when the 118 * Called by native code to destroy the native adapter delegate, when the
119 * adapter is destroyed. 119 * adapter is destroyed.
xunjieli 2015/05/08 20:11:27 nit: need to update the comment.
mmenke 2015/05/08 20:24:19 Done.
120 */ 120 */
121 @SuppressWarnings("unused") 121 @SuppressWarnings("unused")
122 @CalledByNative 122 @CalledByNative
123 void onAdapterDestroyed() { 123 void onUploadDataStreamDestroyed() {
124 Runnable task = new Runnable() { 124 Runnable task = new Runnable() {
125 @Override 125 @Override
126 public void run() { 126 public void run() {
127 destroyDelegate(); 127 destroyDelegate();
128 } 128 }
129 }; 129 };
130 130
131 mExecutor.execute(task); 131 mExecutor.execute(task);
132 } 132 }
133 133
134 /** 134 /**
135 * Helper method called when an exception occurred. This method resets 135 * Helper method called when an exception occurred. This method resets
136 * states and propagates the error to the request. 136 * states and propagates the error to the request.
137 */ 137 */
138 private void onError(Exception exception) { 138 private void onError(Exception exception) {
139 synchronized (mLock) { 139 synchronized (mLock) {
140 if (!mReading && !mRewinding) { 140 if (!mReading && !mRewinding) {
141 throw new IllegalStateException( 141 throw new IllegalStateException(
142 "There is no read or rewind in progress."); 142 "There is no read or rewind in progress.");
143 } 143 }
144 mReading = false; 144 mReading = false;
145 mRewinding = false; 145 mRewinding = false;
146 mByteBuffer = null; 146 mByteBuffer = null;
147 destroyDelegateIfPostponed(); 147 destroyDelegateIfPostponed();
148 } 148 }
149 149
150 // Just fail the request - simpler to fail directly, and 150 // Just fail the request - simpler to fail directly, and
151 // UploadDataStream only supports failing during initialization, not 151 // UploadDataStream only supports failing during initialization, not
152 // while reading. This should be safe, even if we deleted the adapter, 152 // while reading. This should be safe, even if we deleted the adapter,
xunjieli 2015/05/08 20:11:27 nit: s/"adapter"/"native UploadDataStream" to matc
mmenke 2015/05/08 20:24:19 Done.
153 // because in that case, the request has already been cancelled. 153 // because in that case, the request has already been cancelled.
154 mRequest.onUploadException(exception); 154 mRequest.onUploadException(exception);
155 } 155 }
156 156
157 @Override 157 @Override
158 public void onReadSucceeded(boolean lastChunk) { 158 public void onReadSucceeded(boolean lastChunk) {
159 synchronized (mLock) { 159 synchronized (mLock) {
160 if (!mReading) { 160 if (!mReading) {
161 throw new IllegalStateException("Non-existent read succeeded."); 161 throw new IllegalStateException("Non-existent read succeeded.");
162 } 162 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 * an interface with just this method, to minimize CronetURLRequest's 259 * an interface with just this method, to minimize CronetURLRequest's
260 * dependencies on each upload stream type. 260 * dependencies on each upload stream type.
261 */ 261 */
262 void attachToRequest(CronetUrlRequest request, long requestAdapter) { 262 void attachToRequest(CronetUrlRequest request, long requestAdapter) {
263 mRequest = request; 263 mRequest = request;
264 mUploadDataStreamDelegate = 264 mUploadDataStreamDelegate =
265 nativeAttachUploadDataToRequest(requestAdapter, mLength); 265 nativeAttachUploadDataToRequest(requestAdapter, mLength);
266 } 266 }
267 267
268 /** 268 /**
269 * Creates a native UploadDataStreamDelegate and UploadDataStreamAdapter 269 * Creates a native CronetUploadDataStreamDelegate and
270 * for testing. 270 * CronetUploadDataStream for testing.
271 * @return the address of the native CronetUploadDataStreamAdapter object. 271 * @return the address of the native CronetUploadDataStream object.
272 */ 272 */
273 public long createAdapterForTesting() { 273 public long createUploadDataStreamForTesting() {
274 mUploadDataStreamDelegate = nativeCreateDelegateForTesting(); 274 mUploadDataStreamDelegate = nativeCreateDelegateForTesting();
275 return nativeCreateAdapterForTesting(mLength, mUploadDataStreamDelegate) ; 275 return nativeCreateUploadDataStreamForTesting(mLength,
276 mUploadDataStreamDelegate);
276 } 277 }
277 278
278 // Native methods are implemented in upload_data_stream_adapter.cc. 279 // Native methods are implemented in upload_data_stream_adapter.cc.
xunjieli 2015/05/08 20:11:27 nit: need to update file name here.
mmenke 2015/05/08 20:24:18 Done.
279 280
280 private native long nativeAttachUploadDataToRequest(long urlRequestAdapter, 281 private native long nativeAttachUploadDataToRequest(long urlRequestAdapter,
281 long length); 282 long length);
282 283
283 private native long nativeCreateDelegateForTesting(); 284 private native long nativeCreateDelegateForTesting();
284 285
285 private native long nativeCreateAdapterForTesting(long length, 286 private native long nativeCreateUploadDataStreamForTesting(long length,
286 long delegate); 287 long delegate);
287 288
288 @NativeClassQualifiedName("CronetUploadDataStreamDelegate") 289 @NativeClassQualifiedName("CronetUploadDataStreamDelegate")
289 private native void nativeOnReadSucceeded(long nativePtr, 290 private native void nativeOnReadSucceeded(long nativePtr,
290 int bytesRead, boolean finalChunk); 291 int bytesRead, boolean finalChunk);
291 292
292 @NativeClassQualifiedName("CronetUploadDataStreamDelegate") 293 @NativeClassQualifiedName("CronetUploadDataStreamDelegate")
293 private native void nativeOnRewindSucceeded(long nativePtr); 294 private native void nativeOnRewindSucceeded(long nativePtr);
294 295
295 private static native void nativeDestroyDelegate( 296 private static native void nativeDestroyDelegate(
296 long uploadDataStreamDelegate); 297 long uploadDataStreamDelegate);
297 } 298 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698