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

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

Issue 9015009: Use the new callback tracker and delete the old one (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add IsPending Created 8 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 | Annotate | Revision Log
« no previous file with comments | « webkit/plugins/ppapi/ppb_url_loader_impl.h ('k') | webkit/tools/test_shell/test_shell.gypi » ('j') | 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 18 matching lines...) Expand all
29 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 29 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
30 #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h" 30 #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h"
31 #include "webkit/plugins/ppapi/ppb_url_response_info_impl.h" 31 #include "webkit/plugins/ppapi/ppb_url_response_info_impl.h"
32 #include "webkit/plugins/ppapi/resource_helper.h" 32 #include "webkit/plugins/ppapi/resource_helper.h"
33 33
34 using appcache::WebApplicationCacheHostImpl; 34 using appcache::WebApplicationCacheHostImpl;
35 using ppapi::Resource; 35 using ppapi::Resource;
36 using ppapi::thunk::EnterResourceNoLock; 36 using ppapi::thunk::EnterResourceNoLock;
37 using ppapi::thunk::PPB_URLLoader_API; 37 using ppapi::thunk::PPB_URLLoader_API;
38 using ppapi::thunk::PPB_URLRequestInfo_API; 38 using ppapi::thunk::PPB_URLRequestInfo_API;
39 using ppapi::TrackedCallback;
39 using WebKit::WebFrame; 40 using WebKit::WebFrame;
40 using WebKit::WebString; 41 using WebKit::WebString;
41 using WebKit::WebURL; 42 using WebKit::WebURL;
42 using WebKit::WebURLError; 43 using WebKit::WebURLError;
43 using WebKit::WebURLLoader; 44 using WebKit::WebURLLoader;
44 using WebKit::WebURLLoaderOptions; 45 using WebKit::WebURLLoaderOptions;
45 using WebKit::WebURLRequest; 46 using WebKit::WebURLRequest;
46 using WebKit::WebURLResponse; 47 using WebKit::WebURLResponse;
47 48
48 #ifdef _MSC_VER 49 #ifdef _MSC_VER
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 int data_length, 311 int data_length,
311 int encoded_data_length) { 312 int encoded_data_length) {
312 // Note that |loader| will be NULL for document loads. 313 // Note that |loader| will be NULL for document loads.
313 bytes_received_ += data_length; 314 bytes_received_ += data_length;
314 UpdateStatus(); 315 UpdateStatus();
315 316
316 buffer_.insert(buffer_.end(), data, data + data_length); 317 buffer_.insert(buffer_.end(), data, data + data_length);
317 if (user_buffer_) { 318 if (user_buffer_) {
318 RunCallback(FillUserBuffer()); 319 RunCallback(FillUserBuffer());
319 } else { 320 } else {
320 DCHECK(!pending_callback_.get() || pending_callback_->completed()); 321 DCHECK(!TrackedCallback::IsPending(pending_callback_));
321 } 322 }
322 323
323 // To avoid letting the network stack download an entire stream all at once, 324 // To avoid letting the network stack download an entire stream all at once,
324 // defer loading when we have enough buffer. 325 // defer loading when we have enough buffer.
325 // Check the buffer size after potentially moving some to the user buffer. 326 // Check the buffer size after potentially moving some to the user buffer.
326 DCHECK(request_data_.prefetch_buffer_lower_threshold < 327 DCHECK(request_data_.prefetch_buffer_lower_threshold <
327 request_data_.prefetch_buffer_upper_threshold); 328 request_data_.prefetch_buffer_upper_threshold);
328 if (!is_streaming_to_file_ && 329 if (!is_streaming_to_file_ &&
329 !is_asynchronous_load_suspended_ && 330 !is_asynchronous_load_suspended_ &&
330 (buffer_.size() >= static_cast<size_t>( 331 (buffer_.size() >= static_cast<size_t>(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 368
368 // TODO(brettw) bug 96770: We need a way to set the defers loading flag on 369 // TODO(brettw) bug 96770: We need a way to set the defers loading flag on
369 // main document loads (when the loader_ is null). 370 // main document loads (when the loader_ is null).
370 } 371 }
371 372
372 void PPB_URLLoader_Impl::FinishLoading(int32_t done_status) { 373 void PPB_URLLoader_Impl::FinishLoading(int32_t done_status) {
373 done_status_ = done_status; 374 done_status_ = done_status;
374 // If the client hasn't called any function that takes a callback since 375 // If the client hasn't called any function that takes a callback since
375 // the initial call to Open, or called ReadResponseBody and got a 376 // the initial call to Open, or called ReadResponseBody and got a
376 // synchronous return, then the callback will be NULL. 377 // synchronous return, then the callback will be NULL.
377 if (pending_callback_.get() && !pending_callback_->completed()) 378 if (TrackedCallback::IsPending(pending_callback_))
378 RunCallback(done_status_); 379 RunCallback(done_status_);
379 } 380 }
380 381
381 int32_t PPB_URLLoader_Impl::ValidateCallback(PP_CompletionCallback callback) { 382 int32_t PPB_URLLoader_Impl::ValidateCallback(PP_CompletionCallback callback) {
382 // We only support non-blocking calls. 383 // We only support non-blocking calls.
383 if (!callback.func) 384 if (!callback.func)
384 return PP_ERROR_BLOCKS_MAIN_THREAD; 385 return PP_ERROR_BLOCKS_MAIN_THREAD;
385 386
386 if (pending_callback_.get() && !pending_callback_->completed()) 387 if (TrackedCallback::IsPending(pending_callback_))
387 return PP_ERROR_INPROGRESS; 388 return PP_ERROR_INPROGRESS;
388 389
389 return PP_OK; 390 return PP_OK;
390 } 391 }
391 392
392 void PPB_URLLoader_Impl::RegisterCallback(PP_CompletionCallback callback) { 393 void PPB_URLLoader_Impl::RegisterCallback(PP_CompletionCallback callback) {
393 DCHECK(callback.func); 394 DCHECK(callback.func);
394 DCHECK(!pending_callback_.get() || pending_callback_->completed()); 395 DCHECK(!TrackedCallback::IsPending(pending_callback_));
395 396
396 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); 397 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this);
397 if (!plugin_module) 398 if (!plugin_module)
398 return; 399 return;
399 400
400 pending_callback_ = new TrackedCompletionCallback( 401 pending_callback_ = new TrackedCallback(this, callback);
401 plugin_module->GetCallbackTracker(), pp_resource(), callback);
402 } 402 }
403 403
404 void PPB_URLLoader_Impl::RunCallback(int32_t result) { 404 void PPB_URLLoader_Impl::RunCallback(int32_t result) {
405 // This may be null only when this is a main document loader. 405 // This may be null only when this is a main document loader.
406 if (!pending_callback_.get()) { 406 if (!pending_callback_.get()) {
407 CHECK(main_document_loader_); 407 CHECK(main_document_loader_);
408 return; 408 return;
409 } 409 }
410 410 TrackedCallback::ClearAndRun(&pending_callback_, result);
411 scoped_refptr<TrackedCompletionCallback> callback;
412 callback.swap(pending_callback_);
413 callback->Run(result); // Will complete abortively if necessary.
414 } 411 }
415 412
416 size_t PPB_URLLoader_Impl::FillUserBuffer() { 413 size_t PPB_URLLoader_Impl::FillUserBuffer() {
417 DCHECK(user_buffer_); 414 DCHECK(user_buffer_);
418 DCHECK(user_buffer_size_); 415 DCHECK(user_buffer_size_);
419 416
420 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_);
421 std::copy(buffer_.begin(), buffer_.begin() + bytes_to_copy, user_buffer_); 418 std::copy(buffer_.begin(), buffer_.begin() + bytes_to_copy, user_buffer_);
422 buffer_.erase(buffer_.begin(), buffer_.begin() + bytes_to_copy); 419 buffer_.erase(buffer_.begin(), buffer_.begin() + bytes_to_copy);
423 420
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 bool PPB_URLLoader_Impl::RecordDownloadProgress() const { 459 bool PPB_URLLoader_Impl::RecordDownloadProgress() const {
463 return request_data_.record_download_progress; 460 return request_data_.record_download_progress;
464 } 461 }
465 462
466 bool PPB_URLLoader_Impl::RecordUploadProgress() const { 463 bool PPB_URLLoader_Impl::RecordUploadProgress() const {
467 return request_data_.record_upload_progress; 464 return request_data_.record_upload_progress;
468 } 465 }
469 466
470 } // namespace ppapi 467 } // namespace ppapi
471 } // namespace webkit 468 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_url_loader_impl.h ('k') | webkit/tools/test_shell/test_shell.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698