| 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 |
| 11 #include <list> | 11 #include <list> |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <utility> | 14 #include <utility> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/callback.h" | 17 #include "base/callback.h" |
| 18 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
| 19 #include "base/macros.h" | 19 #include "base/macros.h" |
| 20 #include "base/memory/ref_counted.h" |
| 20 #include "base/memory/weak_ptr.h" | 21 #include "base/memory/weak_ptr.h" |
| 21 #include "components/history/core/browser/history_types.h" | 22 #include "components/history/core/browser/history_types.h" |
| 22 #include "components/keyed_service/core/keyed_service.h" | 23 #include "components/keyed_service/core/keyed_service.h" |
| 23 #include "components/precache/core/precache_fetcher.h" | 24 #include "components/precache/core/precache_fetcher.h" |
| 25 #include "net/disk_cache/disk_cache.h" |
| 26 #include "net/http/http_cache.h" |
| 24 #include "url/gurl.h" | 27 #include "url/gurl.h" |
| 25 | 28 |
| 26 namespace base { | 29 namespace base { |
| 27 class FilePath; | 30 class FilePath; |
| 28 class Time; | 31 class Time; |
| 29 class TimeDelta; | 32 class TimeDelta; |
| 30 } | 33 } |
| 31 | 34 |
| 32 namespace content { | 35 namespace content { |
| 33 class BrowserContext; | 36 class BrowserContext; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 48 namespace syncer { | 51 namespace syncer { |
| 49 class SyncService; | 52 class SyncService; |
| 50 } | 53 } |
| 51 | 54 |
| 52 namespace precache { | 55 namespace precache { |
| 53 | 56 |
| 54 class PrecacheDatabase; | 57 class PrecacheDatabase; |
| 55 class PrecacheUnfinishedWork; | 58 class PrecacheUnfinishedWork; |
| 56 | 59 |
| 57 // Visible for test. | 60 // Visible for test. |
| 61 extern const char kPrecacheFieldTrialName[]; |
| 62 extern const char kMinCacheSizeParam[]; |
| 58 size_t NumTopHosts(); | 63 size_t NumTopHosts(); |
| 59 | 64 |
| 60 // Class that manages all precaching-related activities. Owned by the | 65 // Class that manages all precaching-related activities. Owned by the |
| 61 // BrowserContext that it is constructed for. Use | 66 // BrowserContext that it is constructed for. Use |
| 62 // PrecacheManagerFactory::GetForBrowserContext to get an instance of this | 67 // PrecacheManagerFactory::GetForBrowserContext to get an instance of this |
| 63 // class. All methods must be called on the UI thread unless indicated | 68 // class. All methods must be called on the UI thread unless indicated |
| 64 // otherwise. | 69 // otherwise. |
| 65 // TODO(sclittle): Delete precache history when browsing history is deleted. | 70 // TODO(sclittle): Delete precache history when browsing history is deleted. |
| 66 // http://crbug.com/326549 | 71 // http://crbug.com/326549 |
| 67 class PrecacheManager : public KeyedService, | 72 class PrecacheManager : public KeyedService, |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 // From history::HistoryService::TopHosts. | 160 // From history::HistoryService::TopHosts. |
| 156 void OnHostsReceived(const history::TopHostsList& host_counts); | 161 void OnHostsReceived(const history::TopHostsList& host_counts); |
| 157 | 162 |
| 158 // Initializes and Starts a PrecacheFetcher with unfinished work. | 163 // Initializes and Starts a PrecacheFetcher with unfinished work. |
| 159 void InitializeAndStartFetcher(); | 164 void InitializeAndStartFetcher(); |
| 160 | 165 |
| 161 // From history::HistoryService::TopHosts. Used for the control group, which | 166 // From history::HistoryService::TopHosts. Used for the control group, which |
| 162 // gets the list of TopHosts for metrics purposes, but otherwise does nothing. | 167 // gets the list of TopHosts for metrics purposes, but otherwise does nothing. |
| 163 void OnHostsReceivedThenDone(const history::TopHostsList& host_counts); | 168 void OnHostsReceivedThenDone(const history::TopHostsList& host_counts); |
| 164 | 169 |
| 170 // Chain of callbacks for StartPrecaching that make sure that we only precache |
| 171 // if there is a cache big enough. |
| 172 void PrecacheIfCacheIsBigEnough( |
| 173 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter); |
| 174 void OnCacheBackendReceived(int net_error_code); |
| 175 void OnCacheSizeReceived(int cache_size_bytes); |
| 176 void OnCacheSizeReceivedInUIThread(int cache_size_bytes); |
| 177 |
| 165 // Returns true if precaching is allowed for the browser context. | 178 // Returns true if precaching is allowed for the browser context. |
| 166 AllowedType PrecachingAllowed() const; | 179 AllowedType PrecachingAllowed() const; |
| 167 | 180 |
| 168 // Update precache-related metrics in response to a URL being fetched. | 181 // Update precache-related metrics in response to a URL being fetched. |
| 169 void RecordStatsForFetch(const GURL& url, | 182 void RecordStatsForFetch(const GURL& url, |
| 170 const GURL& referrer, | 183 const GURL& referrer, |
| 171 const base::TimeDelta& latency, | 184 const base::TimeDelta& latency, |
| 172 const base::Time& fetch_time, | 185 const base::Time& fetch_time, |
| 173 const net::HttpResponseInfo& info, | 186 const net::HttpResponseInfo& info, |
| 174 int64_t size); | 187 int64_t size); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 // canceled. | 220 // canceled. |
| 208 PrecacheCompletionCallback precache_completion_callback_; | 221 PrecacheCompletionCallback precache_completion_callback_; |
| 209 | 222 |
| 210 // The PrecacheDatabase for tracking precache metrics. Should only be used on | 223 // The PrecacheDatabase for tracking precache metrics. Should only be used on |
| 211 // the DB thread. | 224 // the DB thread. |
| 212 std::unique_ptr<PrecacheDatabase> precache_database_; | 225 std::unique_ptr<PrecacheDatabase> precache_database_; |
| 213 | 226 |
| 214 // Flag indicating whether or not precaching is currently in progress. | 227 // Flag indicating whether or not precaching is currently in progress. |
| 215 bool is_precaching_; | 228 bool is_precaching_; |
| 216 | 229 |
| 230 // Pointer to the backend of the cache. Required to get the size of the cache. |
| 231 // It is not owned and it is reset on demand via callbacks. |
| 232 // It should only be accessed from the IO thread. |
| 233 disk_cache::Backend* cache_backend_; |
| 234 |
| 235 // The minimum cache size allowed for precaching. Initialized by |
| 236 // StartPrecaching and read by OnCacheSizeReceivedInUIThread. |
| 237 int min_cache_size_bytes_; |
| 238 |
| 217 // Work that hasn't yet finished. | 239 // Work that hasn't yet finished. |
| 218 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work_; | 240 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work_; |
| 219 | 241 |
| 220 DISALLOW_COPY_AND_ASSIGN(PrecacheManager); | 242 DISALLOW_COPY_AND_ASSIGN(PrecacheManager); |
| 221 }; | 243 }; |
| 222 | 244 |
| 223 } // namespace precache | 245 } // namespace precache |
| 224 | 246 |
| 225 #endif // COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_ | 247 #endif // COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_ |
| OLD | NEW |