| OLD | NEW |
| 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 12 matching lines...) Expand all Loading... |
| 23 // callback is called. All callbacks are bound with a weak pointer to | 23 // callback is called. All callbacks are bound with a weak pointer to |
| 24 // DownloadHistory to prevent use-after-free bugs. | 24 // DownloadHistory to prevent use-after-free bugs. |
| 25 // ChromeDownloadManagerDelegate owns DownloadHistory, and deletes it in | 25 // ChromeDownloadManagerDelegate owns DownloadHistory, and deletes it in |
| 26 // Shutdown(), which is called by DownloadManagerImpl::Shutdown() after all | 26 // Shutdown(), which is called by DownloadManagerImpl::Shutdown() after all |
| 27 // DownloadItems are destroyed. | 27 // DownloadItems are destroyed. |
| 28 | 28 |
| 29 #include "chrome/browser/download/download_history.h" | 29 #include "chrome/browser/download/download_history.h" |
| 30 | 30 |
| 31 #include "base/metrics/histogram.h" | 31 #include "base/metrics/histogram.h" |
| 32 #include "chrome/browser/download/download_crx_util.h" | 32 #include "chrome/browser/download/download_crx_util.h" |
| 33 #include "chrome/browser/history/download_database.h" | |
| 34 #include "chrome/browser/history/download_row.h" | |
| 35 #include "chrome/browser/history/history_service.h" | 33 #include "chrome/browser/history/history_service.h" |
| 34 #include "components/history/content/browser/download_constants_utils.h" |
| 35 #include "components/history/core/browser/download_database.h" |
| 36 #include "components/history/core/browser/download_row.h" |
| 36 #include "content/public/browser/browser_thread.h" | 37 #include "content/public/browser/browser_thread.h" |
| 37 #include "content/public/browser/download_item.h" | 38 #include "content/public/browser/download_item.h" |
| 38 #include "content/public/browser/download_manager.h" | 39 #include "content/public/browser/download_manager.h" |
| 39 | 40 |
| 40 #if defined(ENABLE_EXTENSIONS) | 41 #if defined(ENABLE_EXTENSIONS) |
| 41 #include "chrome/browser/extensions/api/downloads/downloads_api.h" | 42 #include "chrome/browser/extensions/api/downloads/downloads_api.h" |
| 42 #endif | 43 #endif |
| 43 | 44 |
| 44 namespace { | 45 namespace { |
| 45 | 46 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 item->GetUrlChain(), | 129 item->GetUrlChain(), |
| 129 item->GetReferrerUrl(), | 130 item->GetReferrerUrl(), |
| 130 item->GetMimeType(), | 131 item->GetMimeType(), |
| 131 item->GetOriginalMimeType(), | 132 item->GetOriginalMimeType(), |
| 132 item->GetStartTime(), | 133 item->GetStartTime(), |
| 133 item->GetEndTime(), | 134 item->GetEndTime(), |
| 134 item->GetETag(), | 135 item->GetETag(), |
| 135 item->GetLastModifiedTime(), | 136 item->GetLastModifiedTime(), |
| 136 item->GetReceivedBytes(), | 137 item->GetReceivedBytes(), |
| 137 item->GetTotalBytes(), | 138 item->GetTotalBytes(), |
| 138 item->GetState(), | 139 history::ToHistoryDownloadState(item->GetState()), |
| 139 item->GetDangerType(), | 140 history::ToHistoryDownloadDangerType(item->GetDangerType()), |
| 140 item->GetLastReason(), | 141 history::ToHistoryDownloadInterruptReason(item->GetLastReason()), |
| 141 item->GetId(), | 142 static_cast<history::DownloadId>(item->GetId()), |
| 142 item->GetOpened(), | 143 item->GetOpened(), |
| 143 by_ext_id, | 144 by_ext_id, |
| 144 by_ext_name); | 145 by_ext_name); |
| 145 } | 146 } |
| 146 | 147 |
| 147 bool ShouldUpdateHistory(const history::DownloadRow* previous, | 148 bool ShouldUpdateHistory(const history::DownloadRow* previous, |
| 148 const history::DownloadRow& current) { | 149 const history::DownloadRow& current) { |
| 149 // Ignore url, referrer, mime_type, original_mime_type, start_time, | 150 // Ignore url, referrer, mime_type, original_mime_type, start_time, |
| 150 // id, db_handle, which don't change. | 151 // id, db_handle, which don't change. |
| 151 return ((previous == NULL) || | 152 return ((previous == NULL) || |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 download->GetId() == loading_id_; | 251 download->GetId() == loading_id_; |
| 251 } | 252 } |
| 252 | 253 |
| 253 void DownloadHistory::QueryCallback(scoped_ptr<InfoVector> infos) { | 254 void DownloadHistory::QueryCallback(scoped_ptr<InfoVector> infos) { |
| 254 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 255 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 255 // ManagerGoingDown() may have happened before the history loaded. | 256 // ManagerGoingDown() may have happened before the history loaded. |
| 256 if (!notifier_.GetManager()) | 257 if (!notifier_.GetManager()) |
| 257 return; | 258 return; |
| 258 for (InfoVector::const_iterator it = infos->begin(); | 259 for (InfoVector::const_iterator it = infos->begin(); |
| 259 it != infos->end(); ++it) { | 260 it != infos->end(); ++it) { |
| 260 loading_id_ = it->id; | 261 loading_id_ = static_cast<uint32>(it->id); |
| 261 content::DownloadItem* item = notifier_.GetManager()->CreateDownloadItem( | 262 content::DownloadItem* item = notifier_.GetManager()->CreateDownloadItem( |
| 262 loading_id_, | 263 loading_id_, |
| 263 it->current_path, | 264 it->current_path, |
| 264 it->target_path, | 265 it->target_path, |
| 265 it->url_chain, | 266 it->url_chain, |
| 266 it->referrer_url, | 267 it->referrer_url, |
| 267 it->mime_type, | 268 it->mime_type, |
| 268 it->original_mime_type, | 269 it->original_mime_type, |
| 269 it->start_time, | 270 it->start_time, |
| 270 it->end_time, | 271 it->end_time, |
| 271 it->etag, | 272 it->etag, |
| 272 it->last_modified, | 273 it->last_modified, |
| 273 it->received_bytes, | 274 it->received_bytes, |
| 274 it->total_bytes, | 275 it->total_bytes, |
| 275 it->state, | 276 history::ToContentDownloadState(it->state), |
| 276 it->danger_type, | 277 history::ToContentDownloadDangerType(it->danger_type), |
| 277 it->interrupt_reason, | 278 history::ToContentDownloadInterruptReason(it->interrupt_reason), |
| 278 it->opened); | 279 it->opened); |
| 279 #if defined(ENABLE_EXTENSIONS) | 280 #if defined(ENABLE_EXTENSIONS) |
| 280 if (!it->by_ext_id.empty() && !it->by_ext_name.empty()) { | 281 if (!it->by_ext_id.empty() && !it->by_ext_name.empty()) { |
| 281 new extensions::DownloadedByExtension( | 282 new extensions::DownloadedByExtension( |
| 282 item, it->by_ext_id, it->by_ext_name); | 283 item, it->by_ext_id, it->by_ext_name); |
| 283 item->UpdateObservers(); | 284 item->UpdateObservers(); |
| 284 } | 285 } |
| 285 #endif | 286 #endif |
| 286 DCHECK_EQ(DownloadHistoryData::PERSISTED, | 287 DCHECK_EQ(DownloadHistoryData::PERSISTED, |
| 287 DownloadHistoryData::Get(item)->state()); | 288 DownloadHistoryData::Get(item)->state()); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 removing_ids_.insert(download_id); | 456 removing_ids_.insert(download_id); |
| 456 } | 457 } |
| 457 | 458 |
| 458 void DownloadHistory::RemoveDownloadsBatch() { | 459 void DownloadHistory::RemoveDownloadsBatch() { |
| 459 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 460 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 460 IdSet remove_ids; | 461 IdSet remove_ids; |
| 461 removing_ids_.swap(remove_ids); | 462 removing_ids_.swap(remove_ids); |
| 462 history_->RemoveDownloads(remove_ids); | 463 history_->RemoveDownloads(remove_ids); |
| 463 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadsRemoved(remove_ids)); | 464 FOR_EACH_OBSERVER(Observer, observers_, OnDownloadsRemoved(remove_ids)); |
| 464 } | 465 } |
| OLD | NEW |