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