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/location.h" | 9 #include "base/location.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 | 72 |
73 protected: | 73 protected: |
74 virtual ~AndroidStreamReaderURLRequestJob(); | 74 virtual ~AndroidStreamReaderURLRequestJob(); |
75 | 75 |
76 // Gets the TaskRunner for the worker thread. | 76 // Gets the TaskRunner for the worker thread. |
77 // Overridden in unittests. | 77 // Overridden in unittests. |
78 virtual base::TaskRunner* GetWorkerThreadRunner(); | 78 virtual base::TaskRunner* GetWorkerThreadRunner(); |
79 | 79 |
80 // Creates an InputStreamReader instance. | 80 // Creates an InputStreamReader instance. |
81 // Overridden in unittests to return a mock. | 81 // Overridden in unittests to return a mock. |
82 virtual scoped_refptr<android_webview::InputStreamReader> | 82 virtual scoped_ptr<android_webview::InputStreamReader> |
83 CreateStreamReader(android_webview::InputStream* stream); | 83 CreateStreamReader(android_webview::InputStream* stream); |
84 | 84 |
85 private: | 85 private: |
86 // The requests posted to the worker thread might outlive the job. | |
87 // Thread-safe ref counting is used to ensure that the data is still there | |
88 // when the closure is run on the worker thread. | |
89 // | |
90 class InputStreamReaderWrapper : | |
mnaganov (inactive)
2012/11/29 10:46:55
If this class is only used by AndroidStreamReaderU
mkosiba (inactive)
2012/11/29 15:39:23
I assumed scoped_refptr would complain that the ty
| |
91 public base::RefCountedThreadSafe<InputStreamReaderWrapper> { | |
92 public: | |
93 InputStreamReaderWrapper( | |
94 scoped_ptr<android_webview::InputStream> input_stream, | |
95 scoped_ptr<android_webview::InputStreamReader> input_stream_reader); | |
96 | |
97 const android_webview::InputStream& input_stream() const { | |
98 return *input_stream_; | |
99 } | |
100 | |
101 int Seek(const net::HttpByteRange& byte_range); | |
102 int ReadRawData(net::IOBuffer* buffer, int buffer_size); | |
103 private: | |
104 friend class base::RefCountedThreadSafe<InputStreamReaderWrapper>; | |
105 ~InputStreamReaderWrapper(); | |
106 | |
107 scoped_ptr<android_webview::InputStream> input_stream_; | |
108 scoped_ptr<android_webview::InputStreamReader> input_stream_reader_; | |
109 }; | |
110 | |
86 void StartAsync(); | 111 void StartAsync(); |
87 | 112 |
88 void OnReaderSeekCompleted(int content_size); | 113 void OnReaderSeekCompleted(int content_size); |
89 void OnReaderReadCompleted(int bytes_read); | 114 void OnReaderReadCompleted(int bytes_read); |
90 | 115 |
91 net::HttpByteRange byte_range_; | 116 net::HttpByteRange byte_range_; |
92 scoped_ptr<Delegate> delegate_; | 117 scoped_ptr<Delegate> delegate_; |
93 scoped_refptr<android_webview::InputStreamReader> input_stream_reader_; | 118 scoped_refptr<InputStreamReaderWrapper> input_stream_reader_wrapper_; |
94 scoped_ptr<android_webview::InputStream> stream_; | |
95 base::WeakPtrFactory<AndroidStreamReaderURLRequestJob> weak_factory_; | 119 base::WeakPtrFactory<AndroidStreamReaderURLRequestJob> weak_factory_; |
96 | 120 |
97 DISALLOW_COPY_AND_ASSIGN(AndroidStreamReaderURLRequestJob); | 121 DISALLOW_COPY_AND_ASSIGN(AndroidStreamReaderURLRequestJob); |
98 }; | 122 }; |
99 | 123 |
100 #endif // ANDROID_WEBVIEW_NATIVE_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_ | 124 #endif // ANDROID_WEBVIEW_NATIVE_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_ |
OLD | NEW |