Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: chrome/browser/history/history_backend.cc

Issue 10915180: Make DownloadHistory observe manager, items (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: @r168573 Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/common/cancelable_request.h" 25 #include "chrome/browser/common/cancelable_request.h"
26 #include "chrome/browser/history/download_row.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 #include "sql/error_delegate_util.h" 41 #include "sql/error_delegate_util.h"
42 42
43 #if defined(OS_ANDROID) 43 #if defined(OS_ANDROID)
44 #include "chrome/browser/history/android/android_provider_backend.h" 44 #include "chrome/browser/history/android/android_provider_backend.h"
45 #endif 45 #endif
46 46
(...skipping 1238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 void HistoryBackend::CleanUpInProgressEntries() { 1285 void HistoryBackend::CleanUpInProgressEntries() {
1286 if (db_.get()) { 1286 if (db_.get()) {
1287 // If some "in progress" entries were not updated when Chrome exited, they 1287 // If some "in progress" entries were not updated when Chrome exited, they
1288 // need to be cleaned up. 1288 // need to be cleaned up.
1289 db_->CleanUpInProgressEntries(); 1289 db_->CleanUpInProgressEntries();
1290 } 1290 }
1291 } 1291 }
1292 1292
1293 // Update a particular download entry. 1293 // Update a particular download entry.
1294 void HistoryBackend::UpdateDownload( 1294 void HistoryBackend::UpdateDownload(
1295 const content::DownloadPersistentStoreInfo& data) { 1295 const history::DownloadRow& data) {
1296 if (db_.get()) 1296 if (db_.get())
1297 db_->UpdateDownload(data); 1297 db_->UpdateDownload(data);
1298 } 1298 }
1299 1299
1300 // Update the path of a particular download entry.
1301 void HistoryBackend::UpdateDownloadPath(const FilePath& path,
1302 int64 db_handle) {
1303 if (db_.get())
1304 db_->UpdateDownloadPath(path, db_handle);
1305 }
1306
1307 // Create a new download entry and pass back the db_handle to it. 1300 // Create a new download entry and pass back the db_handle to it.
1308 void HistoryBackend::CreateDownload( 1301 void HistoryBackend::CreateDownload(
1309 scoped_refptr<DownloadCreateRequest> request, 1302 scoped_refptr<DownloadCreateRequest> request,
1310 int32 id, 1303 const history::DownloadRow& history_info) {
1311 const content::DownloadPersistentStoreInfo& history_info) {
1312 int64 db_handle = 0; 1304 int64 db_handle = 0;
1313 if (!request->canceled()) { 1305 if (!request->canceled()) {
1314 if (db_.get()) 1306 if (db_.get())
1315 db_handle = db_->CreateDownload(history_info); 1307 db_handle = db_->CreateDownload(history_info);
1316 request->ForwardResult(id, db_handle); 1308 request->ForwardResult(db_handle);
1317 } 1309 }
1318 } 1310 }
1319 1311
1320 void HistoryBackend::RemoveDownload(int64 db_handle) { 1312 void HistoryBackend::RemoveDownloads(const std::set<int64>& handles) {
1321 if (db_.get()) 1313 if (!db_.get())
1322 db_->RemoveDownload(db_handle); 1314 return;
1323 } 1315 int downloads_count_before = db_->CountDownloads();
1324 1316 base::TimeTicks started_removing = base::TimeTicks::Now();
1325 void HistoryBackend::RemoveDownloadsBetween(const Time remove_begin, 1317 // HistoryBackend uses a long-running Transaction that is committed
1326 const Time remove_end) { 1318 // periodically, so this loop doesn't actually hit the disk too hard.
1327 if (db_.get()) 1319 for (std::set<int64>::const_iterator it = handles.begin();
1328 db_->RemoveDownloadsBetween(remove_begin, remove_end); 1320 it != handles.end(); ++it) {
1321 db_->RemoveDownload(*it);
1322 }
1323 base::TimeTicks finished_removing = base::TimeTicks::Now();
1324 int downloads_count_after = db_->CountDownloads();
1325 int num_downloads_deleted = downloads_count_before - downloads_count_after;
1326 if (num_downloads_deleted >= 0) {
1327 UMA_HISTOGRAM_COUNTS("Download.DatabaseRemoveDownloadsCount",
1328 num_downloads_deleted);
1329 base::TimeDelta micros = (1000 * (finished_removing - started_removing));
1330 UMA_HISTOGRAM_TIMES("Download.DatabaseRemoveDownloadsTime", micros);
1331 if (num_downloads_deleted > 0) {
1332 UMA_HISTOGRAM_TIMES("Download.DatabaseRemoveDownloadsTimePerRecord",
1333 (1000 * micros) / num_downloads_deleted);
1334 }
1335 }
1336 int num_downloads_not_deleted = handles.size() - num_downloads_deleted;
1337 if (num_downloads_not_deleted >= 0) {
1338 UMA_HISTOGRAM_COUNTS("Download.DatabaseRemoveDownloadsCountNotRemoved",
1339 num_downloads_not_deleted);
1340 }
1329 } 1341 }
1330 1342
1331 void HistoryBackend::QueryHistory(scoped_refptr<QueryHistoryRequest> request, 1343 void HistoryBackend::QueryHistory(scoped_refptr<QueryHistoryRequest> request,
1332 const string16& text_query, 1344 const string16& text_query,
1333 const QueryOptions& options) { 1345 const QueryOptions& options) {
1334 if (request->canceled()) 1346 if (request->canceled())
1335 return; 1347 return;
1336 1348
1337 TimeTicks beginning_time = TimeTicks::Now(); 1349 TimeTicks beginning_time = TimeTicks::Now();
1338 1350
(...skipping 1584 matching lines...) Expand 10 before | Expand all | Expand 10 after
2923 info.url_id = visit.url_id; 2935 info.url_id = visit.url_id;
2924 info.time = visit.visit_time; 2936 info.time = visit.visit_time;
2925 info.transition = visit.transition; 2937 info.transition = visit.transition;
2926 // If we don't have a delegate yet during setup or shutdown, we will drop 2938 // If we don't have a delegate yet during setup or shutdown, we will drop
2927 // these notifications. 2939 // these notifications.
2928 if (delegate_.get()) 2940 if (delegate_.get())
2929 delegate_->NotifyVisitDBObserversOnAddVisit(info); 2941 delegate_->NotifyVisitDBObserversOnAddVisit(info);
2930 } 2942 }
2931 2943
2932 } // namespace history 2944 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698