OLD | NEW |
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_CONTENT_PRECACHE_MANAGER_H_ | 5 #ifndef COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_ |
6 #define COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_ | 6 #define COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 // TODO(sclittle): Delete precache history when browsing history is deleted. | 54 // TODO(sclittle): Delete precache history when browsing history is deleted. |
55 // http://crbug.com/326549 | 55 // http://crbug.com/326549 |
56 class PrecacheManager : public KeyedService, | 56 class PrecacheManager : public KeyedService, |
57 public PrecacheFetcher::PrecacheDelegate, | 57 public PrecacheFetcher::PrecacheDelegate, |
58 public base::SupportsWeakPtr<PrecacheManager> { | 58 public base::SupportsWeakPtr<PrecacheManager> { |
59 public: | 59 public: |
60 typedef base::Callback<void(bool)> PrecacheCompletionCallback; | 60 typedef base::Callback<void(bool)> PrecacheCompletionCallback; |
61 | 61 |
62 PrecacheManager(content::BrowserContext* browser_context, | 62 PrecacheManager(content::BrowserContext* browser_context, |
63 const sync_driver::SyncService* const sync_service, | 63 const sync_driver::SyncService* const sync_service, |
64 const history::HistoryService* const history_service); | 64 const history::HistoryService* const history_service, |
| 65 std::unique_ptr<PrecacheDatabase> precache_database, |
| 66 const base::FilePath& db_path); |
65 ~PrecacheManager() override; | 67 ~PrecacheManager() override; |
66 | 68 |
67 // Returns true if the client is in the experiment group -- that is, | 69 // Returns true if the client is in the experiment group -- that is, |
68 // precaching is allowed based on user settings, and enabled as part of a | 70 // precaching is allowed based on user settings, and enabled as part of a |
69 // field trial or by commandline flag. Virtual for testing. | 71 // field trial or by commandline flag. Virtual for testing. |
70 virtual bool IsInExperimentGroup() const; | 72 virtual bool IsInExperimentGroup() const; |
71 | 73 |
72 // Returns true if the client is in the control group -- that is, precaching | 74 // Returns true if the client is in the control group -- that is, precaching |
73 // is allowed based on user settings, and the browser is in the control group | 75 // is allowed based on user settings, and the browser is in the control group |
74 // of the field trial. Virtual for testing. | 76 // of the field trial. Virtual for testing. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 DISALLOWED, | 112 DISALLOWED, |
111 PENDING | 113 PENDING |
112 }; | 114 }; |
113 | 115 |
114 // From KeyedService. | 116 // From KeyedService. |
115 void Shutdown() override; | 117 void Shutdown() override; |
116 | 118 |
117 // From PrecacheFetcher::PrecacheDelegate. | 119 // From PrecacheFetcher::PrecacheDelegate. |
118 void OnDone() override; | 120 void OnDone() override; |
119 | 121 |
| 122 // Callback when fetching unfinished work from storage is done. |
| 123 void OnGetUnfinishedWorkDone( |
| 124 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work); |
| 125 |
120 // From history::HistoryService::TopHosts. | 126 // From history::HistoryService::TopHosts. |
121 void OnHostsReceived(const history::TopHostsList& host_counts); | 127 void OnHostsReceived(const history::TopHostsList& host_counts); |
122 | 128 |
| 129 // Initializes and Starts a PrecacheFetcher with unfinished work. |
| 130 void InitializeAndStartFetcher(); |
| 131 |
123 // From history::HistoryService::TopHosts. Used for the control group, which | 132 // From history::HistoryService::TopHosts. Used for the control group, which |
124 // gets the list of TopHosts for metrics purposes, but otherwise does nothing. | 133 // gets the list of TopHosts for metrics purposes, but otherwise does nothing. |
125 void OnHostsReceivedThenDone(const history::TopHostsList& host_counts); | 134 void OnHostsReceivedThenDone(const history::TopHostsList& host_counts); |
126 | 135 |
127 // Returns true if precaching is allowed for the browser context. | 136 // Returns true if precaching is allowed for the browser context. |
128 AllowedType PrecachingAllowed() const; | 137 AllowedType PrecachingAllowed() const; |
129 | 138 |
130 // Update precache-related metrics in response to a URL being fetched. Called | 139 // Update precache-related metrics in response to a URL being fetched. Called |
131 // by RecordStatsForFetch() by way of an asynchronous HistoryService callback. | 140 // by RecordStatsForFetch() by way of an asynchronous HistoryService callback. |
132 void RecordStatsForFetchInternal(const GURL& url, | 141 void RecordStatsForFetchInternal(const GURL& url, |
(...skipping 22 matching lines...) Expand all Loading... |
155 // canceled. | 164 // canceled. |
156 PrecacheCompletionCallback precache_completion_callback_; | 165 PrecacheCompletionCallback precache_completion_callback_; |
157 | 166 |
158 // The PrecacheDatabase for tracking precache metrics. Should only be used on | 167 // The PrecacheDatabase for tracking precache metrics. Should only be used on |
159 // the DB thread. | 168 // the DB thread. |
160 std::unique_ptr<PrecacheDatabase> precache_database_; | 169 std::unique_ptr<PrecacheDatabase> precache_database_; |
161 | 170 |
162 // Flag indicating whether or not precaching is currently in progress. | 171 // Flag indicating whether or not precaching is currently in progress. |
163 bool is_precaching_; | 172 bool is_precaching_; |
164 | 173 |
| 174 // Work that hasn't yet finished. |
| 175 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work_; |
| 176 |
165 DISALLOW_COPY_AND_ASSIGN(PrecacheManager); | 177 DISALLOW_COPY_AND_ASSIGN(PrecacheManager); |
166 }; | 178 }; |
167 | 179 |
168 } // namespace precache | 180 } // namespace precache |
169 | 181 |
170 #endif // COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_ | 182 #endif // COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_ |
OLD | NEW |