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

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: comments 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
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/i18n/string_search.h" 11 #include "base/i18n/string_search.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/stringprintf.h" 14 #include "base/stringprintf.h"
15 #include "base/timer.h" 15 #include "base/timer.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "net/base/net_util.h"
18 #include "content/browser/browser_thread.h" 17 #include "content/browser/browser_thread.h"
18 #include "content/browser/download/download_create_info.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"
21 #include "content/browser/download/download_file_manager.h" 20 #include "content/browser/download/download_file_manager.h"
22 #include "content/browser/download/download_id.h" 21 #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_persistent_store_info.h" 23 #include "content/browser/download/download_persistent_store_info.h"
25 #include "content/browser/download/download_request_handle.h" 24 #include "content/browser/download/download_request_handle.h"
26 #include "content/browser/download/download_stats.h" 25 #include "content/browser/download/download_stats.h"
27 #include "content/browser/download/interrupt_reasons.h" 26 #include "content/browser/download/interrupt_reasons.h"
28 #include "content/public/browser/content_browser_client.h" 27 #include "content/public/browser/content_browser_client.h"
29 #include "content/public/browser/download_manager_delegate.h" 28 #include "content/public/browser/download_manager_delegate.h"
29 #include "net/base/net_util.h"
30 30
31 // A DownloadItem normally goes through the following states: 31 // A DownloadItem normally goes through the following states:
32 // * Created (when download starts) 32 // * Created (when download starts)
33 // * Made visible to consumers (e.g. Javascript) after the 33 // * Made visible to consumers (e.g. Javascript) after the
34 // destination file has been determined. 34 // destination file has been determined.
35 // * Entered into the history database. 35 // * Entered into the history database.
36 // * Made visible in the download shelf. 36 // * Made visible in the download shelf.
37 // * All data is saved. Note that the actual data download occurs 37 // * All data is saved. Note that the actual data download occurs
38 // in parallel with the above steps, but until those steps are 38 // in parallel with the above steps, but until those steps are
39 // complete, completion of the data download will be ignored. 39 // complete, completion of the data download will be ignored.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 // Our download table ID starts at 1, so we use 0 to represent a download that 114 // Our download table ID starts at 1, so we use 0 to represent a download that
115 // has started, but has not yet had its data persisted in the table. We use fake 115 // has started, but has not yet had its data persisted in the table. We use fake
116 // database handles in incognito mode starting at -1 and progressively getting 116 // database handles in incognito mode starting at -1 and progressively getting
117 // more negative. 117 // more negative.
118 // static 118 // static
119 const int DownloadItem::kUninitializedHandle = 0; 119 const int DownloadItem::kUninitializedHandle = 0;
120 120
121 // Constructor for reading from the history service. 121 // Constructor for reading from the history service.
122 DownloadItem::DownloadItem(DownloadManager* download_manager, 122 DownloadItem::DownloadItem(DownloadManager* download_manager,
123 const DownloadPersistentStoreInfo& info) 123 const DownloadPersistentStoreInfo& info)
124 : download_id_(-1), 124 : download_id_(download_manager->GetNextId()),
125 full_path_(info.path), 125 full_path_(info.path),
126 url_chain_(1, info.url), 126 url_chain_(1, info.url),
127 referrer_url_(info.referrer_url), 127 referrer_url_(info.referrer_url),
128 total_bytes_(info.total_bytes), 128 total_bytes_(info.total_bytes),
129 received_bytes_(info.received_bytes), 129 received_bytes_(info.received_bytes),
130 start_tick_(base::TimeTicks()), 130 start_tick_(base::TimeTicks()),
131 state_(static_cast<DownloadState>(info.state)), 131 state_(static_cast<DownloadState>(info.state)),
132 start_time_(info.start_time), 132 start_time_(info.start_time),
133 end_time_(info.end_time), 133 end_time_(info.end_time),
134 db_handle_(info.db_handle), 134 db_handle_(info.db_handle),
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 delegate_delayed_complete_(false) { 191 delegate_delayed_complete_(false) {
192 Init(true /* actively downloading */); 192 Init(true /* actively downloading */);
193 } 193 }
194 194
195 // Constructing for the "Save Page As..." feature: 195 // Constructing for the "Save Page As..." feature:
196 DownloadItem::DownloadItem(DownloadManager* download_manager, 196 DownloadItem::DownloadItem(DownloadManager* download_manager,
197 const FilePath& path, 197 const FilePath& path,
198 const GURL& url, 198 const GURL& url,
199 bool is_otr, 199 bool is_otr,
200 DownloadId download_id) 200 DownloadId download_id)
201 : download_id_(download_id.local()), 201 : download_id_(download_id),
202 full_path_(path), 202 full_path_(path),
203 url_chain_(1, url), 203 url_chain_(1, url),
204 referrer_url_(GURL()), 204 referrer_url_(GURL()),
205 total_bytes_(0), 205 total_bytes_(0),
206 received_bytes_(0), 206 received_bytes_(0),
207 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), 207 last_reason_(DOWNLOAD_INTERRUPT_REASON_NONE),
208 start_tick_(base::TimeTicks::Now()), 208 start_tick_(base::TimeTicks::Now()),
209 state_(IN_PROGRESS), 209 state_(IN_PROGRESS),
210 start_time_(base::Time::Now()), 210 start_time_(base::Time::Now()),
211 db_handle_(DownloadItem::kUninitializedHandle), 211 db_handle_(DownloadItem::kUninitializedHandle),
(...skipping 13 matching lines...) Expand all
225 } 225 }
226 226
227 DownloadItem::~DownloadItem() { 227 DownloadItem::~DownloadItem() {
228 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 228 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
229 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 229 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
230 230
231 TransitionTo(REMOVING); 231 TransitionTo(REMOVING);
232 download_manager_->AssertQueueStateConsistent(this); 232 download_manager_->AssertQueueStateConsistent(this);
233 } 233 }
234 234
235 DownloadId DownloadItem::global_id() const {
236 return DownloadId(download_manager_, id());
237 }
238
239 void DownloadItem::AddObserver(Observer* observer) { 235 void DownloadItem::AddObserver(Observer* observer) {
240 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 236 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
241 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 237 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
242 238
243 observers_.AddObserver(observer); 239 observers_.AddObserver(observer);
244 } 240 }
245 241
246 void DownloadItem::RemoveObserver(Observer* observer) { 242 void DownloadItem::RemoveObserver(Observer* observer) {
247 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved. 243 // TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
248 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 244 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 763
768 const GURL& DownloadItem::GetURL() const { 764 const GURL& DownloadItem::GetURL() const {
769 return url_chain_.empty() ? 765 return url_chain_.empty() ?
770 GURL::EmptyGURL() : url_chain_.back(); 766 GURL::EmptyGURL() : url_chain_.back();
771 } 767 }
772 768
773 std::string DownloadItem::DebugString(bool verbose) const { 769 std::string DownloadItem::DebugString(bool verbose) const {
774 std::string description = 770 std::string description =
775 base::StringPrintf("{ id = %d" 771 base::StringPrintf("{ id = %d"
776 " state = %s", 772 " state = %s",
777 download_id_, 773 download_id_.local(),
778 DebugDownloadStateString(state())); 774 DebugDownloadStateString(state()));
779 775
780 // Construct a string of the URL chain. 776 // Construct a string of the URL chain.
781 std::string url_list("<none>"); 777 std::string url_list("<none>");
782 if (!url_chain_.empty()) { 778 if (!url_chain_.empty()) {
783 std::vector<GURL>::const_iterator iter = url_chain_.begin(); 779 std::vector<GURL>::const_iterator iter = url_chain_.begin();
784 std::vector<GURL>::const_iterator last = url_chain_.end(); 780 std::vector<GURL>::const_iterator last = url_chain_.end();
785 url_list = (*iter).spec(); 781 url_list = (*iter).spec();
786 ++iter; 782 ++iter;
787 for ( ; verbose && (iter != last); ++iter) { 783 for ( ; verbose && (iter != last); ++iter) {
(...skipping 24 matching lines...) Expand all
812 state_info_.target_name.value().c_str(), 808 state_info_.target_name.value().c_str(),
813 full_path().value().c_str()); 809 full_path().value().c_str());
814 } else { 810 } else {
815 description += base::StringPrintf(" url = \"%s\"", url_list.c_str()); 811 description += base::StringPrintf(" url = \"%s\"", url_list.c_str());
816 } 812 }
817 813
818 description += " }"; 814 description += " }";
819 815
820 return description; 816 return description;
821 } 817 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698