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
3 // found in the LICENSE file.
5 package org
.chromium
.net
;
7 import java
.nio
.ByteBuffer
;
10 * Note: All methods will be called on the thread of the Executor used during
11 * construction of the UrlRequest.
13 public interface UrlRequestListener
{
15 * Called whenever a redirect is encountered. This will only be called
16 * between the call to {@link UrlRequest#start} and
17 * {@link UrlRequestListener#onResponseStarted
18 * UrlRequestListener.onResponseStarted()}. The body of the redirect
19 * response, if it has one, will be ignored.
21 * The redirect will not be followed until the URLRequest's
22 * {@link UrlRequest#followRedirect} method is called, either synchronously
25 * @param request Request being redirected.
26 * @param info Response information.
27 * @param newLocationUrl Location where request is redirected.
29 public void onReceivedRedirect(UrlRequest request
,
31 String newLocationUrl
);
34 * Called when the final set of headers, after all redirects, is received.
35 * Will only be called once for each request.
37 * No other UrlRequestListener method will be called for the request,
38 * including {@link UrlRequestListener#onSucceeded onSucceeded()} and {@link
39 * UrlRequestListener#onFailed onFailed()}, until {@link UrlRequest#read
40 * UrlRequest.read()} is called to attempt to start reading the response
43 * @param request Request that started to get response.
44 * @param info Response information.
46 public void onResponseStarted(UrlRequest request
, ResponseInfo info
);
49 * Called whenever part of the response body has been read. Only part of
50 * the buffer may be populated, even if the entire response body has not yet
53 * No other UrlRequestListener method will be called for the request,
54 * including {@link UrlRequestListener#onSucceeded onSucceeded()} and {@link
55 * UrlRequestListener#onFailed onFailed()}, until {@link
56 * UrlRequest#read UrlRequest.read()} is called to attempt to continue
57 * reading the response body.
59 * @param request Request that received data.
60 * @param info Response information.
61 * @param byteBuffer The buffer that was passed in to
62 * {@link UrlRequest#read}, now containing the received data.
64 public void onReadCompleted(UrlRequest request
,
66 ByteBuffer byteBuffer
);
69 * Called when request is completed successfully, no callbacks will be
72 * @param request Request that succeeded.
73 * @param info Response information.
75 public void onSucceeded(UrlRequest request
, ExtendedResponseInfo info
);
78 * Called if request failed for any reason after start(). Once
79 * called, no other functions can be called. UrlRequestException
80 * provides information about error.
82 * @param request Request that failed.
83 * @param info Response information.
84 * @param error information about error.
86 public void onFailed(UrlRequest request
,
88 UrlRequestException error
);