| 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 |
| 126 void OnSaveUnfinishedWorkDone(bool success); |
| 127 |
| 120 // From history::HistoryService::TopHosts. | 128 // From history::HistoryService::TopHosts. |
| 121 void OnHostsReceived(const history::TopHostsList& host_counts); | 129 void OnHostsReceived(const history::TopHostsList& host_counts); |
| 122 | 130 |
| 131 // Initializes and Starts a PrecacheFetcher with the provided starting hosts. |
| 132 void InitializeAndStartFetcher(const std::vector<std::string>& hosts); |
| 133 |
| 123 // From history::HistoryService::TopHosts. Used for the control group, which | 134 // From history::HistoryService::TopHosts. Used for the control group, which |
| 124 // gets the list of TopHosts for metrics purposes, but otherwise does nothing. | 135 // gets the list of TopHosts for metrics purposes, but otherwise does nothing. |
| 125 void OnHostsReceivedThenDone(const history::TopHostsList& host_counts); | 136 void OnHostsReceivedThenDone(const history::TopHostsList& host_counts); |
| 126 | 137 |
| 127 // Returns true if precaching is allowed for the browser context. | 138 // Returns true if precaching is allowed for the browser context. |
| 128 AllowedType PrecachingAllowed() const; | 139 AllowedType PrecachingAllowed() const; |
| 129 | 140 |
| 130 // Update precache-related metrics in response to a URL being fetched. Called | 141 // Update precache-related metrics in response to a URL being fetched. Called |
| 131 // by RecordStatsForFetch() by way of an asynchronous HistoryService callback. | 142 // by RecordStatsForFetch() by way of an asynchronous HistoryService callback. |
| 132 void RecordStatsForFetchInternal(const GURL& url, | 143 void RecordStatsForFetchInternal(const GURL& url, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 155 // canceled. | 166 // canceled. |
| 156 PrecacheCompletionCallback precache_completion_callback_; | 167 PrecacheCompletionCallback precache_completion_callback_; |
| 157 | 168 |
| 158 // The PrecacheDatabase for tracking precache metrics. Should only be used on | 169 // The PrecacheDatabase for tracking precache metrics. Should only be used on |
| 159 // the DB thread. | 170 // the DB thread. |
| 160 std::unique_ptr<PrecacheDatabase> precache_database_; | 171 std::unique_ptr<PrecacheDatabase> precache_database_; |
| 161 | 172 |
| 162 // Flag indicating whether or not precaching is currently in progress. | 173 // Flag indicating whether or not precaching is currently in progress. |
| 163 bool is_precaching_; | 174 bool is_precaching_; |
| 164 | 175 |
| 176 // Work that hasn't yet finished. |
| 177 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work_; |
| 178 |
| 165 DISALLOW_COPY_AND_ASSIGN(PrecacheManager); | 179 DISALLOW_COPY_AND_ASSIGN(PrecacheManager); |
| 166 }; | 180 }; |
| 167 | 181 |
| 168 } // namespace precache | 182 } // namespace precache |
| 169 | 183 |
| 170 #endif // COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_ | 184 #endif // COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_ |
| OLD | NEW |