Chromium Code Reviews| Index: components/precache/core/precache_session_tables.h |
| diff --git a/components/precache/core/precache_session_tables.h b/components/precache/core/precache_session_tables.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..31e77c190e95decba19637f7050f9fd38c3ab751 |
| --- /dev/null |
| +++ b/components/precache/core/precache_session_tables.h |
| @@ -0,0 +1,104 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_PRECACHE_CORE_PRECACHE_SESSION_TABLES_H_ |
| +#define COMPONENTS_PRECACHE_CORE_PRECACHE_SESSION_TABLES_H_ |
| + |
| +#include <list> |
| +#include <map> |
| + |
| +#include "base/macros.h" |
| +#include "base/time/time.h" |
| +#include "url/gurl.h" |
| + |
| +namespace base { |
| +class TimeTicks; |
| +} |
| + |
| +namespace sql { |
| +class Connection; |
| +} |
| + |
| +namespace precache { |
| + |
| +enum URLType { |
| + MANIFEST = 1, |
| + RESOURCE = 2 |
| +}; |
| + |
| +// Denotes the type of statistics that is recorded. |
| +enum StatType { |
|
sclittle
2016/05/10 00:01:27
Instead of using a Type enum, could you either use
bengr
2016/05/19 01:25:44
Done.
|
| + // The sum total of all bytes in precache responses. |
| + TOTAL_RESPONSE_BYTES = 0, |
| + |
| + // The total precache response bytes retrieved over the network. |
| + NETWORK_RESPONSE_BYTES = 1, |
| + |
| + // The initial number of manifest URLs to fetch. |
| + NUM_MANIFEST_URLS_TO_FETCH = 2, |
| + |
| + // The initial start time of the precache session, before any interruptions. |
| + START_TIME = 3 |
| +}; |
| + |
| +class PrecacheSessionTables { |
| + public: |
| + PrecacheSessionTables(); |
| + virtual ~PrecacheSessionTables(); |
| + |
| + // Initialize the precache task URL table for use with the specified database |
| + // connection. The caller keeps ownership of |db|, and |db| must not be null. |
| + // Init must be called before any other methods. |
| + bool Init(sql::Connection* db); |
| + |
| + // Get the manifest and resource URLs that still need to be fetched. |
| + void GetURLs(std::list<GURL>* manifests, |
| + std::list<GURL>* resources); |
| + |
| + // Get statistics from the last time the precache session state was stored. |
| + void GetStatistics(int64_t* total_response_bytes, |
| + int64_t* network_response_bytes, |
| + int64_t* num_manifest_urls_to_fetch, |
| + base::TimeTicks* start_time); |
| + |
| + // Store outstanding manifest and resource URLs for the current precache |
| + // session. |
| + void StoreURLs(const std::list<GURL>& manifests, |
| + const std::list<GURL>& resources); |
| + |
| + // Store statistics for the current precache session. |
| + void StoreStatistics(int64_t total_response_bytes, |
| + int64_t network_response_bytes, |
| + int64_t num_manifest_urls_to_fetch, |
| + const base::TimeTicks& start_time); |
| + |
| + // Remove all manifest and resource URLs from the database. |
| + void ClearURLs(); |
| + |
| + // Remove all statistics from the database. |
| + void ClearStatistics(); |
| + |
| + private: |
| + // Adds a URL to the table. A |MANIFEST| type |
| + // is a url of a manifest to be fetched; A |RESOURCE| type is a url of a |
| + // page resource to be fetched. Replaces the row if one already exists. |
| + void StoreURL(const GURL& url, URLType type); |
| + |
| + // Adds a statistic of type |StatType| with a corresponding value. Overwrites |
| + // the value if it already exists. |
| + void StoreStatistic(StatType type, int64_t value); |
| + |
| + // Deletes the row from the table that has the given URL, if it exists. |
| + void DeleteURL(const GURL& url); |
| + |
| + bool CreateTablesIfNonExistent(); |
| + |
| + // Non-owned pointer. |
| + sql::Connection* db_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PrecacheSessionTables); |
| +}; |
| + |
| +} // namespace precache |
| +#endif // COMPONENTS_PRECACHE_CORE_PRECACHE_SESSION_TABLES_H_ |