- add sources.
[platform/framework/web/crosswalk.git] / src / android_webview / browser / net / input_stream_reader.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 ANDROID_WEBVIEW_NATIVE_INPUT_STREAM_READER_H_
6 #define ANDROID_WEBVIEW_NATIVE_INPUT_STREAM_READER_H_
7
8 #include "base/memory/ref_counted.h"
9
10 namespace net {
11 class HttpByteRange;
12 class IOBuffer;
13 }
14
15 namespace android_webview {
16
17 class InputStream;
18
19 // Class responsible for reading the InputStream.
20 class InputStreamReader {
21  public:
22   // The constructor is called on the IO thread, not on the worker thread.
23   InputStreamReader(android_webview::InputStream* stream);
24   virtual ~InputStreamReader();
25
26   // Perform a seek operation on the InputStream associated with this job.
27   // On successful completion the InputStream would have skipped reading the
28   // number of bytes equal to the lower range of |byte_range|.
29   // This method should be called on the |g_worker_thread| thread.
30   //
31   // |byte_range| is the range of bytes to be read from |stream|
32   //
33   // A negative return value will indicate an error code, a positive value
34   // will indicate the expected size of the content.
35   virtual int Seek(const net::HttpByteRange& byte_range);
36
37   // Read data from |stream_|.  This method should be called on the
38   // |g_worker_thread| thread.
39   //
40   // A negative return value will indicate an error code, a positive value
41   // will indicate the expected size of the content.
42   virtual int ReadRawData(net::IOBuffer* buffer, int buffer_size);
43
44  private:
45   // Verify the requested range against the stream size.
46   // net::OK is returned on success, the error code otherwise.
47   int VerifyRequestedRange(net::HttpByteRange* byte_range,
48                            int* content_size);
49
50   // Skip to the first byte of the requested read range.
51   // net::OK is returned on success, the error code otherwise.
52   int SkipToRequestedRange(const net::HttpByteRange& byte_range);
53
54   android_webview::InputStream* stream_;
55
56   DISALLOW_COPY_AND_ASSIGN(InputStreamReader);
57 };
58
59 } // namespace android_webview
60
61 #endif //  ANDROID_WEBVIEW_NATIVE_INPUT_STREAM_READER_H_