OLD | NEW |
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 "content/browser/loader/resource_loader.h" | 5 #include "content/browser/loader/resource_loader.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 StartReading(false); // Read the next chunk (OK to complete synchronously). | 590 StartReading(false); // Read the next chunk (OK to complete synchronously). |
591 } else { | 591 } else { |
592 ResponseCompleted(); | 592 ResponseCompleted(); |
593 } | 593 } |
594 } | 594 } |
595 | 595 |
596 void ResourceLoader::ReadMore(int* bytes_read) { | 596 void ResourceLoader::ReadMore(int* bytes_read) { |
597 ResourceRequestInfoImpl* info = GetRequestInfo(); | 597 ResourceRequestInfoImpl* info = GetRequestInfo(); |
598 DCHECK(!is_deferred()); | 598 DCHECK(!is_deferred()); |
599 | 599 |
600 net::IOBuffer* buf; | 600 // Make sure we track the buffer in at least one place. This ensures it gets |
| 601 // deleted even in the case the request has already finished its job and |
| 602 // doesn't use the buffer. |
| 603 scoped_refptr<net::IOBuffer> buf; |
601 int buf_size; | 604 int buf_size; |
602 if (!handler_->OnWillRead(info->GetRequestID(), &buf, &buf_size, -1)) { | 605 if (!handler_->OnWillRead(info->GetRequestID(), &buf, &buf_size, -1)) { |
603 Cancel(); | 606 Cancel(); |
604 return; | 607 return; |
605 } | 608 } |
606 | 609 |
607 DCHECK(buf); | 610 DCHECK(buf); |
608 DCHECK(buf_size > 0); | 611 DCHECK(buf_size > 0); |
609 | 612 |
610 // Make sure we track the buffer in at least one place. This ensures it gets | 613 request_->Read(buf.get(), buf_size, bytes_read); |
611 // deleted even in the case the request has already finished its job and | |
612 // doesn't use the buffer. | |
613 scoped_refptr<net::IOBuffer> tracked_buf(buf); | |
614 | |
615 request_->Read(tracked_buf.get(), buf_size, bytes_read); | |
616 | 614 |
617 // No need to check the return value here as we'll detect errors by | 615 // No need to check the return value here as we'll detect errors by |
618 // inspecting the URLRequest's status. | 616 // inspecting the URLRequest's status. |
619 } | 617 } |
620 | 618 |
621 void ResourceLoader::CompleteRead(int bytes_read) { | 619 void ResourceLoader::CompleteRead(int bytes_read) { |
622 DCHECK(bytes_read >= 0); | 620 DCHECK(bytes_read >= 0); |
623 DCHECK(request_->status().is_success()); | 621 DCHECK(request_->status().is_success()); |
624 | 622 |
625 ResourceRequestInfoImpl* info = GetRequestInfo(); | 623 ResourceRequestInfoImpl* info = GetRequestInfo(); |
(...skipping 29 matching lines...) Expand all Loading... |
655 // we resume. | 653 // we resume. |
656 deferred_stage_ = DEFERRED_FINISH; | 654 deferred_stage_ = DEFERRED_FINISH; |
657 } | 655 } |
658 } | 656 } |
659 | 657 |
660 void ResourceLoader::CallDidFinishLoading() { | 658 void ResourceLoader::CallDidFinishLoading() { |
661 delegate_->DidFinishLoading(this); | 659 delegate_->DidFinishLoading(this); |
662 } | 660 } |
663 | 661 |
664 } // namespace content | 662 } // namespace content |
OLD | NEW |