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 "chrome/browser/history/history_backend.h" | 5 #include "chrome/browser/history/history_backend.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/memory/scoped_vector.h" | 17 #include "base/memory/scoped_vector.h" |
18 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
19 #include "base/metrics/histogram.h" | 19 #include "base/metrics/histogram.h" |
20 #include "base/string_util.h" | 20 #include "base/string_util.h" |
21 #include "base/time.h" | 21 #include "base/time.h" |
22 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
23 #include "chrome/browser/api/bookmarks/bookmark_service.h" | 23 #include "chrome/browser/api/bookmarks/bookmark_service.h" |
24 #include "chrome/browser/autocomplete/history_url_provider.h" | 24 #include "chrome/browser/autocomplete/history_url_provider.h" |
25 #include "chrome/browser/cancelable_request.h" | 25 #include "chrome/browser/cancelable_request.h" |
26 #include "chrome/browser/history/download_persistent_store_info.h" | |
26 #include "chrome/browser/history/history_notifications.h" | 27 #include "chrome/browser/history/history_notifications.h" |
27 #include "chrome/browser/history/history_publisher.h" | 28 #include "chrome/browser/history/history_publisher.h" |
28 #include "chrome/browser/history/in_memory_history_backend.h" | 29 #include "chrome/browser/history/in_memory_history_backend.h" |
29 #include "chrome/browser/history/page_usage_data.h" | 30 #include "chrome/browser/history/page_usage_data.h" |
30 #include "chrome/browser/history/select_favicon_frames.h" | 31 #include "chrome/browser/history/select_favicon_frames.h" |
31 #include "chrome/browser/history/top_sites.h" | 32 #include "chrome/browser/history/top_sites.h" |
32 #include "chrome/browser/history/visit_filter.h" | 33 #include "chrome/browser/history/visit_filter.h" |
33 #include "chrome/common/chrome_constants.h" | 34 #include "chrome/common/chrome_constants.h" |
34 #include "chrome/common/chrome_notification_types.h" | 35 #include "chrome/common/chrome_notification_types.h" |
35 #include "chrome/common/url_constants.h" | 36 #include "chrome/common/url_constants.h" |
36 #include "content/public/browser/download_persistent_store_info.h" | |
37 #include "googleurl/src/gurl.h" | 37 #include "googleurl/src/gurl.h" |
38 #include "grit/chromium_strings.h" | 38 #include "grit/chromium_strings.h" |
39 #include "grit/generated_resources.h" | 39 #include "grit/generated_resources.h" |
40 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 40 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
41 | 41 |
42 #if defined(OS_ANDROID) | 42 #if defined(OS_ANDROID) |
43 #include "chrome/browser/history/android/android_provider_backend.h" | 43 #include "chrome/browser/history/android/android_provider_backend.h" |
44 #endif | 44 #endif |
45 | 45 |
46 using base::Time; | 46 using base::Time; |
(...skipping 1150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1197 if (db_.get()) { | 1197 if (db_.get()) { |
1198 request->value = db_->next_download_id(); | 1198 request->value = db_->next_download_id(); |
1199 } else { | 1199 } else { |
1200 request->value = 0; | 1200 request->value = 0; |
1201 } | 1201 } |
1202 request->ForwardResult(request->value); | 1202 request->ForwardResult(request->value); |
1203 } | 1203 } |
1204 | 1204 |
1205 // Get all the download entries from the database. | 1205 // Get all the download entries from the database. |
1206 void HistoryBackend::QueryDownloads( | 1206 void HistoryBackend::QueryDownloads( |
1207 scoped_refptr<DownloadQueryRequest> request) { | 1207 const HistoryService::DownloadQueryCallback& callback) { |
1208 if (request->canceled()) | 1208 scoped_ptr<std::vector<DownloadPersistentStoreInfo> > results( |
1209 return; | 1209 new std::vector<DownloadPersistentStoreInfo>()); |
Randy Smith (Not in Mondays)
2012/09/11 18:36:53
Random thought: Probably worthwhile making sure yo
benjhayden
2012/09/13 15:18:16
TODOne
| |
1210 if (db_.get()) | 1210 if (db_.get()) |
1211 db_->QueryDownloads(&request->value); | 1211 db_->QueryDownloads(results.get()); |
1212 request->ForwardResult(&request->value); | 1212 callback.Run(results.Pass()); |
1213 } | 1213 } |
1214 | 1214 |
1215 // Clean up entries that has been corrupted (because of the crash, for example). | 1215 // Clean up entries that has been corrupted (because of the crash, for example). |
1216 void HistoryBackend::CleanUpInProgressEntries() { | 1216 void HistoryBackend::CleanUpInProgressEntries() { |
1217 if (db_.get()) { | 1217 if (db_.get()) { |
1218 // If some "in progress" entries were not updated when Chrome exited, they | 1218 // If some "in progress" entries were not updated when Chrome exited, they |
1219 // need to be cleaned up. | 1219 // need to be cleaned up. |
1220 db_->CleanUpInProgressEntries(); | 1220 db_->CleanUpInProgressEntries(); |
1221 } | 1221 } |
1222 } | 1222 } |
1223 | 1223 |
1224 // Update a particular download entry. | 1224 // Update a particular download entry. |
1225 void HistoryBackend::UpdateDownload( | 1225 void HistoryBackend::UpdateDownload( |
1226 const content::DownloadPersistentStoreInfo& data) { | 1226 const DownloadPersistentStoreInfo& data) { |
1227 if (db_.get()) | 1227 if (db_.get()) |
1228 db_->UpdateDownload(data); | 1228 db_->UpdateDownload(data); |
1229 } | 1229 } |
1230 | 1230 |
1231 // Update the path of a particular download entry. | 1231 // Create a new download entry and pass back the db_handle to it. |
1232 void HistoryBackend::UpdateDownloadPath(const FilePath& path, | 1232 void HistoryBackend::CreateDownload( |
1233 int64 db_handle) { | 1233 const DownloadPersistentStoreInfo& history_info, |
1234 const HistoryService::DownloadCreateCallback& callback) { | |
1235 int64 db_handle = 0; | |
1234 if (db_.get()) | 1236 if (db_.get()) |
1235 db_->UpdateDownloadPath(path, db_handle); | 1237 db_handle = db_->CreateDownload(history_info); |
1238 callback.Run(db_handle); | |
1236 } | 1239 } |
1237 | 1240 |
1238 // Create a new download entry and pass back the db_handle to it. | 1241 void HistoryBackend::GetVisibleVisitCountToHostSimple( |
1239 void HistoryBackend::CreateDownload( | 1242 const GURL& url, |
1240 scoped_refptr<DownloadCreateRequest> request, | 1243 const HistoryService::GetVisibleVisitCountToHostSimpleCallback& callback) { |
1241 int32 id, | 1244 int count = 0; |
1242 const content::DownloadPersistentStoreInfo& history_info) { | 1245 Time first_visit; |
1243 int64 db_handle = 0; | 1246 const bool success = db_.get() && |
1244 if (!request->canceled()) { | 1247 db_->GetVisibleVisitCountToHost(url, &count, &first_visit); |
1245 if (db_.get()) | 1248 callback.Run(success, count, first_visit); |
1246 db_handle = db_->CreateDownload(history_info); | |
1247 request->ForwardResult(id, db_handle); | |
1248 } | |
1249 } | 1249 } |
1250 | 1250 |
1251 void HistoryBackend::RemoveDownload(int64 db_handle) { | 1251 void HistoryBackend::RemoveDownloads(const std::set<int64>& handles) { |
1252 if (db_.get()) | 1252 if (db_.get()) |
1253 db_->RemoveDownload(db_handle); | 1253 db_->RemoveDownloads(handles); |
1254 } | |
1255 | |
1256 void HistoryBackend::RemoveDownloadsBetween(const Time remove_begin, | |
1257 const Time remove_end) { | |
1258 if (db_.get()) | |
1259 db_->RemoveDownloadsBetween(remove_begin, remove_end); | |
1260 } | 1254 } |
1261 | 1255 |
1262 void HistoryBackend::QueryHistory(scoped_refptr<QueryHistoryRequest> request, | 1256 void HistoryBackend::QueryHistory(scoped_refptr<QueryHistoryRequest> request, |
1263 const string16& text_query, | 1257 const string16& text_query, |
1264 const QueryOptions& options) { | 1258 const QueryOptions& options) { |
1265 if (request->canceled()) | 1259 if (request->canceled()) |
1266 return; | 1260 return; |
1267 | 1261 |
1268 TimeTicks beginning_time = TimeTicks::Now(); | 1262 TimeTicks beginning_time = TimeTicks::Now(); |
1269 | 1263 |
(...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2310 // Removing the icon mapping may have orphaned the associated favicon so | 2304 // Removing the icon mapping may have orphaned the associated favicon so |
2311 // we must recheck it. This is not super fast, but this case will get | 2305 // we must recheck it. This is not super fast, but this case will get |
2312 // triggered rarely, since normally a page will always map to the same | 2306 // triggered rarely, since normally a page will always map to the same |
2313 // favicon IDs. It will mostly happen for favicons we import. | 2307 // favicon IDs. It will mostly happen for favicons we import. |
2314 if (!thumbnail_db_->HasMappingFor(m->icon_id)) | 2308 if (!thumbnail_db_->HasMappingFor(m->icon_id)) |
2315 thumbnail_db_->DeleteFavicon(m->icon_id); | 2309 thumbnail_db_->DeleteFavicon(m->icon_id); |
2316 mappings_changed = true; | 2310 mappings_changed = true; |
2317 } | 2311 } |
2318 } | 2312 } |
2319 | 2313 |
2320 for (size_t i = 0; i < unmapped_icon_ids.size(); ++i ) { | 2314 for (size_t i = 0; i < unmapped_icon_ids.size(); ++i) { |
2321 thumbnail_db_->AddIconMapping(page_url, unmapped_icon_ids[i]); | 2315 thumbnail_db_->AddIconMapping(page_url, unmapped_icon_ids[i]); |
2322 mappings_changed = true; | 2316 mappings_changed = true; |
2323 } | 2317 } |
2324 return mappings_changed; | 2318 return mappings_changed; |
2325 } | 2319 } |
2326 | 2320 |
2327 void HistoryBackend::Commit() { | 2321 void HistoryBackend::Commit() { |
2328 if (!db_.get()) | 2322 if (!db_.get()) |
2329 return; | 2323 return; |
2330 | 2324 |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2710 info.url_id = visit.url_id; | 2704 info.url_id = visit.url_id; |
2711 info.time = visit.visit_time; | 2705 info.time = visit.visit_time; |
2712 info.transition = visit.transition; | 2706 info.transition = visit.transition; |
2713 // If we don't have a delegate yet during setup or shutdown, we will drop | 2707 // If we don't have a delegate yet during setup or shutdown, we will drop |
2714 // these notifications. | 2708 // these notifications. |
2715 if (delegate_.get()) | 2709 if (delegate_.get()) |
2716 delegate_->NotifyVisitDBObserversOnAddVisit(info); | 2710 delegate_->NotifyVisitDBObserversOnAddVisit(info); |
2717 } | 2711 } |
2718 | 2712 |
2719 } // namespace history | 2713 } // namespace history |
OLD | NEW |