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 // File method ordering: Methods in this file are in the same order as | 5 // File method ordering: Methods in this file are in the same order as |
6 // in download_item_impl.h, with the following exception: The public | 6 // in download_item_impl.h, with the following exception: The public |
7 // interface Start is placed in chronological order with the other | 7 // interface Start is placed in chronological order with the other |
8 // (private) routines that together define a DownloadItem's state | 8 // (private) routines that together define a DownloadItem's state |
9 // transitions as the download progresses. See "Download progression | 9 // transitions as the download progresses. See "Download progression |
10 // cascade" later in this file. | 10 // cascade" later in this file. |
(...skipping 909 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
920 } | 920 } |
921 | 921 |
922 const net::BoundNetLog& DownloadItemImpl::GetBoundNetLog() const { | 922 const net::BoundNetLog& DownloadItemImpl::GetBoundNetLog() const { |
923 return bound_net_log_; | 923 return bound_net_log_; |
924 } | 924 } |
925 | 925 |
926 void DownloadItemImpl::SetTotalBytes(int64 total_bytes) { | 926 void DownloadItemImpl::SetTotalBytes(int64 total_bytes) { |
927 total_bytes_ = total_bytes; | 927 total_bytes_ = total_bytes; |
928 } | 928 } |
929 | 929 |
930 // Updates from the download thread may have been posted while this download | |
931 // was being cancelled in the UI thread, so we'll accept them unless we're | |
932 // complete. | |
933 void DownloadItemImpl::UpdateProgress(int64 bytes_so_far, | |
934 int64 bytes_per_sec, | |
935 const std::string& hash_state) { | |
936 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
937 VLOG(20) << __FUNCTION__ << " so_far=" << bytes_so_far | |
938 << " per_sec=" << bytes_per_sec << " download=" << DebugString(true); | |
939 | |
940 if (state_ != IN_PROGRESS_INTERNAL) { | |
941 // Ignore if we're no longer in-progress. This can happen if we race a | |
942 // Cancel on the UI thread with an update on the FILE thread. | |
943 // | |
944 // TODO(rdsmith): Arguably we should let this go through, as this means | |
945 // the download really did get further than we know before it was | |
946 // cancelled. But the gain isn't very large, and the code is more | |
947 // fragile if it has to support in progress updates in a non-in-progress | |
948 // state. This issue should be readdressed when we revamp performance | |
949 // reporting. | |
950 return; | |
951 } | |
952 bytes_per_sec_ = bytes_per_sec; | |
953 hash_state_ = hash_state; | |
954 received_bytes_ = bytes_so_far; | |
955 | |
956 // If we've received more data than we were expecting (bad server info?), | |
957 // revert to 'unknown size mode'. | |
958 if (received_bytes_ > total_bytes_) | |
959 total_bytes_ = 0; | |
960 | |
961 if (bound_net_log_.IsLoggingAllEvents()) { | |
962 bound_net_log_.AddEvent( | |
963 net::NetLog::TYPE_DOWNLOAD_ITEM_UPDATED, | |
964 net::NetLog::Int64Callback("bytes_so_far", received_bytes_)); | |
965 } | |
966 | |
967 UpdateObservers(); | |
968 } | |
969 | |
970 void DownloadItemImpl::OnAllDataSaved(const std::string& final_hash) { | 930 void DownloadItemImpl::OnAllDataSaved(const std::string& final_hash) { |
971 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 931 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
972 | 932 |
973 DCHECK_EQ(IN_PROGRESS_INTERNAL, state_); | 933 DCHECK_EQ(IN_PROGRESS_INTERNAL, state_); |
974 DCHECK(!all_data_saved_); | 934 DCHECK(!all_data_saved_); |
975 all_data_saved_ = true; | 935 all_data_saved_ = true; |
976 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true); | 936 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true); |
977 | 937 |
978 // Store final hash and null out intermediate serialized hash state. | 938 // Store final hash and null out intermediate serialized hash state. |
979 hash_ = final_hash; | 939 hash_ = final_hash; |
980 hash_state_ = ""; | 940 hash_state_ = ""; |
981 | 941 |
982 UpdateObservers(); | 942 UpdateObservers(); |
983 } | 943 } |
984 | 944 |
985 void DownloadItemImpl::MarkAsComplete() { | 945 void DownloadItemImpl::MarkAsComplete() { |
986 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 946 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
987 | 947 |
988 DCHECK(all_data_saved_); | 948 DCHECK(all_data_saved_); |
989 end_time_ = base::Time::Now(); | 949 end_time_ = base::Time::Now(); |
990 TransitionTo(COMPLETE_INTERNAL); | 950 TransitionTo(COMPLETE_INTERNAL); |
991 } | 951 } |
992 void DownloadItemImpl::DestinationUpdate(int64 bytes_so_far, | 952 void DownloadItemImpl::DestinationUpdate(int64 bytes_so_far, |
993 int64 bytes_per_sec, | 953 int64 bytes_per_sec, |
994 const std::string& hash_state) { | 954 const std::string& hash_state) { |
995 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 955 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
996 VLOG(20) << __FUNCTION__ << " download=" << DebugString(true); | 956 VLOG(20) << __FUNCTION__ << " so_far=" << bytes_so_far |
| 957 << " per_sec=" << bytes_per_sec << " download=" << DebugString(true); |
997 | 958 |
998 if (!IsInProgress()) { | 959 if (!IsInProgress()) { |
999 // Ignore if we're no longer in-progress. This can happen if we race a | 960 // Ignore if we're no longer in-progress. This can happen if we race a |
1000 // Cancel on the UI thread with an update on the FILE thread. | 961 // Cancel on the UI thread with an update on the FILE thread. |
1001 // | 962 // |
1002 // TODO(rdsmith): Arguably we should let this go through, as this means | 963 // TODO(rdsmith): Arguably we should let this go through, as this means |
1003 // the download really did get further than we know before it was | 964 // the download really did get further than we know before it was |
1004 // cancelled. But the gain isn't very large, and the code is more | 965 // cancelled. But the gain isn't very large, and the code is more |
1005 // fragile if it has to support in progress updates in a non-in-progress | 966 // fragile if it has to support in progress updates in a non-in-progress |
1006 // state. This issue should be readdressed when we revamp performance | 967 // state. This issue should be readdressed when we revamp performance |
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1658 case RESUME_MODE_USER_CONTINUE: | 1619 case RESUME_MODE_USER_CONTINUE: |
1659 return "USER_CONTINUE"; | 1620 return "USER_CONTINUE"; |
1660 case RESUME_MODE_USER_RESTART: | 1621 case RESUME_MODE_USER_RESTART: |
1661 return "USER_RESTART"; | 1622 return "USER_RESTART"; |
1662 } | 1623 } |
1663 NOTREACHED() << "Unknown resume mode " << mode; | 1624 NOTREACHED() << "Unknown resume mode " << mode; |
1664 return "unknown"; | 1625 return "unknown"; |
1665 } | 1626 } |
1666 | 1627 |
1667 } // namespace content | 1628 } // namespace content |
OLD | NEW |