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 <stdint.h> |
| 9 |
8 #include <set> | 10 #include <set> |
9 #include <vector> | 11 #include <vector> |
10 | 12 |
11 #include "base/basictypes.h" | |
12 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/macros.h" |
13 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
14 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
15 #include "chrome/browser/download/all_download_item_notifier.h" | 17 #include "chrome/browser/download/all_download_item_notifier.h" |
16 #include "components/history/core/browser/history_service.h" | 18 #include "components/history/core/browser/history_service.h" |
17 #include "content/public/browser/download_item.h" | 19 #include "content/public/browser/download_item.h" |
18 #include "content/public/browser/download_manager.h" | 20 #include "content/public/browser/download_manager.h" |
19 | 21 |
20 namespace history { | 22 namespace history { |
21 struct DownloadRow; | 23 struct DownloadRow; |
22 } // namespace history | 24 } // namespace history |
23 | 25 |
24 // Observes a single DownloadManager and all its DownloadItems, keeping the | 26 // Observes a single DownloadManager and all its DownloadItems, keeping the |
25 // DownloadDatabase up to date. | 27 // DownloadDatabase up to date. |
26 class DownloadHistory : public AllDownloadItemNotifier::Observer { | 28 class DownloadHistory : public AllDownloadItemNotifier::Observer { |
27 public: | 29 public: |
28 typedef std::set<uint32> IdSet; | 30 typedef std::set<uint32_t> IdSet; |
29 | 31 |
30 // Caller must guarantee that HistoryService outlives HistoryAdapter. | 32 // Caller must guarantee that HistoryService outlives HistoryAdapter. |
31 class HistoryAdapter { | 33 class HistoryAdapter { |
32 public: | 34 public: |
33 explicit HistoryAdapter(history::HistoryService* history); | 35 explicit HistoryAdapter(history::HistoryService* history); |
34 virtual ~HistoryAdapter(); | 36 virtual ~HistoryAdapter(); |
35 | 37 |
36 virtual void QueryDownloads( | 38 virtual void QueryDownloads( |
37 const history::HistoryService::DownloadQueryCallback& callback); | 39 const history::HistoryService::DownloadQueryCallback& callback); |
38 | 40 |
39 virtual void CreateDownload( | 41 virtual void CreateDownload( |
40 const history::DownloadRow& info, | 42 const history::DownloadRow& info, |
41 const history::HistoryService::DownloadCreateCallback& callback); | 43 const history::HistoryService::DownloadCreateCallback& callback); |
42 | 44 |
43 virtual void UpdateDownload(const history::DownloadRow& data); | 45 virtual void UpdateDownload(const history::DownloadRow& data); |
44 | 46 |
45 virtual void RemoveDownloads(const std::set<uint32>& ids); | 47 virtual void RemoveDownloads(const std::set<uint32_t>& ids); |
46 | 48 |
47 private: | 49 private: |
48 history::HistoryService* history_; | 50 history::HistoryService* history_; |
49 DISALLOW_COPY_AND_ASSIGN(HistoryAdapter); | 51 DISALLOW_COPY_AND_ASSIGN(HistoryAdapter); |
50 }; | 52 }; |
51 | 53 |
52 class Observer { | 54 class Observer { |
53 public: | 55 public: |
54 Observer(); | 56 Observer(); |
55 virtual ~Observer(); | 57 virtual ~Observer(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 // Callback from |history_| containing all entries in the downloads database | 101 // Callback from |history_| containing all entries in the downloads database |
100 // table. | 102 // table. |
101 void QueryCallback( | 103 void QueryCallback( |
102 scoped_ptr<std::vector<history::DownloadRow> > infos); | 104 scoped_ptr<std::vector<history::DownloadRow> > infos); |
103 | 105 |
104 // May add |item| to |history_|. | 106 // May add |item| to |history_|. |
105 void MaybeAddToHistory(content::DownloadItem* item); | 107 void MaybeAddToHistory(content::DownloadItem* item); |
106 | 108 |
107 // Callback from |history_| when an item was successfully inserted into the | 109 // Callback from |history_| when an item was successfully inserted into the |
108 // database. | 110 // database. |
109 void ItemAdded(uint32 id, bool success); | 111 void ItemAdded(uint32_t id, bool success); |
110 | 112 |
111 // AllDownloadItemNotifier::Observer | 113 // AllDownloadItemNotifier::Observer |
112 void OnDownloadCreated(content::DownloadManager* manager, | 114 void OnDownloadCreated(content::DownloadManager* manager, |
113 content::DownloadItem* item) override; | 115 content::DownloadItem* item) override; |
114 void OnDownloadUpdated(content::DownloadManager* manager, | 116 void OnDownloadUpdated(content::DownloadManager* manager, |
115 content::DownloadItem* item) override; | 117 content::DownloadItem* item) override; |
116 void OnDownloadOpened(content::DownloadManager* manager, | 118 void OnDownloadOpened(content::DownloadManager* manager, |
117 content::DownloadItem* item) override; | 119 content::DownloadItem* item) override; |
118 void OnDownloadRemoved(content::DownloadManager* manager, | 120 void OnDownloadRemoved(content::DownloadManager* manager, |
119 content::DownloadItem* item) override; | 121 content::DownloadItem* item) override; |
120 | 122 |
121 // Schedule a record to be removed from |history_| the next time | 123 // Schedule a record to be removed from |history_| the next time |
122 // RemoveDownloadsBatch() runs. Schedule RemoveDownloadsBatch() to be run soon | 124 // RemoveDownloadsBatch() runs. Schedule RemoveDownloadsBatch() to be run soon |
123 // if it isn't already scheduled. | 125 // if it isn't already scheduled. |
124 void ScheduleRemoveDownload(uint32 download_id); | 126 void ScheduleRemoveDownload(uint32_t download_id); |
125 | 127 |
126 // Removes all |removing_ids_| from |history_|. | 128 // Removes all |removing_ids_| from |history_|. |
127 void RemoveDownloadsBatch(); | 129 void RemoveDownloadsBatch(); |
128 | 130 |
129 AllDownloadItemNotifier notifier_; | 131 AllDownloadItemNotifier notifier_; |
130 | 132 |
131 scoped_ptr<HistoryAdapter> history_; | 133 scoped_ptr<HistoryAdapter> history_; |
132 | 134 |
133 // Identifier of the item being created in QueryCallback(), matched up with | 135 // Identifier of the item being created in QueryCallback(), matched up with |
134 // created items in OnDownloadCreated() so that the item is not re-added to | 136 // created items in OnDownloadCreated() so that the item is not re-added to |
135 // the database. | 137 // the database. |
136 uint32 loading_id_; | 138 uint32_t loading_id_; |
137 | 139 |
138 // Identifiers of items that are scheduled for removal from history, to | 140 // Identifiers of items that are scheduled for removal from history, to |
139 // facilitate batching removals together for database efficiency. | 141 // facilitate batching removals together for database efficiency. |
140 IdSet removing_ids_; | 142 IdSet removing_ids_; |
141 | 143 |
142 // |GetId()|s of items that were removed while they were being added, so that | 144 // |GetId()|s of items that were removed while they were being added, so that |
143 // they can be removed when the database finishes adding them. | 145 // they can be removed when the database finishes adding them. |
144 // TODO(benjhayden) Can this be removed now that it doesn't need to wait for | 146 // TODO(benjhayden) Can this be removed now that it doesn't need to wait for |
145 // the db_handle, and can rely on PostTask sequentiality? | 147 // the db_handle, and can rely on PostTask sequentiality? |
146 IdSet removed_while_adding_; | 148 IdSet removed_while_adding_; |
147 | 149 |
148 // Count the number of items in the history for UMA. | 150 // Count the number of items in the history for UMA. |
149 int64 history_size_; | 151 int64_t history_size_; |
150 | 152 |
151 base::ObserverList<Observer> observers_; | 153 base::ObserverList<Observer> observers_; |
152 | 154 |
153 base::WeakPtrFactory<DownloadHistory> weak_ptr_factory_; | 155 base::WeakPtrFactory<DownloadHistory> weak_ptr_factory_; |
154 | 156 |
155 DISALLOW_COPY_AND_ASSIGN(DownloadHistory); | 157 DISALLOW_COPY_AND_ASSIGN(DownloadHistory); |
156 }; | 158 }; |
157 | 159 |
158 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_HISTORY_H_ | 160 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_HISTORY_H_ |
OLD | NEW |