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

Side by Side Diff: components/cronet/android/test/test_upload_data_stream_handler.h

Issue 849903002: [Cronet] Upload support for async APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move delegate destructor to implementation file to avoid chromium style error Created 5 years, 10 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_CRONET_ANDROID_TEST_TEST_UPLOAD_DATA_STREAM_HANDLER_H_
6 #define COMPONENTS_CRONET_ANDROID_TEST_TEST_UPLOAD_DATA_STREAM_HANDLER_H_
7
8 #include <jni.h>
9
10 #include "base/android/scoped_java_ref.h"
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/threading/thread.h"
15 #include "net/base/io_buffer.h"
16 #include "net/base/upload_data_stream.h"
17
18 namespace cronet {
19
20 /**
21 * This class allows a net::UploadDataStream to be driven directly from
22 * Java, for use in tests.
23 */
24 class TestUploadDataStreamHandler {
25 public:
26 TestUploadDataStreamHandler(
27 scoped_ptr<net::UploadDataStream> upload_data_stream,
28 JNIEnv* env,
29 jobject jtest_upload_data_stream_handler);
30
31 ~TestUploadDataStreamHandler();
32
33 // Destroys |network_thread_| created by this class.
34 void Destroy(JNIEnv* env, jobject jcaller);
35
36 // Posts a task to |network_thread_| to call the corresponding method of
37 // net::UploadDataStream on |upload_data_stream_|.
38
39 void Init(JNIEnv* env, jobject jcaller);
40 void Read(JNIEnv* env, jobject jcaller);
41 void Reset(JNIEnv* env, jobject jcaller);
42
43 // Posts a task to |network_thread_| to check whether init complete callback
44 // has been invoked by net::UploadDataStream asynchronously, and notifies the
45 // Java side of the result.
46 void CheckInitCallbackNotInvoked(JNIEnv* env, jobject jcaller);
47 // Posts a task to |network_thread_| to check whether read complete callback
48 // has been invoked by net::UploadDataStream asynchronously, and notifies the
49 // Java side of the result.
50 void CheckReadCallbackNotInvoked(JNIEnv* env, jobject jcaller);
51
52 private:
53 // Complete callbacks that are passed to the |upload_data_stream_|.
54 void OnInitCompleted(int res);
55 void OnReadCompleted(int res);
56
57 // Helper methods that run corresponding task on |network_thread_|.
58
59 void InitOnNetworkThread();
60 void ReadOnNetworkThread();
61 void ResetOnNetworkThread();
62 void CheckInitCallbackNotInvokedOnNetworkThread();
63 void CheckReadCallbackNotInvokedOnNetworkThread();
64
65 // Notify the Java TestUploadDataStreamHandler that read has completed.
66 void NotifyJavaReadCompleted();
67
68 // True if |OnInitCompleted| callback has been invoked. It is set to false
69 // when init or reset is called again. Created on a Java thread, but is only
70 // accessed from |network_thread_|.
71 bool init_callback_invoked_;
72 // True if |OnReadCompleted| callback has been invoked. It is set to false
73 // when init or reset is called again. Created on a Java thread, but is only
74 // accessed from |network_thread_|.
75 bool read_callback_invoked_;
76 // Indicates the number of bytes read. It is reset to 0 when init, reset, or
77 // read is called again. Created on a Java thread, but is only accessed from
78 // |network_thread_|.
79 int bytes_read_;
80
81 // Created and destroyed on the same Java thread. This is where methods of
82 // net::UploadDataStream run on.
83 scoped_ptr<base::Thread> network_thread_;
84 // Created on a Java thread. Accessed only on |network_thread_|.
85 scoped_ptr<net::UploadDataStream> upload_data_stream_;
86 // Created and accessed only on |network_thread_|.
87 scoped_refptr<net::IOBufferWithSize> read_buffer_;
88 // A Java reference pointer for calling methods on the Java
89 // TestUploadDataStreamHandler object. Initialized during construction.
90 base::android::ScopedJavaGlobalRef<jobject> jtest_upload_data_stream_handler_;
91
92 DISALLOW_COPY_AND_ASSIGN(TestUploadDataStreamHandler);
93 };
94
95 bool TestUploadDataStreamHandlerRegisterJni(JNIEnv* env);
96
97 } // namespace cronet
98
99 #endif // COMPONENTS_CRONET_ANDROID_TEST_TEST_UPLOAD_DATA_STREAM_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698