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> |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 DownloadDatabase (stores a list of downloads) | 61 DownloadDatabase (stores a list of downloads) |
62 VisitDatabase (stores a list of visits for the URLs) | 62 VisitDatabase (stores a list of visits for the URLs) |
63 VisitSegmentDatabase (stores groups of URLs for the most visited view). | 63 VisitSegmentDatabase (stores groups of URLs for the most visited view). |
64 | 64 |
65 ExpireHistoryBackend (manages deleting things older than 3 months) | 65 ExpireHistoryBackend (manages deleting things older than 3 months) |
66 */ | 66 */ |
67 | 67 |
68 namespace history { | 68 namespace history { |
69 | 69 |
70 namespace { | 70 namespace { |
71 | |
71 void RunUnlessCanceled( | 72 void RunUnlessCanceled( |
72 const base::Closure& closure, | 73 const base::Closure& closure, |
73 const base::CancelableTaskTracker::IsCanceledCallback& is_canceled) { | 74 const base::CancelableTaskTracker::IsCanceledCallback& is_canceled) { |
74 if (!is_canceled.Run()) | 75 if (!is_canceled.Run()) |
75 closure.Run(); | 76 closure.Run(); |
76 } | 77 } |
78 | |
79 void NullErrorHandler(int error, sql::Statement* stmt) { | |
80 // Does nothing. Prevents DCHECKING on SQLITE errors on Debug builds. | |
81 } | |
Scott Hess - ex-Googler
2016/07/10 05:16:52
This makes me suspect you have something going on
afakhry
2016/07/11 16:47:45
When I try to prevent reentrant error callbacks in
Scott Hess - ex-Googler
2016/07/13 01:18:46
I have written a number of tests which test induce
afakhry
2016/07/13 19:57:58
I think this is not needed now. What I used to do
| |
82 | |
77 } // namespace | 83 } // namespace |
78 | 84 |
79 // How long we'll wait to do a commit, so that things are batched together. | 85 // How long we'll wait to do a commit, so that things are batched together. |
80 const int kCommitIntervalSeconds = 10; | 86 const int kCommitIntervalSeconds = 10; |
81 | 87 |
82 // The amount of time before we re-fetch the favicon. | 88 // The amount of time before we re-fetch the favicon. |
83 const int kFaviconRefetchDays = 7; | 89 const int kFaviconRefetchDays = 7; |
84 | 90 |
85 // The maximum number of items we'll allow in the redirect list before | 91 // The maximum number of items we'll allow in the redirect list before |
86 // deleting some. | 92 // deleting some. |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 } | 205 } |
200 | 206 |
201 // HistoryBackend -------------------------------------------------------------- | 207 // HistoryBackend -------------------------------------------------------------- |
202 | 208 |
203 HistoryBackend::HistoryBackend( | 209 HistoryBackend::HistoryBackend( |
204 Delegate* delegate, | 210 Delegate* delegate, |
205 std::unique_ptr<HistoryBackendClient> backend_client, | 211 std::unique_ptr<HistoryBackendClient> backend_client, |
206 scoped_refptr<base::SequencedTaskRunner> task_runner) | 212 scoped_refptr<base::SequencedTaskRunner> task_runner) |
207 : delegate_(delegate), | 213 : delegate_(delegate), |
208 scheduled_kill_db_(false), | 214 scheduled_kill_db_(false), |
215 error_callback_(base::Bind(&HistoryBackend::DatabaseErrorCallback, | |
216 base::Unretained(this))), | |
209 expirer_(this, backend_client.get(), task_runner), | 217 expirer_(this, backend_client.get(), task_runner), |
210 recent_redirects_(kMaxRedirectCount), | 218 recent_redirects_(kMaxRedirectCount), |
211 backend_destroy_message_loop_(nullptr), | 219 backend_destroy_message_loop_(nullptr), |
212 segment_queried_(false), | 220 segment_queried_(false), |
213 backend_client_(std::move(backend_client)), | 221 backend_client_(std::move(backend_client)), |
214 task_runner_(task_runner) {} | 222 task_runner_(task_runner) {} |
215 | 223 |
216 HistoryBackend::~HistoryBackend() { | 224 HistoryBackend::~HistoryBackend() { |
217 DCHECK(!scheduled_commit_) << "Deleting without cleanup"; | 225 DCHECK(!scheduled_commit_) << "Deleting without cleanup"; |
218 STLDeleteContainerPointers(queued_history_db_tasks_.begin(), | 226 STLDeleteContainerPointers(queued_history_db_tasks_.begin(), |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
641 base::FilePath thumbnail_name = GetFaviconsFileName(); | 649 base::FilePath thumbnail_name = GetFaviconsFileName(); |
642 | 650 |
643 // Delete the old index database files which are no longer used. | 651 // Delete the old index database files which are no longer used. |
644 DeleteFTSIndexDatabases(); | 652 DeleteFTSIndexDatabases(); |
645 | 653 |
646 // History database. | 654 // History database. |
647 db_.reset(new HistoryDatabase( | 655 db_.reset(new HistoryDatabase( |
648 history_database_params.download_interrupt_reason_none, | 656 history_database_params.download_interrupt_reason_none, |
649 history_database_params.download_interrupt_reason_crash)); | 657 history_database_params.download_interrupt_reason_crash)); |
650 | 658 |
651 // Unretained to avoid a ref loop with db_. | 659 db_->set_error_callback(error_callback_); |
652 db_->set_error_callback(base::Bind(&HistoryBackend::DatabaseErrorCallback, | |
653 base::Unretained(this))); | |
654 | 660 |
655 sql::InitStatus status = db_->Init(history_name); | 661 sql::InitStatus status = db_->Init(history_name); |
656 switch (status) { | 662 switch (status) { |
657 case sql::INIT_OK: | 663 case sql::INIT_OK: |
658 break; | 664 break; |
659 case sql::INIT_TOO_NEW: | 665 case sql::INIT_TOO_NEW: |
660 delegate_->NotifyProfileError(status); | 666 db_diagnostics_["Corrupted file"] = history_name.AsUTF8Unsafe(); |
667 delegate_->NotifyProfileError(status, db_diagnostics_); | |
661 db_.reset(); | 668 db_.reset(); |
662 return; | 669 return; |
663 case sql::INIT_FAILURE: { | 670 case sql::INIT_FAILURE: { |
664 // A null db_ will cause all calls on this object to notice this error | 671 // A null db_ will cause all calls on this object to notice this error |
665 // and to not continue. If the error callback scheduled killing the | 672 // and to not continue. If the error callback scheduled killing the |
666 // database, the task it posted has not executed yet. Try killing the | 673 // database, the task it posted has not executed yet. Try killing the |
667 // database now before we close it. | 674 // database now before we close it. |
668 bool kill_db = scheduled_kill_db_; | 675 bool kill_db = scheduled_kill_db_; |
669 if (kill_db) | 676 if (kill_db) |
670 KillHistoryDatabase(); | 677 KillHistoryDatabase(); |
671 UMA_HISTOGRAM_BOOLEAN("History.AttemptedToFixProfileError", kill_db); | 678 UMA_HISTOGRAM_BOOLEAN("History.AttemptedToFixProfileError", kill_db); |
672 delegate_->NotifyProfileError(status); | 679 db_diagnostics_["Corrupted file"] = history_name.AsUTF8Unsafe(); |
680 delegate_->NotifyProfileError(status, db_diagnostics_); | |
673 db_.reset(); | 681 db_.reset(); |
674 return; | 682 return; |
675 } | 683 } |
676 default: | 684 default: |
677 NOTREACHED(); | 685 NOTREACHED(); |
678 } | 686 } |
679 | 687 |
680 // Fill the in-memory database and send it back to the history service on the | 688 // Fill the in-memory database and send it back to the history service on the |
681 // main thread. | 689 // main thread. |
682 { | 690 { |
(...skipping 1720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2403 // that we can delete all associated icons in the case of deleting an | 2411 // that we can delete all associated icons in the case of deleting an |
2404 // unvisited bookmarked URL. | 2412 // unvisited bookmarked URL. |
2405 if (visits.empty()) | 2413 if (visits.empty()) |
2406 expirer_.DeleteURL(*i); // There are no more visits; nuke the URL. | 2414 expirer_.DeleteURL(*i); // There are no more visits; nuke the URL. |
2407 } | 2415 } |
2408 } | 2416 } |
2409 | 2417 |
2410 void HistoryBackend::DatabaseErrorCallback(int error, sql::Statement* stmt) { | 2418 void HistoryBackend::DatabaseErrorCallback(int error, sql::Statement* stmt) { |
2411 if (!scheduled_kill_db_ && sql::IsErrorCatastrophic(error)) { | 2419 if (!scheduled_kill_db_ && sql::IsErrorCatastrophic(error)) { |
2412 scheduled_kill_db_ = true; | 2420 scheduled_kill_db_ = true; |
2421 | |
2422 // Gather diagnostic info, but prevent reentrant error callbacks. | |
2423 db_->set_error_callback(base::Bind(&NullErrorHandler)); | |
2424 db_diagnostics_ = db_->GetDiagnosticMap(); | |
michaeln
2016/07/12 20:05:32
This function is similar to Connection::ReportDiag
Scott Hess - ex-Googler
2016/07/13 01:18:46
This is reasonable - note the comment in that code
afakhry
2016/07/13 19:57:58
Done.
| |
2425 db_->set_error_callback(error_callback_); | |
2426 | |
2413 // Don't just do the close/delete here, as we are being called by |db| and | 2427 // Don't just do the close/delete here, as we are being called by |db| and |
2414 // that seems dangerous. | 2428 // that seems dangerous. |
2415 // TODO(shess): Consider changing KillHistoryDatabase() to use | 2429 // TODO(shess): Consider changing KillHistoryDatabase() to use |
2416 // RazeAndClose(). Then it can be cleared immediately. | 2430 // RazeAndClose(). Then it can be cleared immediately. |
2417 task_runner_->PostTask( | 2431 task_runner_->PostTask( |
2418 FROM_HERE, base::Bind(&HistoryBackend::KillHistoryDatabase, this)); | 2432 FROM_HERE, base::Bind(&HistoryBackend::KillHistoryDatabase, this)); |
2419 } | 2433 } |
2420 } | 2434 } |
2421 | 2435 |
2422 void HistoryBackend::KillHistoryDatabase() { | 2436 void HistoryBackend::KillHistoryDatabase() { |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2623 // transaction is currently open. | 2637 // transaction is currently open. |
2624 db_->CommitTransaction(); | 2638 db_->CommitTransaction(); |
2625 db_->Vacuum(); | 2639 db_->Vacuum(); |
2626 db_->BeginTransaction(); | 2640 db_->BeginTransaction(); |
2627 db_->GetStartDate(&first_recorded_time_); | 2641 db_->GetStartDate(&first_recorded_time_); |
2628 | 2642 |
2629 return true; | 2643 return true; |
2630 } | 2644 } |
2631 | 2645 |
2632 } // namespace history | 2646 } // namespace history |
OLD | NEW |