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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 } | 282 } |
283 | 283 |
284 base::FilePath HistoryBackend::GetThumbnailFileName() const { | 284 base::FilePath HistoryBackend::GetThumbnailFileName() const { |
285 return history_dir_.Append(kThumbnailsFilename); | 285 return history_dir_.Append(kThumbnailsFilename); |
286 } | 286 } |
287 | 287 |
288 base::FilePath HistoryBackend::GetFaviconsFileName() const { | 288 base::FilePath HistoryBackend::GetFaviconsFileName() const { |
289 return history_dir_.Append(kFaviconsFilename); | 289 return history_dir_.Append(kFaviconsFilename); |
290 } | 290 } |
291 | 291 |
292 base::FilePath HistoryBackend::GetArchivedFileName() const { | |
293 return history_dir_.Append(kArchivedHistoryFilename); | |
294 } | |
295 | |
296 SegmentID HistoryBackend::GetLastSegmentID(VisitID from_visit) { | 292 SegmentID HistoryBackend::GetLastSegmentID(VisitID from_visit) { |
297 // Set is used to detect referrer loops. Should not happen, but can | 293 // Set is used to detect referrer loops. Should not happen, but can |
298 // if the database is corrupt. | 294 // if the database is corrupt. |
299 std::set<VisitID> visit_set; | 295 std::set<VisitID> visit_set; |
300 VisitID visit_id = from_visit; | 296 VisitID visit_id = from_visit; |
301 while (visit_id) { | 297 while (visit_id) { |
302 VisitRow row; | 298 VisitRow row; |
303 if (!db_->GetRowForVisit(visit_id, &row)) | 299 if (!db_->GetRowForVisit(visit_id, &row)) |
304 return 0; | 300 return 0; |
305 if (row.segment_id) | 301 if (row.segment_id) |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 // the blocks the caller, yet allows other messages through. For this reason | 607 // the blocks the caller, yet allows other messages through. For this reason |
612 // we only set db_ to the created database if creation is successful. That | 608 // we only set db_ to the created database if creation is successful. That |
613 // way other methods won't do anything as db_ is still null. | 609 // way other methods won't do anything as db_ is still null. |
614 | 610 |
615 TimeTicks beginning_time = TimeTicks::Now(); | 611 TimeTicks beginning_time = TimeTicks::Now(); |
616 | 612 |
617 // Compute the file names. | 613 // Compute the file names. |
618 history_dir_ = history_database_params.history_dir; | 614 history_dir_ = history_database_params.history_dir; |
619 base::FilePath history_name = history_dir_.Append(kHistoryFilename); | 615 base::FilePath history_name = history_dir_.Append(kHistoryFilename); |
620 base::FilePath thumbnail_name = GetFaviconsFileName(); | 616 base::FilePath thumbnail_name = GetFaviconsFileName(); |
621 base::FilePath archived_name = GetArchivedFileName(); | |
622 | 617 |
623 // Delete the old index database files which are no longer used. | 618 // Delete the old index database files which are no longer used. |
624 DeleteFTSIndexDatabases(); | 619 DeleteFTSIndexDatabases(); |
625 | 620 |
626 // History database. | 621 // History database. |
627 db_.reset(new HistoryDatabase( | 622 db_.reset(new HistoryDatabase( |
628 history_database_params.download_interrupt_reason_none, | 623 history_database_params.download_interrupt_reason_none, |
629 history_database_params.download_interrupt_reason_crash)); | 624 history_database_params.download_interrupt_reason_crash)); |
630 | 625 |
631 // Unretained to avoid a ref loop with db_. | 626 // Unretained to avoid a ref loop with db_. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 if (thumbnail_db_->Init(thumbnail_name) != sql::INIT_OK) { | 670 if (thumbnail_db_->Init(thumbnail_name) != sql::INIT_OK) { |
676 // Unlike the main database, we don't error out when the database is too | 671 // Unlike the main database, we don't error out when the database is too |
677 // new because this error is much less severe. Generally, this shouldn't | 672 // new because this error is much less severe. Generally, this shouldn't |
678 // happen since the thumbnail and main database versions should be in sync. | 673 // happen since the thumbnail and main database versions should be in sync. |
679 // We'll just continue without thumbnails & favicons in this case or any | 674 // We'll just continue without thumbnails & favicons in this case or any |
680 // other error. | 675 // other error. |
681 LOG(WARNING) << "Could not initialize the thumbnail database."; | 676 LOG(WARNING) << "Could not initialize the thumbnail database."; |
682 thumbnail_db_.reset(); | 677 thumbnail_db_.reset(); |
683 } | 678 } |
684 | 679 |
685 // Nuke any files corresponding to the legacy Archived History Database, which | |
686 // previously retained expired (> 3 months old) history entries, but, in the | |
687 // end, was not used for much, and consequently has been removed as of M37. | |
688 // TODO(engedy): Remove this code after the end of 2014. | |
689 sql::Connection::Delete(archived_name); | |
690 | |
691 // Generate the history and thumbnail database metrics only after performing | 680 // Generate the history and thumbnail database metrics only after performing |
692 // any migration work. | 681 // any migration work. |
693 if (base::RandInt(1, 100) == 50) { | 682 if (base::RandInt(1, 100) == 50) { |
694 // Only do this computation sometimes since it can be expensive. | 683 // Only do this computation sometimes since it can be expensive. |
695 db_->ComputeDatabaseMetrics(history_name); | 684 db_->ComputeDatabaseMetrics(history_name); |
696 if (thumbnail_db_) | 685 if (thumbnail_db_) |
697 thumbnail_db_->ComputeDatabaseMetrics(); | 686 thumbnail_db_->ComputeDatabaseMetrics(); |
698 } | 687 } |
699 | 688 |
700 expirer_.SetDatabases(db_.get(), thumbnail_db_.get()); | 689 expirer_.SetDatabases(db_.get(), thumbnail_db_.get()); |
(...skipping 2007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2708 // transaction is currently open. | 2697 // transaction is currently open. |
2709 db_->CommitTransaction(); | 2698 db_->CommitTransaction(); |
2710 db_->Vacuum(); | 2699 db_->Vacuum(); |
2711 db_->BeginTransaction(); | 2700 db_->BeginTransaction(); |
2712 db_->GetStartDate(&first_recorded_time_); | 2701 db_->GetStartDate(&first_recorded_time_); |
2713 | 2702 |
2714 return true; | 2703 return true; |
2715 } | 2704 } |
2716 | 2705 |
2717 } // namespace history | 2706 } // namespace history |
OLD | NEW |