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

Side by Side Diff: webkit/plugins/ppapi/ppb_url_loader_impl.cc

Issue 7920001: Don't try to call setDefersLoading when the loader is null. This does a bit of cleanup so the che... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 3 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
« no previous file with comments | « webkit/plugins/ppapi/ppb_url_loader_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "webkit/plugins/ppapi/ppb_url_loader_impl.h" 5 #include "webkit/plugins/ppapi/ppb_url_loader_impl.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "net/base/net_errors.h" 8 #include "net/base/net_errors.h"
9 #include "ppapi/c/pp_completion_callback.h" 9 #include "ppapi/c/pp_completion_callback.h"
10 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/c/pp_errors.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 return this; 89 return this;
90 } 90 }
91 91
92 void PPB_URLLoader_Impl::InstanceWasDeleted() { 92 void PPB_URLLoader_Impl::InstanceWasDeleted() {
93 Resource::InstanceWasDeleted(); 93 Resource::InstanceWasDeleted();
94 loader_.reset(); 94 loader_.reset();
95 } 95 }
96 96
97 int32_t PPB_URLLoader_Impl::Open(PP_Resource request_id, 97 int32_t PPB_URLLoader_Impl::Open(PP_Resource request_id,
98 PP_CompletionCallback callback) { 98 PP_CompletionCallback callback) {
99 // Main document loads are already open, so don't allow people to open them
100 // again.
101 if (main_document_loader_)
102 return PP_ERROR_NOACCESS;
bbudge 2011/09/16 00:06:12 Maybe PP_ERROR_INPROGRESS is a more appropriate er
brettw 2011/09/16 18:05:40 Done.
103
99 EnterResourceNoLock<PPB_URLRequestInfo_API> enter_request(request_id, true); 104 EnterResourceNoLock<PPB_URLRequestInfo_API> enter_request(request_id, true);
100 if (enter_request.failed()) 105 if (enter_request.failed())
101 return PP_ERROR_BADARGUMENT; 106 return PP_ERROR_BADARGUMENT;
102 PPB_URLRequestInfo_Impl* request = static_cast<PPB_URLRequestInfo_Impl*>( 107 PPB_URLRequestInfo_Impl* request = static_cast<PPB_URLRequestInfo_Impl*>(
103 enter_request.object()); 108 enter_request.object());
104 109
105 int32_t rv = ValidateCallback(callback); 110 int32_t rv = ValidateCallback(callback);
106 if (rv != PP_OK) 111 if (rv != PP_OK)
107 return rv; 112 return rv;
108 113
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 return PP_OK_COMPLETIONPENDING; 154 return PP_OK_COMPLETIONPENDING;
150 } 155 }
151 156
152 int32_t PPB_URLLoader_Impl::FollowRedirect(PP_CompletionCallback callback) { 157 int32_t PPB_URLLoader_Impl::FollowRedirect(PP_CompletionCallback callback) {
153 int32_t rv = ValidateCallback(callback); 158 int32_t rv = ValidateCallback(callback);
154 if (rv != PP_OK) 159 if (rv != PP_OK)
155 return rv; 160 return rv;
156 161
157 WebURL redirect_url = GURL(response_info_->redirect_url()); 162 WebURL redirect_url = GURL(response_info_->redirect_url());
158 163
159 loader_->setDefersLoading(false); // Allow the redirect to continue. 164 SetDefersLoading(false); // Allow the redirect to continue.
160 RegisterCallback(callback); 165 RegisterCallback(callback);
161 return PP_OK_COMPLETIONPENDING; 166 return PP_OK_COMPLETIONPENDING;
162 } 167 }
163 168
164 PP_Bool PPB_URLLoader_Impl::GetUploadProgress(int64_t* bytes_sent, 169 PP_Bool PPB_URLLoader_Impl::GetUploadProgress(int64_t* bytes_sent,
165 int64_t* total_bytes_to_be_sent) { 170 int64_t* total_bytes_to_be_sent) {
166 if (!RecordUploadProgress()) { 171 if (!RecordUploadProgress()) {
167 *bytes_sent = 0; 172 *bytes_sent = 0;
168 *total_bytes_to_be_sent = 0; 173 *total_bytes_to_be_sent = 0;
169 return PP_FALSE; 174 return PP_FALSE;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 if (rv != PP_OK) 231 if (rv != PP_OK)
227 return rv; 232 return rv;
228 if (!response_info_ || !response_info_->body()) 233 if (!response_info_ || !response_info_->body())
229 return PP_ERROR_FAILED; 234 return PP_ERROR_FAILED;
230 235
231 // We may have already reached EOF. 236 // We may have already reached EOF.
232 if (done_status_ != PP_OK_COMPLETIONPENDING) 237 if (done_status_ != PP_OK_COMPLETIONPENDING)
233 return done_status_; 238 return done_status_;
234 239
235 is_streaming_to_file_ = true; 240 is_streaming_to_file_ = true;
236 if (is_asynchronous_load_suspended_) { 241 if (is_asynchronous_load_suspended_)
237 loader_->setDefersLoading(false); 242 SetDefersLoading(false);
238 is_asynchronous_load_suspended_ = false;
239 }
240 243
241 // Wait for didFinishLoading / didFail. 244 // Wait for didFinishLoading / didFail.
242 RegisterCallback(callback); 245 RegisterCallback(callback);
243 return PP_OK_COMPLETIONPENDING; 246 return PP_OK_COMPLETIONPENDING;
244 } 247 }
245 248
246 void PPB_URLLoader_Impl::Close() { 249 void PPB_URLLoader_Impl::Close() {
247 if (loader_.get()) 250 if (loader_.get())
248 loader_->cancel(); 251 loader_->cancel();
249 else if (main_document_loader_) 252 else if (main_document_loader_)
(...skipping 10 matching lines...) Expand all
260 PP_URLLoaderTrusted_StatusCallback cb) { 263 PP_URLLoaderTrusted_StatusCallback cb) {
261 status_callback_ = cb; 264 status_callback_ = cb;
262 } 265 }
263 266
264 void PPB_URLLoader_Impl::willSendRequest( 267 void PPB_URLLoader_Impl::willSendRequest(
265 WebURLLoader* loader, 268 WebURLLoader* loader,
266 WebURLRequest& new_request, 269 WebURLRequest& new_request,
267 const WebURLResponse& redirect_response) { 270 const WebURLResponse& redirect_response) {
268 if (!request_data_.follow_redirects) { 271 if (!request_data_.follow_redirects) {
269 SaveResponse(redirect_response); 272 SaveResponse(redirect_response);
270 loader_->setDefersLoading(true); 273 SetDefersLoading(true);
271 RunCallback(PP_OK); 274 RunCallback(PP_OK);
272 } 275 }
273 } 276 }
274 277
275 void PPB_URLLoader_Impl::didSendData( 278 void PPB_URLLoader_Impl::didSendData(
276 WebURLLoader* loader, 279 WebURLLoader* loader,
277 unsigned long long bytes_sent, 280 unsigned long long bytes_sent,
278 unsigned long long total_bytes_to_be_sent) { 281 unsigned long long total_bytes_to_be_sent) {
279 // TODO(darin): Bounds check input? 282 // TODO(darin): Bounds check input?
280 bytes_sent_ = static_cast<int64_t>(bytes_sent); 283 bytes_sent_ = static_cast<int64_t>(bytes_sent);
(...skipping 15 matching lines...) Expand all
296 void PPB_URLLoader_Impl::didDownloadData(WebURLLoader* loader, 299 void PPB_URLLoader_Impl::didDownloadData(WebURLLoader* loader,
297 int data_length) { 300 int data_length) {
298 bytes_received_ += data_length; 301 bytes_received_ += data_length;
299 UpdateStatus(); 302 UpdateStatus();
300 } 303 }
301 304
302 void PPB_URLLoader_Impl::didReceiveData(WebURLLoader* loader, 305 void PPB_URLLoader_Impl::didReceiveData(WebURLLoader* loader,
303 const char* data, 306 const char* data,
304 int data_length, 307 int data_length,
305 int encoded_data_length) { 308 int encoded_data_length) {
309 // Note that |loader| will be NULL for document loads.
306 bytes_received_ += data_length; 310 bytes_received_ += data_length;
307 UpdateStatus(); 311 UpdateStatus();
308 312
309 buffer_.insert(buffer_.end(), data, data + data_length); 313 buffer_.insert(buffer_.end(), data, data + data_length);
310 if (user_buffer_) { 314 if (user_buffer_) {
311 RunCallback(FillUserBuffer()); 315 RunCallback(FillUserBuffer());
312 } else { 316 } else {
313 DCHECK(!pending_callback_.get() || pending_callback_->completed()); 317 DCHECK(!pending_callback_.get() || pending_callback_->completed());
314 } 318 }
315 319
316 // To avoid letting the network stack download an entire stream all at once, 320 // To avoid letting the network stack download an entire stream all at once,
317 // defer loading when we have enough buffer. 321 // defer loading when we have enough buffer.
318 // Check the buffer size after potentially moving some to the user buffer. 322 // Check the buffer size after potentially moving some to the user buffer.
319 DCHECK(request_data_.prefetch_buffer_lower_threshold < 323 DCHECK(request_data_.prefetch_buffer_lower_threshold <
320 request_data_.prefetch_buffer_upper_threshold); 324 request_data_.prefetch_buffer_upper_threshold);
321 if (!is_streaming_to_file_ && 325 if (!is_streaming_to_file_ &&
322 !is_asynchronous_load_suspended_ && 326 !is_asynchronous_load_suspended_ &&
323 (buffer_.size() >= static_cast<size_t>( 327 (buffer_.size() >= static_cast<size_t>(
324 request_data_.prefetch_buffer_upper_threshold))) { 328 request_data_.prefetch_buffer_upper_threshold))) {
325 DVLOG(1) << "Suspending async load - buffer size: " << buffer_.size(); 329 DVLOG(1) << "Suspending async load - buffer size: " << buffer_.size();
326 loader->setDefersLoading(true); 330 SetDefersLoading(true);
327 is_asynchronous_load_suspended_ = true;
328 } 331 }
329 } 332 }
330 333
331 void PPB_URLLoader_Impl::didFinishLoading(WebURLLoader* loader, 334 void PPB_URLLoader_Impl::didFinishLoading(WebURLLoader* loader,
332 double finish_time) { 335 double finish_time) {
333 FinishLoading(PP_OK); 336 FinishLoading(PP_OK);
334 } 337 }
335 338
336 void PPB_URLLoader_Impl::didFail(WebURLLoader* loader, 339 void PPB_URLLoader_Impl::didFail(WebURLLoader* loader,
337 const WebURLError& error) { 340 const WebURLError& error) {
338 int32_t pp_error = PP_ERROR_FAILED; 341 int32_t pp_error = PP_ERROR_FAILED;
339 if (error.domain.equals(WebString::fromUTF8(net::kErrorDomain))) { 342 if (error.domain.equals(WebString::fromUTF8(net::kErrorDomain))) {
340 // TODO(bbudge): Extend pp_errors.h to cover interesting network errors 343 // TODO(bbudge): Extend pp_errors.h to cover interesting network errors
341 // from the net error domain. 344 // from the net error domain.
342 switch (error.reason) { 345 switch (error.reason) {
343 case net::ERR_ACCESS_DENIED: 346 case net::ERR_ACCESS_DENIED:
344 case net::ERR_NETWORK_ACCESS_DENIED: 347 case net::ERR_NETWORK_ACCESS_DENIED:
345 pp_error = PP_ERROR_NOACCESS; 348 pp_error = PP_ERROR_NOACCESS;
346 break; 349 break;
347 } 350 }
348 } else { 351 } else {
349 // It's a WebKit error. 352 // It's a WebKit error.
350 pp_error = PP_ERROR_NOACCESS; 353 pp_error = PP_ERROR_NOACCESS;
351 } 354 }
352 355
353 FinishLoading(pp_error); 356 FinishLoading(pp_error);
354 } 357 }
355 358
359 void PPB_URLLoader_Impl::SetDefersLoading(bool defers_loading) {
360 if (loader_.get()) {
361 loader_->setDefersLoading(defers_loading);
362 is_asynchronous_load_suspended_ = defers_loading;
363 }
364
365 // TODO(brettw) bug 96770: We need a way to set the defers loading flag on
366 // main document loads (when the loader_ is null).
367 }
368
356 void PPB_URLLoader_Impl::FinishLoading(int32_t done_status) { 369 void PPB_URLLoader_Impl::FinishLoading(int32_t done_status) {
357 done_status_ = done_status; 370 done_status_ = done_status;
358 // If the client hasn't called any function that takes a callback since 371 // If the client hasn't called any function that takes a callback since
359 // the initial call to Open, or called ReadResponseBody and got a 372 // the initial call to Open, or called ReadResponseBody and got a
360 // synchronous return, then the callback will be NULL. 373 // synchronous return, then the callback will be NULL.
361 if (pending_callback_.get() && !pending_callback_->completed()) 374 if (pending_callback_.get() && !pending_callback_->completed())
362 RunCallback(done_status_); 375 RunCallback(done_status_);
363 } 376 }
364 377
365 int32_t PPB_URLLoader_Impl::ValidateCallback(PP_CompletionCallback callback) { 378 int32_t PPB_URLLoader_Impl::ValidateCallback(PP_CompletionCallback callback) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 416
404 size_t bytes_to_copy = std::min(buffer_.size(), user_buffer_size_); 417 size_t bytes_to_copy = std::min(buffer_.size(), user_buffer_size_);
405 std::copy(buffer_.begin(), buffer_.begin() + bytes_to_copy, user_buffer_); 418 std::copy(buffer_.begin(), buffer_.begin() + bytes_to_copy, user_buffer_);
406 buffer_.erase(buffer_.begin(), buffer_.begin() + bytes_to_copy); 419 buffer_.erase(buffer_.begin(), buffer_.begin() + bytes_to_copy);
407 420
408 // If the buffer is getting too empty, resume asynchronous loading. 421 // If the buffer is getting too empty, resume asynchronous loading.
409 if (is_asynchronous_load_suspended_ && 422 if (is_asynchronous_load_suspended_ &&
410 buffer_.size() <= static_cast<size_t>( 423 buffer_.size() <= static_cast<size_t>(
411 request_data_.prefetch_buffer_lower_threshold)) { 424 request_data_.prefetch_buffer_lower_threshold)) {
412 DVLOG(1) << "Resuming async load - buffer size: " << buffer_.size(); 425 DVLOG(1) << "Resuming async load - buffer size: " << buffer_.size();
413 loader_->setDefersLoading(false); 426 SetDefersLoading(false);
414 is_asynchronous_load_suspended_ = false;
415 } 427 }
416 428
417 // Reset for next time. 429 // Reset for next time.
418 user_buffer_ = NULL; 430 user_buffer_ = NULL;
419 user_buffer_size_ = 0; 431 user_buffer_size_ = 0;
420 return bytes_to_copy; 432 return bytes_to_copy;
421 } 433 }
422 434
423 void PPB_URLLoader_Impl::SaveResponse(const WebURLResponse& response) { 435 void PPB_URLLoader_Impl::SaveResponse(const WebURLResponse& response) {
424 scoped_refptr<PPB_URLResponseInfo_Impl> response_info( 436 scoped_refptr<PPB_URLResponseInfo_Impl> response_info(
(...skipping 22 matching lines...) Expand all
447 bool PPB_URLLoader_Impl::RecordDownloadProgress() const { 459 bool PPB_URLLoader_Impl::RecordDownloadProgress() const {
448 return request_data_.record_download_progress; 460 return request_data_.record_download_progress;
449 } 461 }
450 462
451 bool PPB_URLLoader_Impl::RecordUploadProgress() const { 463 bool PPB_URLLoader_Impl::RecordUploadProgress() const {
452 return request_data_.record_upload_progress; 464 return request_data_.record_upload_progress;
453 } 465 }
454 466
455 } // namespace ppapi 467 } // namespace ppapi
456 } // namespace webkit 468 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_url_loader_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698