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 <list> | 7 #include <list> |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
17 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
20 #include "base/time.h" | 20 #include "base/time.h" |
21 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
22 #include "chrome/browser/autocomplete/history_url_provider.h" | 22 #include "chrome/browser/autocomplete/history_url_provider.h" |
23 #include "chrome/browser/bookmarks/bookmark_service.h" | 23 #include "chrome/browser/bookmarks/bookmark_service.h" |
24 #include "chrome/browser/cancelable_request.h" | 24 #include "chrome/browser/cancelable_request.h" |
| 25 #include "chrome/browser/history/download_persistent_store_info.h" |
25 #include "chrome/browser/history/history_notifications.h" | 26 #include "chrome/browser/history/history_notifications.h" |
26 #include "chrome/browser/history/history_publisher.h" | 27 #include "chrome/browser/history/history_publisher.h" |
27 #include "chrome/browser/history/in_memory_history_backend.h" | 28 #include "chrome/browser/history/in_memory_history_backend.h" |
28 #include "chrome/browser/history/page_usage_data.h" | 29 #include "chrome/browser/history/page_usage_data.h" |
29 #include "chrome/browser/history/top_sites.h" | 30 #include "chrome/browser/history/top_sites.h" |
30 #include "chrome/browser/history/visit_filter.h" | 31 #include "chrome/browser/history/visit_filter.h" |
31 #include "chrome/common/chrome_constants.h" | 32 #include "chrome/common/chrome_constants.h" |
32 #include "chrome/common/chrome_notification_types.h" | 33 #include "chrome/common/chrome_notification_types.h" |
33 #include "chrome/common/url_constants.h" | 34 #include "chrome/common/url_constants.h" |
34 #include "content/public/browser/download_persistent_store_info.h" | |
35 #include "googleurl/src/gurl.h" | 35 #include "googleurl/src/gurl.h" |
36 #include "grit/chromium_strings.h" | 36 #include "grit/chromium_strings.h" |
37 #include "grit/generated_resources.h" | 37 #include "grit/generated_resources.h" |
38 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 38 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
39 | 39 |
40 #if defined(OS_ANDROID) | 40 #if defined(OS_ANDROID) |
41 #include "chrome/browser/history/android/android_provider_backend.h" | 41 #include "chrome/browser/history/android/android_provider_backend.h" |
42 #endif | 42 #endif |
43 | 43 |
44 using base::Time; | 44 using base::Time; |
(...skipping 1144 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 1228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2490 info.url_id = visit.url_id; | 2484 info.url_id = visit.url_id; |
2491 info.time = visit.visit_time; | 2485 info.time = visit.visit_time; |
2492 info.transition = visit.transition; | 2486 info.transition = visit.transition; |
2493 // If we don't have a delegate yet during setup or shutdown, we will drop | 2487 // If we don't have a delegate yet during setup or shutdown, we will drop |
2494 // these notifications. | 2488 // these notifications. |
2495 if (delegate_.get()) | 2489 if (delegate_.get()) |
2496 delegate_->NotifyVisitDBObserversOnAddVisit(info); | 2490 delegate_->NotifyVisitDBObserversOnAddVisit(info); |
2497 } | 2491 } |
2498 | 2492 |
2499 } // namespace history | 2493 } // namespace history |
OLD | NEW |