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

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: Changed ordering of target_path and current_path everywhere to match that of DownloadItemImpl. 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 106
107 const char DownloadHistoryData::kKey[] = 107 const char DownloadHistoryData::kKey[] =
108 "DownloadItem DownloadHistoryData"; 108 "DownloadItem DownloadHistoryData";
109 109
110 history::DownloadRow GetDownloadRow( 110 history::DownloadRow GetDownloadRow(
111 content::DownloadItem* item) { 111 content::DownloadItem* item) {
112 // TODO(asanka): Persist GetTargetFilePath() as well. 112 // TODO(asanka): Persist GetTargetFilePath() as well.
113 DownloadHistoryData* data = DownloadHistoryData::Get(item); 113 DownloadHistoryData* data = DownloadHistoryData::Get(item);
114 return history::DownloadRow( 114 return history::DownloadRow(
115 item->GetFullPath(), 115 item->GetFullPath(),
116 item->GetURL(), 116 item->GetTargetFilePath(),
117 item->GetUrlChain(),
117 item->GetReferrerUrl(), 118 item->GetReferrerUrl(),
118 item->GetStartTime(), 119 item->GetStartTime(),
119 item->GetEndTime(), 120 item->GetEndTime(),
120 item->GetReceivedBytes(), 121 item->GetReceivedBytes(),
121 item->GetTotalBytes(), 122 item->GetTotalBytes(),
122 item->GetState(), 123 item->GetState(),
124 item->GetLastReason(),
123 ((data != NULL) ? data->db_handle() 125 ((data != NULL) ? data->db_handle()
124 : history::DownloadDatabase::kUninitializedHandle), 126 : history::DownloadDatabase::kUninitializedHandle),
125 item->GetOpened()); 127 item->GetOpened());
126 } 128 }
127 129
128 bool ShouldUpdateHistory(const history::DownloadRow* previous, 130 bool ShouldUpdateHistory(const history::DownloadRow* previous,
129 const history::DownloadRow& current) { 131 const history::DownloadRow& current) {
130 // Ignore url, referrer, start_time, db_handle, which don't change. 132 // Ignore url, referrer, start_time, db_handle, which don't change.
131 return ((previous == NULL) || 133 return ((previous == NULL) ||
132 (previous->path != current.path) || 134 (previous->current_path != current.current_path) ||
135 (previous->target_path != current.target_path) ||
133 (previous->end_time != current.end_time) || 136 (previous->end_time != current.end_time) ||
134 (previous->received_bytes != current.received_bytes) || 137 (previous->received_bytes != current.received_bytes) ||
135 (previous->total_bytes != current.total_bytes) || 138 (previous->total_bytes != current.total_bytes) ||
136 (previous->state != current.state) || 139 (previous->state != current.state) ||
140 (previous->interrupt_reason != current.interrupt_reason) ||
137 (previous->opened != current.opened)); 141 (previous->opened != current.opened));
138 } 142 }
139 143
140 typedef std::vector<history::DownloadRow> InfoVector; 144 typedef std::vector<history::DownloadRow> InfoVector;
141 145
142 } // anonymous namespace 146 } // anonymous namespace
143 147
144 DownloadHistory::HistoryAdapter::HistoryAdapter(HistoryService* history) 148 DownloadHistory::HistoryAdapter::HistoryAdapter(HistoryService* history)
145 : history_(history) { 149 : history_(history) {
146 } 150 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 if (!notifier_.GetManager()) 221 if (!notifier_.GetManager())
218 return; 222 return;
219 for (InfoVector::const_iterator it = infos->begin(); 223 for (InfoVector::const_iterator it = infos->begin();
220 it != infos->end(); ++it) { 224 it != infos->end(); ++it) {
221 // OnDownloadCreated() is called inside DM::CreateDownloadItem(), so set 225 // OnDownloadCreated() is called inside DM::CreateDownloadItem(), so set
222 // loading_db_handle_ to match up the created item with its db_handle. All 226 // loading_db_handle_ to match up the created item with its db_handle. All
223 // methods run on the UI thread and CreateDownloadItem() is synchronous. 227 // methods run on the UI thread and CreateDownloadItem() is synchronous.
224 loading_db_handle_ = it->db_handle; 228 loading_db_handle_ = it->db_handle;
225 content::DownloadItem* download_item = 229 content::DownloadItem* download_item =
226 notifier_.GetManager()->CreateDownloadItem( 230 notifier_.GetManager()->CreateDownloadItem(
227 it->path, 231 it->current_path,
228 it->url, 232 it->target_path,
233 it->url_chain,
229 it->referrer_url, 234 it->referrer_url,
230 it->start_time, 235 it->start_time,
231 it->end_time, 236 it->end_time,
232 it->received_bytes, 237 it->received_bytes,
233 it->total_bytes, 238 it->total_bytes,
234 it->state, 239 it->state,
240 it->interrupt_reason,
235 it->opened); 241 it->opened);
236 DownloadHistoryData* data = DownloadHistoryData::Get(download_item); 242 DownloadHistoryData* data = DownloadHistoryData::Get(download_item);
237 243
238 // If this DCHECK fails, then you probably added an Observer that 244 // If this DCHECK fails, then you probably added an Observer that
239 // synchronously creates a DownloadItem in response to 245 // synchronously creates a DownloadItem in response to
240 // DownloadManager::OnDownloadCreated(), and your observer runs before 246 // DownloadManager::OnDownloadCreated(), and your observer runs before
241 // DownloadHistory, and DownloadManager creates items synchronously. Just 247 // DownloadHistory, and DownloadManager creates items synchronously. Just
242 // bounce your DownloadItem creation off the message loop to flush 248 // bounce your DownloadItem creation off the message loop to flush
243 // DownloadHistory::OnDownloadCreated. 249 // DownloadHistory::OnDownloadCreated.
244 DCHECK_EQ(it->db_handle, data->db_handle()); 250 DCHECK_EQ(it->db_handle, data->db_handle());
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 426
421 void DownloadHistory::RemoveDownloadsBatch() { 427 void DownloadHistory::RemoveDownloadsBatch() {
422 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 428 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
423 HandleSet remove_handles; 429 HandleSet remove_handles;
424 IdSet remove_ids; 430 IdSet remove_ids;
425 removing_handles_.swap(remove_handles); 431 removing_handles_.swap(remove_handles);
426 removing_ids_.swap(remove_ids); 432 removing_ids_.swap(remove_ids);
427 history_->RemoveDownloads(remove_handles); 433 history_->RemoveDownloads(remove_handles);
428 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadsRemoved(remove_ids)); 434 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadsRemoved(remove_ids));
429 } 435 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698