OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_HISTORY_VISIT_DATABASE_H_ | 5 #ifndef CHROME_BROWSER_HISTORY_VISIT_DATABASE_H_ |
6 #define CHROME_BROWSER_HISTORY_VISIT_DATABASE_H_ | 6 #define CHROME_BROWSER_HISTORY_VISIT_DATABASE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/observer_list_threadsafe.h" | |
9 #include "chrome/browser/history/history_types.h" | 10 #include "chrome/browser/history/history_types.h" |
10 | 11 |
11 namespace sql { | 12 namespace sql { |
12 class Connection; | 13 class Connection; |
13 class Statement; | 14 class Statement; |
14 } | 15 } |
15 | 16 |
16 namespace history { | 17 namespace history { |
17 | 18 |
18 class VisitFilter; | 19 class VisitFilter; |
19 | 20 |
21 // Abbreviated information about a visit. | |
22 struct BriefVisitInfo { | |
23 URLID url_id; | |
24 base::Time time; | |
25 content::PageTransition transition; | |
26 }; | |
27 | |
28 // An observer of VisitDatabase. | |
29 class VisitDatabaseObserver { | |
cbentzel
2012/04/17 20:28:16
Should this handle DeleteVisit and UpdateVisit as
tburkard
2012/04/17 20:51:36
I'm not concerned about these for now, the majorit
| |
30 public: | |
31 virtual ~VisitDatabaseObserver() {} | |
32 virtual void OnAddVisit(BriefVisitInfo info) = 0; | |
cbentzel
2012/04/17 20:28:16
Why doesn't this take a const VisitRow& as an argu
tburkard
2012/04/17 20:51:36
Either would work. I figured I'd use BriefVisitIn
cbentzel
2012/04/17 20:57:51
Brett should make the call here - and OWNERS requi
| |
33 }; | |
34 | |
20 // A visit database is one which stores visits for URLs, that is, times and | 35 // A visit database is one which stores visits for URLs, that is, times and |
21 // linking information. A visit database must also be a URLDatabase, as this | 36 // linking information. A visit database must also be a URLDatabase, as this |
22 // modifies tables used by URLs directly and could be thought of as inheriting | 37 // modifies tables used by URLs directly and could be thought of as inheriting |
23 // from URLDatabase. However, this inheritance is not explicit as things would | 38 // from URLDatabase. However, this inheritance is not explicit as things would |
24 // get too complicated and have multiple inheritance. | 39 // get too complicated and have multiple inheritance. |
25 class VisitDatabase { | 40 class VisitDatabase { |
26 public: | 41 public: |
27 // Must call InitVisitTable() before using to make sure the database is | 42 // Must call InitVisitTable() before using to make sure the database is |
28 // initialized. | 43 // initialized. |
29 VisitDatabase(); | 44 VisitDatabase(); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 int* count, | 180 int* count, |
166 base::Time* first_visit); | 181 base::Time* first_visit); |
167 | 182 |
168 // Get the time of the first item in our database. | 183 // Get the time of the first item in our database. |
169 bool GetStartDate(base::Time* first_visit); | 184 bool GetStartDate(base::Time* first_visit); |
170 | 185 |
171 // Get the source information about the given visits. | 186 // Get the source information about the given visits. |
172 void GetVisitsSource(const VisitVector& visits, | 187 void GetVisitsSource(const VisitVector& visits, |
173 VisitSourceMap* sources); | 188 VisitSourceMap* sources); |
174 | 189 |
190 // Adds or removes observers for the VisitDatabase. Should be run on | |
191 // the thread in which the observer would like to be notified. | |
192 void AddVisitDatabaseObserver(VisitDatabaseObserver* observer); | |
193 void RemoveVisitDatabaseObserver(VisitDatabaseObserver* observer); | |
194 | |
195 // Obtains BriefVisitInfo for the specified number of most recent visits | |
196 // from the visit database. | |
197 void GetBriefVisitInfoOfMostRecentVisits( | |
198 int max_visits, | |
199 std::vector<BriefVisitInfo>* result_vector); | |
200 | |
175 protected: | 201 protected: |
176 // Returns the database for the functions in this interface. | 202 // Returns the database for the functions in this interface. |
177 virtual sql::Connection& GetDB() = 0; | 203 virtual sql::Connection& GetDB() = 0; |
178 | 204 |
179 // Called by the derived classes on initialization to make sure the tables | 205 // Called by the derived classes on initialization to make sure the tables |
180 // and indices are properly set up. Must be called before anything else. | 206 // and indices are properly set up. Must be called before anything else. |
181 bool InitVisitTable(); | 207 bool InitVisitTable(); |
182 | 208 |
183 // Convenience to fill a VisitRow. Assumes the visit values are bound starting | 209 // Convenience to fill a VisitRow. Assumes the visit values are bound starting |
184 // at index 0. | 210 // at index 0. |
185 static void FillVisitRow(sql::Statement& statement, VisitRow* visit); | 211 static void FillVisitRow(sql::Statement& statement, VisitRow* visit); |
186 | 212 |
187 // Convenience to fill a VisitVector. Assumes that statement.step() | 213 // Convenience to fill a VisitVector. Assumes that statement.step() |
188 // hasn't happened yet. | 214 // hasn't happened yet. |
189 static bool FillVisitVector(sql::Statement& statement, VisitVector* visits); | 215 static bool FillVisitVector(sql::Statement& statement, VisitVector* visits); |
190 | 216 |
191 // Called by the derived classes to migrate the older visits table which | 217 // Called by the derived classes to migrate the older visits table which |
192 // don't have visit_duration column yet. | 218 // don't have visit_duration column yet. |
193 bool MigrateVisitsWithoutDuration(); | 219 bool MigrateVisitsWithoutDuration(); |
194 | 220 |
195 private: | 221 private: |
222 scoped_refptr<ObserverListThreadSafe<VisitDatabaseObserver> > observers_; | |
196 | 223 |
197 DISALLOW_COPY_AND_ASSIGN(VisitDatabase); | 224 DISALLOW_COPY_AND_ASSIGN(VisitDatabase); |
198 }; | 225 }; |
199 | 226 |
200 } // history | 227 } // history |
201 | 228 |
202 #endif // CHROME_BROWSER_HISTORY_VISIT_DATABASE_H_ | 229 #endif // CHROME_BROWSER_HISTORY_VISIT_DATABASE_H_ |
OLD | NEW |