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> |
11 #include <memory> | 11 #include <memory> |
12 #include <set> | 12 #include <set> |
13 #include <utility> | 13 #include <utility> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/bind.h" | 16 #include "base/bind.h" |
17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
18 #include "base/files/file_enumerator.h" | 18 #include "base/files/file_enumerator.h" |
19 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
20 #include "base/metrics/histogram_macros.h" | 20 #include "base/metrics/histogram_macros.h" |
21 #include "base/rand_util.h" | 21 #include "base/rand_util.h" |
22 #include "base/sequenced_task_runner.h" | 22 #include "base/sequenced_task_runner.h" |
23 #include "base/single_thread_task_runner.h" | 23 #include "base/single_thread_task_runner.h" |
24 #include "base/strings/string_util.h" | 24 #include "base/strings/string_util.h" |
25 #include "base/strings/stringprintf.h" | |
25 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
26 #include "base/time/time.h" | 27 #include "base/time/time.h" |
27 #include "build/build_config.h" | 28 #include "build/build_config.h" |
28 #include "components/favicon_base/select_favicon_frames.h" | 29 #include "components/favicon_base/select_favicon_frames.h" |
29 #include "components/history/core/browser/download_constants.h" | 30 #include "components/history/core/browser/download_constants.h" |
30 #include "components/history/core/browser/download_row.h" | 31 #include "components/history/core/browser/download_row.h" |
31 #include "components/history/core/browser/history_backend_client.h" | 32 #include "components/history/core/browser/history_backend_client.h" |
32 #include "components/history/core/browser/history_backend_observer.h" | 33 #include "components/history/core/browser/history_backend_observer.h" |
33 #include "components/history/core/browser/history_constants.h" | 34 #include "components/history/core/browser/history_constants.h" |
34 #include "components/history/core/browser/history_database.h" | 35 #include "components/history/core/browser/history_database.h" |
(...skipping 26 matching lines...) Expand all Loading... | |
61 DownloadDatabase (stores a list of downloads) | 62 DownloadDatabase (stores a list of downloads) |
62 VisitDatabase (stores a list of visits for the URLs) | 63 VisitDatabase (stores a list of visits for the URLs) |
63 VisitSegmentDatabase (stores groups of URLs for the most visited view). | 64 VisitSegmentDatabase (stores groups of URLs for the most visited view). |
64 | 65 |
65 ExpireHistoryBackend (manages deleting things older than 3 months) | 66 ExpireHistoryBackend (manages deleting things older than 3 months) |
66 */ | 67 */ |
67 | 68 |
68 namespace history { | 69 namespace history { |
69 | 70 |
70 namespace { | 71 namespace { |
72 | |
71 void RunUnlessCanceled( | 73 void RunUnlessCanceled( |
72 const base::Closure& closure, | 74 const base::Closure& closure, |
73 const base::CancelableTaskTracker::IsCanceledCallback& is_canceled) { | 75 const base::CancelableTaskTracker::IsCanceledCallback& is_canceled) { |
74 if (!is_canceled.Run()) | 76 if (!is_canceled.Run()) |
75 closure.Run(); | 77 closure.Run(); |
76 } | 78 } |
79 | |
77 } // namespace | 80 } // namespace |
78 | 81 |
79 // How long we'll wait to do a commit, so that things are batched together. | 82 // How long we'll wait to do a commit, so that things are batched together. |
80 const int kCommitIntervalSeconds = 10; | 83 const int kCommitIntervalSeconds = 10; |
81 | 84 |
82 // The amount of time before we re-fetch the favicon. | 85 // The amount of time before we re-fetch the favicon. |
83 const int kFaviconRefetchDays = 7; | 86 const int kFaviconRefetchDays = 7; |
84 | 87 |
85 // The maximum number of items we'll allow in the redirect list before | 88 // The maximum number of items we'll allow in the redirect list before |
86 // deleting some. | 89 // deleting some. |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
649 history_database_params.download_interrupt_reason_crash)); | 652 history_database_params.download_interrupt_reason_crash)); |
650 | 653 |
651 // Unretained to avoid a ref loop with db_. | 654 // Unretained to avoid a ref loop with db_. |
652 db_->set_error_callback(base::Bind(&HistoryBackend::DatabaseErrorCallback, | 655 db_->set_error_callback(base::Bind(&HistoryBackend::DatabaseErrorCallback, |
653 base::Unretained(this))); | 656 base::Unretained(this))); |
654 | 657 |
655 sql::InitStatus status = db_->Init(history_name); | 658 sql::InitStatus status = db_->Init(history_name); |
656 switch (status) { | 659 switch (status) { |
657 case sql::INIT_OK: | 660 case sql::INIT_OK: |
658 break; | 661 break; |
659 case sql::INIT_TOO_NEW: | |
660 delegate_->NotifyProfileError(status); | |
661 db_.reset(); | |
662 return; | |
663 case sql::INIT_FAILURE: { | 662 case sql::INIT_FAILURE: { |
664 // A null db_ will cause all calls on this object to notice this error | 663 // 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 | 664 // and to not continue. If the error callback scheduled killing the |
666 // database, the task it posted has not executed yet. Try killing the | 665 // database, the task it posted has not executed yet. Try killing the |
667 // database now before we close it. | 666 // database now before we close it. |
668 bool kill_db = scheduled_kill_db_; | 667 bool kill_db = scheduled_kill_db_; |
669 if (kill_db) | 668 if (kill_db) |
670 KillHistoryDatabase(); | 669 KillHistoryDatabase(); |
671 UMA_HISTOGRAM_BOOLEAN("History.AttemptedToFixProfileError", kill_db); | 670 UMA_HISTOGRAM_BOOLEAN("History.AttemptedToFixProfileError", kill_db); |
672 delegate_->NotifyProfileError(status); | 671 } // Falls through. |
672 case sql::INIT_TOO_NEW: { | |
673 const std::string corrupted_file_name = | |
674 history_name.DirName().BaseName().AsUTF8Unsafe() + "/" + | |
675 history_name.BaseName().AsUTF8Unsafe(); | |
sky
2016/07/18 21:06:01
Why are you building the name like this and not us
afakhry
2016/07/26 23:33:47
shess@, michaeln@ and I have agreed to not use the
sky
2016/07/26 23:47:50
Might the user want to try removing the file? In w
| |
676 base::StringAppendF(&db_diagnostics_, "Corrupted file: %s\n", | |
sky
2016/07/18 21:06:01
If we're going to show this to users, which it app
afakhry
2016/07/26 23:33:47
Please take a look at this screenshot: https://dri
| |
677 corrupted_file_name.c_str()); | |
678 delegate_->NotifyProfileError(status, db_diagnostics_); | |
673 db_.reset(); | 679 db_.reset(); |
674 return; | 680 return; |
675 } | 681 } |
676 default: | 682 default: |
677 NOTREACHED(); | 683 NOTREACHED(); |
678 } | 684 } |
679 | 685 |
680 // Fill the in-memory database and send it back to the history service on the | 686 // Fill the in-memory database and send it back to the history service on the |
681 // main thread. | 687 // main thread. |
682 { | 688 { |
(...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 | 2409 // that we can delete all associated icons in the case of deleting an |
2404 // unvisited bookmarked URL. | 2410 // unvisited bookmarked URL. |
2405 if (visits.empty()) | 2411 if (visits.empty()) |
2406 expirer_.DeleteURL(*i); // There are no more visits; nuke the URL. | 2412 expirer_.DeleteURL(*i); // There are no more visits; nuke the URL. |
2407 } | 2413 } |
2408 } | 2414 } |
2409 | 2415 |
2410 void HistoryBackend::DatabaseErrorCallback(int error, sql::Statement* stmt) { | 2416 void HistoryBackend::DatabaseErrorCallback(int error, sql::Statement* stmt) { |
2411 if (!scheduled_kill_db_ && sql::IsErrorCatastrophic(error)) { | 2417 if (!scheduled_kill_db_ && sql::IsErrorCatastrophic(error)) { |
2412 scheduled_kill_db_ = true; | 2418 scheduled_kill_db_ = true; |
2419 | |
2420 db_diagnostics_ = db_->GetDiagnosticInfo(error, stmt); | |
2421 | |
2413 // Don't just do the close/delete here, as we are being called by |db| and | 2422 // Don't just do the close/delete here, as we are being called by |db| and |
2414 // that seems dangerous. | 2423 // that seems dangerous. |
2415 // TODO(shess): Consider changing KillHistoryDatabase() to use | 2424 // TODO(shess): Consider changing KillHistoryDatabase() to use |
2416 // RazeAndClose(). Then it can be cleared immediately. | 2425 // RazeAndClose(). Then it can be cleared immediately. |
2417 task_runner_->PostTask( | 2426 task_runner_->PostTask( |
2418 FROM_HERE, base::Bind(&HistoryBackend::KillHistoryDatabase, this)); | 2427 FROM_HERE, base::Bind(&HistoryBackend::KillHistoryDatabase, this)); |
2419 } | 2428 } |
2420 } | 2429 } |
2421 | 2430 |
2422 void HistoryBackend::KillHistoryDatabase() { | 2431 void HistoryBackend::KillHistoryDatabase() { |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2623 // transaction is currently open. | 2632 // transaction is currently open. |
2624 db_->CommitTransaction(); | 2633 db_->CommitTransaction(); |
2625 db_->Vacuum(); | 2634 db_->Vacuum(); |
2626 db_->BeginTransaction(); | 2635 db_->BeginTransaction(); |
2627 db_->GetStartDate(&first_recorded_time_); | 2636 db_->GetStartDate(&first_recorded_time_); |
2628 | 2637 |
2629 return true; | 2638 return true; |
2630 } | 2639 } |
2631 | 2640 |
2632 } // namespace history | 2641 } // namespace history |
OLD | NEW |