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

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

Issue 1552723002: Convert Pass()→std::move() in //android_webview (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
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 #include "android_webview/browser/net/android_stream_reader_url_request_job.h" 5 #include "android_webview/browser/net/android_stream_reader_url_request_job.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility>
8 9
9 #include "android_webview/browser/input_stream.h" 10 #include "android_webview/browser/input_stream.h"
10 #include "android_webview/browser/net/input_stream_reader.h" 11 #include "android_webview/browser/net/input_stream_reader.h"
11 #include "base/android/jni_android.h" 12 #include "base/android/jni_android.h"
12 #include "base/android/jni_string.h" 13 #include "base/android/jni_string.h"
13 #include "base/bind.h" 14 #include "base/bind.h"
14 #include "base/bind_helpers.h" 15 #include "base/bind_helpers.h"
15 #include "base/lazy_instance.h" 16 #include "base/lazy_instance.h"
16 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
17 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
(...skipping 29 matching lines...) Expand all
47 48
48 } // namespace 49 } // namespace
49 50
50 // The requests posted to the worker thread might outlive the job. Thread-safe 51 // The requests posted to the worker thread might outlive the job. Thread-safe
51 // ref counting is used to ensure that the InputStream and InputStreamReader 52 // ref counting is used to ensure that the InputStream and InputStreamReader
52 // members of this class are still there when the closure is run on the worker 53 // members of this class are still there when the closure is run on the worker
53 // thread. 54 // thread.
54 class InputStreamReaderWrapper : 55 class InputStreamReaderWrapper :
55 public base::RefCountedThreadSafe<InputStreamReaderWrapper> { 56 public base::RefCountedThreadSafe<InputStreamReaderWrapper> {
56 public: 57 public:
57 InputStreamReaderWrapper( 58 InputStreamReaderWrapper(scoped_ptr<InputStream> input_stream,
58 scoped_ptr<InputStream> input_stream, 59 scoped_ptr<InputStreamReader> input_stream_reader)
59 scoped_ptr<InputStreamReader> input_stream_reader) 60 : input_stream_(std::move(input_stream)),
60 : input_stream_(input_stream.Pass()), 61 input_stream_reader_(std::move(input_stream_reader)) {
61 input_stream_reader_(input_stream_reader.Pass()) {
62 DCHECK(input_stream_); 62 DCHECK(input_stream_);
63 DCHECK(input_stream_reader_); 63 DCHECK(input_stream_reader_);
64 } 64 }
65 65
66 InputStream* input_stream() { 66 InputStream* input_stream() {
67 return input_stream_.get(); 67 return input_stream_.get();
68 } 68 }
69 69
70 int Seek(const net::HttpByteRange& byte_range) { 70 int Seek(const net::HttpByteRange& byte_range) {
71 return input_stream_reader_->Seek(byte_range); 71 return input_stream_reader_->Seek(byte_range);
(...skipping 12 matching lines...) Expand all
84 84
85 DISALLOW_COPY_AND_ASSIGN(InputStreamReaderWrapper); 85 DISALLOW_COPY_AND_ASSIGN(InputStreamReaderWrapper);
86 }; 86 };
87 87
88 AndroidStreamReaderURLRequestJob::AndroidStreamReaderURLRequestJob( 88 AndroidStreamReaderURLRequestJob::AndroidStreamReaderURLRequestJob(
89 net::URLRequest* request, 89 net::URLRequest* request,
90 net::NetworkDelegate* network_delegate, 90 net::NetworkDelegate* network_delegate,
91 scoped_ptr<Delegate> delegate) 91 scoped_ptr<Delegate> delegate)
92 : URLRequestJob(request, network_delegate), 92 : URLRequestJob(request, network_delegate),
93 range_parse_result_(net::OK), 93 range_parse_result_(net::OK),
94 delegate_(delegate.Pass()), 94 delegate_(std::move(delegate)),
95 weak_factory_(this) { 95 weak_factory_(this) {
96 DCHECK(delegate_); 96 DCHECK(delegate_);
97 } 97 }
98 98
99 AndroidStreamReaderURLRequestJob::AndroidStreamReaderURLRequestJob( 99 AndroidStreamReaderURLRequestJob::AndroidStreamReaderURLRequestJob(
100 net::URLRequest* request, 100 net::URLRequest* request,
101 net::NetworkDelegate* network_delegate, 101 net::NetworkDelegate* network_delegate,
102 scoped_ptr<DelegateObtainer> delegate_obtainer, 102 scoped_ptr<DelegateObtainer> delegate_obtainer,
103 bool) 103 bool)
104 : URLRequestJob(request, network_delegate), 104 : URLRequestJob(request, network_delegate),
105 range_parse_result_(net::OK), 105 range_parse_result_(net::OK),
106 delegate_obtainer_(delegate_obtainer.Pass()), 106 delegate_obtainer_(std::move(delegate_obtainer)),
107 weak_factory_(this) { 107 weak_factory_(this) {
108 DCHECK(delegate_obtainer_); 108 DCHECK(delegate_obtainer_);
109 } 109 }
110 110
111 AndroidStreamReaderURLRequestJob::~AndroidStreamReaderURLRequestJob() { 111 AndroidStreamReaderURLRequestJob::~AndroidStreamReaderURLRequestJob() {
112 } 112 }
113 113
114 namespace { 114 namespace {
115 115
116 typedef base::Callback< 116 typedef base::Callback<
117 void(scoped_ptr<AndroidStreamReaderURLRequestJob::Delegate>, 117 void(scoped_ptr<AndroidStreamReaderURLRequestJob::Delegate>,
118 scoped_ptr<InputStream>)> OnInputStreamOpenedCallback; 118 scoped_ptr<InputStream>)> OnInputStreamOpenedCallback;
119 119
120 // static 120 // static
121 void OpenInputStreamOnWorkerThread( 121 void OpenInputStreamOnWorkerThread(
122 scoped_refptr<base::SingleThreadTaskRunner> job_thread_task_runner, 122 scoped_refptr<base::SingleThreadTaskRunner> job_thread_task_runner,
123 scoped_ptr<AndroidStreamReaderURLRequestJob::Delegate> delegate, 123 scoped_ptr<AndroidStreamReaderURLRequestJob::Delegate> delegate,
124 const GURL& url, 124 const GURL& url,
125 OnInputStreamOpenedCallback callback) { 125 OnInputStreamOpenedCallback callback) {
126 JNIEnv* env = AttachCurrentThread(); 126 JNIEnv* env = AttachCurrentThread();
127 DCHECK(env); 127 DCHECK(env);
128 128
129 scoped_ptr<InputStream> input_stream = delegate->OpenInputStream(env, url); 129 scoped_ptr<InputStream> input_stream = delegate->OpenInputStream(env, url);
130 job_thread_task_runner->PostTask( 130 job_thread_task_runner->PostTask(
131 FROM_HERE, base::Bind(callback, base::Passed(delegate.Pass()), 131 FROM_HERE, base::Bind(callback, base::Passed(std::move(delegate)),
132 base::Passed(input_stream.Pass()))); 132 base::Passed(std::move(input_stream))));
133 } 133 }
134 134
135 } // namespace 135 } // namespace
136 136
137 void AndroidStreamReaderURLRequestJob::Start() { 137 void AndroidStreamReaderURLRequestJob::Start() {
138 DCHECK(thread_checker_.CalledOnValidThread()); 138 DCHECK(thread_checker_.CalledOnValidThread());
139 if (!delegate_) { 139 if (!delegate_) {
140 DCHECK(delegate_obtainer_); 140 DCHECK(delegate_obtainer_);
141 delegate_obtainer_->ObtainDelegate( 141 delegate_obtainer_->ObtainDelegate(
142 request(), 142 request(),
(...skipping 16 matching lines...) Expand all
159 scoped_ptr<InputStreamReader> 159 scoped_ptr<InputStreamReader>
160 AndroidStreamReaderURLRequestJob::CreateStreamReader(InputStream* stream) { 160 AndroidStreamReaderURLRequestJob::CreateStreamReader(InputStream* stream) {
161 return make_scoped_ptr(new InputStreamReader(stream)); 161 return make_scoped_ptr(new InputStreamReader(stream));
162 } 162 }
163 163
164 void AndroidStreamReaderURLRequestJob::OnInputStreamOpened( 164 void AndroidStreamReaderURLRequestJob::OnInputStreamOpened(
165 scoped_ptr<Delegate> returned_delegate, 165 scoped_ptr<Delegate> returned_delegate,
166 scoped_ptr<android_webview::InputStream> input_stream) { 166 scoped_ptr<android_webview::InputStream> input_stream) {
167 DCHECK(thread_checker_.CalledOnValidThread()); 167 DCHECK(thread_checker_.CalledOnValidThread());
168 DCHECK(returned_delegate); 168 DCHECK(returned_delegate);
169 delegate_ = returned_delegate.Pass(); 169 delegate_ = std::move(returned_delegate);
170 170
171 if (!input_stream) { 171 if (!input_stream) {
172 bool restart_required = false; 172 bool restart_required = false;
173 delegate_->OnInputStreamOpenFailed(request(), &restart_required); 173 delegate_->OnInputStreamOpenFailed(request(), &restart_required);
174 if (restart_required) { 174 if (restart_required) {
175 NotifyRestartRequired(); 175 NotifyRestartRequired();
176 } else { 176 } else {
177 // Clear the IO_PENDING status set in Start(). 177 // Clear the IO_PENDING status set in Start().
178 SetStatus(net::URLRequestStatus()); 178 SetStatus(net::URLRequestStatus());
179 HeadersComplete(kHTTPNotFound, kHTTPNotFoundText); 179 HeadersComplete(kHTTPNotFound, kHTTPNotFoundText);
180 } 180 }
181 return; 181 return;
182 } 182 }
183 183
184 scoped_ptr<InputStreamReader> input_stream_reader( 184 scoped_ptr<InputStreamReader> input_stream_reader(
185 CreateStreamReader(input_stream.get())); 185 CreateStreamReader(input_stream.get()));
186 DCHECK(input_stream_reader); 186 DCHECK(input_stream_reader);
187 187
188 DCHECK(!input_stream_reader_wrapper_.get()); 188 DCHECK(!input_stream_reader_wrapper_.get());
189 input_stream_reader_wrapper_ = new InputStreamReaderWrapper( 189 input_stream_reader_wrapper_ = new InputStreamReaderWrapper(
190 input_stream.Pass(), input_stream_reader.Pass()); 190 std::move(input_stream), std::move(input_stream_reader));
191 191
192 PostTaskAndReplyWithResult( 192 PostTaskAndReplyWithResult(
193 GetWorkerThreadRunner(), 193 GetWorkerThreadRunner(),
194 FROM_HERE, 194 FROM_HERE,
195 base::Bind(&InputStreamReaderWrapper::Seek, 195 base::Bind(&InputStreamReaderWrapper::Seek,
196 input_stream_reader_wrapper_, 196 input_stream_reader_wrapper_,
197 byte_range_), 197 byte_range_),
198 base::Bind(&AndroidStreamReaderURLRequestJob::OnReaderSeekCompleted, 198 base::Bind(&AndroidStreamReaderURLRequestJob::OnReaderSeekCompleted,
199 weak_factory_.GetWeakPtr())); 199 weak_factory_.GetWeakPtr()));
200 } 200 }
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 byte_range_ = ranges[0]; 385 byte_range_ = ranges[0];
386 } else { 386 } else {
387 // We don't support multiple range requests in one single URL request, 387 // We don't support multiple range requests in one single URL request,
388 // because we need to do multipart encoding here. 388 // because we need to do multipart encoding here.
389 range_parse_result_ = net::ERR_REQUEST_RANGE_NOT_SATISFIABLE; 389 range_parse_result_ = net::ERR_REQUEST_RANGE_NOT_SATISFIABLE;
390 } 390 }
391 } 391 }
392 } 392 }
393 393
394 } // namespace android_webview 394 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698