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

Unified Diff: components/cronet/android/wrapped_channel_upload_element_reader.cc

Issue 442803002: Remove explicit JNI references by adding UrlRequest.readFromUploadChannel callback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove spurious space. Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/cronet/android/wrapped_channel_upload_element_reader.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/cronet/android/wrapped_channel_upload_element_reader.cc
diff --git a/components/cronet/android/wrapped_channel_upload_element_reader.cc b/components/cronet/android/wrapped_channel_upload_element_reader.cc
index 6628591722f8c26d478a589230d29462d6313be0..db6fc78a77a54d39960fd69f6aa8624e6aa7f79e 100644
--- a/components/cronet/android/wrapped_channel_upload_element_reader.cc
+++ b/components/cronet/android/wrapped_channel_upload_element_reader.cc
@@ -4,53 +4,20 @@
#include "components/cronet/android/wrapped_channel_upload_element_reader.h"
-#include <jni.h>
-
#include "base/android/jni_android.h"
#include "base/logging.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
-namespace {
-jclass g_class_readablebytechannel;
-jclass g_class_channel;
-jmethodID g_method_read;
-jmethodID g_method_close;
-} //namespace
-
namespace cronet {
-bool WrappedChannelRegisterJni(JNIEnv* env) {
- g_class_readablebytechannel = static_cast<jclass>(env->NewGlobalRef(
- env->FindClass("java/nio/channels/ReadableByteChannel")));
- // TODO(mef): Per previous discussions the best way to do this is to have a
- // cronet-specific java wrapper that exposes necessary methods annotated as
- // @AccessedByNative and use jni generator to generate a wrapper method for
- // that.
- g_method_read = env->GetMethodID(
- g_class_readablebytechannel, "read", "(Ljava/nio/ByteBuffer;)I");
-
- // Due to a bug in the version of ART that shipped with 4.4, we're looking up
- // the close() method on the base interface. See b/15651032 for details.
- g_class_channel = static_cast<jclass>(env->NewGlobalRef(
- env->FindClass("java/nio/channels/Channel")));
- g_method_close = env->GetMethodID(g_class_channel, "close", "()V");
- if (!g_class_readablebytechannel || !g_method_read || !g_method_close) {
- return false;
- }
- return true;
-}
-
-WrappedChannelElementReader::WrappedChannelElementReader(JNIEnv* env,
- jobject channel,
- uint64 length)
- : length_(length), offset_(0) {
- channel_ = env->NewGlobalRef(channel);
+WrappedChannelElementReader::WrappedChannelElementReader(
+ scoped_refptr<URLRequestPeer::URLRequestPeerDelegate> delegate,
+ uint64 length)
+ : length_(length), offset_(0), delegate_(delegate) {
}
WrappedChannelElementReader::~WrappedChannelElementReader() {
- JNIEnv* env = base::android::AttachCurrentThread();
- env->DeleteGlobalRef(channel_);
}
int WrappedChannelElementReader::Init(const net::CompletionCallback& callback) {
@@ -74,18 +41,11 @@ int WrappedChannelElementReader::Read(net::IOBuffer* buf,
int buf_length,
const net::CompletionCallback& callback) {
DCHECK(!callback.is_null());
- JNIEnv* env = base::android::AttachCurrentThread();
- jobject jbuf = env->NewDirectByteBuffer(reinterpret_cast<void*>(buf->data()),
- buf_length);
- jint bytes_read = env->CallIntMethod(channel_, g_method_read, jbuf);
- base::android::CheckException(env);
-
- env->DeleteLocalRef(jbuf);
- if (bytes_read <= 0) {
- env->CallVoidMethod(channel_, g_method_close);
- base::android::CheckException(env);
- return bytes_read;
- }
+ DCHECK(delegate_);
+ // TODO(mef): Post the read to file thread.
+ int bytes_read = delegate_->ReadFromUploadChannel(buf, buf_length);
+ if (bytes_read < 0)
+ return net::ERR_FAILED;
offset_ += bytes_read;
return bytes_read;
}
« no previous file with comments | « components/cronet/android/wrapped_channel_upload_element_reader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698