OLD | NEW |
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 status_callback_(NULL) { | 69 status_callback_(NULL) { |
70 } | 70 } |
71 | 71 |
72 PPB_URLLoader_Impl::~PPB_URLLoader_Impl() { | 72 PPB_URLLoader_Impl::~PPB_URLLoader_Impl() { |
73 } | 73 } |
74 | 74 |
75 PPB_URLLoader_API* PPB_URLLoader_Impl::AsPPB_URLLoader_API() { | 75 PPB_URLLoader_API* PPB_URLLoader_Impl::AsPPB_URLLoader_API() { |
76 return this; | 76 return this; |
77 } | 77 } |
78 | 78 |
79 void PPB_URLLoader_Impl::ClearInstance() { | 79 void PPB_URLLoader_Impl::InstanceWasDeleted() { |
80 Resource::ClearInstance(); | 80 Resource::InstanceWasDeleted(); |
81 loader_.reset(); | 81 loader_.reset(); |
82 } | 82 } |
83 | 83 |
84 int32_t PPB_URLLoader_Impl::Open(PP_Resource request_id, | 84 int32_t PPB_URLLoader_Impl::Open(PP_Resource request_id, |
85 PP_CompletionCallback callback) { | 85 PP_CompletionCallback callback) { |
86 EnterResourceNoLock<PPB_URLRequestInfo_API> enter_request(request_id, true); | 86 EnterResourceNoLock<PPB_URLRequestInfo_API> enter_request(request_id, true); |
87 if (enter_request.failed()) | 87 if (enter_request.failed()) |
88 return PP_ERROR_BADARGUMENT; | 88 return PP_ERROR_BADARGUMENT; |
89 PPB_URLRequestInfo_Impl* request = static_cast<PPB_URLRequestInfo_Impl*>( | 89 PPB_URLRequestInfo_Impl* request = static_cast<PPB_URLRequestInfo_Impl*>( |
90 enter_request.object()); | 90 enter_request.object()); |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 if (pending_callback_.get() && !pending_callback_->completed()) | 355 if (pending_callback_.get() && !pending_callback_->completed()) |
356 return PP_ERROR_INPROGRESS; | 356 return PP_ERROR_INPROGRESS; |
357 | 357 |
358 return PP_OK; | 358 return PP_OK; |
359 } | 359 } |
360 | 360 |
361 void PPB_URLLoader_Impl::RegisterCallback(PP_CompletionCallback callback) { | 361 void PPB_URLLoader_Impl::RegisterCallback(PP_CompletionCallback callback) { |
362 DCHECK(callback.func); | 362 DCHECK(callback.func); |
363 DCHECK(!pending_callback_.get() || pending_callback_->completed()); | 363 DCHECK(!pending_callback_.get() || pending_callback_->completed()); |
364 | 364 |
365 PP_Resource resource_id = GetReferenceNoAddRef(); | |
366 CHECK(resource_id); | |
367 pending_callback_ = new TrackedCompletionCallback( | 365 pending_callback_ = new TrackedCompletionCallback( |
368 instance()->module()->GetCallbackTracker(), resource_id, callback); | 366 instance()->module()->GetCallbackTracker(), pp_resource(), callback); |
369 } | 367 } |
370 | 368 |
371 void PPB_URLLoader_Impl::RunCallback(int32_t result) { | 369 void PPB_URLLoader_Impl::RunCallback(int32_t result) { |
372 // This may be null only when this is a main document loader. | 370 // This may be null only when this is a main document loader. |
373 if (!pending_callback_.get()) { | 371 if (!pending_callback_.get()) { |
374 CHECK(main_document_loader_); | 372 CHECK(main_document_loader_); |
375 return; | 373 return; |
376 } | 374 } |
377 | 375 |
378 scoped_refptr<TrackedCompletionCallback> callback; | 376 scoped_refptr<TrackedCompletionCallback> callback; |
(...skipping 28 matching lines...) Expand all Loading... |
407 void PPB_URLLoader_Impl::SaveResponse(const WebURLResponse& response) { | 405 void PPB_URLLoader_Impl::SaveResponse(const WebURLResponse& response) { |
408 scoped_refptr<PPB_URLResponseInfo_Impl> response_info( | 406 scoped_refptr<PPB_URLResponseInfo_Impl> response_info( |
409 new PPB_URLResponseInfo_Impl(instance())); | 407 new PPB_URLResponseInfo_Impl(instance())); |
410 if (response_info->Initialize(response)) | 408 if (response_info->Initialize(response)) |
411 response_info_ = response_info; | 409 response_info_ = response_info; |
412 } | 410 } |
413 | 411 |
414 void PPB_URLLoader_Impl::UpdateStatus() { | 412 void PPB_URLLoader_Impl::UpdateStatus() { |
415 if (status_callback_ && | 413 if (status_callback_ && |
416 (RecordDownloadProgress() || RecordUploadProgress())) { | 414 (RecordDownloadProgress() || RecordUploadProgress())) { |
417 PP_Resource pp_resource = GetReferenceNoAddRef(); | 415 // Here we go through some effort to only send the exact information that |
418 if (pp_resource) { | 416 // the requestor wanted in the request flags. It would be just as |
419 // The PP_Resource on the plugin will be NULL if the plugin has no | 417 // efficient to send all of it, but we don't want people to rely on |
420 // reference to this object. That's fine, because then we don't need to | 418 // getting download progress when they happen to set the upload progress |
421 // call UpdateStatus. | 419 // flag. |
422 // | 420 status_callback_( |
423 // Here we go through some effort to only send the exact information that | 421 instance()->pp_instance(), pp_resource(), |
424 // the requestor wanted in the request flags. It would be just as | 422 RecordUploadProgress() ? bytes_sent_ : -1, |
425 // efficient to send all of it, but we don't want people to rely on | 423 RecordUploadProgress() ? total_bytes_to_be_sent_ : -1, |
426 // getting download progress when they happen to set the upload progress | 424 RecordDownloadProgress() ? bytes_received_ : -1, |
427 // flag. | 425 RecordDownloadProgress() ? total_bytes_to_be_received_ : -1); |
428 status_callback_( | |
429 instance()->pp_instance(), pp_resource, | |
430 RecordUploadProgress() ? bytes_sent_ : -1, | |
431 RecordUploadProgress() ? total_bytes_to_be_sent_ : -1, | |
432 RecordDownloadProgress() ? bytes_received_ : -1, | |
433 RecordDownloadProgress() ? total_bytes_to_be_received_ : -1); | |
434 } | |
435 } | 426 } |
436 } | 427 } |
437 | 428 |
438 bool PPB_URLLoader_Impl::RecordDownloadProgress() const { | 429 bool PPB_URLLoader_Impl::RecordDownloadProgress() const { |
439 return request_info_ && request_info_->record_download_progress(); | 430 return request_info_ && request_info_->record_download_progress(); |
440 } | 431 } |
441 | 432 |
442 bool PPB_URLLoader_Impl::RecordUploadProgress() const { | 433 bool PPB_URLLoader_Impl::RecordUploadProgress() const { |
443 return request_info_ && request_info_->record_upload_progress(); | 434 return request_info_ && request_info_->record_upload_progress(); |
444 } | 435 } |
445 | 436 |
446 } // namespace ppapi | 437 } // namespace ppapi |
447 } // namespace webkit | 438 } // namespace webkit |
OLD | NEW |