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_EXPIRE_HISTORY_BACKEND_H_ | 5 #ifndef CHROME_BROWSER_HISTORY_EXPIRE_HISTORY_BACKEND_H_ |
6 #define CHROME_BROWSER_HISTORY_EXPIRE_HISTORY_BACKEND_H_ | 6 #define CHROME_BROWSER_HISTORY_EXPIRE_HISTORY_BACKEND_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "components/history/core/browser/history_types.h" | 17 #include "components/history/core/browser/history_types.h" |
18 | 18 |
19 class GURL; | 19 class GURL; |
20 class TestingProfile; | 20 class TestingProfile; |
21 | 21 |
22 namespace history { | 22 namespace history { |
23 | 23 |
24 class HistoryClient; | 24 class HistoryClient; |
25 class HistoryDatabase; | 25 class HistoryDatabase; |
26 struct HistoryDetails; | |
27 class ThumbnailDatabase; | 26 class ThumbnailDatabase; |
28 | 27 |
29 // Delegate used to broadcast notifications to the main thread. | 28 // Delegate used to broadcast notifications to the main thread. |
30 class BroadcastNotificationDelegate { | 29 class ExpireHistoryBackendDelegate { |
31 public: | 30 public: |
32 // Schedules a broadcast of the given notification on the application main | |
33 // thread. | |
34 virtual void BroadcastNotifications(int type, | |
35 scoped_ptr<HistoryDetails> details) = 0; | |
36 | |
37 // Tells typed url sync code to handle URL modifications or deletions. | 31 // Tells typed url sync code to handle URL modifications or deletions. |
38 virtual void NotifySyncURLsModified(URLRows* rows) = 0; | 32 virtual void NotifyURLsModified(const URLRows& rows) = 0; |
39 virtual void NotifySyncURLsDeleted(bool all_history, | 33 virtual void NotifyURLsDeleted(bool all_history, |
40 bool expired, | 34 bool expired, |
41 URLRows* rows) = 0; | 35 const URLRows& rows, |
| 36 const std::set<GURL>& favicon_urls) = 0; |
42 | 37 |
43 protected: | 38 protected: |
44 virtual ~BroadcastNotificationDelegate() {} | 39 virtual ~ExpireHistoryBackendDelegate() {} |
45 }; | 40 }; |
46 | 41 |
47 // Encapsulates visit expiration criteria and type of visits to expire. | 42 // Encapsulates visit expiration criteria and type of visits to expire. |
48 class ExpiringVisitsReader { | 43 class ExpiringVisitsReader { |
49 public: | 44 public: |
50 virtual ~ExpiringVisitsReader() {} | 45 virtual ~ExpiringVisitsReader() {} |
51 // Populates |visits| from |db|, using provided |end_time| and |max_visits| | 46 // Populates |visits| from |db|, using provided |end_time| and |max_visits| |
52 // cap. | 47 // cap. |
53 virtual bool Read(base::Time end_time, HistoryDatabase* db, | 48 virtual bool Read(base::Time end_time, HistoryDatabase* db, |
54 VisitVector* visits, int max_visits) const = 0; | 49 VisitVector* visits, int max_visits) const = 0; |
55 }; | 50 }; |
56 | 51 |
57 typedef std::vector<const ExpiringVisitsReader*> ExpiringVisitsReaders; | 52 typedef std::vector<const ExpiringVisitsReader*> ExpiringVisitsReaders; |
58 | 53 |
59 // Helper component to HistoryBackend that manages expiration and deleting of | 54 // Helper component to HistoryBackend that manages expiration and deleting of |
60 // history. | 55 // history. |
61 // | 56 // |
62 // It will automatically start periodically expiring old history once you call | 57 // It will automatically start periodically expiring old history once you call |
63 // StartExpiringOldStuff(). | 58 // StartExpiringOldStuff(). |
64 class ExpireHistoryBackend { | 59 class ExpireHistoryBackend { |
65 public: | 60 public: |
66 // The delegate pointer must be non-NULL. We will NOT take ownership of it. | 61 // The delegate pointer must be non-NULL. We will NOT take ownership of it. |
67 // HistoryClient may be NULL. The HistoryClient is used when expiring URLS so | 62 // HistoryClient may be NULL. The HistoryClient is used when expiring URLS so |
68 // that we don't remove any URLs or favicons that are bookmarked (visits are | 63 // that we don't remove any URLs or favicons that are bookmarked (visits are |
69 // removed though). | 64 // removed though). |
70 ExpireHistoryBackend(BroadcastNotificationDelegate* delegate, | 65 ExpireHistoryBackend(ExpireHistoryBackendDelegate* delegate, |
71 HistoryClient* history_client); | 66 HistoryClient* history_client); |
72 ~ExpireHistoryBackend(); | 67 ~ExpireHistoryBackend(); |
73 | 68 |
74 // Completes initialization by setting the databases that this class will use. | 69 // Completes initialization by setting the databases that this class will use. |
75 void SetDatabases(HistoryDatabase* main_db, | 70 void SetDatabases(HistoryDatabase* main_db, |
76 ThumbnailDatabase* thumb_db); | 71 ThumbnailDatabase* thumb_db); |
77 | 72 |
78 // Begins periodic expiration of history older than the given threshold. This | 73 // Begins periodic expiration of history older than the given threshold. This |
79 // will continue until the object is deleted. | 74 // will continue until the object is deleted. |
80 void StartExpiringOldStuff(base::TimeDelta expiration_threshold); | 75 void StartExpiringOldStuff(base::TimeDelta expiration_threshold); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 | 235 |
241 // Returns the reader for all visits. This method is only used by the unit | 236 // Returns the reader for all visits. This method is only used by the unit |
242 // tests. | 237 // tests. |
243 const ExpiringVisitsReader* GetAllVisitsReader(); | 238 const ExpiringVisitsReader* GetAllVisitsReader(); |
244 | 239 |
245 // Returns the reader for AUTO_SUBFRAME visits. This method is only used by | 240 // Returns the reader for AUTO_SUBFRAME visits. This method is only used by |
246 // the unit tests. | 241 // the unit tests. |
247 const ExpiringVisitsReader* GetAutoSubframeVisitsReader(); | 242 const ExpiringVisitsReader* GetAutoSubframeVisitsReader(); |
248 | 243 |
249 // Non-owning pointer to the notification delegate (guaranteed non-NULL). | 244 // Non-owning pointer to the notification delegate (guaranteed non-NULL). |
250 BroadcastNotificationDelegate* delegate_; | 245 ExpireHistoryBackendDelegate* delegate_; |
251 | 246 |
252 // Non-owning pointers to the databases we deal with (MAY BE NULL). | 247 // Non-owning pointers to the databases we deal with (MAY BE NULL). |
253 HistoryDatabase* main_db_; // Main history database. | 248 HistoryDatabase* main_db_; // Main history database. |
254 ThumbnailDatabase* thumb_db_; // Thumbnails and favicons. | 249 ThumbnailDatabase* thumb_db_; // Thumbnails and favicons. |
255 | 250 |
256 // The threshold for "old" history where we will automatically delete it. | 251 // The threshold for "old" history where we will automatically delete it. |
257 base::TimeDelta expiration_threshold_; | 252 base::TimeDelta expiration_threshold_; |
258 | 253 |
259 // List of all distinct types of readers. This list is used to populate the | 254 // List of all distinct types of readers. This list is used to populate the |
260 // work queue. | 255 // work queue. |
(...skipping 19 matching lines...) Expand all Loading... |
280 // Used to generate runnable methods to do timers on this class. They will be | 275 // Used to generate runnable methods to do timers on this class. They will be |
281 // automatically canceled when this class is deleted. | 276 // automatically canceled when this class is deleted. |
282 base::WeakPtrFactory<ExpireHistoryBackend> weak_factory_; | 277 base::WeakPtrFactory<ExpireHistoryBackend> weak_factory_; |
283 | 278 |
284 DISALLOW_COPY_AND_ASSIGN(ExpireHistoryBackend); | 279 DISALLOW_COPY_AND_ASSIGN(ExpireHistoryBackend); |
285 }; | 280 }; |
286 | 281 |
287 } // namespace history | 282 } // namespace history |
288 | 283 |
289 #endif // CHROME_BROWSER_HISTORY_EXPIRE_HISTORY_BACKEND_H_ | 284 #endif // CHROME_BROWSER_HISTORY_EXPIRE_HISTORY_BACKEND_H_ |
OLD | NEW |