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 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1189 if (db_.get()) { | 1189 if (db_.get()) { |
1190 request->value = db_->next_download_id(); | 1190 request->value = db_->next_download_id(); |
1191 } else { | 1191 } else { |
1192 request->value = 0; | 1192 request->value = 0; |
1193 } | 1193 } |
1194 request->ForwardResult(request->value); | 1194 request->ForwardResult(request->value); |
1195 } | 1195 } |
1196 | 1196 |
1197 // Get all the download entries from the database. | 1197 // Get all the download entries from the database. |
1198 void HistoryBackend::QueryDownloads( | 1198 void HistoryBackend::QueryDownloads( |
1199 scoped_refptr<DownloadQueryRequest> request) { | 1199 const HistoryService::DownloadQueryCallback& callback) { |
1200 if (request->canceled()) | 1200 scoped_ptr<std::vector<DownloadPersistentStoreInfo> > results( |
1201 return; | 1201 new std::vector<DownloadPersistentStoreInfo>()); |
1202 if (db_.get()) | 1202 if (db_.get()) |
1203 db_->QueryDownloads(&request->value); | 1203 db_->QueryDownloads(results.get()); |
1204 request->ForwardResult(&request->value); | 1204 callback.Run(results.Pass()); |
1205 } | 1205 } |
1206 | 1206 |
1207 // Clean up entries that has been corrupted (because of the crash, for example). | 1207 // Clean up entries that has been corrupted (because of the crash, for example). |
1208 void HistoryBackend::CleanUpInProgressEntries() { | 1208 void HistoryBackend::CleanUpInProgressEntries() { |
1209 if (db_.get()) { | 1209 if (db_.get()) { |
1210 // If some "in progress" entries were not updated when Chrome exited, they | 1210 // If some "in progress" entries were not updated when Chrome exited, they |
1211 // need to be cleaned up. | 1211 // need to be cleaned up. |
1212 db_->CleanUpInProgressEntries(); | 1212 db_->CleanUpInProgressEntries(); |
1213 } | 1213 } |
1214 } | 1214 } |
1215 | 1215 |
1216 // Update a particular download entry. | 1216 // Update a particular download entry. |
1217 void HistoryBackend::UpdateDownload( | 1217 void HistoryBackend::UpdateDownload( |
1218 const content::DownloadPersistentStoreInfo& data) { | 1218 const DownloadPersistentStoreInfo& data) { |
1219 if (db_.get()) | 1219 if (db_.get()) |
1220 db_->UpdateDownload(data); | 1220 db_->UpdateDownload(data); |
1221 } | 1221 } |
1222 | 1222 |
1223 // Update the path of a particular download entry. | 1223 // Create a new download entry and pass back the db_handle to it. |
1224 void HistoryBackend::UpdateDownloadPath(const FilePath& path, | 1224 void HistoryBackend::CreateDownload( |
1225 int64 db_handle) { | 1225 const DownloadPersistentStoreInfo& history_info, |
| 1226 const HistoryService::DownloadCreateCallback& callback) { |
| 1227 int64 db_handle = 0; |
1226 if (db_.get()) | 1228 if (db_.get()) |
1227 db_->UpdateDownloadPath(path, db_handle); | 1229 db_handle = db_->CreateDownload(history_info); |
| 1230 callback.Run(db_handle); |
1228 } | 1231 } |
1229 | 1232 |
1230 // Create a new download entry and pass back the db_handle to it. | 1233 void HistoryBackend::GetVisibleVisitCountToHostSimple( |
1231 void HistoryBackend::CreateDownload( | 1234 const GURL& url, |
1232 scoped_refptr<DownloadCreateRequest> request, | 1235 const HistoryService::GetVisibleVisitCountToHostSimpleCallback& callback) { |
1233 int32 id, | 1236 int count = 0; |
1234 const content::DownloadPersistentStoreInfo& history_info) { | 1237 Time first_visit; |
1235 int64 db_handle = 0; | 1238 const bool success = db_.get() && |
1236 if (!request->canceled()) { | 1239 db_->GetVisibleVisitCountToHost(url, &count, &first_visit); |
1237 if (db_.get()) | 1240 callback.Run(success, count, first_visit); |
1238 db_handle = db_->CreateDownload(history_info); | |
1239 request->ForwardResult(id, db_handle); | |
1240 } | |
1241 } | 1241 } |
1242 | 1242 |
1243 void HistoryBackend::RemoveDownload(int64 db_handle) { | 1243 void HistoryBackend::RemoveDownloads(const std::set<int64>& handles) { |
1244 if (db_.get()) | 1244 if (db_.get()) |
1245 db_->RemoveDownload(db_handle); | 1245 db_->RemoveDownloads(handles); |
1246 } | |
1247 | |
1248 void HistoryBackend::RemoveDownloadsBetween(const Time remove_begin, | |
1249 const Time remove_end) { | |
1250 if (db_.get()) | |
1251 db_->RemoveDownloadsBetween(remove_begin, remove_end); | |
1252 } | 1246 } |
1253 | 1247 |
1254 void HistoryBackend::QueryHistory(scoped_refptr<QueryHistoryRequest> request, | 1248 void HistoryBackend::QueryHistory(scoped_refptr<QueryHistoryRequest> request, |
1255 const string16& text_query, | 1249 const string16& text_query, |
1256 const QueryOptions& options) { | 1250 const QueryOptions& options) { |
1257 if (request->canceled()) | 1251 if (request->canceled()) |
1258 return; | 1252 return; |
1259 | 1253 |
1260 TimeTicks beginning_time = TimeTicks::Now(); | 1254 TimeTicks beginning_time = TimeTicks::Now(); |
1261 | 1255 |
(...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2393 // Removing the icon mapping may have orphaned the associated favicon so | 2387 // Removing the icon mapping may have orphaned the associated favicon so |
2394 // we must recheck it. This is not super fast, but this case will get | 2388 // we must recheck it. This is not super fast, but this case will get |
2395 // triggered rarely, since normally a page will always map to the same | 2389 // triggered rarely, since normally a page will always map to the same |
2396 // favicon IDs. It will mostly happen for favicons we import. | 2390 // favicon IDs. It will mostly happen for favicons we import. |
2397 if (!thumbnail_db_->HasMappingFor(m->icon_id)) | 2391 if (!thumbnail_db_->HasMappingFor(m->icon_id)) |
2398 thumbnail_db_->DeleteFavicon(m->icon_id); | 2392 thumbnail_db_->DeleteFavicon(m->icon_id); |
2399 mappings_changed = true; | 2393 mappings_changed = true; |
2400 } | 2394 } |
2401 } | 2395 } |
2402 | 2396 |
2403 for (size_t i = 0; i < unmapped_icon_ids.size(); ++i ) { | 2397 for (size_t i = 0; i < unmapped_icon_ids.size(); ++i) { |
2404 thumbnail_db_->AddIconMapping(page_url, unmapped_icon_ids[i]); | 2398 thumbnail_db_->AddIconMapping(page_url, unmapped_icon_ids[i]); |
2405 mappings_changed = true; | 2399 mappings_changed = true; |
2406 } | 2400 } |
2407 return mappings_changed; | 2401 return mappings_changed; |
2408 } | 2402 } |
2409 | 2403 |
2410 void HistoryBackend::Commit() { | 2404 void HistoryBackend::Commit() { |
2411 if (!db_.get()) | 2405 if (!db_.get()) |
2412 return; | 2406 return; |
2413 | 2407 |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2793 info.url_id = visit.url_id; | 2787 info.url_id = visit.url_id; |
2794 info.time = visit.visit_time; | 2788 info.time = visit.visit_time; |
2795 info.transition = visit.transition; | 2789 info.transition = visit.transition; |
2796 // If we don't have a delegate yet during setup or shutdown, we will drop | 2790 // If we don't have a delegate yet during setup or shutdown, we will drop |
2797 // these notifications. | 2791 // these notifications. |
2798 if (delegate_.get()) | 2792 if (delegate_.get()) |
2799 delegate_->NotifyVisitDBObserversOnAddVisit(info); | 2793 delegate_->NotifyVisitDBObserversOnAddVisit(info); |
2800 } | 2794 } |
2801 | 2795 |
2802 } // namespace history | 2796 } // namespace history |
OLD | NEW |