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 #include "components/history/core/browser/history_backend.h" | 5 #include "components/history/core/browser/history_backend.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <list> | 9 #include <list> |
10 #include <map> | 10 #include <map> |
11 #include <set> | 11 #include <set> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/basictypes.h" | |
15 #include "base/bind.h" | 14 #include "base/bind.h" |
16 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
17 #include "base/files/file_enumerator.h" | 16 #include "base/files/file_enumerator.h" |
18 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
19 #include "base/memory/scoped_vector.h" | 18 #include "base/memory/scoped_vector.h" |
20 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
21 #include "base/metrics/histogram_macros.h" | 20 #include "base/metrics/histogram_macros.h" |
22 #include "base/rand_util.h" | 21 #include "base/rand_util.h" |
23 #include "base/sequenced_task_runner.h" | 22 #include "base/sequenced_task_runner.h" |
24 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" |
25 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
26 #include "base/time/time.h" | 25 #include "base/time/time.h" |
| 26 #include "build/build_config.h" |
27 #include "components/favicon_base/select_favicon_frames.h" | 27 #include "components/favicon_base/select_favicon_frames.h" |
28 #include "components/history/core/browser/download_constants.h" | 28 #include "components/history/core/browser/download_constants.h" |
29 #include "components/history/core/browser/download_row.h" | 29 #include "components/history/core/browser/download_row.h" |
30 #include "components/history/core/browser/history_backend_client.h" | 30 #include "components/history/core/browser/history_backend_client.h" |
31 #include "components/history/core/browser/history_backend_observer.h" | 31 #include "components/history/core/browser/history_backend_observer.h" |
32 #include "components/history/core/browser/history_constants.h" | 32 #include "components/history/core/browser/history_constants.h" |
33 #include "components/history/core/browser/history_database.h" | 33 #include "components/history/core/browser/history_database.h" |
34 #include "components/history/core/browser/history_database_params.h" | 34 #include "components/history/core/browser/history_database_params.h" |
35 #include "components/history/core/browser/history_db_task.h" | 35 #include "components/history/core/browser/history_db_task.h" |
36 #include "components/history/core/browser/in_memory_history_backend.h" | 36 #include "components/history/core/browser/in_memory_history_backend.h" |
(...skipping 1110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1147 void HistoryBackend::AddObserver(HistoryBackendObserver* observer) { | 1147 void HistoryBackend::AddObserver(HistoryBackendObserver* observer) { |
1148 observers_.AddObserver(observer); | 1148 observers_.AddObserver(observer); |
1149 } | 1149 } |
1150 | 1150 |
1151 void HistoryBackend::RemoveObserver(HistoryBackendObserver* observer) { | 1151 void HistoryBackend::RemoveObserver(HistoryBackendObserver* observer) { |
1152 observers_.RemoveObserver(observer); | 1152 observers_.RemoveObserver(observer); |
1153 } | 1153 } |
1154 | 1154 |
1155 // Downloads ------------------------------------------------------------------- | 1155 // Downloads ------------------------------------------------------------------- |
1156 | 1156 |
1157 uint32 HistoryBackend::GetNextDownloadId() { | 1157 uint32_t HistoryBackend::GetNextDownloadId() { |
1158 return db_ ? db_->GetNextDownloadId() : kInvalidDownloadId; | 1158 return db_ ? db_->GetNextDownloadId() : kInvalidDownloadId; |
1159 } | 1159 } |
1160 | 1160 |
1161 // Get all the download entries from the database. | 1161 // Get all the download entries from the database. |
1162 void HistoryBackend::QueryDownloads(std::vector<DownloadRow>* rows) { | 1162 void HistoryBackend::QueryDownloads(std::vector<DownloadRow>* rows) { |
1163 if (db_) | 1163 if (db_) |
1164 db_->QueryDownloads(rows); | 1164 db_->QueryDownloads(rows); |
1165 } | 1165 } |
1166 | 1166 |
1167 // Update a particular download entry. | 1167 // Update a particular download entry. |
1168 void HistoryBackend::UpdateDownload(const DownloadRow& data) { | 1168 void HistoryBackend::UpdateDownload(const DownloadRow& data) { |
1169 if (!db_) | 1169 if (!db_) |
1170 return; | 1170 return; |
1171 db_->UpdateDownload(data); | 1171 db_->UpdateDownload(data); |
1172 ScheduleCommit(); | 1172 ScheduleCommit(); |
1173 } | 1173 } |
1174 | 1174 |
1175 bool HistoryBackend::CreateDownload(const DownloadRow& history_info) { | 1175 bool HistoryBackend::CreateDownload(const DownloadRow& history_info) { |
1176 if (!db_) | 1176 if (!db_) |
1177 return false; | 1177 return false; |
1178 bool success = db_->CreateDownload(history_info); | 1178 bool success = db_->CreateDownload(history_info); |
1179 ScheduleCommit(); | 1179 ScheduleCommit(); |
1180 return success; | 1180 return success; |
1181 } | 1181 } |
1182 | 1182 |
1183 void HistoryBackend::RemoveDownloads(const std::set<uint32>& ids) { | 1183 void HistoryBackend::RemoveDownloads(const std::set<uint32_t>& ids) { |
1184 if (!db_) | 1184 if (!db_) |
1185 return; | 1185 return; |
1186 size_t downloads_count_before = db_->CountDownloads(); | 1186 size_t downloads_count_before = db_->CountDownloads(); |
1187 base::TimeTicks started_removing = base::TimeTicks::Now(); | 1187 base::TimeTicks started_removing = base::TimeTicks::Now(); |
1188 // HistoryBackend uses a long-running Transaction that is committed | 1188 // HistoryBackend uses a long-running Transaction that is committed |
1189 // periodically, so this loop doesn't actually hit the disk too hard. | 1189 // periodically, so this loop doesn't actually hit the disk too hard. |
1190 for (std::set<uint32>::const_iterator it = ids.begin(); it != ids.end(); | 1190 for (std::set<uint32_t>::const_iterator it = ids.begin(); it != ids.end(); |
1191 ++it) { | 1191 ++it) { |
1192 db_->RemoveDownload(*it); | 1192 db_->RemoveDownload(*it); |
1193 } | 1193 } |
1194 ScheduleCommit(); | 1194 ScheduleCommit(); |
1195 base::TimeTicks finished_removing = base::TimeTicks::Now(); | 1195 base::TimeTicks finished_removing = base::TimeTicks::Now(); |
1196 size_t downloads_count_after = db_->CountDownloads(); | 1196 size_t downloads_count_after = db_->CountDownloads(); |
1197 | 1197 |
1198 DCHECK_LE(downloads_count_after, downloads_count_before); | 1198 DCHECK_LE(downloads_count_after, downloads_count_before); |
1199 if (downloads_count_after > downloads_count_before) | 1199 if (downloads_count_after > downloads_count_before) |
1200 return; | 1200 return; |
(...skipping 1501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2702 // transaction is currently open. | 2702 // transaction is currently open. |
2703 db_->CommitTransaction(); | 2703 db_->CommitTransaction(); |
2704 db_->Vacuum(); | 2704 db_->Vacuum(); |
2705 db_->BeginTransaction(); | 2705 db_->BeginTransaction(); |
2706 db_->GetStartDate(&first_recorded_time_); | 2706 db_->GetStartDate(&first_recorded_time_); |
2707 | 2707 |
2708 return true; | 2708 return true; |
2709 } | 2709 } |
2710 | 2710 |
2711 } // namespace history | 2711 } // namespace history |
OLD | NEW |