OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "android_webview/native/input_stream_impl.h" | 5 #include "android_webview/browser/input_stream_impl.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 // Disable "Warnings treated as errors" for input_stream_jni as it's a Java | 8 // Disable "Warnings treated as errors" for input_stream_jni as it's a Java |
9 // system class and we have to generate C++ hooks for all methods in the class | 9 // system class and we have to generate C++ hooks for all methods in the class |
10 // even if they're unused. | 10 // even if they're unused. |
11 #pragma GCC diagnostic push | 11 #pragma GCC diagnostic push |
12 #pragma GCC diagnostic ignored "-Wunused-function" | 12 #pragma GCC diagnostic ignored "-Wunused-function" |
13 #include "jni/InputStreamUtil_jni.h" | 13 #include "jni/InputStreamUtil_jni.h" |
14 #pragma GCC diagnostic pop | 14 #pragma GCC diagnostic pop |
15 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
16 | 16 |
17 using base::android::AttachCurrentThread; | 17 using base::android::AttachCurrentThread; |
18 using base::android::ClearException; | 18 using base::android::ClearException; |
19 using base::android::JavaRef; | 19 using base::android::JavaRef; |
20 | 20 |
21 namespace android_webview { | 21 namespace android_webview { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 // This should be the same as InputStramUtil.EXCEPTION_THROWN_STATUS. | 25 // This should be the same as InputStramUtil.EXCEPTION_THROWN_STATUS. |
26 const int kExceptionThrownStatusCode = -2; | 26 const int kExceptionThrownStatusCode = -2; |
27 | |
28 } | 27 } |
29 | 28 |
30 // Maximum number of bytes to be read in a single read. | 29 // Maximum number of bytes to be read in a single read. |
31 const int InputStreamImpl::kBufferSize = 4096; | 30 const int InputStreamImpl::kBufferSize = 4096; |
32 | 31 |
33 // static | 32 // static |
34 const InputStreamImpl* InputStreamImpl::FromInputStream( | 33 const InputStreamImpl* InputStreamImpl::FromInputStream( |
35 const InputStream* input_stream) { | 34 const InputStream* input_stream) { |
36 return static_cast<const InputStreamImpl*>(input_stream); | 35 return static_cast<const InputStreamImpl*>(input_stream); |
37 } | 36 } |
38 | 37 |
39 // TODO: Use unsafe version for all Java_InputStream methods in this file | 38 // TODO: Use unsafe version for all Java_InputStream methods in this file |
40 // once BUG 157880 is fixed and implement graceful exception handling. | 39 // once BUG 157880 is fixed and implement graceful exception handling. |
41 | 40 |
42 InputStreamImpl::InputStreamImpl() { | 41 InputStreamImpl::InputStreamImpl() {} |
43 } | |
44 | 42 |
45 InputStreamImpl::InputStreamImpl(const JavaRef<jobject>& stream) | 43 InputStreamImpl::InputStreamImpl(const JavaRef<jobject>& stream) |
46 : jobject_(stream) { | 44 : jobject_(stream) { |
47 DCHECK(!stream.is_null()); | 45 DCHECK(!stream.is_null()); |
48 } | 46 } |
49 | 47 |
50 InputStreamImpl::~InputStreamImpl() { | 48 InputStreamImpl::~InputStreamImpl() { |
51 JNIEnv* env = AttachCurrentThread(); | 49 JNIEnv* env = AttachCurrentThread(); |
52 Java_InputStreamUtil_close(env, jobject_); | 50 Java_InputStreamUtil_close(env, jobject_); |
53 } | 51 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 remaining_length -= transfer_length; | 119 remaining_length -= transfer_length; |
122 dest_write_ptr += transfer_length; | 120 dest_write_ptr += transfer_length; |
123 } | 121 } |
124 // bytes_read can be strictly less than the req. length if EOF is encountered. | 122 // bytes_read can be strictly less than the req. length if EOF is encountered. |
125 DCHECK_GE(remaining_length, 0); | 123 DCHECK_GE(remaining_length, 0); |
126 DCHECK_LE(remaining_length, length); | 124 DCHECK_LE(remaining_length, length); |
127 *bytes_read = length - remaining_length; | 125 *bytes_read = length - remaining_length; |
128 return true; | 126 return true; |
129 } | 127 } |
130 | 128 |
131 } // namespace android_webview | 129 } // namespace android_webview |
OLD | NEW |