Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: android_webview/browser/net/android_stream_reader_url_request_job.h

Issue 12377051: [android_webview] Don't intercept resource and asset URLRequests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use request restart to fall-through to other handlers Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/ref_counted.h"
boliu 2013/03/06 02:30:18 How did scoped_refptr ever compile without this..?
mkosiba (inactive) 2013/03/06 19:05:27 by being included from something else (most likely
10 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
12 #include "base/threading/non_thread_safe.h" 13 #include "base/threading/thread_checker.h"
13 #include "net/http/http_byte_range.h" 14 #include "net/http/http_byte_range.h"
14 #include "net/url_request/url_request_job.h" 15 #include "net/url_request/url_request_job.h"
15 16
16 namespace android_webview { 17 namespace android_webview {
17 class InputStream; 18 class InputStream;
18 class InputStreamReader; 19 class InputStreamReader;
19 } 20 }
20 21
21 namespace base { 22 namespace base {
22 class TaskRunner; 23 class TaskRunner;
23 } 24 }
24 25
25 namespace net { 26 namespace net {
26 class URLRequest; 27 class URLRequest;
27 } 28 }
28 29
29 class InputStreamReaderWrapper; 30 class InputStreamReaderWrapper;
30 31
31 // A request job that reads data from a Java InputStream. 32 // A request job that reads data from a Java InputStream.
32 class AndroidStreamReaderURLRequestJob : public net::URLRequestJob { 33 class AndroidStreamReaderURLRequestJob : public net::URLRequestJob {
33 public: 34 public:
34 /* 35 /*
35 * We use a delegate so that we can share code for this job in slightly 36 * We use a delegate so that we can share code for this job in slightly
36 * different contexts. 37 * different contexts.
37 */ 38 */
38 class Delegate { 39 class Delegate {
39 public: 40 public:
41 // This method is called from a worker thread, not from the IO thread.
40 virtual scoped_ptr<android_webview::InputStream> OpenInputStream( 42 virtual scoped_ptr<android_webview::InputStream> OpenInputStream(
41 JNIEnv* env, 43 JNIEnv* env,
42 net::URLRequest* request) = 0; 44 const GURL& url) = 0;
45
46 // This method is called on the Job's thread if the result of calling
47 // OpenInputStream was null.
48 // Setting the |restart| parameter to true will cause the request to be
49 // restarted with a new job.
50 virtual void OnInputStreamOpenFailed(
51 net::URLRequest* request,
52 bool* restart) = 0;
43 53
44 virtual bool GetMimeType( 54 virtual bool GetMimeType(
45 JNIEnv* env, 55 JNIEnv* env,
46 net::URLRequest* request, 56 net::URLRequest* request,
47 android_webview::InputStream* stream, 57 android_webview::InputStream* stream,
48 std::string* mime_type) = 0; 58 std::string* mime_type) = 0;
49 59
50 virtual bool GetCharset( 60 virtual bool GetCharset(
51 JNIEnv* env, 61 JNIEnv* env,
52 net::URLRequest* request, 62 net::URLRequest* request,
(...skipping 25 matching lines...) Expand all
78 // Gets the TaskRunner for the worker thread. 88 // Gets the TaskRunner for the worker thread.
79 // Overridden in unittests. 89 // Overridden in unittests.
80 virtual base::TaskRunner* GetWorkerThreadRunner(); 90 virtual base::TaskRunner* GetWorkerThreadRunner();
81 91
82 // Creates an InputStreamReader instance. 92 // Creates an InputStreamReader instance.
83 // Overridden in unittests to return a mock. 93 // Overridden in unittests to return a mock.
84 virtual scoped_ptr<android_webview::InputStreamReader> 94 virtual scoped_ptr<android_webview::InputStreamReader>
85 CreateStreamReader(android_webview::InputStream* stream); 95 CreateStreamReader(android_webview::InputStream* stream);
86 96
87 private: 97 private:
88 void StartAsync(); 98 struct OpenInputStreamResult;
89 99 static scoped_ptr<OpenInputStreamResult> OpenInputStreamOnWorkerThread(
100 scoped_ptr<Delegate> delegate,
101 const GURL& url);
102 void OnInputStreamOpened(scoped_ptr<OpenInputStreamResult> result);
90 void OnReaderSeekCompleted(int content_size); 103 void OnReaderSeekCompleted(int content_size);
91 void OnReaderReadCompleted(int bytes_read); 104 void OnReaderReadCompleted(int bytes_read);
92 105
93 net::HttpByteRange byte_range_; 106 net::HttpByteRange byte_range_;
94 scoped_ptr<Delegate> delegate_; 107 scoped_ptr<Delegate> delegate_;
95 scoped_refptr<InputStreamReaderWrapper> input_stream_reader_wrapper_; 108 scoped_refptr<InputStreamReaderWrapper> input_stream_reader_wrapper_;
96 base::WeakPtrFactory<AndroidStreamReaderURLRequestJob> weak_factory_; 109 base::WeakPtrFactory<AndroidStreamReaderURLRequestJob> weak_factory_;
110 base::ThreadChecker thread_checker_;
97 111
98 DISALLOW_COPY_AND_ASSIGN(AndroidStreamReaderURLRequestJob); 112 DISALLOW_COPY_AND_ASSIGN(AndroidStreamReaderURLRequestJob);
99 }; 113 };
100 114
101 #endif // ANDROID_WEBVIEW_NATIVE_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_ 115 #endif // ANDROID_WEBVIEW_NATIVE_ANDROID_STREAM_READER_URL_REQUEST_JOB_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698