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

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

Issue 8401001: Fix history importing by delaying DownloadManager creation. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: fix ifndefs Created 9 years, 1 month 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 <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 // Our download table ID starts at 1, so we use 0 to represent a download that 117 // Our download table ID starts at 1, so we use 0 to represent a download that
118 // has started, but has not yet had its data persisted in the table. We use fake 118 // has started, but has not yet had its data persisted in the table. We use fake
119 // database handles in incognito mode starting at -1 and progressively getting 119 // database handles in incognito mode starting at -1 and progressively getting
120 // more negative. 120 // more negative.
121 // static 121 // static
122 const int DownloadItem::kUninitializedHandle = 0; 122 const int DownloadItem::kUninitializedHandle = 0;
123 123
124 // Constructor for reading from the history service. 124 // Constructor for reading from the history service.
125 DownloadItem::DownloadItem(DownloadManager* download_manager, 125 DownloadItem::DownloadItem(DownloadManager* download_manager,
126 const DownloadPersistentStoreInfo& info) 126 const DownloadPersistentStoreInfo& info)
127 : download_id_(-1), 127 : download_id_(download_manager->GetNextId()),
128 full_path_(info.path), 128 full_path_(info.path),
129 url_chain_(1, info.url), 129 url_chain_(1, info.url),
130 referrer_url_(info.referrer_url), 130 referrer_url_(info.referrer_url),
131 total_bytes_(info.total_bytes), 131 total_bytes_(info.total_bytes),
132 received_bytes_(info.received_bytes), 132 received_bytes_(info.received_bytes),
133 start_tick_(base::TimeTicks()), 133 start_tick_(base::TimeTicks()),
134 state_(static_cast<DownloadState>(info.state)), 134 state_(static_cast<DownloadState>(info.state)),
135 start_time_(info.start_time), 135 start_time_(info.start_time),
136 end_time_(info.end_time), 136 end_time_(info.end_time),
137 db_handle_(info.db_handle), 137 db_handle_(info.db_handle),
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 delegate_delayed_complete_(false) { 194 delegate_delayed_complete_(false) {
195 Init(true /* actively downloading */); 195 Init(true /* actively downloading */);
196 } 196 }
197 197
198 // Constructing for the "Save Page As..." feature: 198 // Constructing for the "Save Page As..." feature:
199 DownloadItem::DownloadItem(DownloadManager* download_manager, 199 DownloadItem::DownloadItem(DownloadManager* download_manager,
200 const FilePath& path, 200 const FilePath& path,
201 const GURL& url, 201 const GURL& url,
202 bool is_otr, 202 bool is_otr,
203 DownloadId download_id) 203 DownloadId download_id)
204 : download_id_(download_id.local()), 204 : download_id_(download_id),
205 full_path_(path), 205 full_path_(path),
206 url_chain_(1, url), 206 url_chain_(1, url),
207 referrer_url_(GURL()), 207 referrer_url_(GURL()),
208 total_bytes_(0), 208 total_bytes_(0),
209 received_bytes_(0), 209 received_bytes_(0),
210 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), 210 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE),
211 start_tick_(base::TimeTicks::Now()), 211 start_tick_(base::TimeTicks::Now()),
212 state_(IN_PROGRESS), 212 state_(IN_PROGRESS),
213 start_time_(base::Time::Now()), 213 start_time_(base::Time::Now()),
214 db_handle_(DownloadItem::kUninitializedHandle), 214 db_handle_(DownloadItem::kUninitializedHandle),
(...skipping 13 matching lines...) Expand all
228 } 228 }
229 229
230 DownloadItem::~DownloadItem() { 230 DownloadItem::~DownloadItem() {
231 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 231 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
232 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 232 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
233 233
234 TransitionTo(REMOVING); 234 TransitionTo(REMOVING);
235 download_manager_->AssertQueueStateConsistent(this); 235 download_manager_->AssertQueueStateConsistent(this);
236 } 236 }
237 237
238 DownloadId DownloadItem::global_id() const {
239 return DownloadId(download_manager_, id());
240 }
241
242 void DownloadItem::AddObserver(Observer* observer) { 238 void DownloadItem::AddObserver(Observer* observer) {
243 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 239 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
244 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 240 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
245 241
246 observers_.AddObserver(observer); 242 observers_.AddObserver(observer);
247 } 243 }
248 244
249 void DownloadItem::RemoveObserver(Observer* observer) { 245 void DownloadItem::RemoveObserver(Observer* observer) {
250 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 246 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
251 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 247 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 766
771 const GURL& DownloadItem::GetURL() const { 767 const GURL& DownloadItem::GetURL() const {
772 return url_chain_.empty() ? 768 return url_chain_.empty() ?
773 GURL::EmptyGURL() : url_chain_.back(); 769 GURL::EmptyGURL() : url_chain_.back();
774 } 770 }
775 771
776 std::string DownloadItem::DebugString(bool verbose) const { 772 std::string DownloadItem::DebugString(bool verbose) const {
777 std::string description = 773 std::string description =
778 base::StringPrintf("{ id = %d" 774 base::StringPrintf("{ id = %d"
779 " state = %s", 775 " state = %s",
780 download_id_, 776 download_id_.local(),
781 DebugDownloadStateString(state())); 777 DebugDownloadStateString(state()));
782 778
783 // Construct a string of the URL chain. 779 // Construct a string of the URL chain.
784 std::string url_list("<none>"); 780 std::string url_list("<none>");
785 if (!url_chain_.empty()) { 781 if (!url_chain_.empty()) {
786 std::vector<GURL>::const_iterator iter = url_chain_.begin(); 782 std::vector<GURL>::const_iterator iter = url_chain_.begin();
787 std::vector<GURL>::const_iterator last = url_chain_.end(); 783 std::vector<GURL>::const_iterator last = url_chain_.end();
788 url_list = (*iter).spec(); 784 url_list = (*iter).spec();
789 ++iter; 785 ++iter;
790 for ( ; verbose && (iter != last); ++iter) { 786 for ( ; verbose && (iter != last); ++iter) {
(...skipping 24 matching lines...) Expand all
815 state_info_.target_name.value().c_str(), 811 state_info_.target_name.value().c_str(),
816 full_path().value().c_str()); 812 full_path().value().c_str());
817 } else { 813 } else {
818 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); 814 description += base::StringPrintf(" url = \"%s\"", url_list.c_str());
819 } 815 }
820 816
821 description += " }"; 817 description += " }";
822 818
823 return description; 819 return description;
824 } 820 }
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