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

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

Issue 2131323002: [Cronet] Check whether request is done before spinning up message loop (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: self review Created 4 years, 5 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 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.urlconnection; 5 package org.chromium.net.urlconnection;
6 6
7 import android.util.Pair; 7 import android.util.Pair;
8 8
9 import org.chromium.base.Log; 9 import org.chromium.base.Log;
10 import org.chromium.net.CronetEngine; 10 import org.chromium.net.CronetEngine;
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 } 462 }
463 if (instanceFollowRedirects && sameProtocol) { 463 if (instanceFollowRedirects && sameProtocol) {
464 mRequest.followRedirect(); 464 mRequest.followRedirect();
465 return; 465 return;
466 } 466 }
467 } catch (MalformedURLException e) { 467 } catch (MalformedURLException e) {
468 // Ignored. Just cancel the request and not follow the redirect. 468 // Ignored. Just cancel the request and not follow the redirect.
469 } 469 }
470 mResponseInfo = info; 470 mResponseInfo = info;
471 mRequest.cancel(); 471 mRequest.cancel();
472 setResponseDataCompleted(null); 472 setRequestCompleted(null);
473 } 473 }
474 474
475 @Override 475 @Override
476 public void onSucceeded(UrlRequest request, UrlResponseInfo info) { 476 public void onSucceeded(UrlRequest request, UrlResponseInfo info) {
477 mResponseInfo = info; 477 mResponseInfo = info;
478 setResponseDataCompleted(null); 478 setRequestCompleted(null);
479 } 479 }
480 480
481 @Override 481 @Override
482 public void onFailed( 482 public void onFailed(
483 UrlRequest request, UrlResponseInfo info, UrlRequestException ex ception) { 483 UrlRequest request, UrlResponseInfo info, UrlRequestException ex ception) {
484 if (exception == null) { 484 if (exception == null) {
485 throw new IllegalStateException( 485 throw new IllegalStateException(
486 "Exception cannot be null in onFailed."); 486 "Exception cannot be null in onFailed.");
487 } 487 }
488 mResponseInfo = info; 488 mResponseInfo = info;
489 mException = exception; 489 mException = exception;
490 setResponseDataCompleted(mException); 490 setRequestCompleted(mException);
491 } 491 }
492 492
493 @Override 493 @Override
494 public void onCanceled(UrlRequest request, UrlResponseInfo info) { 494 public void onCanceled(UrlRequest request, UrlResponseInfo info) {
495 mResponseInfo = info; 495 mResponseInfo = info;
496 setResponseDataCompleted(new IOException("stream closed")); 496 setRequestCompleted(new IOException("stream closed"));
497 } 497 }
498 498
499 /** 499 /**
500 * Notifies {@link #mInputStream} that transferring of response data has 500 * Notifies {@link #mInputStream} that transferring of response data has
501 * completed. 501 * completed.
502 * @param exception if not {@code null}, it is the exception to report w hen 502 * @param exception if not {@code null}, it is the exception to report w hen
503 * caller tries to read more data. 503 * caller tries to read more data.
504 */ 504 */
505 private void setResponseDataCompleted(IOException exception) { 505 private void setRequestCompleted(IOException exception) {
mef 2016/07/08 17:42:06 Why the rename? Can you update the comment?
xunjieli 2016/07/08 17:56:26 Done. I think it is not neccessary to change it,
506 if (mInputStream != null) { 506 if (mInputStream != null) {
507 mInputStream.setResponseDataCompleted(exception); 507 mInputStream.setResponseDataCompleted(exception);
508 } 508 }
509 if (mOutputStream != null) {
510 mOutputStream.setRequestCompleted(exception);
511 }
509 mMessageLoop.quit(); 512 mMessageLoop.quit();
510 } 513 }
511 } 514 }
512 515
513 /** 516 /**
514 * Blocks until the respone headers are received. 517 * Blocks until the respone headers are received.
515 */ 518 */
516 private void getResponse() throws IOException { 519 private void getResponse() throws IOException {
517 // Check to see if enough data has been received. 520 // Check to see if enough data has been received.
518 if (mOutputStream != null) { 521 if (mOutputStream != null) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 // Strips Content-Encoding response header. See crbug.com/592700. 600 // Strips Content-Encoding response header. See crbug.com/592700.
598 if (!entry.getKey().equalsIgnoreCase("Content-Encoding")) { 601 if (!entry.getKey().equalsIgnoreCase("Content-Encoding")) {
599 mResponseHeadersList.add( 602 mResponseHeadersList.add(
600 new AbstractMap.SimpleImmutableEntry<String, String>(ent ry)); 603 new AbstractMap.SimpleImmutableEntry<String, String>(ent ry));
601 } 604 }
602 } 605 }
603 mResponseHeadersList = Collections.unmodifiableList(mResponseHeadersList ); 606 mResponseHeadersList = Collections.unmodifiableList(mResponseHeadersList );
604 return mResponseHeadersList; 607 return mResponseHeadersList;
605 } 608 }
606 } 609 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698