OLD | NEW |
---|---|
(Empty) | |
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. | |
mmenke
2014/09/02 19:48:03
nit: Blank line after license header.
mef
2014/09/03 20:58:57
Done.
| |
4 package org.chromium.net; | |
5 | |
6 import java.nio.ByteBuffer; | |
7 | |
8 // Note: All methods must be called on the executor passed in during creation. | |
mmenke
2014/09/02 19:48:03
nit: Executor
mef
2014/09/03 20:58:58
Done.
| |
9 public abstract interface AsyncUrlRequest { | |
mmenke
2014/09/02 19:48:03
Maybe some class level description?
mef
2014/09/03 20:58:58
Done.
| |
10 /** | |
11 * Methods to set the request body. Could instead use a single method that | |
12 * takes a class, and three implementations of that class, but this allows | |
13 * file/string bodies to easily be handled C++-side. | |
14 */ | |
15 | |
16 /** | |
17 * Set request body using a constant ByteBuffer. | |
18 * Note: Not sure if taking another type would be better. | |
19 * @param buffer | |
20 */ | |
21 public void setRequestBodyByteBuffer(ByteBuffer buffer); | |
mmenke
2014/09/02 19:48:03
Let's get rid of all the request body stuff - I th
mef
2014/09/03 20:58:58
Done.
| |
22 | |
23 /** | |
24 * Set request body using a file. File must not be modified until | |
25 * request is finished. | |
26 * TODO(mmenke): After cancelling, file won’t be closed instantly. | |
27 * Figure out how to better handle it (In case someone wants to delete | |
28 * the file). | |
29 * @param filePath | |
30 */ | |
31 public void setRequestBodyFile(String filePath); | |
32 | |
33 /** | |
34 * The request body will be passed to the AsyncUrlRequest as needed, | |
35 * and uploaded using chunked encoding, since the length may not be known. | |
36 */ | |
37 public void setStreamRequestBody(); | |
38 | |
39 /** | |
40 * Appends data to the body, when setStreamRequestBody is called. Can be | |
41 * called at any point before the request is cancelled, | |
42 * fails with an error, or onResponseStarted is called on the listener. | |
43 * The request takes ownership of the buffer, and will delete it once the | |
44 * data is sent. While the request will call the listener’s | |
45 * needUploadData method when all appended data has been uploaded, | |
46 * there’s no need for the embedder to wait for that callback before | |
47 * appending more data. | |
48 * If the request retries, or is redirected, the embedder must replay | |
49 * the original data. See AsyncUrlRequestListener for those methods. | |
50 * @param buffer | |
51 */ | |
52 public void appendBodyData(ByteBuffer buffer); | |
53 | |
54 /** | |
55 * Called when the last bytes to be uploaded have been appended with | |
56 * appendBodyData. | |
57 */ | |
58 public void bodyComplete(); | |
59 | |
60 /** | |
61 * More setters go here. They may only be called before start (Maybe | |
62 * also allow during redirects). Could optionally instead use arguments | |
63 * to URLRequestFactory when creating the request. | |
64 */ | |
65 | |
66 /** | |
67 * Starts the request, all callbacks go to listener. | |
68 * @param listener | |
69 */ | |
70 public void start(AsyncUrlRequestListener listener); | |
71 | |
72 /** | |
73 * Can be called at any time. | |
74 */ | |
75 public void cancel(); | |
76 | |
77 /** | |
78 * | |
79 * @return | |
mmenke
2014/09/02 19:48:03
@return {boolean} true if the request has been can
mef
2014/09/03 20:58:58
Are you sure about error case? What would happen t
| |
80 */ | |
81 public boolean isCanceled(); | |
82 | |
83 /** | |
84 * Can be called at any time, but the request may continue behind the | |
85 * scenes, depending on when it’s called. None of the listener’s methods | |
86 * will be called while paused, until and unless the request is resumed. | |
87 * (Note: This allows us to have more than one ByteBuffer in flight, | |
88 * if we want, as well as allow pausing at any point). | |
89 */ | |
90 public void pause(); | |
mmenke
2014/09/02 19:48:03
I want to take a little extra time to think about
mef
2014/09/03 20:58:58
Acknowledged.
mmenke
2014/09/03 21:19:19
Wow, that's a mess. I really should be more caref
| |
91 | |
92 /** | |
93 * Returns false if cancelled (Or not paused, of course). | |
94 * @return | |
95 */ | |
96 public boolean isPaused(); | |
97 | |
98 /** | |
99 * When resuming, any pending callback to the listener will be called | |
100 * asynchronously. | |
101 */ | |
102 public void resume(); | |
103 | |
104 /** | |
105 * Note: There are deliberately no accessors for the results of the request | |
106 * here. Having none removes any ambiguity over when they are populated, | |
107 * particularly in the redirect case. | |
108 */ | |
109 } | |
110 | |
OLD | NEW |