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..9f766c5c96f04e58c39b71eabfed13ae9f2a668e |
| --- /dev/null |
| +++ b/components/precache/core/precache_database.h |
| @@ -0,0 +1,68 @@ |
| +// 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; |
|
mmenke
2013/10/30 18:29:08
nit: Alphabetize.
sclittle
2013/10/30 20:29:48
Done.
|
| + |
| +// 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(scoped_ptr<sql::Connection> db); |
| + |
| + // 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. |
|
mmenke
2013/10/30 18:29:08
I don't believe this is true - when you pass by re
sclittle
2013/10/30 20:29:48
Done. I've changed it to pass Time by reference as
|
| + void ReportAndDeleteOldStats(base::Time end_date); |
| + |
| + // Update precache-related 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. |
|
mmenke
2013/10/30 18:29:08
Again, this is not true. Should pass URL by refer
sclittle
2013/10/30 20:29:48
Done.
|
| + void RecordURLFetched(GURL url, base::Time fetch_time, int64 size, |
| + bool was_cached, bool is_precaching, bool is_cellular); |
|
mmenke
2013/10/30 18:29:08
You definitely need to define is_precaching here.
mmenke
2013/10/30 18:29:08
nit: |is_cellular| could be clearer - I suggest i
sclittle
2013/10/30 20:29:48
Done.
sclittle
2013/10/30 20:29:48
It actually meant whether or not we are currently
|
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<PrecacheDatabase>; |
| + friend class PrecacheDatabaseTest; |
| + |
| + ~PrecacheDatabase(); |
| + |
| + bool IsDatabaseAccessible() const; |
| + |
| + 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_ |