| 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/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
| 21 #include "components/history/core/browser/history_types.h" | 21 #include "components/history/core/browser/history_types.h" |
| 22 #include "components/keyed_service/core/keyed_service.h" | 22 #include "components/keyed_service/core/keyed_service.h" |
| 23 #include "components/precache/core/precache_fetcher.h" | 23 #include "components/precache/core/precache_fetcher.h" |
| 24 #include "url/gurl.h" | 24 #include "url/gurl.h" |
| 25 | 25 |
| 26 namespace base { | 26 namespace base { |
| 27 class FilePath; |
| 27 class Time; | 28 class Time; |
| 28 } | 29 } |
| 29 | 30 |
| 30 namespace content { | 31 namespace content { |
| 31 class BrowserContext; | 32 class BrowserContext; |
| 32 } | 33 } |
| 33 | 34 |
| 34 namespace history { | 35 namespace history { |
| 35 class HistoryService; | 36 class HistoryService; |
| 36 } | 37 } |
| 37 | 38 |
| 38 namespace sync_driver { | 39 namespace sync_driver { |
| 39 class SyncService; | 40 class SyncService; |
| 40 } | 41 } |
| 41 | 42 |
| 42 namespace precache { | 43 namespace precache { |
| 43 | 44 |
| 44 class PrecacheDatabase; | 45 class PrecacheDatabase; |
| 46 class PrecacheUnfinishedWork; |
| 45 | 47 |
| 46 // Visible for test. | 48 // Visible for test. |
| 47 size_t NumTopHosts(); | 49 size_t NumTopHosts(); |
| 48 | 50 |
| 49 // Class that manages all precaching-related activities. Owned by the | 51 // Class that manages all precaching-related activities. Owned by the |
| 50 // BrowserContext that it is constructed for. Use | 52 // BrowserContext that it is constructed for. Use |
| 51 // PrecacheManagerFactory::GetForBrowserContext to get an instance of this | 53 // PrecacheManagerFactory::GetForBrowserContext to get an instance of this |
| 52 // class. All methods must be called on the UI thread unless indicated | 54 // class. All methods must be called on the UI thread unless indicated |
| 53 // otherwise. | 55 // otherwise. |
| 54 // TODO(sclittle): Delete precache history when browsing history is deleted. | 56 // TODO(sclittle): Delete precache history when browsing history is deleted. |
| 55 // http://crbug.com/326549 | 57 // http://crbug.com/326549 |
| 56 class PrecacheManager : public KeyedService, | 58 class PrecacheManager : public KeyedService, |
| 57 public PrecacheFetcher::PrecacheDelegate, | 59 public PrecacheFetcher::PrecacheDelegate, |
| 58 public base::SupportsWeakPtr<PrecacheManager> { | 60 public base::SupportsWeakPtr<PrecacheManager> { |
| 59 public: | 61 public: |
| 60 typedef base::Callback<void(bool)> PrecacheCompletionCallback; | 62 typedef base::Callback<void(bool)> PrecacheCompletionCallback; |
| 61 | 63 |
| 62 PrecacheManager(content::BrowserContext* browser_context, | 64 PrecacheManager(content::BrowserContext* browser_context, |
| 63 const sync_driver::SyncService* const sync_service, | 65 const sync_driver::SyncService* const sync_service, |
| 64 const history::HistoryService* const history_service); | 66 const history::HistoryService* const history_service, |
| 67 const base::FilePath& db_path, |
| 68 std::unique_ptr<PrecacheDatabase> precache_database); |
| 65 ~PrecacheManager() override; | 69 ~PrecacheManager() override; |
| 66 | 70 |
| 67 // Returns true if the client is in the experiment group -- that is, | 71 // 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 | 72 // precaching is allowed based on user settings, and enabled as part of a |
| 69 // field trial or by commandline flag. Virtual for testing. | 73 // field trial or by commandline flag. Virtual for testing. |
| 70 virtual bool IsInExperimentGroup() const; | 74 virtual bool IsInExperimentGroup() const; |
| 71 | 75 |
| 72 // Returns true if the client is in the control group -- that is, precaching | 76 // 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 | 77 // is allowed based on user settings, and the browser is in the control group |
| 74 // of the field trial. Virtual for testing. | 78 // of the field trial. Virtual for testing. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 DISALLOWED, | 114 DISALLOWED, |
| 111 PENDING | 115 PENDING |
| 112 }; | 116 }; |
| 113 | 117 |
| 114 // From KeyedService. | 118 // From KeyedService. |
| 115 void Shutdown() override; | 119 void Shutdown() override; |
| 116 | 120 |
| 117 // From PrecacheFetcher::PrecacheDelegate. | 121 // From PrecacheFetcher::PrecacheDelegate. |
| 118 void OnDone() override; | 122 void OnDone() override; |
| 119 | 123 |
| 124 // Callback when fetching unfinished work from storage is done. |
| 125 void OnGetUnfinishedWorkDone( |
| 126 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work); |
| 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 unfinished work. |
| 132 void InitializeAndStartFetcher(); |
| 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 |