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

Side by Side Diff: components/history/core/browser/history_backend.cc

Issue 2107493002: Offer user to send feedback from profile error dialog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ios compile error Created 4 years, 5 months 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
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 "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
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 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 base::FilePath thumbnail_name = GetFaviconsFileName(); 644 base::FilePath thumbnail_name = GetFaviconsFileName();
642 645
643 // Delete the old index database files which are no longer used. 646 // Delete the old index database files which are no longer used.
644 DeleteFTSIndexDatabases(); 647 DeleteFTSIndexDatabases();
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_.
652 db_->set_error_callback(base::Bind(&HistoryBackend::DatabaseErrorCallback, 654 db_->set_error_callback(base::Bind(&HistoryBackend::DatabaseErrorCallback,
653 base::Unretained(this))); 655 base::Unretained(this)));
654 656
655 sql::InitStatus status = db_->Init(history_name); 657 sql::InitStatus status = db_->Init(history_name);
656 switch (status) { 658 switch (status) {
657 case sql::INIT_OK: 659 case sql::INIT_OK:
658 break; 660 break;
659 case sql::INIT_TOO_NEW:
660 delegate_->NotifyProfileError(status);
661 db_.reset();
662 return;
663 case sql::INIT_FAILURE: { 661 case sql::INIT_FAILURE: {
664 // A null db_ will cause all calls on this object to notice this error 662 // 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 663 // and to not continue. If the error callback scheduled killing the
666 // database, the task it posted has not executed yet. Try killing the 664 // database, the task it posted has not executed yet. Try killing the
667 // database now before we close it. 665 // database now before we close it.
668 bool kill_db = scheduled_kill_db_; 666 bool kill_db = scheduled_kill_db_;
669 if (kill_db) 667 if (kill_db)
670 KillHistoryDatabase(); 668 KillHistoryDatabase();
671 UMA_HISTOGRAM_BOOLEAN("History.AttemptedToFixProfileError", kill_db); 669 UMA_HISTOGRAM_BOOLEAN("History.AttemptedToFixProfileError", kill_db);
672 delegate_->NotifyProfileError(status); 670 } // Falls through.
671 case sql::INIT_TOO_NEW: {
672 const std::string corrupted_file_name =
673 history_name.DirName().BaseName().AsUTF8Unsafe() + "/" +
674 history_name.BaseName().AsUTF8Unsafe();
675 base::StringAppendF(&db_diagnostics_, "Corrupted file: %s\n",
676 corrupted_file_name.c_str());
677 delegate_->NotifyProfileError(status, db_diagnostics_);
673 db_.reset(); 678 db_.reset();
674 return; 679 return;
675 } 680 }
676 default: 681 default:
677 NOTREACHED(); 682 NOTREACHED();
678 } 683 }
679 684
680 // Fill the in-memory database and send it back to the history service on the 685 // Fill the in-memory database and send it back to the history service on the
681 // main thread. 686 // main thread.
682 { 687 {
(...skipping 1720 matching lines...) Expand 10 before | Expand all | Expand 10 after
2403 // that we can delete all associated icons in the case of deleting an 2408 // that we can delete all associated icons in the case of deleting an
2404 // unvisited bookmarked URL. 2409 // unvisited bookmarked URL.
2405 if (visits.empty()) 2410 if (visits.empty())
2406 expirer_.DeleteURL(*i); // There are no more visits; nuke the URL. 2411 expirer_.DeleteURL(*i); // There are no more visits; nuke the URL.
2407 } 2412 }
2408 } 2413 }
2409 2414
2410 void HistoryBackend::DatabaseErrorCallback(int error, sql::Statement* stmt) { 2415 void HistoryBackend::DatabaseErrorCallback(int error, sql::Statement* stmt) {
2411 if (!scheduled_kill_db_ && sql::IsErrorCatastrophic(error)) { 2416 if (!scheduled_kill_db_ && sql::IsErrorCatastrophic(error)) {
2412 scheduled_kill_db_ = true; 2417 scheduled_kill_db_ = true;
2418
2419 db_diagnostics_ = db_->GetDiagnosticInfo(error, stmt);
2420
2413 // Don't just do the close/delete here, as we are being called by |db| and 2421 // Don't just do the close/delete here, as we are being called by |db| and
2414 // that seems dangerous. 2422 // that seems dangerous.
2415 // TODO(shess): Consider changing KillHistoryDatabase() to use 2423 // TODO(shess): Consider changing KillHistoryDatabase() to use
2416 // RazeAndClose(). Then it can be cleared immediately. 2424 // RazeAndClose(). Then it can be cleared immediately.
2417 task_runner_->PostTask( 2425 task_runner_->PostTask(
2418 FROM_HERE, base::Bind(&HistoryBackend::KillHistoryDatabase, this)); 2426 FROM_HERE, base::Bind(&HistoryBackend::KillHistoryDatabase, this));
2419 } 2427 }
2420 } 2428 }
2421 2429
2422 void HistoryBackend::KillHistoryDatabase() { 2430 void HistoryBackend::KillHistoryDatabase() {
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
2623 // transaction is currently open. 2631 // transaction is currently open.
2624 db_->CommitTransaction(); 2632 db_->CommitTransaction();
2625 db_->Vacuum(); 2633 db_->Vacuum();
2626 db_->BeginTransaction(); 2634 db_->BeginTransaction();
2627 db_->GetStartDate(&first_recorded_time_); 2635 db_->GetStartDate(&first_recorded_time_);
2628 2636
2629 return true; 2637 return true;
2630 } 2638 }
2631 2639
2632 } // namespace history 2640 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698