| 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 <list> | 8 #include <list> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 } | 25 } |
| 26 | 26 |
| 27 namespace content { | 27 namespace content { |
| 28 class BrowserContext; | 28 class BrowserContext; |
| 29 } | 29 } |
| 30 | 30 |
| 31 namespace history { | 31 namespace history { |
| 32 class HistoryService; | 32 class HistoryService; |
| 33 } | 33 } |
| 34 | 34 |
| 35 namespace sync_driver { |
| 36 class SyncService; |
| 37 } |
| 38 |
| 35 namespace precache { | 39 namespace precache { |
| 36 | 40 |
| 37 class PrecacheDatabase; | 41 class PrecacheDatabase; |
| 38 | 42 |
| 39 // Visible for test. | 43 // Visible for test. |
| 40 int NumTopHosts(); | 44 int NumTopHosts(); |
| 41 | 45 |
| 42 // Class that manages all precaching-related activities. Owned by the | 46 // Class that manages all precaching-related activities. Owned by the |
| 43 // BrowserContext that it is constructed for. Use | 47 // BrowserContext that it is constructed for. Use |
| 44 // PrecacheManagerFactory::GetForBrowserContext to get an instance of this | 48 // PrecacheManagerFactory::GetForBrowserContext to get an instance of this |
| 45 // class. All methods must be called on the UI thread unless indicated | 49 // class. All methods must be called on the UI thread unless indicated |
| 46 // otherwise. | 50 // otherwise. |
| 47 // TODO(sclittle): Delete precache history when browsing history is deleted. | 51 // TODO(sclittle): Delete precache history when browsing history is deleted. |
| 48 // http://crbug.com/326549 | 52 // http://crbug.com/326549 |
| 49 class PrecacheManager : public KeyedService, | 53 class PrecacheManager : public KeyedService, |
| 50 public PrecacheFetcher::PrecacheDelegate, | 54 public PrecacheFetcher::PrecacheDelegate, |
| 51 public base::SupportsWeakPtr<PrecacheManager> { | 55 public base::SupportsWeakPtr<PrecacheManager> { |
| 52 public: | 56 public: |
| 53 typedef base::Closure PrecacheCompletionCallback; | 57 typedef base::Closure PrecacheCompletionCallback; |
| 54 | 58 |
| 55 explicit PrecacheManager(content::BrowserContext* browser_context); | 59 explicit PrecacheManager(content::BrowserContext* browser_context, |
| 60 sync_driver::SyncService* sync_service); |
| 56 ~PrecacheManager() override; | 61 ~PrecacheManager() override; |
| 57 | 62 |
| 58 // Returns true if precaching is enabled as part of a field trial or by the | 63 // Returns true if precaching is enabled as part of a field trial or by the |
| 59 // command line flag. This method can be called on any thread. | 64 // command line flag. This method can be called on any thread. |
| 60 static bool IsPrecachingEnabled(); | 65 static bool IsPrecachingEnabled(); |
| 61 | 66 |
| 62 // Returns true if precaching is allowed for the browser context. | 67 // Returns true if precaching is allowed for the browser context. |
| 63 bool IsPrecachingAllowed(); | 68 bool IsPrecachingAllowed(); |
| 64 | 69 |
| 65 // Starts precaching resources that the user is predicted to fetch in the | 70 // Starts precaching resources that the user is predicted to fetch in the |
| (...skipping 22 matching lines...) Expand all Loading... |
| 88 | 93 |
| 89 // From PrecacheFetcher::PrecacheDelegate. | 94 // From PrecacheFetcher::PrecacheDelegate. |
| 90 void OnDone() override; | 95 void OnDone() override; |
| 91 | 96 |
| 92 // From history::HistoryService::TopHosts. | 97 // From history::HistoryService::TopHosts. |
| 93 void OnHostsReceived(const history::TopHostsList& host_counts); | 98 void OnHostsReceived(const history::TopHostsList& host_counts); |
| 94 | 99 |
| 95 // The browser context that owns this PrecacheManager. | 100 // The browser context that owns this PrecacheManager. |
| 96 content::BrowserContext* browser_context_; | 101 content::BrowserContext* browser_context_; |
| 97 | 102 |
| 103 // The sync service corresponding to the browser context. Used to determine |
| 104 // whether precache can run. May be null. |
| 105 sync_driver::SyncService* sync_service_; |
| 106 |
| 98 // The PrecacheFetcher used to precache resources. Should only be used on the | 107 // The PrecacheFetcher used to precache resources. Should only be used on the |
| 99 // UI thread. | 108 // UI thread. |
| 100 scoped_ptr<PrecacheFetcher> precache_fetcher_; | 109 scoped_ptr<PrecacheFetcher> precache_fetcher_; |
| 101 | 110 |
| 102 // The callback that will be run if precaching finishes without being | 111 // The callback that will be run if precaching finishes without being |
| 103 // canceled. | 112 // canceled. |
| 104 PrecacheCompletionCallback precache_completion_callback_; | 113 PrecacheCompletionCallback precache_completion_callback_; |
| 105 | 114 |
| 106 // The PrecacheDatabase for tracking precache metrics. Should only be used on | 115 // The PrecacheDatabase for tracking precache metrics. Should only be used on |
| 107 // the DB thread. | 116 // the DB thread. |
| 108 scoped_refptr<PrecacheDatabase> precache_database_; | 117 scoped_refptr<PrecacheDatabase> precache_database_; |
| 109 | 118 |
| 110 // Flag indicating whether or not precaching is currently in progress. | 119 // Flag indicating whether or not precaching is currently in progress. |
| 111 bool is_precaching_; | 120 bool is_precaching_; |
| 112 | 121 |
| 113 DISALLOW_COPY_AND_ASSIGN(PrecacheManager); | 122 DISALLOW_COPY_AND_ASSIGN(PrecacheManager); |
| 114 }; | 123 }; |
| 115 | 124 |
| 116 } // namespace precache | 125 } // namespace precache |
| 117 | 126 |
| 118 #endif // COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_ | 127 #endif // COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_ |
| OLD | NEW |