Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Side by Side Diff: chrome/browser/download/download_item.cc

Issue 7192016: chrome.experimental.downloads (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: DownloadQuery, single DownloadMap Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/download/download_item.h ('k') | chrome/browser/download/download_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/download/download_item.h" 5 #include "chrome/browser/download/download_item.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/i18n/case_conversion.h" 10 #include "base/i18n/case_conversion.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } 113 }
114 return dangerous_file ? 114 return dangerous_file ?
115 DownloadItem::DANGEROUS_FILE : DownloadItem::NOT_DANGEROUS; 115 DownloadItem::DANGEROUS_FILE : DownloadItem::NOT_DANGEROUS;
116 } 116 }
117 117
118 } // namespace 118 } // namespace
119 119
120 // Constructor for reading from the history service. 120 // Constructor for reading from the history service.
121 DownloadItem::DownloadItem(DownloadManager* download_manager, 121 DownloadItem::DownloadItem(DownloadManager* download_manager,
122 const DownloadHistoryInfo& info) 122 const DownloadHistoryInfo& info)
123 : download_id_(-1), 123 : download_id_(info.db_handle),
124 full_path_(info.path), 124 full_path_(info.path),
125 url_chain_(1, info.url), 125 url_chain_(1, info.url),
126 referrer_url_(info.referrer_url), 126 referrer_url_(info.referrer_url),
127 total_bytes_(info.total_bytes), 127 total_bytes_(info.total_bytes),
128 received_bytes_(info.received_bytes), 128 received_bytes_(info.received_bytes),
129 start_tick_(base::TimeTicks()), 129 start_tick_(base::TimeTicks()),
130 state_(static_cast<DownloadState>(info.state)), 130 state_(static_cast<DownloadState>(info.state)),
131 start_time_(info.start_time), 131 start_time_(info.start_time),
132 db_handle_(info.db_handle),
133 download_manager_(download_manager), 132 download_manager_(download_manager),
134 is_paused_(false), 133 is_paused_(false),
135 open_when_complete_(false), 134 open_when_complete_(false),
136 file_externally_removed_(false), 135 file_externally_removed_(false),
137 safety_state_(SAFE), 136 safety_state_(SAFE),
138 auto_opened_(false), 137 auto_opened_(false),
139 is_otr_(false), 138 is_otr_(false),
140 is_temporary_(false), 139 is_temporary_(false),
141 all_data_saved_(false), 140 all_data_saved_(false),
142 opened_(false), 141 opened_(false),
(...skipping 21 matching lines...) Expand all
164 content_disposition_(info.content_disposition), 163 content_disposition_(info.content_disposition),
165 mime_type_(info.mime_type), 164 mime_type_(info.mime_type),
166 original_mime_type_(info.original_mime_type), 165 original_mime_type_(info.original_mime_type),
167 referrer_charset_(info.referrer_charset), 166 referrer_charset_(info.referrer_charset),
168 total_bytes_(info.total_bytes), 167 total_bytes_(info.total_bytes),
169 received_bytes_(0), 168 received_bytes_(0),
170 last_os_error_(0), 169 last_os_error_(0),
171 start_tick_(base::TimeTicks::Now()), 170 start_tick_(base::TimeTicks::Now()),
172 state_(IN_PROGRESS), 171 state_(IN_PROGRESS),
173 start_time_(info.start_time), 172 start_time_(info.start_time),
174 db_handle_(DownloadHistory::kUninitializedHandle),
175 download_manager_(download_manager), 173 download_manager_(download_manager),
176 is_paused_(false), 174 is_paused_(false),
177 open_when_complete_(false), 175 open_when_complete_(false),
178 file_externally_removed_(false), 176 file_externally_removed_(false),
179 safety_state_(SAFE), 177 safety_state_(SAFE),
180 auto_opened_(false), 178 auto_opened_(false),
181 is_otr_(is_otr), 179 is_otr_(is_otr),
182 is_temporary_(!info.save_info.file_path.empty()), 180 is_temporary_(!info.save_info.file_path.empty()),
183 all_data_saved_(false), 181 all_data_saved_(false),
184 opened_(false), 182 opened_(false),
185 open_enabled_(true) { 183 open_enabled_(true) {
186 Init(true /* actively downloading */); 184 Init(true /* actively downloading */);
187 } 185 }
188 186
189 // Constructing for the "Save Page As..." feature: 187 // Constructing for the "Save Page As..." feature:
190 DownloadItem::DownloadItem(DownloadManager* download_manager, 188 DownloadItem::DownloadItem(DownloadManager* download_manager,
191 const FilePath& path, 189 const FilePath& path,
192 const GURL& url, 190 const GURL& url,
193 bool is_otr) 191 bool is_otr)
194 : download_id_(1), 192 : download_id_(-1),
195 full_path_(path), 193 full_path_(path),
196 url_chain_(1, url), 194 url_chain_(1, url),
197 referrer_url_(GURL()), 195 referrer_url_(GURL()),
198 total_bytes_(0), 196 total_bytes_(0),
199 received_bytes_(0), 197 received_bytes_(0),
200 last_os_error_(0), 198 last_os_error_(0),
201 start_tick_(base::TimeTicks::Now()), 199 start_tick_(base::TimeTicks::Now()),
202 state_(IN_PROGRESS), 200 state_(IN_PROGRESS),
203 start_time_(base::Time::Now()), 201 start_time_(base::Time::Now()),
204 db_handle_(DownloadHistory::kUninitializedHandle),
205 download_manager_(download_manager), 202 download_manager_(download_manager),
206 is_paused_(false), 203 is_paused_(false),
207 open_when_complete_(false), 204 open_when_complete_(false),
208 file_externally_removed_(false), 205 file_externally_removed_(false),
209 safety_state_(SAFE), 206 safety_state_(SAFE),
210 auto_opened_(false), 207 auto_opened_(false),
211 is_otr_(is_otr), 208 is_otr_(is_otr),
212 is_temporary_(false), 209 is_temporary_(false),
213 all_data_saved_(false), 210 all_data_saved_(false),
214 opened_(false), 211 opened_(false),
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 529
533 void DownloadItem::Remove() { 530 void DownloadItem::Remove() {
534 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 531 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
535 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 532 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
536 533
537 download_manager_->AssertQueueStateConsistent(this); 534 download_manager_->AssertQueueStateConsistent(this);
538 Cancel(true); 535 Cancel(true);
539 download_manager_->AssertQueueStateConsistent(this); 536 download_manager_->AssertQueueStateConsistent(this);
540 537
541 state_ = REMOVING; 538 state_ = REMOVING;
542 download_manager_->RemoveDownload(db_handle_); 539 download_manager_->RemoveDownload(id());
543 // We have now been deleted. 540 // We have now been deleted.
544 } 541 }
545 542
546 bool DownloadItem::TimeRemaining(base::TimeDelta* remaining) const { 543 bool DownloadItem::TimeRemaining(base::TimeDelta* remaining) const {
547 if (total_bytes_ <= 0) 544 if (total_bytes_ <= 0)
548 return false; // We never received the content_length for this download. 545 return false; // We never received the content_length for this download.
549 546
550 int64 speed = CurrentSpeed(); 547 int64 speed = CurrentSpeed();
551 if (speed == 0) 548 if (speed == 0)
552 return false; 549 return false;
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 } 721 }
725 722
726 DownloadHistoryInfo DownloadItem::GetHistoryInfo() const { 723 DownloadHistoryInfo DownloadItem::GetHistoryInfo() const {
727 return DownloadHistoryInfo(full_path(), 724 return DownloadHistoryInfo(full_path(),
728 GetURL(), 725 GetURL(),
729 referrer_url(), 726 referrer_url(),
730 start_time(), 727 start_time(),
731 received_bytes(), 728 received_bytes(),
732 total_bytes(), 729 total_bytes(),
733 state(), 730 state(),
734 db_handle()); 731 id());
735 } 732 }
736 733
737 FilePath DownloadItem::GetTargetFilePath() const { 734 FilePath DownloadItem::GetTargetFilePath() const {
738 return full_path_.DirName().Append(state_info_.target_name); 735 return full_path_.DirName().Append(state_info_.target_name);
739 } 736 }
740 737
741 FilePath DownloadItem::GetFileNameToReportUser() const { 738 FilePath DownloadItem::GetFileNameToReportUser() const {
742 if (state_info_.path_uniquifier > 0) { 739 if (state_info_.path_uniquifier > 0) {
743 FilePath name(state_info_.target_name); 740 FilePath name(state_info_.target_name);
744 download_util::AppendNumberToPath(&name, state_info_.path_uniquifier); 741 download_util::AppendNumberToPath(&name, state_info_.path_uniquifier);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 ++iter; 805 ++iter;
809 for ( ; verbose && (iter != last); ++iter) { 806 for ( ; verbose && (iter != last); ++iter) {
810 url_list += " ->\n\t"; 807 url_list += " ->\n\t";
811 const GURL& next_url = *iter; 808 const GURL& next_url = *iter;
812 url_list += next_url.spec(); 809 url_list += next_url.spec();
813 } 810 }
814 } 811 }
815 812
816 if (verbose) { 813 if (verbose) {
817 description += base::StringPrintf( 814 description += base::StringPrintf(
818 " db_handle = %" PRId64 815 " id = %" PRId32
819 " total_bytes = %" PRId64 816 " total_bytes = %" PRId64
820 " received_bytes = %" PRId64 817 " received_bytes = %" PRId64
821 " is_paused = %c" 818 " is_paused = %c"
822 " is_extension_install = %c" 819 " is_extension_install = %c"
823 " is_otr = %c" 820 " is_otr = %c"
824 " safety_state = %s" 821 " safety_state = %s"
825 " url_chain = \n\t\"%s\"\n\t" 822 " url_chain = \n\t\"%s\"\n\t"
826 " target_name = \"%" PRFilePath "\"" 823 " target_name = \"%" PRFilePath "\""
827 " full_path = \"%" PRFilePath "\"", 824 " full_path = \"%" PRFilePath "\"",
828 db_handle(), 825 id(),
829 total_bytes(), 826 total_bytes(),
830 received_bytes(), 827 received_bytes(),
831 is_paused() ? 'T' : 'F', 828 is_paused() ? 'T' : 'F',
832 is_extension_install() ? 'T' : 'F', 829 is_extension_install() ? 'T' : 'F',
833 is_otr() ? 'T' : 'F', 830 is_otr() ? 'T' : 'F',
834 DebugSafetyStateString(safety_state()), 831 DebugSafetyStateString(safety_state()),
835 url_list.c_str(), 832 url_list.c_str(),
836 state_info_.target_name.value().c_str(), 833 state_info_.target_name.value().c_str(),
837 full_path().value().c_str()); 834 full_path().value().c_str());
838 } else { 835 } else {
839 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); 836 description += base::StringPrintf(" url = \"%s\"", url_list.c_str());
840 } 837 }
841 838
842 description += " }"; 839 description += " }";
843 840
844 return description; 841 return description;
845 } 842 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_item.h ('k') | chrome/browser/download/download_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698