Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / browser / android / net / input_stream_impl.h
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
3 // found in the LICENSE file.
4
5 #ifndef XWALK_RUNTIME_BROWSER_ANDROID_NET_INPUT_STREAM_IMPL_H_
6 #define XWALK_RUNTIME_BROWSER_ANDROID_NET_INPUT_STREAM_IMPL_H_
7
8 #include "base/android/scoped_java_ref.h"
9 #include "base/compiler_specific.h"
10 #include "xwalk/runtime/browser/android/net/input_stream.h"
11
12 namespace net {
13 class IOBuffer;
14 }
15
16 namespace xwalk {
17
18 class InputStreamImpl : public InputStream {
19  public:
20   // Maximum size of |buffer_|.
21   static const int kBufferSize;
22
23   static const InputStreamImpl* FromInputStream(
24       const InputStream* input_stream);
25
26   // |stream| should be an instance of the InputStream Java class.
27   // |stream| can't be null.
28   explicit InputStreamImpl(const base::android::JavaRef<jobject>& stream);
29   virtual ~InputStreamImpl();
30
31   // Gets the underlying Java object. Guaranteed non-NULL.
32   const jobject jobj() const { return jobject_.obj(); }
33
34   // InputStream implementation.
35   bool BytesAvailable(int* bytes_available) const override;
36   bool Skip(int64_t n, int64_t* bytes_skipped) override;
37   bool Read(net::IOBuffer* dest, int length, int* bytes_read) override;
38
39  protected:
40   // Parameterless constructor exposed for testing.
41   InputStreamImpl();
42
43  private:
44   base::android::ScopedJavaGlobalRef<jobject> jobject_;
45   base::android::ScopedJavaGlobalRef<jbyteArray> buffer_;
46
47   DISALLOW_COPY_AND_ASSIGN(InputStreamImpl);
48 };
49
50 bool RegisterInputStream(JNIEnv* env);
51
52 }  // namespace xwalk
53
54 #endif  // XWALK_RUNTIME_BROWSER_ANDROID_NET_INPUT_STREAM_IMPL_H_