Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_PRECACHE_CORE_PRECACHE_DATABASE_H_ | |
| 6 #define COMPONENTS_PRECACHE_CORE_PRECACHE_DATABASE_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/memory/ref_counted.h" | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/threading/non_thread_safe.h" | |
| 12 | |
| 13 class GURL; | |
| 14 | |
| 15 namespace base { | |
| 16 class Time; | |
| 17 } | |
| 18 | |
| 19 namespace sql { | |
| 20 class Connection; | |
| 21 } | |
| 22 | |
| 23 namespace precache { | |
| 24 | |
| 25 class PrecacheStatisticsTable; | |
| 26 class PrecacheURLTable; | |
| 27 | |
| 28 // Class that tracks information related to precaching. This class can be | |
| 29 // constructed or destroyed on any threads, but all other methods must be called | |
| 30 // on the same thread (e.g. the DB thread). | |
| 31 class PrecacheDatabase : public base::RefCountedThreadSafe<PrecacheDatabase>, | |
| 32 base::NonThreadSafe { | |
| 33 public: | |
| 34 // A PrecacheDatabase can be constructed on any thread. | |
| 35 PrecacheDatabase(); | |
| 36 | |
| 37 // Initializes the precache database with the specified connection. The | |
| 38 // PrecacheDatabase takes ownership of |db|. Init must be called before any | |
| 39 // other methods. | |
| 40 void Init(scoped_ptr<sql::Connection> db); | |
| 41 | |
| 42 // Reports UMA of precache statistics for days up to and including the day of | |
| 43 // |end_date|. The precache statistics for these days are deleted from the | |
| 44 // database after they have been reported, and expired precache history is | |
| 45 // deleted from the precache URL table. | |
| 46 void ReportAndDeleteOldStats(const base::Time& end_date); | |
| 47 | |
| 48 // Update precache-related metrics in response to a URL being fetched. | |
| 49 // |is_precache| indicates whether or not the fetch is a precache request, and | |
| 50 // |is_connection_cellular| indicates whether the current network connection | |
| 51 // is a cellular network. | |
| 52 void RecordURLFetched(const GURL& url, const base::Time& fetch_time, | |
| 53 int64 size, bool was_cached, bool is_precache, | |
| 54 bool is_connection_cellular); | |
|
davidben
2013/11/06 23:50:53
What if you split this into RecordURLFetched and R
sclittle
2013/11/09 01:07:58
Done.
| |
| 55 | |
| 56 private: | |
| 57 friend class base::RefCountedThreadSafe<PrecacheDatabase>; | |
| 58 friend class PrecacheDatabaseTest; | |
| 59 | |
| 60 ~PrecacheDatabase(); | |
| 61 | |
| 62 bool IsDatabaseAccessible() const; | |
| 63 | |
| 64 scoped_ptr<sql::Connection> db_; | |
| 65 | |
| 66 // Table that keeps track of URLs that are in the cache because of precaching, | |
| 67 // and wouldn't be in the cache otherwise. | |
| 68 scoped_ptr<PrecacheURLTable> precache_url_table_; | |
| 69 | |
| 70 // Table that keeps track of daily cumulative statistics that are relevant to | |
| 71 // precaching. | |
| 72 scoped_ptr<PrecacheStatisticsTable> precache_statistics_table_; | |
| 73 | |
| 74 DISALLOW_COPY_AND_ASSIGN(PrecacheDatabase); | |
| 75 }; | |
| 76 | |
| 77 } // namespace precache | |
| 78 | |
| 79 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_DATABASE_H_ | |
| OLD | NEW |