Chromium Code Reviews| Index: components/precache/core/precache_database.h |
| diff --git a/components/precache/core/precache_database.h b/components/precache/core/precache_database.h |
| index 94d045107b83c744dae7d00bf50e5dcdcedd826b..a0e22022696a8aa56aba95db5464d2e19de734bf 100644 |
| --- a/components/precache/core/precache_database.h |
| +++ b/components/precache/core/precache_database.h |
| @@ -7,6 +7,7 @@ |
| #include <stdint.h> |
| +#include <list> |
| #include <memory> |
| #include <string> |
| #include <vector> |
| @@ -14,8 +15,11 @@ |
| #include "base/callback.h" |
| #include "base/containers/hash_tables.h" |
| #include "base/macros.h" |
| +#include "base/memory/ref_counted.h" |
| #include "base/memory/weak_ptr.h" |
| #include "base/threading/thread_checker.h" |
| +#include "components/precache/core/precache_fetcher.h" |
| +#include "components/precache/core/precache_session_tables.h" |
| #include "components/precache/core/precache_url_table.h" |
| class GURL; |
| @@ -31,6 +35,56 @@ class Connection; |
| namespace precache { |
| +// Represents the precache work that is left over after a precache session |
| +// is interrupted. |
| +class UnfinishedWork : public base::RefCountedThreadSafe<UnfinishedWork> { |
|
sclittle
2016/05/10 00:01:26
See my comment in precache_fetcher.cc about passin
bengr
2016/05/19 01:25:44
Done.
|
| + public: |
| + // Constructor used when saving unfinished work to storage. |
| + // |manifest_urls_to_fetch| and |resource_urls_to_fetch| are the |
| + // remaining manifest and resource URLs to fetch. |total_response_bytes| |
| + // and |network_response_bytes| are counts of bytes receieved, the former |
| + // including bytes received from local cache. |num_manifest_urls_to_fetch| |
| + // is the initial number of manifest URLs that needed to be fetched. The |
| + // |start_time_of_session| is the time the precache session began, before |
| + // any interruptions. |
| + UnfinishedWork(const std::list<GURL>& manifest_urls_to_fetch, |
| + const std::list<GURL>& resource_urls_to_fetch, |
| + int64_t total_response_bytes, |
| + int64_t network_response_bytes, |
| + int64_t num_manifest_urls_to_fetch, |
| + const base::TimeTicks& start_time_of_session); |
| + |
| + // Constructor used when retrieving unfinished work from storage. No work |
| + // saved before |earliest_start_time_of_session| will be retrieved. |
| + explicit UnfinishedWork( |
| + const base::TimeTicks& earliest_start_time_of_session); |
| + |
| + // Manifest URLs remaining to be fetched. |
| + std::list<GURL> manifests; |
|
sclittle
2016/05/10 00:01:26
If you just have publicly visible members, then co
bengr
2016/05/19 01:25:44
Done.
|
| + |
| + // Resource URLs remaining to be fetched. |
| + std::list<GURL> resources; |
| + |
| + // Count of the total received bytes. |
| + int64_t total_bytes; |
| + |
| + // Count of the total received bytes over the network. |
| + int64_t network_bytes; |
| + |
| + // The total number of manifest URLs that the precache session started with. |
| + int64_t num_manifest_urls; |
| + |
| + // The original time the precache session started, not the time it resumed. |
| + base::TimeTicks start_time; |
|
sclittle
2016/05/10 00:01:26
Should this be base::Time instead? I don't think i
bengr
2016/05/19 01:25:44
Done.
|
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<UnfinishedWork>; |
| + |
| + ~UnfinishedWork(); |
| + |
| + DISALLOW_COPY_AND_ASSIGN(UnfinishedWork); |
| +}; |
| + |
| // Class that tracks information related to precaching. This class may be |
| // constructed on any thread, but all calls to, and destruction of this class |
| // must be done on the the DB thread. |
| @@ -71,6 +125,18 @@ class PrecacheDatabase { |
| int host_rank, |
| bool is_connection_cellular); |
| + // Gets the state required to continue a precache session. |
| + void GetUnfinishedWork(scoped_refptr<UnfinishedWork> unfinished_work); |
| + |
| + // Stores the state required to continue a precache session so that the |
| + // session can be resumed later. |
| + void SaveUnfinishedWork(scoped_refptr<UnfinishedWork> unfinished_work); |
| + |
| + // Clears all precache session state. |
| + void ClearPrecacheSessionState(); |
| + |
| + base::WeakPtr<PrecacheDatabase> GetWeakPtr(); |
| + |
| private: |
| friend class PrecacheDatabaseTest; |
| @@ -97,6 +163,10 @@ class PrecacheDatabase { |
| // then this table will not be up to date until the next call to Flush(). |
| PrecacheURLTable precache_url_table_; |
| + // Tables that persist the state required to pause and resume a precache |
| + // session. |
| + PrecacheSessionTables precache_session_tables_; |
| + |
| // A vector of write operations to be run on the database. |
| std::vector<base::Closure> buffered_writes_; |