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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1b20c3599bd8ba0da89203e8e6b9732fd0b7f877 |
| --- /dev/null |
| +++ b/components/precache/core/precache_database.h |
| @@ -0,0 +1,86 @@ |
| +// Copyright 2013 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_DATABASE_H_ |
| +#define COMPONENTS_PRECACHE_CORE_PRECACHE_DATABASE_H_ |
| + |
| +#include "base/basictypes.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/threading/thread_checker.h" |
| + |
| +class GURL; |
| + |
| +namespace base { |
| +class Time; |
| +} |
| + |
| +namespace sql { |
| +class Connection; |
| +} |
| + |
| +namespace precache { |
| + |
| +class PrecacheStatisticsTable; |
| +class PrecacheURLTable; |
| + |
| +// Class that tracks information related to precaching. This class can be |
| +// constructed or destroyed on any threads, but all other methods must be called |
| +// on the same thread (e.g. the DB thread). |
| +class PrecacheDatabase : public base::RefCountedThreadSafe<PrecacheDatabase> { |
| + public: |
| + // A PrecacheDatabase can be constructed on any thread. |
| + PrecacheDatabase(); |
| + |
| + // Initializes the precache database with the specified connection. The |
| + // PrecacheDatabase takes ownership of |db|. Init must be called before any |
| + // other methods. |
| + void Init(scoped_ptr<sql::Connection> db); |
| + |
| + // Reports UMA of precache statistics for days up to but not including the day |
| + // of |current_time|. The precache statistics for these days are deleted from |
| + // the database after they have been reported, and expired precache history is |
| + // deleted from the precache URL table. |
| + void ReportAndDeleteOldStats(const base::Time& current_time); |
| + |
| + // Update precache-related metrics in response to a URL being fetched, where |
| + // the fetch was motivated by precaching. |
| + void RecordURLPrecached(const GURL& url, const base::Time& fetch_time, |
| + int64 size, bool was_cached); |
| + |
| + // Update precache-related metrics in response to a URL being fetched, where |
| + // the fetch was not motivated by precaching. |is_connection_cellular| |
| + // indicates whether the current network connection is a cellular network. |
| + void RecordURLFetched(const GURL& url, const base::Time& fetch_time, |
| + int64 size, bool was_cached, |
| + bool is_connection_cellular); |
|
Scott Hess - ex-Googler
2013/11/27 01:32:33
While the |size| storage is 64-bit signed integer
sclittle
2013/12/02 21:12:52
The value for |size| would originally come from UR
|
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<PrecacheDatabase>; |
| + friend class PrecacheDatabaseTest; |
| + |
| + ~PrecacheDatabase(); |
| + |
| + bool IsDatabaseAccessible() const; |
| + |
| + scoped_ptr<sql::Connection> db_; |
| + |
| + // Table that keeps track of URLs that are in the cache because of precaching, |
| + // and wouldn't be in the cache otherwise. |
| + scoped_ptr<PrecacheURLTable> precache_url_table_; |
| + |
| + // Table that keeps track of daily cumulative statistics that are relevant to |
| + // precaching. |
| + scoped_ptr<PrecacheStatisticsTable> precache_statistics_table_; |
| + |
| + // ThreadChecker used to ensure that all methods other than the constructor |
| + // or destructor are called on the same thread. |
| + base::ThreadChecker thread_checker_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PrecacheDatabase); |
| +}; |
| + |
| +} // namespace precache |
| + |
| +#endif // COMPONENTS_PRECACHE_CORE_PRECACHE_DATABASE_H_ |