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

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

Issue 11363222: Persist download interrupt reason, both target and current paths, and url_chain. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporated Ben's comments. Created 8 years 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) 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 // DownloadHistory manages persisting DownloadItems to the history service by 5 // DownloadHistory manages persisting DownloadItems to the history service by
6 // observing a single DownloadManager and all its DownloadItems using an 6 // observing a single DownloadManager and all its DownloadItems using an
7 // AllDownloadItemNotifier. 7 // AllDownloadItemNotifier.
8 // 8 //
9 // DownloadHistory decides whether and when to add items to, remove items from, 9 // DownloadHistory decides whether and when to add items to, remove items from,
10 // and update items in the database. DownloadHistory uses DownloadHistoryData to 10 // and update items in the database. DownloadHistory uses DownloadHistoryData to
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 100
101 const char DownloadHistoryData::kKey[] = 101 const char DownloadHistoryData::kKey[] =
102 "DownloadItem DownloadHistoryData"; 102 "DownloadItem DownloadHistoryData";
103 103
104 history::DownloadRow GetDownloadRow( 104 history::DownloadRow GetDownloadRow(
105 content::DownloadItem* item) { 105 content::DownloadItem* item) {
106 // TODO(asanka): Persist GetTargetFilePath() as well. 106 // TODO(asanka): Persist GetTargetFilePath() as well.
107 DownloadHistoryData* data = DownloadHistoryData::Get(item); 107 DownloadHistoryData* data = DownloadHistoryData::Get(item);
108 return history::DownloadRow( 108 return history::DownloadRow(
109 item->GetFullPath(), 109 item->GetFullPath(),
110 item->GetURL(), 110 item->GetTargetFilePath(),
111 item->GetUrlChain(),
111 item->GetReferrerUrl(), 112 item->GetReferrerUrl(),
112 item->GetStartTime(), 113 item->GetStartTime(),
113 item->GetEndTime(), 114 item->GetEndTime(),
114 item->GetReceivedBytes(), 115 item->GetReceivedBytes(),
115 item->GetTotalBytes(), 116 item->GetTotalBytes(),
116 item->GetState(), 117 item->GetState(),
118 item->GetLastReason(),
117 ((data != NULL) ? data->db_handle() 119 ((data != NULL) ? data->db_handle()
118 : history::DownloadDatabase::kUninitializedHandle), 120 : history::DownloadDatabase::kUninitializedHandle),
119 item->GetOpened()); 121 item->GetOpened());
120 } 122 }
121 123
122 bool ShouldUpdateHistory(const history::DownloadRow* previous, 124 bool ShouldUpdateHistory(const history::DownloadRow* previous,
123 const history::DownloadRow& current) { 125 const history::DownloadRow& current) {
124 // Ignore url, referrer, start_time, db_handle, which don't change. 126 // Ignore url, referrer, start_time, db_handle, which don't change.
125 return ((previous == NULL) || 127 return ((previous == NULL) ||
126 (previous->path != current.path) || 128 (previous->current_path != current.current_path) ||
129 (previous->target_path != current.target_path) ||
127 (previous->end_time != current.end_time) || 130 (previous->end_time != current.end_time) ||
128 (previous->received_bytes != current.received_bytes) || 131 (previous->received_bytes != current.received_bytes) ||
129 (previous->total_bytes != current.total_bytes) || 132 (previous->total_bytes != current.total_bytes) ||
130 (previous->state != current.state) || 133 (previous->state != current.state) ||
134 (previous->interrupt_reason != current.interrupt_reason) ||
131 (previous->opened != current.opened)); 135 (previous->opened != current.opened));
132 } 136 }
133 137
134 typedef std::vector<history::DownloadRow> InfoVector; 138 typedef std::vector<history::DownloadRow> InfoVector;
135 139
136 } // anonymous namespace 140 } // anonymous namespace
137 141
138 DownloadHistory::HistoryAdapter::HistoryAdapter(HistoryService* history) 142 DownloadHistory::HistoryAdapter::HistoryAdapter(HistoryService* history)
139 : history_(history) { 143 : history_(history) {
140 } 144 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 if (!notifier_.GetManager()) 215 if (!notifier_.GetManager())
212 return; 216 return;
213 for (InfoVector::const_iterator it = infos->begin(); 217 for (InfoVector::const_iterator it = infos->begin();
214 it != infos->end(); ++it) { 218 it != infos->end(); ++it) {
215 // OnDownloadCreated() is called inside DM::CreateDownloadItem(), so set 219 // OnDownloadCreated() is called inside DM::CreateDownloadItem(), so set
216 // loading_db_handle_ to match up the created item with its db_handle. All 220 // loading_db_handle_ to match up the created item with its db_handle. All
217 // methods run on the UI thread and CreateDownloadItem() is synchronous. 221 // methods run on the UI thread and CreateDownloadItem() is synchronous.
218 loading_db_handle_ = it->db_handle; 222 loading_db_handle_ = it->db_handle;
219 content::DownloadItem* download_item = 223 content::DownloadItem* download_item =
220 notifier_.GetManager()->CreateDownloadItem( 224 notifier_.GetManager()->CreateDownloadItem(
221 it->path, 225 it->current_path,
222 it->url, 226 it->target_path,
227 it->url_chain,
223 it->referrer_url, 228 it->referrer_url,
224 it->start_time, 229 it->start_time,
225 it->end_time, 230 it->end_time,
226 it->received_bytes, 231 it->received_bytes,
227 it->total_bytes, 232 it->total_bytes,
228 it->state, 233 it->state,
234 it->interrupt_reason,
229 it->opened); 235 it->opened);
230 DownloadHistoryData* data = DownloadHistoryData::Get(download_item); 236 DownloadHistoryData* data = DownloadHistoryData::Get(download_item);
231 237
232 // If this DCHECK fails, then you probably added an Observer that 238 // If this DCHECK fails, then you probably added an Observer that
233 // synchronously creates a DownloadItem in response to 239 // synchronously creates a DownloadItem in response to
234 // DownloadManager::OnDownloadCreated(), and your observer runs before 240 // DownloadManager::OnDownloadCreated(), and your observer runs before
235 // DownloadHistory, and DownloadManager creates items synchronously. Just 241 // DownloadHistory, and DownloadManager creates items synchronously. Just
236 // bounce your DownloadItem creation off the message loop to flush 242 // bounce your DownloadItem creation off the message loop to flush
237 // DownloadHistory::OnDownloadCreated. 243 // DownloadHistory::OnDownloadCreated.
238 DCHECK_EQ(it->db_handle, data->db_handle()); 244 DCHECK_EQ(it->db_handle, data->db_handle());
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 420
415 void DownloadHistory::RemoveDownloadsBatch() { 421 void DownloadHistory::RemoveDownloadsBatch() {
416 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 422 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
417 HandleSet remove_handles; 423 HandleSet remove_handles;
418 IdSet remove_ids; 424 IdSet remove_ids;
419 removing_handles_.swap(remove_handles); 425 removing_handles_.swap(remove_handles);
420 removing_ids_.swap(remove_ids); 426 removing_ids_.swap(remove_ids);
421 history_->RemoveDownloads(remove_handles); 427 history_->RemoveDownloads(remove_handles);
422 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadsRemoved(remove_ids)); 428 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadsRemoved(remove_ids));
423 } 429 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698