| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 | 50 |
| 51 namespace syncer { | 51 namespace syncer { |
| 52 class SyncService; | 52 class SyncService; |
| 53 } | 53 } |
| 54 | 54 |
| 55 namespace precache { | 55 namespace precache { |
| 56 | 56 |
| 57 class PrecacheDatabase; | 57 class PrecacheDatabase; |
| 58 class PrecacheUnfinishedWork; | 58 class PrecacheUnfinishedWork; |
| 59 | 59 |
| 60 extern const char kPrecacheFieldTrialName[]; |
| 61 |
| 60 // Visible for test. | 62 // Visible for test. |
| 61 extern const char kPrecacheFieldTrialName[]; | |
| 62 extern const char kMinCacheSizeParam[]; | 63 extern const char kMinCacheSizeParam[]; |
| 63 size_t NumTopHosts(); | 64 size_t NumTopHosts(); |
| 64 | 65 |
| 65 // Class that manages all precaching-related activities. Owned by the | 66 // Class that manages all precaching-related activities. Owned by the |
| 66 // BrowserContext that it is constructed for. Use | 67 // BrowserContext that it is constructed for. Use |
| 67 // PrecacheManagerFactory::GetForBrowserContext to get an instance of this | 68 // PrecacheManagerFactory::GetForBrowserContext to get an instance of this |
| 68 // class. All methods must be called on the UI thread unless indicated | 69 // class. All methods must be called on the UI thread unless indicated |
| 69 // otherwise. | 70 // otherwise. |
| 70 // TODO(sclittle): Delete precache history when browsing history is deleted. | 71 // TODO(sclittle): Delete precache history when browsing history is deleted. |
| 71 // http://crbug.com/326549 | 72 // http://crbug.com/326549 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 // Returns true if precaching is currently in progress, or false otherwise. | 113 // Returns true if precaching is currently in progress, or false otherwise. |
| 113 bool IsPrecaching() const; | 114 bool IsPrecaching() const; |
| 114 | 115 |
| 115 // Posts a task to the DB thread to delete all history entries from the | 116 // Posts a task to the DB thread to delete all history entries from the |
| 116 // database. Does not wait for completion of this task. | 117 // database. Does not wait for completion of this task. |
| 117 void ClearHistory(); | 118 void ClearHistory(); |
| 118 | 119 |
| 119 // Update precache about an URL being fetched. Metrics related to precache are | 120 // Update precache about an URL being fetched. Metrics related to precache are |
| 120 // updated and any ongoing precache will be cancelled if this is an user | 121 // updated and any ongoing precache will be cancelled if this is an user |
| 121 // initiated request. Should be called on UI thread. | 122 // initiated request. Should be called on UI thread. |
| 122 void UpdatePrecacheMetricsAndState(const GURL& url, | 123 void UpdatePrecacheMetricsAndState( |
| 123 const GURL& referrer, | 124 const GURL& url, |
| 124 const base::TimeDelta& latency, | 125 const GURL& referrer, |
| 125 const base::Time& fetch_time, | 126 const base::TimeDelta& latency, |
| 126 const net::HttpResponseInfo& info, | 127 const base::Time& fetch_time, |
| 127 int64_t size, | 128 const net::HttpResponseInfo& info, |
| 128 bool is_user_traffic); | 129 int64_t size, |
| 130 bool is_user_traffic, |
| 131 const base::Callback<void(base::Time)>& register_synthetic_trial); |
| 129 | 132 |
| 130 private: | 133 private: |
| 131 friend class PrecacheManagerTest; | 134 friend class PrecacheManagerTest; |
| 132 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, DeleteExpiredPrecacheHistory); | 135 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, DeleteExpiredPrecacheHistory); |
| 133 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, | 136 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, |
| 134 RecordStatsForFetchDuringPrecaching); | 137 RecordStatsForFetchDuringPrecaching); |
| 135 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, RecordStatsForFetchHTTP); | 138 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, RecordStatsForFetchHTTP); |
| 136 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, RecordStatsForFetchHTTPS); | 139 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, RecordStatsForFetchHTTPS); |
| 137 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, RecordStatsForFetchInTopHosts); | 140 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, RecordStatsForFetchInTopHosts); |
| 138 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, | 141 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, |
| 139 RecordStatsForFetchWithEmptyURL); | 142 RecordStatsForFetchWithEmptyURL); |
| 140 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, RecordStatsForFetchWithNonHTTP); | 143 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, RecordStatsForFetchWithNonHTTP); |
| 141 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, | 144 FRIEND_TEST_ALL_PREFIXES(PrecacheManagerTest, |
| 142 RecordStatsForFetchWithSizeZero); | 145 RecordStatsForFetchWithSizeZero); |
| 143 | 146 |
| 144 enum class AllowedType { | 147 enum class AllowedType { |
| 145 ALLOWED, | 148 ALLOWED, |
| 146 DISALLOWED, | 149 DISALLOWED, |
| 147 PENDING | 150 PENDING |
| 148 }; | 151 }; |
| 149 | 152 |
| 150 // From KeyedService. | 153 // From KeyedService. |
| 151 void Shutdown() override; | 154 void Shutdown() override; |
| 152 | 155 |
| 153 // From PrecacheFetcher::PrecacheDelegate. | 156 // From PrecacheFetcher::PrecacheDelegate. |
| 154 void OnDone() override; | 157 void OnDone() override; |
| 155 | 158 |
| 159 // Registers the precache synthetic field trial for users whom the precache |
| 160 // task was run recently. |last_precache_time| is the last time precache task |
| 161 // was run. |
| 162 void RegisterSyntheticFieldTrial(const base::Time last_precache_time); |
| 163 |
| 156 // Callback when fetching unfinished work from storage is done. | 164 // Callback when fetching unfinished work from storage is done. |
| 157 void OnGetUnfinishedWorkDone( | 165 void OnGetUnfinishedWorkDone( |
| 158 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work); | 166 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work); |
| 159 | 167 |
| 160 // From history::HistoryService::TopHosts. | 168 // From history::HistoryService::TopHosts. |
| 161 void OnHostsReceived(const history::TopHostsList& host_counts); | 169 void OnHostsReceived(const history::TopHostsList& host_counts); |
| 162 | 170 |
| 163 // Initializes and Starts a PrecacheFetcher with unfinished work. | 171 // Initializes and Starts a PrecacheFetcher with unfinished work. |
| 164 void InitializeAndStartFetcher(); | 172 void InitializeAndStartFetcher(); |
| 165 | 173 |
| 166 // From history::HistoryService::TopHosts. Used for the control group, which | 174 // From history::HistoryService::TopHosts. Used for the control group, which |
| 167 // gets the list of TopHosts for metrics purposes, but otherwise does nothing. | 175 // gets the list of TopHosts for metrics purposes, but otherwise does nothing. |
| 168 void OnHostsReceivedThenDone(const history::TopHostsList& host_counts); | 176 void OnHostsReceivedThenDone(const history::TopHostsList& host_counts); |
| 169 | 177 |
| 170 // Chain of callbacks for StartPrecaching that make sure that we only precache | 178 // Chain of callbacks for StartPrecaching that make sure that we only precache |
| 171 // if there is a cache big enough. | 179 // if there is a cache big enough. |
| 172 void PrecacheIfCacheIsBigEnough( | 180 void PrecacheIfCacheIsBigEnough( |
| 173 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter); | 181 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter); |
| 174 void OnCacheBackendReceived(int net_error_code); | 182 void OnCacheBackendReceived(int net_error_code); |
| 175 void OnCacheSizeReceived(int cache_size_bytes); | 183 void OnCacheSizeReceived(int cache_size_bytes); |
| 176 void OnCacheSizeReceivedInUIThread(int cache_size_bytes); | 184 void OnCacheSizeReceivedInUIThread(int cache_size_bytes); |
| 177 | 185 |
| 178 // Returns true if precaching is allowed for the browser context. | 186 // Returns true if precaching is allowed for the browser context. |
| 179 AllowedType PrecachingAllowed() const; | 187 AllowedType PrecachingAllowed() const; |
| 180 | 188 |
| 181 // Update precache-related metrics in response to a URL being fetched. | 189 // Update precache-related metrics in response to a URL being fetched. |
| 182 void RecordStatsForFetch(const GURL& url, | 190 void RecordStatsForFetch( |
| 183 const GURL& referrer, | 191 const GURL& url, |
| 184 const base::TimeDelta& latency, | 192 const GURL& referrer, |
| 185 const base::Time& fetch_time, | 193 const base::TimeDelta& latency, |
| 186 const net::HttpResponseInfo& info, | 194 const base::Time& fetch_time, |
| 187 int64_t size); | 195 const net::HttpResponseInfo& info, |
| 196 int64_t size, |
| 197 const base::Callback<void(base::Time)>& register_synthetic_trial, |
| 198 base::Time last_precache_time); |
| 188 | 199 |
| 189 // Update precache-related metrics in response to a URL being fetched. Called | 200 // Update precache-related metrics in response to a URL being fetched. Called |
| 190 // by RecordStatsForFetch() by way of an asynchronous HistoryService callback. | 201 // by RecordStatsForFetch() by way of an asynchronous HistoryService callback. |
| 191 void RecordStatsForFetchInternal(const GURL& url, | 202 void RecordStatsForFetchInternal(const GURL& url, |
| 192 const std::string& referrer_host, | 203 const std::string& referrer_host, |
| 193 const base::TimeDelta& latency, | 204 const base::TimeDelta& latency, |
| 194 const base::Time& fetch_time, | 205 const base::Time& fetch_time, |
| 195 const net::HttpResponseInfo& info, | 206 const net::HttpResponseInfo& info, |
| 196 int64_t size, | 207 int64_t size, |
| 197 int host_rank); | 208 int host_rank); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 249 |
| 239 // Work that hasn't yet finished. | 250 // Work that hasn't yet finished. |
| 240 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work_; | 251 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work_; |
| 241 | 252 |
| 242 DISALLOW_COPY_AND_ASSIGN(PrecacheManager); | 253 DISALLOW_COPY_AND_ASSIGN(PrecacheManager); |
| 243 }; | 254 }; |
| 244 | 255 |
| 245 } // namespace precache | 256 } // namespace precache |
| 246 | 257 |
| 247 #endif // COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_ | 258 #endif // COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_ |
| OLD | NEW |