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..d5904b7b987c442dc197fdab6c49d856d85128e4 |
| --- /dev/null |
| +++ b/components/precache/core/precache_database.h |
| @@ -0,0 +1,67 @@ |
| +// 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/non_thread_safe.h" |
| +#include "base/time/time.h" |
| +#include "url/gurl.h" |
| + |
| +namespace sql { |
| +class Connection; |
| +} |
| + |
| +namespace precache { |
| + |
| +class PrecacheURLTable; |
| +class PrecacheStatisticsTable; |
| + |
| +// 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>, |
| + base::NonThreadSafe { |
| + 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(sql::Connection* db); |
|
mmenke
2013/10/29 18:23:34
May want to pass in the db as a scoped_ptr<sql::Co
sclittle
2013/10/29 23:40:45
Done.
|
| + |
| + // Reports UMA of precache statistics for days up to and including the day of |
| + // |end_date|. 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. |end_date| is passed by value and not |
| + // by const reference so that this method can be posted on a thread. |
| + void ReportAndDeleteOldStats(base::Time end_date); |
| + |
| + // Update metrics in response to a URL being fetched. Parameters are passed by |
| + // value and not by const reference so that this method can be posted on a |
| + // thread. |
| + void RecordURLFetched(GURL url, base::Time fetch_time, int64 size, |
| + bool was_cached, bool is_precaching, bool is_cellular); |
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<PrecacheDatabase>; |
| + friend class PrecacheDatabaseTest; |
| + ~PrecacheDatabase(); |
|
mmenke
2013/10/29 18:23:34
nit: Think there should be a blank line between f
sclittle
2013/10/29 23:40:45
Done.
|
| + |
| + bool CantAccessDatabase(); |
| + |
| + scoped_ptr<sql::Connection> db_; |
| + scoped_ptr<PrecacheURLTable> precache_url_table_; |
| + scoped_ptr<PrecacheStatisticsTable> precache_statistics_table_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PrecacheDatabase); |
| +}; |
| + |
| +} // namespace precache |
| + |
| +#endif // COMPONENTS_PRECACHE_CORE_PRECACHE_DATABASE_H_ |