| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef COMPONENTS_PRECACHE_CORE_PRECACHE_SESSION_TABLE_H_ | 5 #ifndef COMPONENTS_PRECACHE_CORE_PRECACHE_SESSION_TABLE_H_ |
| 6 #define COMPONENTS_PRECACHE_CORE_PRECACHE_SESSION_TABLE_H_ | 6 #define COMPONENTS_PRECACHE_CORE_PRECACHE_SESSION_TABLE_H_ |
| 7 | 7 |
| 8 #include <list> | |
| 9 #include <map> | |
| 10 #include <memory> | 8 #include <memory> |
| 11 | 9 |
| 12 #include "base/macros.h" | 10 #include "base/macros.h" |
| 13 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 14 #include "url/gurl.h" | 12 #include "components/precache/core/proto/quota.pb.h" |
| 15 | |
| 16 namespace base { | |
| 17 class TimeTicks; | |
| 18 } | |
| 19 | 13 |
| 20 namespace sql { | 14 namespace sql { |
| 21 class Connection; | 15 class Connection; |
| 22 } | 16 } |
| 23 | 17 |
| 24 namespace precache { | 18 namespace precache { |
| 25 | 19 |
| 26 class PrecacheUnfinishedWork; | 20 class PrecacheUnfinishedWork; |
| 27 | 21 |
| 28 // Denotes the type of session information being stored. | 22 // Denotes the type of session information being stored. |
| 29 enum SessionDataType { | 23 enum class SessionDataType { |
| 30 // Unfinished work to do sometime later. | 24 // Unfinished work to do sometime later. |
| 31 UNFINISHED_WORK = 0, | 25 UNFINISHED_WORK = 0, |
| 26 |
| 32 // Timestamp of the last precache. | 27 // Timestamp of the last precache. |
| 33 LAST_PRECACHE_TIMESTAMP = 1, | 28 LAST_PRECACHE_TIMESTAMP = 1, |
| 29 |
| 30 // Remaining quota limits. |
| 31 QUOTA = 2, |
| 34 }; | 32 }; |
| 35 | 33 |
| 36 class PrecacheSessionTable { | 34 class PrecacheSessionTable { |
| 37 public: | 35 public: |
| 38 PrecacheSessionTable(); | 36 PrecacheSessionTable(); |
| 39 virtual ~PrecacheSessionTable(); | 37 virtual ~PrecacheSessionTable(); |
| 40 | 38 |
| 41 // Initializes the precache task URL table for use with the specified database | 39 // Initializes the precache task URL table for use with the specified database |
| 42 // connection. The caller keeps ownership of |db|, and |db| must not be null. | 40 // connection. The caller keeps ownership of |db|, and |db| must not be null. |
| 43 // Init must be called before any other methods. | 41 // Init must be called before any other methods. |
| 44 bool Init(sql::Connection* db); | 42 bool Init(sql::Connection* db); |
| 45 | 43 |
| 46 // -- Time since last precache -- | 44 // -- Time since last precache -- |
| 47 | 45 |
| 48 void SetLastPrecacheTimestamp(const base::Time& time); | 46 void SetLastPrecacheTimestamp(const base::Time& time); |
| 49 | 47 |
| 50 // If none present, it will return base::Time(), so it can be checked via | 48 // If none present, it will return base::Time(), so it can be checked via |
| 51 // is_null(). | 49 // is_null(). |
| 52 base::Time GetLastPrecacheTimestamp(); | 50 base::Time GetLastPrecacheTimestamp(); |
| 53 | 51 |
| 54 void DeleteLastPrecacheTimestamp(); | 52 void DeleteLastPrecacheTimestamp(); |
| 55 | 53 |
| 54 // Precache quota. |
| 55 void SaveQuota(const PrecacheQuota& quota); |
| 56 PrecacheQuota GetQuota(); |
| 57 |
| 56 // -- Unfinished work -- | 58 // -- Unfinished work -- |
| 57 | 59 |
| 58 // Stores unfinished work. | 60 // Stores unfinished work. |
| 59 void SaveUnfinishedWork( | 61 void SaveUnfinishedWork( |
| 60 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work); | 62 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work); |
| 61 | 63 |
| 62 // Retrieves unfinished work. | 64 // Retrieves unfinished work. |
| 63 std::unique_ptr<PrecacheUnfinishedWork> GetUnfinishedWork(); | 65 std::unique_ptr<PrecacheUnfinishedWork> GetUnfinishedWork(); |
| 64 | 66 |
| 65 // Removes all unfinished work from the database. | 67 // Removes all unfinished work from the database. |
| 66 void DeleteUnfinishedWork(); | 68 void DeleteUnfinishedWork(); |
| 67 | 69 |
| 68 private: | 70 private: |
| 69 bool CreateTableIfNonExistent(); | 71 bool CreateTableIfNonExistent(); |
| 70 | 72 |
| 73 void SetSessionDataType(SessionDataType id, const std::string& data); |
| 74 std::string GetSessionDataType(SessionDataType id); |
| 75 |
| 71 // Non-owned pointer. | 76 // Non-owned pointer. |
| 72 sql::Connection* db_; | 77 sql::Connection* db_; |
| 73 | 78 |
| 74 DISALLOW_COPY_AND_ASSIGN(PrecacheSessionTable); | 79 DISALLOW_COPY_AND_ASSIGN(PrecacheSessionTable); |
| 75 }; | 80 }; |
| 76 | 81 |
| 77 } // namespace precache | 82 } // namespace precache |
| 78 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_SESSION_TABLE_H_ | 83 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_SESSION_TABLE_H_ |
| OLD | NEW |