| 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 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_HISTORY_H_ | 5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_HISTORY_H_ |
| 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_HISTORY_H_ | 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_HISTORY_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 const history::DownloadRow& info) {} | 60 const history::DownloadRow& info) {} |
| 61 | 61 |
| 62 // Fires when RemoveDownloads messages are sent to the DB thread. | 62 // Fires when RemoveDownloads messages are sent to the DB thread. |
| 63 virtual void OnDownloadsRemoved(const IdSet& ids) {} | 63 virtual void OnDownloadsRemoved(const IdSet& ids) {} |
| 64 | 64 |
| 65 // Fires when the DownloadHistory is being destroyed so that implementors | 65 // Fires when the DownloadHistory is being destroyed so that implementors |
| 66 // can RemoveObserver() and nullify their DownloadHistory*s. | 66 // can RemoveObserver() and nullify their DownloadHistory*s. |
| 67 virtual void OnDownloadHistoryDestroyed() {} | 67 virtual void OnDownloadHistoryDestroyed() {} |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 // Returns true if the item is persisted. | 70 // Returns true if the download is persisted. Not reliable when called from |
| 71 static bool IsPersisted(content::DownloadItem* item); | 71 // within a DownloadManager::Observer::OnDownloadCreated handler since the |
| 72 // persisted state may not yet have been updated for a download that was |
| 73 // restored from history. |
| 74 static bool IsPersisted(const content::DownloadItem* item); |
| 72 | 75 |
| 73 // Neither |manager| nor |history| may be NULL. | 76 // Neither |manager| nor |history| may be NULL. |
| 74 // DownloadService creates DownloadHistory some time after DownloadManager is | 77 // DownloadService creates DownloadHistory some time after DownloadManager is |
| 75 // created and destroys DownloadHistory as DownloadManager is shutting down. | 78 // created and destroys DownloadHistory as DownloadManager is shutting down. |
| 76 DownloadHistory( | 79 DownloadHistory( |
| 77 content::DownloadManager* manager, | 80 content::DownloadManager* manager, |
| 78 scoped_ptr<HistoryAdapter> history); | 81 scoped_ptr<HistoryAdapter> history); |
| 79 | 82 |
| 80 virtual ~DownloadHistory(); | 83 virtual ~DownloadHistory(); |
| 81 | 84 |
| 82 void AddObserver(Observer* observer); | 85 void AddObserver(Observer* observer); |
| 83 void RemoveObserver(Observer* observer); | 86 void RemoveObserver(Observer* observer); |
| 84 | 87 |
| 88 // Returns true if the download was restored from history. Safe to call from |
| 89 // within a DownloadManager::Observer::OnDownloadCreated handler and can be |
| 90 // used to distinguish between downloads that were created due to new requests |
| 91 // vs. downloads that were created due to being restored from history. Note |
| 92 // that the return value is only reliable for downloads that were restored by |
| 93 // this specific DownloadHistory instance. |
| 94 bool WasRestoredFromHistory(const content::DownloadItem* item) const; |
| 95 |
| 85 private: | 96 private: |
| 86 typedef std::set<content::DownloadItem*> ItemSet; | 97 typedef std::set<content::DownloadItem*> ItemSet; |
| 87 | 98 |
| 88 // Callback from |history_| containing all entries in the downloads database | 99 // Callback from |history_| containing all entries in the downloads database |
| 89 // table. | 100 // table. |
| 90 void QueryCallback( | 101 void QueryCallback( |
| 91 scoped_ptr<std::vector<history::DownloadRow> > infos); | 102 scoped_ptr<std::vector<history::DownloadRow> > infos); |
| 92 | 103 |
| 93 // May add |item| to |history_|. | 104 // May add |item| to |history_|. |
| 94 void MaybeAddToHistory(content::DownloadItem* item); | 105 void MaybeAddToHistory(content::DownloadItem* item); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 int64 history_size_; | 149 int64 history_size_; |
| 139 | 150 |
| 140 ObserverList<Observer> observers_; | 151 ObserverList<Observer> observers_; |
| 141 | 152 |
| 142 base::WeakPtrFactory<DownloadHistory> weak_ptr_factory_; | 153 base::WeakPtrFactory<DownloadHistory> weak_ptr_factory_; |
| 143 | 154 |
| 144 DISALLOW_COPY_AND_ASSIGN(DownloadHistory); | 155 DISALLOW_COPY_AND_ASSIGN(DownloadHistory); |
| 145 }; | 156 }; |
| 146 | 157 |
| 147 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_HISTORY_H_ | 158 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_HISTORY_H_ |
| OLD | NEW |