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

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 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/thread_checker.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 public:
33 // A PrecacheDatabase can be constructed on any thread.
34 PrecacheDatabase();
35
36 // Initializes the precache database with the specified connection. The
37 // PrecacheDatabase takes ownership of |db|. Init must be called before any
38 // other methods.
39 void Init(scoped_ptr<sql::Connection> db);
40
41 // Reports UMA of precache statistics for days up to but not including the day
42 // of |current_time|. The precache statistics for these days are deleted from
43 // the database after they have been reported, and expired precache history is
44 // deleted from the precache URL table.
45 void ReportAndDeleteOldStats(const base::Time& current_time);
46
47 // Update precache-related metrics in response to a URL being fetched, where
48 // the fetch was motivated by precaching.
49 void RecordURLPrecached(const GURL& url, const base::Time& fetch_time,
50 int64 size, bool was_cached);
51
52 // Update precache-related metrics in response to a URL being fetched, where
53 // the fetch was not motivated by precaching. |is_connection_cellular|
54 // indicates whether the current network connection is a cellular network.
55 void RecordURLFetched(const GURL& url, const base::Time& fetch_time,
56 int64 size, bool was_cached,
57 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
58
59 private:
60 friend class base::RefCountedThreadSafe<PrecacheDatabase>;
61 friend class PrecacheDatabaseTest;
62
63 ~PrecacheDatabase();
64
65 bool IsDatabaseAccessible() const;
66
67 scoped_ptr<sql::Connection> db_;
68
69 // Table that keeps track of URLs that are in the cache because of precaching,
70 // and wouldn't be in the cache otherwise.
71 scoped_ptr<PrecacheURLTable> precache_url_table_;
72
73 // Table that keeps track of daily cumulative statistics that are relevant to
74 // precaching.
75 scoped_ptr<PrecacheStatisticsTable> precache_statistics_table_;
76
77 // ThreadChecker used to ensure that all methods other than the constructor
78 // or destructor are called on the same thread.
79 base::ThreadChecker thread_checker_;
80
81 DISALLOW_COPY_AND_ASSIGN(PrecacheDatabase);
82 };
83
84 } // namespace precache
85
86 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698