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 // Make sure we track the buffer in at least one place. This ensures it gets | 600 net::IOBuffer* buf; |
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; | |
604 int buf_size; | 601 int buf_size; |
605 if (!handler_->OnWillRead(info->GetRequestID(), &buf, &buf_size, -1)) { | 602 if (!handler_->OnWillRead(info->GetRequestID(), &buf, &buf_size, -1)) { |
606 Cancel(); | 603 Cancel(); |
607 return; | 604 return; |
608 } | 605 } |
609 | 606 |
610 DCHECK(buf); | 607 DCHECK(buf); |
611 DCHECK(buf_size > 0); | 608 DCHECK(buf_size > 0); |
612 | 609 |
613 request_->Read(buf.get(), buf_size, bytes_read); | 610 // Make sure we track the buffer in at least one place. This ensures it gets |
| 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); |
614 | 616 |
615 // No need to check the return value here as we'll detect errors by | 617 // No need to check the return value here as we'll detect errors by |
616 // inspecting the URLRequest's status. | 618 // inspecting the URLRequest's status. |
617 } | 619 } |
618 | 620 |
619 void ResourceLoader::CompleteRead(int bytes_read) { | 621 void ResourceLoader::CompleteRead(int bytes_read) { |
620 DCHECK(bytes_read >= 0); | 622 DCHECK(bytes_read >= 0); |
621 DCHECK(request_->status().is_success()); | 623 DCHECK(request_->status().is_success()); |
622 | 624 |
623 ResourceRequestInfoImpl* info = GetRequestInfo(); | 625 ResourceRequestInfoImpl* info = GetRequestInfo(); |
(...skipping 29 matching lines...) Expand all Loading... |
653 // we resume. | 655 // we resume. |
654 deferred_stage_ = DEFERRED_FINISH; | 656 deferred_stage_ = DEFERRED_FINISH; |
655 } | 657 } |
656 } | 658 } |
657 | 659 |
658 void ResourceLoader::CallDidFinishLoading() { | 660 void ResourceLoader::CallDidFinishLoading() { |
659 delegate_->DidFinishLoading(this); | 661 delegate_->DidFinishLoading(this); |
660 } | 662 } |
661 | 663 |
662 } // namespace content | 664 } // namespace content |
OLD | NEW |