OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_PRECACHE_CORE_PRECACHE_REFERRER_HOST_TABLE_H_ |
| 6 #define COMPONENTS_PRECACHE_CORE_PRECACHE_REFERRER_HOST_TABLE_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 |
| 10 #include <map> |
| 11 #include <string> |
| 12 |
| 13 #include "base/macros.h" |
| 14 #include "base/time/time.h" |
| 15 |
| 16 namespace sql { |
| 17 class Connection; |
| 18 } |
| 19 |
| 20 namespace precache { |
| 21 |
| 22 struct PrecacheReferrerHostEntry { |
| 23 static const int64_t kInvalidId; |
| 24 |
| 25 PrecacheReferrerHostEntry() : id(kInvalidId) {} |
| 26 PrecacheReferrerHostEntry(int64_t id, |
| 27 const std::string& referrer_host, |
| 28 int64_t manifest_id, |
| 29 const base::Time& time) |
| 30 : id(id), |
| 31 referrer_host(referrer_host), |
| 32 manifest_id(manifest_id), |
| 33 time(time) {} |
| 34 |
| 35 // Comparison for testing. |
| 36 bool operator==(const PrecacheReferrerHostEntry& entry) const; |
| 37 |
| 38 int64_t id; |
| 39 std::string referrer_host; |
| 40 int64_t manifest_id; |
| 41 base::Time time; |
| 42 }; |
| 43 |
| 44 class PrecacheReferrerHostTable { |
| 45 public: |
| 46 PrecacheReferrerHostTable(); |
| 47 ~PrecacheReferrerHostTable(); |
| 48 |
| 49 // Initialize the precache referrer host table for use with the specified |
| 50 // database connection. The caller keeps ownership of |db|, and |db| must not |
| 51 // be NULL. Init must be called before any other methods. |
| 52 bool Init(sql::Connection* db); |
| 53 |
| 54 // Returns the referrer host information about |referrer_host|. |
| 55 PrecacheReferrerHostEntry GetReferrerHost(const std::string& referrer_host); |
| 56 |
| 57 // Updates the referrer host information about |referrer_host|. |
| 58 int64_t UpdateReferrerHost(const std::string& referrer_host, |
| 59 int64_t manifest_id, |
| 60 const base::Time& time); |
| 61 |
| 62 // Deletes entries that were created before the time of |delete_end|. |
| 63 void DeleteAllEntriesBefore(const base::Time& delete_end); |
| 64 |
| 65 // Delete all entries. |
| 66 void DeleteAll(); |
| 67 |
| 68 // Used by tests to get the contents of the table. |
| 69 std::map<std::string, PrecacheReferrerHostEntry> GetAllDataForTesting(); |
| 70 |
| 71 private: |
| 72 bool CreateTableIfNonExistent(); |
| 73 |
| 74 // Not owned by |this|. |
| 75 sql::Connection* db_; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(PrecacheReferrerHostTable); |
| 78 }; |
| 79 |
| 80 } // namespace precache |
| 81 |
| 82 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_REFERRER_HOST_TABLE_H_ |
OLD | NEW |