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 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
645 | 648 |
646 // History database. | 649 // History database. |
647 db_.reset(new HistoryDatabase( | 650 db_.reset(new HistoryDatabase( |
648 history_database_params.download_interrupt_reason_none, | 651 history_database_params.download_interrupt_reason_none, |
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 |
658 db_diagnostics_.clear(); | |
655 sql::InitStatus status = db_->Init(history_name); | 659 sql::InitStatus status = db_->Init(history_name); |
656 switch (status) { | 660 switch (status) { |
657 case sql::INIT_OK: | 661 case sql::INIT_OK: |
658 break; | 662 break; |
659 case sql::INIT_TOO_NEW: | |
660 delegate_->NotifyProfileError(status); | |
661 db_.reset(); | |
662 return; | |
663 case sql::INIT_FAILURE: { | 663 case sql::INIT_FAILURE: { |
664 // A null db_ will cause all calls on this object to notice this error | 664 // 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 | 665 // and to not continue. If the error callback scheduled killing the |
666 // database, the task it posted has not executed yet. Try killing the | 666 // database, the task it posted has not executed yet. Try killing the |
667 // database now before we close it. | 667 // database now before we close it. |
668 bool kill_db = scheduled_kill_db_; | 668 bool kill_db = scheduled_kill_db_; |
669 if (kill_db) | 669 if (kill_db) |
670 KillHistoryDatabase(); | 670 KillHistoryDatabase(); |
671 UMA_HISTOGRAM_BOOLEAN("History.AttemptedToFixProfileError", kill_db); | 671 UMA_HISTOGRAM_BOOLEAN("History.AttemptedToFixProfileError", kill_db); |
672 delegate_->NotifyProfileError(status); | 672 } // Falls through. |
673 case sql::INIT_TOO_NEW: { | |
674 const std::string corrupted_file_name = | |
sky
2016/08/02 13:27:21
You have similar code to this in chrome. Please ex
afakhry
2016/08/02 23:58:24
Yes, absolutely! Thanks.
However, The sql diagnos
sky
2016/08/03 15:19:30
How about sql/?
Also, style guide suggests out par
afakhry
2016/08/03 17:51:23
Yes, it's in sql/error_delegate_util.h.
Done for t
| |
675 history_name.DirName().BaseName().AsUTF8Unsafe() + "/" + | |
676 history_name.BaseName().AsUTF8Unsafe(); | |
677 base::StringAppendF(&db_diagnostics_, "Corrupted file: %s\n", | |
678 corrupted_file_name.c_str()); | |
679 delegate_->NotifyProfileError(status, db_diagnostics_); | |
673 db_.reset(); | 680 db_.reset(); |
674 return; | 681 return; |
675 } | 682 } |
676 default: | 683 default: |
677 NOTREACHED(); | 684 NOTREACHED(); |
678 } | 685 } |
679 | 686 |
680 // Fill the in-memory database and send it back to the history service on the | 687 // Fill the in-memory database and send it back to the history service on the |
681 // main thread. | 688 // main thread. |
682 { | 689 { |
(...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 | 2410 // that we can delete all associated icons in the case of deleting an |
2404 // unvisited bookmarked URL. | 2411 // unvisited bookmarked URL. |
2405 if (visits.empty()) | 2412 if (visits.empty()) |
2406 expirer_.DeleteURL(*i); // There are no more visits; nuke the URL. | 2413 expirer_.DeleteURL(*i); // There are no more visits; nuke the URL. |
2407 } | 2414 } |
2408 } | 2415 } |
2409 | 2416 |
2410 void HistoryBackend::DatabaseErrorCallback(int error, sql::Statement* stmt) { | 2417 void HistoryBackend::DatabaseErrorCallback(int error, sql::Statement* stmt) { |
2411 if (!scheduled_kill_db_ && sql::IsErrorCatastrophic(error)) { | 2418 if (!scheduled_kill_db_ && sql::IsErrorCatastrophic(error)) { |
2412 scheduled_kill_db_ = true; | 2419 scheduled_kill_db_ = true; |
2420 | |
2421 db_diagnostics_ = db_->GetDiagnosticInfo(error, stmt); | |
2422 | |
2413 // Don't just do the close/delete here, as we are being called by |db| and | 2423 // Don't just do the close/delete here, as we are being called by |db| and |
2414 // that seems dangerous. | 2424 // that seems dangerous. |
2415 // TODO(shess): Consider changing KillHistoryDatabase() to use | 2425 // TODO(shess): Consider changing KillHistoryDatabase() to use |
2416 // RazeAndClose(). Then it can be cleared immediately. | 2426 // RazeAndClose(). Then it can be cleared immediately. |
2417 task_runner_->PostTask( | 2427 task_runner_->PostTask( |
2418 FROM_HERE, base::Bind(&HistoryBackend::KillHistoryDatabase, this)); | 2428 FROM_HERE, base::Bind(&HistoryBackend::KillHistoryDatabase, this)); |
2419 } | 2429 } |
2420 } | 2430 } |
2421 | 2431 |
2422 void HistoryBackend::KillHistoryDatabase() { | 2432 void HistoryBackend::KillHistoryDatabase() { |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2623 // transaction is currently open. | 2633 // transaction is currently open. |
2624 db_->CommitTransaction(); | 2634 db_->CommitTransaction(); |
2625 db_->Vacuum(); | 2635 db_->Vacuum(); |
2626 db_->BeginTransaction(); | 2636 db_->BeginTransaction(); |
2627 db_->GetStartDate(&first_recorded_time_); | 2637 db_->GetStartDate(&first_recorded_time_); |
2628 | 2638 |
2629 return true; | 2639 return true; |
2630 } | 2640 } |
2631 | 2641 |
2632 } // namespace history | 2642 } // namespace history |
OLD | NEW |