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

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

Issue 7793003: Revert 98656 - Make a new integer field in sql::MetaTable (a per-profile db) containing a counter... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 3 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 | « content/browser/download/download_item.h ('k') | content/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 "content/browser/download/download_item.h" 5 #include "content/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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
14 #include "base/timer.h" 14 #include "base/timer.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "net/base/net_util.h" 16 #include "net/base/net_util.h"
17 #include "content/browser/browser_thread.h" 17 #include "content/browser/browser_thread.h"
18 #include "content/browser/content_browser_client.h" 18 #include "content/browser/content_browser_client.h"
19 #include "content/browser/download/download_file.h" 19 #include "content/browser/download/download_file.h"
20 #include "content/browser/download/download_create_info.h" 20 #include "content/browser/download/download_create_info.h"
21 #include "content/browser/download/download_file_manager.h" 21 #include "content/browser/download/download_file_manager.h"
22 #include "content/browser/download/download_id.h"
23 #include "content/browser/download/download_manager.h" 22 #include "content/browser/download/download_manager.h"
24 #include "content/browser/download/download_manager_delegate.h" 23 #include "content/browser/download/download_manager_delegate.h"
25 #include "content/browser/download/download_persistent_store_info.h" 24 #include "content/browser/download/download_persistent_store_info.h"
26 #include "content/browser/download/download_request_handle.h" 25 #include "content/browser/download/download_request_handle.h"
27 #include "content/browser/download/download_stats.h" 26 #include "content/browser/download/download_stats.h"
28 27
29 // A DownloadItem normally goes through the following states: 28 // A DownloadItem normally goes through the following states:
30 // * Created (when download starts) 29 // * Created (when download starts)
31 // * Made visible to consumers (e.g. Javascript) after the 30 // * Made visible to consumers (e.g. Javascript) after the
32 // destination file has been determined. 31 // destination file has been determined.
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 opened_(false), 183 opened_(false),
185 open_enabled_(true) { 184 open_enabled_(true) {
186 Init(true /* actively downloading */); 185 Init(true /* actively downloading */);
187 } 186 }
188 187
189 // Constructing for the "Save Page As..." feature: 188 // Constructing for the "Save Page As..." feature:
190 DownloadItem::DownloadItem(DownloadManager* download_manager, 189 DownloadItem::DownloadItem(DownloadManager* download_manager,
191 const FilePath& path, 190 const FilePath& path,
192 const GURL& url, 191 const GURL& url,
193 bool is_otr, 192 bool is_otr,
194 DownloadId download_id) 193 int download_id)
195 : download_id_(download_id.local()), 194 : download_id_(download_id),
196 full_path_(path), 195 full_path_(path),
197 url_chain_(1, url), 196 url_chain_(1, url),
198 referrer_url_(GURL()), 197 referrer_url_(GURL()),
199 total_bytes_(0), 198 total_bytes_(0),
200 received_bytes_(0), 199 received_bytes_(0),
201 last_os_error_(0), 200 last_os_error_(0),
202 start_tick_(base::TimeTicks::Now()), 201 start_tick_(base::TimeTicks::Now()),
203 state_(IN_PROGRESS), 202 state_(IN_PROGRESS),
204 start_time_(base::Time::Now()), 203 start_time_(base::Time::Now()),
205 db_handle_(DownloadItem::kUninitializedHandle), 204 db_handle_(DownloadItem::kUninitializedHandle),
(...skipping 12 matching lines...) Expand all
218 } 217 }
219 218
220 DownloadItem::~DownloadItem() { 219 DownloadItem::~DownloadItem() {
221 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 220 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
222 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 221 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
223 222
224 TransitionTo(REMOVING); 223 TransitionTo(REMOVING);
225 download_manager_->AssertQueueStateConsistent(this); 224 download_manager_->AssertQueueStateConsistent(this);
226 } 225 }
227 226
228 DownloadId DownloadItem::global_id() const {
229 return DownloadId(download_manager_, id());
230 }
231
232 void DownloadItem::AddObserver(Observer* observer) { 227 void DownloadItem::AddObserver(Observer* observer) {
233 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 228 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
234 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 229 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
235 230
236 observers_.AddObserver(observer); 231 observers_.AddObserver(observer);
237 } 232 }
238 233
239 void DownloadItem::RemoveObserver(Observer* observer) { 234 void DownloadItem::RemoveObserver(Observer* observer) {
240 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 235 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
241 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 236 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 568
574 VLOG(20) << __FUNCTION__ << "()" 569 VLOG(20) << __FUNCTION__ << "()"
575 << " needs rename = " << NeedsRename() 570 << " needs rename = " << NeedsRename()
576 << " " << DebugString(true); 571 << " " << DebugString(true);
577 DCHECK_NE(DANGEROUS, safety_state()); 572 DCHECK_NE(DANGEROUS, safety_state());
578 DCHECK(file_manager); 573 DCHECK(file_manager);
579 574
580 if (NeedsRename()) { 575 if (NeedsRename()) {
581 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 576 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
582 NewRunnableMethod(file_manager, 577 NewRunnableMethod(file_manager,
583 &DownloadFileManager::RenameCompletingDownloadFile, global_id(), 578 &DownloadFileManager::RenameCompletingDownloadFile, id(),
584 GetTargetFilePath(), safety_state() == SAFE)); 579 GetTargetFilePath(), safety_state() == SAFE));
585 return; 580 return;
586 } 581 }
587 582
588 Completed(); 583 Completed();
589 584
590 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, NewRunnableMethod( 585 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
591 file_manager, &DownloadFileManager::CompleteDownload, global_id())); 586 NewRunnableMethod(file_manager, &DownloadFileManager::CompleteDownload,
587 id()));
592 } 588 }
593 589
594 void DownloadItem::OnDownloadRenamedToFinalName(const FilePath& full_path) { 590 void DownloadItem::OnDownloadRenamedToFinalName(const FilePath& full_path) {
595 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 591 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
596 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 592 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
597 593
598 VLOG(20) << __FUNCTION__ << "()" 594 VLOG(20) << __FUNCTION__ << "()"
599 << " full_path = \"" << full_path.value() << "\"" 595 << " full_path = \"" << full_path.value() << "\""
600 << " needed rename = " << NeedsRename() 596 << " needed rename = " << NeedsRename()
601 << " " << DebugString(false); 597 << " " << DebugString(false);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 GetTargetFilePath() : full_path_; 703 GetTargetFilePath() : full_path_;
708 } 704 }
709 705
710 void DownloadItem::OffThreadCancel(DownloadFileManager* file_manager) { 706 void DownloadItem::OffThreadCancel(DownloadFileManager* file_manager) {
711 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 707 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
712 request_handle_.CancelRequest(); 708 request_handle_.CancelRequest();
713 709
714 BrowserThread::PostTask( 710 BrowserThread::PostTask(
715 BrowserThread::FILE, FROM_HERE, 711 BrowserThread::FILE, FROM_HERE,
716 NewRunnableMethod( 712 NewRunnableMethod(
717 file_manager, &DownloadFileManager::CancelDownload, global_id())); 713 file_manager, &DownloadFileManager::CancelDownload, download_id_));
718 } 714 }
719 715
720 void DownloadItem::Init(bool active) { 716 void DownloadItem::Init(bool active) {
721 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 717 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
722 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 718 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
723 719
724 UpdateTarget(); 720 UpdateTarget();
725 if (active) { 721 if (active) {
726 StartProgressTimer(); 722 StartProgressTimer();
727 download_stats::RecordDownloadCount(download_stats::START_COUNT); 723 download_stats::RecordDownloadCount(download_stats::START_COUNT);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 state_info_.target_name.value().c_str(), 795 state_info_.target_name.value().c_str(),
800 full_path().value().c_str()); 796 full_path().value().c_str());
801 } else { 797 } else {
802 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); 798 description += base::StringPrintf(" url = \"%s\"", url_list.c_str());
803 } 799 }
804 800
805 description += " }"; 801 description += " }";
806 802
807 return description; 803 return description;
808 } 804 }
OLDNEW
« no previous file with comments | « content/browser/download/download_item.h ('k') | content/browser/download/download_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698