Chromium Code Reviews| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 } | 48 } |
| 49 | 49 |
| 50 namespace syncer { | 50 namespace syncer { |
| 51 class SyncService; | 51 class SyncService; |
| 52 } | 52 } |
| 53 | 53 |
| 54 namespace precache { | 54 namespace precache { |
| 55 | 55 |
| 56 class PrecacheDatabase; | 56 class PrecacheDatabase; |
| 57 class PrecacheUnfinishedWork; | 57 class PrecacheUnfinishedWork; |
| 58 class PrecacheManifest; | |
| 58 | 59 |
| 59 extern const char kPrecacheFieldTrialName[]; | 60 extern const char kPrecacheFieldTrialName[]; |
| 60 | 61 |
| 61 // Visible for test. | 62 // Visible for test. |
| 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 |
| 72 class PrecacheManager : public KeyedService, | 73 class PrecacheManager : public KeyedService, |
| 73 public PrecacheFetcher::PrecacheDelegate, | 74 public PrecacheFetcher::PrecacheDelegate, |
| 74 public base::SupportsWeakPtr<PrecacheManager> { | 75 public base::SupportsWeakPtr<PrecacheManager> { |
| 75 public: | 76 public: |
| 77 class Delegate { | |
| 78 public: | |
| 79 // Called when a precache manifest has been successfully fetched and parsed. | |
| 80 virtual void OnManifestFetched(const std::string& host, | |
| 81 const PrecacheManifest& manifest) = 0; | |
| 82 }; | |
| 83 | |
| 76 typedef base::Callback<void(bool)> PrecacheCompletionCallback; | 84 typedef base::Callback<void(bool)> PrecacheCompletionCallback; |
| 77 | 85 |
| 78 PrecacheManager(content::BrowserContext* browser_context, | 86 PrecacheManager(content::BrowserContext* browser_context, |
| 79 const syncer::SyncService* sync_service, | 87 const syncer::SyncService* sync_service, |
| 80 const history::HistoryService* history_service, | 88 const history::HistoryService* history_service, |
| 81 const data_reduction_proxy::DataReductionProxySettings* | 89 const data_reduction_proxy::DataReductionProxySettings* |
| 82 data_reduction_proxy_settings, | 90 data_reduction_proxy_settings, |
| 91 Delegate* delegate, | |
| 83 const base::FilePath& db_path, | 92 const base::FilePath& db_path, |
| 84 std::unique_ptr<PrecacheDatabase> precache_database); | 93 std::unique_ptr<PrecacheDatabase> precache_database); |
| 85 ~PrecacheManager() override; | 94 ~PrecacheManager() override; |
| 86 | 95 |
| 87 // Returns true if the client is in the experiment group -- that is, | 96 // Returns true if the client is in the experiment group -- that is, |
| 88 // precaching is allowed based on user settings, and enabled as part of a | 97 // precaching is allowed based on user settings, and enabled as part of a |
| 89 // field trial or by commandline flag. Virtual for testing. | 98 // field trial or by commandline flag. Virtual for testing. |
| 90 virtual bool IsInExperimentGroup() const; | 99 virtual bool IsInExperimentGroup() const; |
| 91 | 100 |
| 92 // Returns true if the client is in the control group -- that is, precaching | 101 // Returns true if the client is in the control group -- that is, precaching |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 ALLOWED, | 155 ALLOWED, |
| 147 DISALLOWED, | 156 DISALLOWED, |
| 148 PENDING | 157 PENDING |
| 149 }; | 158 }; |
| 150 | 159 |
| 151 // From KeyedService. | 160 // From KeyedService. |
| 152 void Shutdown() override; | 161 void Shutdown() override; |
| 153 | 162 |
| 154 // From PrecacheFetcher::PrecacheDelegate. | 163 // From PrecacheFetcher::PrecacheDelegate. |
| 155 void OnDone() override; | 164 void OnDone() override; |
| 165 void OnManifestFetched(const std::string& host, | |
| 166 const PrecacheManifest& manifest) override; | |
| 156 | 167 |
| 157 // Registers the precache synthetic field trial for users whom the precache | 168 // Registers the precache synthetic field trial for users whom the precache |
| 158 // task was run recently. |last_precache_time| is the last time precache task | 169 // task was run recently. |last_precache_time| is the last time precache task |
| 159 // was run. | 170 // was run. |
| 160 void RegisterSyntheticFieldTrial(const base::Time last_precache_time); | 171 void RegisterSyntheticFieldTrial(const base::Time last_precache_time); |
| 161 | 172 |
| 162 // Callback when fetching unfinished work from storage is done. | 173 // Callback when fetching unfinished work from storage is done. |
| 163 void OnGetUnfinishedWorkDone( | 174 void OnGetUnfinishedWorkDone( |
| 164 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work); | 175 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work); |
| 165 | 176 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 | 223 |
| 213 // The history service corresponding to the browser context. Used to determine | 224 // The history service corresponding to the browser context. Used to determine |
| 214 // the list of top hosts. May be null. | 225 // the list of top hosts. May be null. |
| 215 const history::HistoryService* const history_service_; | 226 const history::HistoryService* const history_service_; |
| 216 | 227 |
| 217 // The data reduction proxy settings object corresponding to the browser | 228 // The data reduction proxy settings object corresponding to the browser |
| 218 // context. Used to determine if the proxy is enabled. | 229 // context. Used to determine if the proxy is enabled. |
| 219 const data_reduction_proxy::DataReductionProxySettings* const | 230 const data_reduction_proxy::DataReductionProxySettings* const |
| 220 data_reduction_proxy_settings_; | 231 data_reduction_proxy_settings_; |
| 221 | 232 |
| 233 // The Delegate corresponding to the browser context. Used to notify the | |
| 234 // browser about a new available manifest. May be null. | |
| 235 Delegate* delegate_; | |
|
Benoit L
2017/03/21 13:24:15
I understand why this is fine here, as the service
alexilin
2017/03/21 15:32:13
Isn't it clear from DependsOn() list in factory cl
Benoit L
2017/03/21 15:46:15
Acknowledged.
| |
| 236 | |
| 222 // The PrecacheFetcher used to precache resources. Should only be used on the | 237 // The PrecacheFetcher used to precache resources. Should only be used on the |
| 223 // UI thread. | 238 // UI thread. |
| 224 std::unique_ptr<PrecacheFetcher> precache_fetcher_; | 239 std::unique_ptr<PrecacheFetcher> precache_fetcher_; |
| 225 | 240 |
| 226 // The callback that will be run if precaching finishes without being | 241 // The callback that will be run if precaching finishes without being |
| 227 // canceled. | 242 // canceled. |
| 228 PrecacheCompletionCallback precache_completion_callback_; | 243 PrecacheCompletionCallback precache_completion_callback_; |
| 229 | 244 |
| 230 // The PrecacheDatabase for tracking precache metrics. Should only be used on | 245 // The PrecacheDatabase for tracking precache metrics. Should only be used on |
| 231 // the DB thread. | 246 // the DB thread. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 245 | 260 |
| 246 // Work that hasn't yet finished. | 261 // Work that hasn't yet finished. |
| 247 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work_; | 262 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work_; |
| 248 | 263 |
| 249 DISALLOW_COPY_AND_ASSIGN(PrecacheManager); | 264 DISALLOW_COPY_AND_ASSIGN(PrecacheManager); |
| 250 }; | 265 }; |
| 251 | 266 |
| 252 } // namespace precache | 267 } // namespace precache |
| 253 | 268 |
| 254 #endif // COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_ | 269 #endif // COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_ |
| OLD | NEW |