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 28 matching lines...) Expand all Loading... |
39 is_success_(false), | 39 is_success_(false), |
40 save_source_(save_source), | 40 save_source_(save_source), |
41 package_(package) { | 41 package_(package) { |
42 DCHECK(package); | 42 DCHECK(package); |
43 } | 43 } |
44 | 44 |
45 SaveItem::~SaveItem() {} | 45 SaveItem::~SaveItem() {} |
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_EQ(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_t 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 } |
(...skipping 26 matching lines...) Expand all Loading... |
86 | 86 |
87 // Set finish state for a save item | 87 // Set finish state for a save item |
88 void SaveItem::Finish(int64_t size, bool is_success) { | 88 void SaveItem::Finish(int64_t size, bool is_success) { |
89 DCHECK(has_final_name() || !is_success_); | 89 DCHECK(has_final_name() || !is_success_); |
90 state_ = COMPLETE; | 90 state_ = COMPLETE; |
91 is_success_ = is_success; | 91 is_success_ = is_success; |
92 UpdateSize(size); | 92 UpdateSize(size); |
93 } | 93 } |
94 | 94 |
95 void SaveItem::SetTargetPath(const base::FilePath& full_path) { | 95 void SaveItem::SetTargetPath(const base::FilePath& full_path) { |
96 DCHECK(!full_path.empty() && !has_final_name()); | 96 DCHECK(!full_path.empty()); |
| 97 DCHECK(!has_final_name()); |
97 full_path_ = full_path; | 98 full_path_ = full_path; |
98 } | 99 } |
99 | 100 |
100 void SaveItem::SetTotalBytes(int64_t total_bytes) { | 101 void SaveItem::SetTotalBytes(int64_t total_bytes) { |
101 DCHECK_EQ(0, total_bytes_); | 102 DCHECK_EQ(0, total_bytes_); |
102 total_bytes_ = total_bytes; | 103 total_bytes_ = total_bytes; |
103 } | 104 } |
104 | 105 |
105 } // namespace content | 106 } // namespace content |
OLD | NEW |