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

Side by Side Diff: components/cronet/android/cronet_upload_data_stream_delegate.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_CRONET_UPLOAD_DATA_STREAM_DELEGATE_H_
6 #define COMPONENTS_CRONET_ANDROID_CRONET_UPLOAD_DATA_STREAM_DELEGATE_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/weak_ptr.h"
14 #include "components/cronet/android/cronet_upload_data_stream_adapter.h"
15 #include "net/base/io_buffer.h"
16
17 namespace base {
18 class SingleThreadTaskRunner;
19 } // namespace base
20
21 namespace cronet {
22
23 // The Delegate holds onto a reference to the IOBuffer that is currently being
24 // written to in Java, so may not be deleted until any read operation in Java
25 // has completed.
26 //
27 // The Delegate is owned by the Java CronetUploadDataStream, and also owns a
28 // reference to it. The Delegate is only destroyed after the URLRequest
29 // destroys the adapter and the CronetUploadDataStream has no read operation
30 // pending, at which point it also releases its reference to the
31 // CronetUploadDataStream.
32 //
33 // Failures don't go through the delegate, but directly to the Java request
34 // object, since normally reads aren't allowed to fail during an upload.
35 class CronetUploadDataStreamDelegate
36 : public CronetUploadDataStreamAdapter::Delegate {
37 public:
38 CronetUploadDataStreamDelegate(JNIEnv* env, jobject jupload_data_stream);
39 ~CronetUploadDataStreamDelegate() override;
40
41 // CronetUploadDataStreamAdapter::Delegate implementation. Called on network
42 // thread.
43 void InitializeOnNetworkThread(
44 base::WeakPtr<CronetUploadDataStreamAdapter> adapter) override;
45 void Read(net::IOBuffer* buffer, int buf_len) override;
46 void Rewind() override;
47 void OnAdapterDestroyed() override;
48
49 // Callbacks from Java, called on some Java thread.
50 void OnReadSucceeded(JNIEnv* env,
51 jobject obj,
52 int bytes_read,
53 bool final_chunk);
54 void OnRewindSucceeded(JNIEnv* env, jobject obj);
55
56 private:
57 // Initialized on construction, effectively constant.
58 base::android::ScopedJavaGlobalRef<jobject> jupload_data_stream_;
59
60 // These are initialized in InitializeOnNetworkThread, so are safe to access
61 // during Java callbacks, which all happen after initialization.
62 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
63 base::WeakPtr<CronetUploadDataStreamAdapter> adapter_;
64
65 // Used to keep the read buffer alive until the callback from Java has been
66 // received.
67 scoped_refptr<net::IOBuffer> buffer_;
68
69 DISALLOW_COPY_AND_ASSIGN(CronetUploadDataStreamDelegate);
70 };
71
72 // Explicitly register static JNI functions.
73 bool CronetUploadDataStreamDelegateRegisterJni(JNIEnv* env);
74
75 } // namespace cronet
76
77 #endif // COMPONENTS_CRONET_ANDROID_CRONET_UPLOAD_DATA_STREAM_DELEGATE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698