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