Chromium Code Reviews| 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 #ifndef ANDROID_WEBVIEW_NATIVE_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_ | 5 #ifndef ANDROID_WEBVIEW_NATIVE_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_ |
| 6 #define ANDROID_WEBVIEW_NATIVE_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_ | 6 #define ANDROID_WEBVIEW_NATIVE_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_ |
| 7 | 7 |
| 8 #include "base/android/scoped_java_ref.h" | 8 #include "base/android/scoped_java_ref.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/memory/weak_ptr.h" | |
| 10 #include "base/threading/non_thread_safe.h" | 11 #include "base/threading/non_thread_safe.h" |
| 11 #include "net/http/http_byte_range.h" | 12 #include "net/http/http_byte_range.h" |
| 12 #include "net/url_request/url_request_job.h" | 13 #include "net/url_request/url_request_job.h" |
| 13 | 14 |
| 14 namespace net { | 15 namespace net { |
| 15 class URLRequest; | 16 class URLRequest; |
| 16 } | 17 } |
| 17 | 18 |
| 18 // A request job that reads data from a Java InputStream. | 19 // A request job that reads data from a Java InputStream. |
| 19 class AndroidStreamReaderURLRequestJob : public net::URLRequestJob { | 20 class AndroidStreamReaderURLRequestJob : public net::URLRequestJob { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 36 | 37 |
| 37 virtual bool GetCharset( | 38 virtual bool GetCharset( |
| 38 JNIEnv* env, | 39 JNIEnv* env, |
| 39 net::URLRequest* request, | 40 net::URLRequest* request, |
| 40 jobject stream, | 41 jobject stream, |
| 41 std::string* charset) = 0; | 42 std::string* charset) = 0; |
| 42 | 43 |
| 43 virtual ~Delegate() {} | 44 virtual ~Delegate() {} |
| 44 }; | 45 }; |
| 45 | 46 |
| 46 explicit AndroidStreamReaderURLRequestJob( | 47 AndroidStreamReaderURLRequestJob( |
| 47 net::URLRequest* request, | 48 net::URLRequest* request, |
| 48 net::NetworkDelegate* network_delegate, | 49 net::NetworkDelegate* network_delegate, |
| 49 scoped_ptr<Delegate> delegate); | 50 scoped_ptr<Delegate> delegate); |
| 50 | 51 |
| 51 // URLRequestJob: | 52 // URLRequestJob: |
| 52 virtual void Start() OVERRIDE; | 53 virtual void Start() OVERRIDE; |
| 53 virtual bool ReadRawData(net::IOBuffer* buf, | 54 virtual bool ReadRawData(net::IOBuffer* buf, |
| 54 int buf_size, | 55 int buf_size, |
| 55 int* bytes_read) OVERRIDE; | 56 int* bytes_read) OVERRIDE; |
| 56 virtual void SetExtraRequestHeaders( | 57 virtual void SetExtraRequestHeaders( |
| 57 const net::HttpRequestHeaders& headers) OVERRIDE; | 58 const net::HttpRequestHeaders& headers) OVERRIDE; |
| 58 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; | 59 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; |
| 59 virtual bool GetCharset(std::string* charset) OVERRIDE; | 60 virtual bool GetCharset(std::string* charset) OVERRIDE; |
| 60 | 61 |
| 61 protected: | 62 protected: |
| 62 virtual ~AndroidStreamReaderURLRequestJob(); | 63 virtual ~AndroidStreamReaderURLRequestJob(); |
| 63 | 64 |
| 64 private: | 65 private: |
| 65 // Verify the requested range against the stream size. | 66 // Verify the requested range against the stream size. |
| 66 bool VerifyRequestedRange(JNIEnv* env); | 67 bool VerifyRequestedRange(JNIEnv* env); |
| 67 | 68 |
| 68 // Skip to the first byte of the requested read range. | 69 // Skip to the first byte of the requested read range. |
| 69 bool SkipToRequestedRange(JNIEnv* env); | 70 bool SkipToRequestedRange(JNIEnv* env); |
| 70 | 71 |
| 72 void StartAsync(); | |
| 73 | |
| 71 net::HttpByteRange byte_range_; | 74 net::HttpByteRange byte_range_; |
| 72 scoped_ptr<Delegate> delegate_; | 75 scoped_ptr<Delegate> delegate_; |
| 73 base::android::ScopedJavaGlobalRef<jobject> stream_; | 76 base::android::ScopedJavaGlobalRef<jobject> stream_; |
| 74 base::android::ScopedJavaGlobalRef<jbyteArray> buffer_; | 77 base::android::ScopedJavaGlobalRef<jbyteArray> buffer_; |
| 78 base::WeakPtrFactory<AndroidStreamReaderURLRequestJob> weak_factory_; | |
|
joth
2012/10/15 17:01:46
net::URLRequestJob is refcounted, so it feels like
mnaganov (inactive)
2012/10/15 17:18:25
I was following the practice that the majority of
mkosiba (inactive)
2012/10/15 17:24:03
hmm.. all of the other URLRequestJob impls use a w
| |
| 75 | 79 |
| 76 DISALLOW_COPY_AND_ASSIGN(AndroidStreamReaderURLRequestJob); | 80 DISALLOW_COPY_AND_ASSIGN(AndroidStreamReaderURLRequestJob); |
| 77 }; | 81 }; |
| 78 | 82 |
| 79 bool RegisterAndroidStreamReaderUrlRequestJob(JNIEnv* env); | 83 bool RegisterAndroidStreamReaderUrlRequestJob(JNIEnv* env); |
| 80 | 84 |
| 81 #endif // ANDROID_WEBVIEW_NATIVE_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_ | 85 #endif // ANDROID_WEBVIEW_NATIVE_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_ |
| OLD | NEW |