Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: components/precache/core/precache_database.h

Issue 27047003: Precache tracking database (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@precache
Patch Set: Addressed comments Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 {
Scott Hess - ex-Googler 2013/11/19 18:47:48 Why are you subclassing base::NonThreadSafe rather
sclittle 2013/11/19 23:27:10 Changed to ThreadChecker.
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 but not including the day
43 // of |current_time|. The precache statistics for these days are deleted from
44 // the database after they have been reported, and expired precache history is
45 // deleted from the precache URL table.
46 void ReportAndDeleteOldStats(const base::Time& current_time);
47
48 // Update precache-related metrics in response to a URL being fetched, where
49 // the fetch was motivated by precaching.
50 void RecordURLPrecached(const GURL& url, const base::Time& fetch_time,
51 int64 size, bool was_cached);
52
53 // Update precache-related metrics in response to a URL being fetched, where
54 // the fetch was not motivated by precaching. |is_connection_cellular|
55 // indicates whether the current network connection is a cellular network.
56 void RecordURLFetched(const GURL& url, const base::Time& fetch_time,
57 int64 size, bool was_cached,
58 bool is_connection_cellular);
59
60 private:
61 friend class base::RefCountedThreadSafe<PrecacheDatabase>;
62 friend class PrecacheDatabaseTest;
63
64 ~PrecacheDatabase();
65
66 bool IsDatabaseAccessible() const;
67
68 scoped_ptr<sql::Connection> db_;
69
70 // Table that keeps track of URLs that are in the cache because of precaching,
71 // and wouldn't be in the cache otherwise.
72 scoped_ptr<PrecacheURLTable> precache_url_table_;
73
74 // Table that keeps track of daily cumulative statistics that are relevant to
75 // precaching.
76 scoped_ptr<PrecacheStatisticsTable> precache_statistics_table_;
77
78 DISALLOW_COPY_AND_ASSIGN(PrecacheDatabase);
79 };
80
81 } // namespace precache
82
83 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698