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/download/save_item.h" | 5 #include "content/browser/download/save_item.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "content/browser/download/save_file.h" | 9 #include "content/browser/download/save_file.h" |
10 #include "content/browser/download/save_file_manager.h" | 10 #include "content/browser/download/save_file_manager.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 } | 45 } |
46 | 46 |
47 // Set start state for save item. | 47 // Set start state for save item. |
48 void SaveItem::Start() { | 48 void SaveItem::Start() { |
49 DCHECK(state_ == WAIT_START); | 49 DCHECK(state_ == WAIT_START); |
50 state_ = IN_PROGRESS; | 50 state_ = IN_PROGRESS; |
51 } | 51 } |
52 | 52 |
53 // If we've received more data than we were expecting (bad server info?), | 53 // If we've received more data than we were expecting (bad server info?), |
54 // revert to 'unknown size mode'. | 54 // revert to 'unknown size mode'. |
55 void SaveItem::UpdateSize(int64 bytes_so_far) { | 55 void SaveItem::UpdateSize(int64_t bytes_so_far) { |
56 received_bytes_ = bytes_so_far; | 56 received_bytes_ = bytes_so_far; |
57 if (received_bytes_ >= total_bytes_) | 57 if (received_bytes_ >= total_bytes_) |
58 total_bytes_ = 0; | 58 total_bytes_ = 0; |
59 } | 59 } |
60 | 60 |
61 // Updates from the file thread may have been posted while this saving job | 61 // Updates from the file thread may have been posted while this saving job |
62 // was being canceled in the UI thread, so we'll accept them unless we're | 62 // was being canceled in the UI thread, so we'll accept them unless we're |
63 // complete. | 63 // complete. |
64 void SaveItem::Update(int64 bytes_so_far) { | 64 void SaveItem::Update(int64_t bytes_so_far) { |
65 if (state_ != IN_PROGRESS) { | 65 if (state_ != IN_PROGRESS) { |
66 NOTREACHED(); | 66 NOTREACHED(); |
67 return; | 67 return; |
68 } | 68 } |
69 UpdateSize(bytes_so_far); | 69 UpdateSize(bytes_so_far); |
70 } | 70 } |
71 | 71 |
72 // Cancel this saving item job. If the job is not in progress, ignore | 72 // Cancel this saving item job. If the job is not in progress, ignore |
73 // this command. The SavePackage will each in-progress SaveItem's cancel | 73 // this command. The SavePackage will each in-progress SaveItem's cancel |
74 // when canceling whole saving page job. | 74 // when canceling whole saving page job. |
75 void SaveItem::Cancel() { | 75 void SaveItem::Cancel() { |
76 // If item is in WAIT_START mode, which means no request has been sent. | 76 // If item is in WAIT_START mode, which means no request has been sent. |
77 // So we need not to cancel it. | 77 // So we need not to cancel it. |
78 if (state_ != IN_PROGRESS) { | 78 if (state_ != IN_PROGRESS) { |
79 // Small downloads might be complete before method has a chance to run. | 79 // Small downloads might be complete before method has a chance to run. |
80 return; | 80 return; |
81 } | 81 } |
82 state_ = CANCELED; | 82 state_ = CANCELED; |
83 is_success_ = false; | 83 is_success_ = false; |
84 Finish(received_bytes_, false); | 84 Finish(received_bytes_, false); |
85 package_->SaveCanceled(this); | 85 package_->SaveCanceled(this); |
86 } | 86 } |
87 | 87 |
88 // Set finish state for a save item | 88 // Set finish state for a save item |
89 void SaveItem::Finish(int64 size, bool is_success) { | 89 void SaveItem::Finish(int64_t size, bool is_success) { |
90 DCHECK(has_final_name() || !is_success_); | 90 DCHECK(has_final_name() || !is_success_); |
91 state_ = COMPLETE; | 91 state_ = COMPLETE; |
92 is_success_ = is_success; | 92 is_success_ = is_success; |
93 UpdateSize(size); | 93 UpdateSize(size); |
94 } | 94 } |
95 | 95 |
96 // Calculate the percentage of the save item | 96 // Calculate the percentage of the save item |
97 int SaveItem::PercentComplete() const { | 97 int SaveItem::PercentComplete() const { |
98 switch (state_) { | 98 switch (state_) { |
99 case COMPLETE: | 99 case COMPLETE: |
(...skipping 15 matching lines...) Expand all Loading... |
115 } | 115 } |
116 | 116 |
117 // Rename the save item with new path. | 117 // Rename the save item with new path. |
118 void SaveItem::Rename(const base::FilePath& full_path) { | 118 void SaveItem::Rename(const base::FilePath& full_path) { |
119 DCHECK(!full_path.empty() && !has_final_name()); | 119 DCHECK(!full_path.empty() && !has_final_name()); |
120 full_path_ = full_path; | 120 full_path_ = full_path; |
121 file_name_ = full_path_.BaseName(); | 121 file_name_ = full_path_.BaseName(); |
122 has_final_name_ = true; | 122 has_final_name_ = true; |
123 } | 123 } |
124 | 124 |
125 void SaveItem::SetTotalBytes(int64 total_bytes) { | 125 void SaveItem::SetTotalBytes(int64_t total_bytes) { |
126 DCHECK_EQ(0, total_bytes_); | 126 DCHECK_EQ(0, total_bytes_); |
127 total_bytes_ = total_bytes; | 127 total_bytes_ = total_bytes; |
128 } | 128 } |
129 | 129 |
130 } // namespace content | 130 } // namespace content |
OLD | NEW |