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

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

Issue 2123813002: Report Precache.TimeSinceLastPrecache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: gclient sync Created 4 years, 5 months 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
« no previous file with comments | « components/precache/core/BUILD.gn ('k') | components/precache/core/precache_database.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_PRECACHE_CORE_PRECACHE_DATABASE_H_ 5 #ifndef COMPONENTS_PRECACHE_CORE_PRECACHE_DATABASE_H_
6 #define COMPONENTS_PRECACHE_CORE_PRECACHE_DATABASE_H_ 6 #define COMPONENTS_PRECACHE_CORE_PRECACHE_DATABASE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <list> 10 #include <list>
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // Init must be called before any other methods. 51 // Init must be called before any other methods.
52 bool Init(const base::FilePath& db_path); 52 bool Init(const base::FilePath& db_path);
53 53
54 // Deletes precache history from the precache URL table that is more than 60 54 // Deletes precache history from the precache URL table that is more than 60
55 // days older than |current_time|. 55 // days older than |current_time|.
56 void DeleteExpiredPrecacheHistory(const base::Time& current_time); 56 void DeleteExpiredPrecacheHistory(const base::Time& current_time);
57 57
58 // Delete all history entries from the database. 58 // Delete all history entries from the database.
59 void ClearHistory(); 59 void ClearHistory();
60 60
61 // Setter and getter for the last precache timestamp.
62 void SetLastPrecacheTimestamp(const base::Time& time);
63 base::Time GetLastPrecacheTimestamp();
64
61 // Report precache-related metrics in response to a URL being fetched, where 65 // Report precache-related metrics in response to a URL being fetched, where
62 // the fetch was motivated by precaching. 66 // the fetch was motivated by precaching.
63 void RecordURLPrefetch(const GURL& url, 67 void RecordURLPrefetch(const GURL& url,
64 const base::TimeDelta& latency, 68 const base::TimeDelta& latency,
65 const base::Time& fetch_time, 69 const base::Time& fetch_time,
66 int64_t size, 70 int64_t size,
67 bool was_cached); 71 bool was_cached);
68 72
69 // Report precache-related metrics in response to a URL being fetched, where 73 // Report precache-related metrics in response to a URL being fetched, where
70 // the fetch was not motivated by precaching. |is_connection_cellular| 74 // the fetch was not motivated by precaching. |is_connection_cellular|
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 106
103 // Same as Flush(), but also updates the flag |is_flush_posted_| to indicate 107 // Same as Flush(), but also updates the flag |is_flush_posted_| to indicate
104 // that a flush is no longer posted. 108 // that a flush is no longer posted.
105 void PostedFlush(); 109 void PostedFlush();
106 110
107 // Post a call to PostedFlush() on the current thread's MessageLoop, if 111 // Post a call to PostedFlush() on the current thread's MessageLoop, if
108 // |buffered_writes_| is non-empty and there isn't already a flush call 112 // |buffered_writes_| is non-empty and there isn't already a flush call
109 // posted. 113 // posted.
110 void MaybePostFlush(); 114 void MaybePostFlush();
111 115
116 // Records the time since the last precache.
117 void RecordTimeSinceLastPrecache(const base::Time& fetch_time);
118
112 std::unique_ptr<sql::Connection> db_; 119 std::unique_ptr<sql::Connection> db_;
113 120
114 // Table that keeps track of URLs that are in the cache because of precaching, 121 // Table that keeps track of URLs that are in the cache because of precaching,
115 // and wouldn't be in the cache otherwise. If |buffered_writes_| is non-empty, 122 // and wouldn't be in the cache otherwise. If |buffered_writes_| is non-empty,
116 // then this table will not be up to date until the next call to Flush(). 123 // then this table will not be up to date until the next call to Flush().
117 PrecacheURLTable precache_url_table_; 124 PrecacheURLTable precache_url_table_;
118 125
119 // Table that persists state related to a precache session, including 126 // Table that persists state related to a precache session, including
120 // unfinished work to be done. 127 // unfinished work to be done.
121 PrecacheSessionTable precache_session_table_; 128 PrecacheSessionTable precache_session_table_;
122 129
123 // A vector of write operations to be run on the database. 130 // A vector of write operations to be run on the database.
124 std::vector<base::Closure> buffered_writes_; 131 std::vector<base::Closure> buffered_writes_;
125 132
126 // Set of URLs that have been modified in |buffered_writes_|. It's a hash set 133 // Set of URLs that have been modified in |buffered_writes_|. It's a hash set
127 // of strings, and not GURLs, because there is no hash function on GURL. 134 // of strings, and not GURLs, because there is no hash function on GURL.
128 base::hash_set<std::string> buffered_urls_; 135 base::hash_set<std::string> buffered_urls_;
129 136
130 // Flag indicating whether or not a call to Flush() has been posted to run in 137 // Flag indicating whether or not a call to Flush() has been posted to run in
131 // the future. 138 // the future.
132 bool is_flush_posted_; 139 bool is_flush_posted_;
133 140
134 // ThreadChecker used to ensure that all methods other than the constructor 141 // ThreadChecker used to ensure that all methods other than the constructor
135 // or destructor are called on the same thread. 142 // or destructor are called on the same thread.
136 base::ThreadChecker thread_checker_; 143 base::ThreadChecker thread_checker_;
137 144
145 // Time of the last precache. This is a cached copy of
146 // precache_session_table_.GetLastPrecacheTimestamp.
147 base::Time last_precache_timestamp_;
148
149 // This must be the last member of this class.
138 base::WeakPtrFactory<PrecacheDatabase> weak_factory_; 150 base::WeakPtrFactory<PrecacheDatabase> weak_factory_;
139 151
140 DISALLOW_COPY_AND_ASSIGN(PrecacheDatabase); 152 DISALLOW_COPY_AND_ASSIGN(PrecacheDatabase);
141 }; 153 };
142 154
143 } // namespace precache 155 } // namespace precache
144 156
145 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_DATABASE_H_ 157 #endif // COMPONENTS_PRECACHE_CORE_PRECACHE_DATABASE_H_
OLDNEW
« no previous file with comments | « components/precache/core/BUILD.gn ('k') | components/precache/core/precache_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698