1 // Copyright 2016 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package org.chromium.net.impl; 6 7 import androidx.annotation.IntDef; 8 import androidx.annotation.Nullable; 9 10 import org.chromium.net.CronetException; 11 import org.chromium.net.RequestFinishedInfo; 12 import org.chromium.net.UrlResponseInfo; 13 14 import java.lang.annotation.Retention; 15 import java.lang.annotation.RetentionPolicy; 16 import java.util.Collection; 17 import java.util.Collections; 18 19 /** Implements information about a finished request. Passed to {@link RequestFinishedInfo.Listener}. */ 20 public class RequestFinishedInfoImpl extends RequestFinishedInfo { 21 private final String mUrl; 22 private final Collection<Object> mAnnotations; 23 private final RequestFinishedInfo.Metrics mMetrics; 24 25 @FinishedReason private final int mFinishedReason; 26 27 @Nullable private final UrlResponseInfo mResponseInfo; 28 @Nullable private final CronetException mException; 29 30 @IntDef({SUCCEEDED, FAILED, CANCELED}) 31 @Retention(RetentionPolicy.SOURCE) 32 public @interface FinishedReason {} 33 RequestFinishedInfoImpl( String url, Collection<Object> annotations, RequestFinishedInfo.Metrics metrics, @FinishedReason int finishedReason, @Nullable UrlResponseInfo responseInfo, @Nullable CronetException exception)34 public RequestFinishedInfoImpl( 35 String url, 36 Collection<Object> annotations, 37 RequestFinishedInfo.Metrics metrics, 38 @FinishedReason int finishedReason, 39 @Nullable UrlResponseInfo responseInfo, 40 @Nullable CronetException exception) { 41 mUrl = url; 42 mAnnotations = annotations; 43 mMetrics = metrics; 44 mFinishedReason = finishedReason; 45 mResponseInfo = responseInfo; 46 mException = exception; 47 } 48 49 @Override getUrl()50 public String getUrl() { 51 return mUrl; 52 } 53 54 @Override getAnnotations()55 public Collection<Object> getAnnotations() { 56 if (mAnnotations == null) { 57 return Collections.emptyList(); 58 } 59 return mAnnotations; 60 } 61 62 @Override getMetrics()63 public Metrics getMetrics() { 64 return mMetrics; 65 } 66 67 @Override 68 @FinishedReason getFinishedReason()69 public int getFinishedReason() { 70 return mFinishedReason; 71 } 72 73 @Override 74 @Nullable getResponseInfo()75 public UrlResponseInfo getResponseInfo() { 76 return mResponseInfo; 77 } 78 79 @Override 80 @Nullable getException()81 public CronetException getException() { 82 return mException; 83 } 84 } 85