| 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 "chrome/browser/history/expire_history_backend.h" | 5 #include "chrome/browser/history/expire_history_backend.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 // space savings by deleting them quickly. | 40 // space savings by deleting them quickly. |
| 41 const int kEarlyExpirationAdvanceDays = 3; | 41 const int kEarlyExpirationAdvanceDays = 3; |
| 42 | 42 |
| 43 // Reads all types of visits starting from beginning of time to the given end | 43 // Reads all types of visits starting from beginning of time to the given end |
| 44 // time. This is the most general reader. | 44 // time. This is the most general reader. |
| 45 class AllVisitsReader : public ExpiringVisitsReader { | 45 class AllVisitsReader : public ExpiringVisitsReader { |
| 46 public: | 46 public: |
| 47 virtual bool Read(base::Time end_time, | 47 virtual bool Read(base::Time end_time, |
| 48 HistoryDatabase* db, | 48 HistoryDatabase* db, |
| 49 VisitVector* visits, | 49 VisitVector* visits, |
| 50 int max_visits) const OVERRIDE { | 50 int max_visits) const override { |
| 51 DCHECK(db) << "must have a database to operate upon"; | 51 DCHECK(db) << "must have a database to operate upon"; |
| 52 DCHECK(visits) << "visit vector has to exist in order to populate it"; | 52 DCHECK(visits) << "visit vector has to exist in order to populate it"; |
| 53 | 53 |
| 54 db->GetAllVisitsInRange(base::Time(), end_time, max_visits, visits); | 54 db->GetAllVisitsInRange(base::Time(), end_time, max_visits, visits); |
| 55 // When we got the maximum number of visits we asked for, we say there could | 55 // When we got the maximum number of visits we asked for, we say there could |
| 56 // be additional things to expire now. | 56 // be additional things to expire now. |
| 57 return static_cast<int>(visits->size()) == max_visits; | 57 return static_cast<int>(visits->size()) == max_visits; |
| 58 } | 58 } |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 // Reads only AUTO_SUBFRAME visits, within a computed range. The range is | 61 // Reads only AUTO_SUBFRAME visits, within a computed range. The range is |
| 62 // computed as follows: | 62 // computed as follows: |
| 63 // * |begin_time| is read from the meta table. This value is updated whenever | 63 // * |begin_time| is read from the meta table. This value is updated whenever |
| 64 // there are no more additional visits to expire by this reader. | 64 // there are no more additional visits to expire by this reader. |
| 65 // * |end_time| is advanced forward by a constant (kEarlyExpirationAdvanceDay), | 65 // * |end_time| is advanced forward by a constant (kEarlyExpirationAdvanceDay), |
| 66 // but not past the current time. | 66 // but not past the current time. |
| 67 class AutoSubframeVisitsReader : public ExpiringVisitsReader { | 67 class AutoSubframeVisitsReader : public ExpiringVisitsReader { |
| 68 public: | 68 public: |
| 69 virtual bool Read(base::Time end_time, | 69 virtual bool Read(base::Time end_time, |
| 70 HistoryDatabase* db, | 70 HistoryDatabase* db, |
| 71 VisitVector* visits, | 71 VisitVector* visits, |
| 72 int max_visits) const OVERRIDE { | 72 int max_visits) const override { |
| 73 DCHECK(db) << "must have a database to operate upon"; | 73 DCHECK(db) << "must have a database to operate upon"; |
| 74 DCHECK(visits) << "visit vector has to exist in order to populate it"; | 74 DCHECK(visits) << "visit vector has to exist in order to populate it"; |
| 75 | 75 |
| 76 base::Time begin_time = db->GetEarlyExpirationThreshold(); | 76 base::Time begin_time = db->GetEarlyExpirationThreshold(); |
| 77 // Advance |end_time| to expire early. | 77 // Advance |end_time| to expire early. |
| 78 base::Time early_end_time = end_time + | 78 base::Time early_end_time = end_time + |
| 79 base::TimeDelta::FromDays(kEarlyExpirationAdvanceDays); | 79 base::TimeDelta::FromDays(kEarlyExpirationAdvanceDays); |
| 80 | 80 |
| 81 // We don't want to set the early expiration threshold to a time in the | 81 // We don't want to set the early expiration threshold to a time in the |
| 82 // future. | 82 // future. |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 HistoryClient* ExpireHistoryBackend::GetHistoryClient() { | 516 HistoryClient* ExpireHistoryBackend::GetHistoryClient() { |
| 517 // We use the history client to determine if a URL is bookmarked. The data is | 517 // We use the history client to determine if a URL is bookmarked. The data is |
| 518 // loaded on a separate thread and may not be done by the time we get here. | 518 // loaded on a separate thread and may not be done by the time we get here. |
| 519 // We therefore block until the bookmarks have finished loading. | 519 // We therefore block until the bookmarks have finished loading. |
| 520 if (history_client_) | 520 if (history_client_) |
| 521 history_client_->BlockUntilBookmarksLoaded(); | 521 history_client_->BlockUntilBookmarksLoaded(); |
| 522 return history_client_; | 522 return history_client_; |
| 523 } | 523 } |
| 524 | 524 |
| 525 } // namespace history | 525 } // namespace history |
| OLD | NEW |