| 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 13 matching lines...) Expand all Loading... |
| 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 <utility> | 31 #include <utility> |
| 32 | 32 |
| 33 #include "base/macros.h" | 33 #include "base/macros.h" |
| 34 #include "base/memory/ptr_util.h" |
| 34 #include "base/metrics/histogram_macros.h" | 35 #include "base/metrics/histogram_macros.h" |
| 35 #include "chrome/browser/download/download_crx_util.h" | 36 #include "chrome/browser/download/download_crx_util.h" |
| 36 #include "components/history/content/browser/download_conversions.h" | 37 #include "components/history/content/browser/download_conversions.h" |
| 37 #include "components/history/core/browser/download_database.h" | 38 #include "components/history/core/browser/download_database.h" |
| 38 #include "components/history/core/browser/download_row.h" | 39 #include "components/history/core/browser/download_row.h" |
| 39 #include "components/history/core/browser/history_service.h" | 40 #include "components/history/core/browser/history_service.h" |
| 40 #include "content/public/browser/browser_thread.h" | 41 #include "content/public/browser/browser_thread.h" |
| 41 #include "content/public/browser/download_item.h" | 42 #include "content/public/browser/download_item.h" |
| 42 #include "content/public/browser/download_manager.h" | 43 #include "content/public/browser/download_manager.h" |
| 43 #include "extensions/features/features.h" | 44 #include "extensions/features/features.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 70 | 71 |
| 71 static const DownloadHistoryData* Get(const content::DownloadItem* item) { | 72 static const DownloadHistoryData* Get(const content::DownloadItem* item) { |
| 72 const base::SupportsUserData::Data* data = item->GetUserData(kKey); | 73 const base::SupportsUserData::Data* data = item->GetUserData(kKey); |
| 73 return (data == NULL) ? NULL | 74 return (data == NULL) ? NULL |
| 74 : static_cast<const DownloadHistoryData*>(data); | 75 : static_cast<const DownloadHistoryData*>(data); |
| 75 } | 76 } |
| 76 | 77 |
| 77 explicit DownloadHistoryData(content::DownloadItem* item) | 78 explicit DownloadHistoryData(content::DownloadItem* item) |
| 78 : state_(NOT_PERSISTED), | 79 : state_(NOT_PERSISTED), |
| 79 was_restored_from_history_(false) { | 80 was_restored_from_history_(false) { |
| 80 item->SetUserData(kKey, this); | 81 item->SetUserData(kKey, base::WrapUnique(this)); |
| 81 } | 82 } |
| 82 | 83 |
| 83 ~DownloadHistoryData() override {} | 84 ~DownloadHistoryData() override {} |
| 84 | 85 |
| 85 PersistenceState state() const { return state_; } | 86 PersistenceState state() const { return state_; } |
| 86 void SetState(PersistenceState s) { state_ = s; } | 87 void SetState(PersistenceState s) { state_ = s; } |
| 87 | 88 |
| 88 bool was_restored_from_history() const { return was_restored_from_history_; } | 89 bool was_restored_from_history() const { return was_restored_from_history_; } |
| 89 void set_was_restored_from_history(bool value) { | 90 void set_was_restored_from_history(bool value) { |
| 90 was_restored_from_history_ = value; | 91 was_restored_from_history_ = value; |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 } | 497 } |
| 497 | 498 |
| 498 void DownloadHistory::RemoveDownloadsBatch() { | 499 void DownloadHistory::RemoveDownloadsBatch() { |
| 499 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 500 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 500 IdSet remove_ids; | 501 IdSet remove_ids; |
| 501 removing_ids_.swap(remove_ids); | 502 removing_ids_.swap(remove_ids); |
| 502 history_->RemoveDownloads(remove_ids); | 503 history_->RemoveDownloads(remove_ids); |
| 503 for (Observer& observer : observers_) | 504 for (Observer& observer : observers_) |
| 504 observer.OnDownloadsRemoved(remove_ids); | 505 observer.OnDownloadsRemoved(remove_ids); |
| 505 } | 506 } |
| OLD | NEW |