| 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 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 // otherwise. | 36 // otherwise. |
| 37 // TODO(sclittle): Delete precache history when browsing history is deleted. | 37 // TODO(sclittle): Delete precache history when browsing history is deleted. |
| 38 // http://crbug.com/326549 | 38 // http://crbug.com/326549 |
| 39 class PrecacheManager : public KeyedService, | 39 class PrecacheManager : public KeyedService, |
| 40 public PrecacheFetcher::PrecacheDelegate, | 40 public PrecacheFetcher::PrecacheDelegate, |
| 41 public base::SupportsWeakPtr<PrecacheManager> { | 41 public base::SupportsWeakPtr<PrecacheManager> { |
| 42 public: | 42 public: |
| 43 typedef base::Closure PrecacheCompletionCallback; | 43 typedef base::Closure PrecacheCompletionCallback; |
| 44 | 44 |
| 45 explicit PrecacheManager(content::BrowserContext* browser_context); | 45 explicit PrecacheManager(content::BrowserContext* browser_context); |
| 46 virtual ~PrecacheManager(); | 46 ~PrecacheManager() override; |
| 47 | 47 |
| 48 // Returns true if precaching is enabled as part of a field trial or by the | 48 // Returns true if precaching is enabled as part of a field trial or by the |
| 49 // command line flag. This method can be called on any thread. | 49 // command line flag. This method can be called on any thread. |
| 50 static bool IsPrecachingEnabled(); | 50 static bool IsPrecachingEnabled(); |
| 51 | 51 |
| 52 // Returns true if precaching is allowed for the browser context. | 52 // Returns true if precaching is allowed for the browser context. |
| 53 bool IsPrecachingAllowed(); | 53 bool IsPrecachingAllowed(); |
| 54 | 54 |
| 55 // Starts precaching resources that the user is predicted to fetch in the | 55 // Starts precaching resources that the user is predicted to fetch in the |
| 56 // future. If precaching is already currently in progress, then this method | 56 // future. If precaching is already currently in progress, then this method |
| (...skipping 10 matching lines...) Expand all Loading... |
| 67 bool IsPrecaching() const; | 67 bool IsPrecaching() const; |
| 68 | 68 |
| 69 // Update precache-related metrics in response to a URL being fetched. | 69 // Update precache-related metrics in response to a URL being fetched. |
| 70 void RecordStatsForFetch(const GURL& url, | 70 void RecordStatsForFetch(const GURL& url, |
| 71 const base::Time& fetch_time, | 71 const base::Time& fetch_time, |
| 72 int64 size, | 72 int64 size, |
| 73 bool was_cached); | 73 bool was_cached); |
| 74 | 74 |
| 75 private: | 75 private: |
| 76 // From KeyedService. | 76 // From KeyedService. |
| 77 virtual void Shutdown() override; | 77 void Shutdown() override; |
| 78 | 78 |
| 79 // From PrecacheFetcher::PrecacheDelegate. | 79 // From PrecacheFetcher::PrecacheDelegate. |
| 80 virtual void OnDone() override; | 80 void OnDone() override; |
| 81 | 81 |
| 82 void OnURLsReceived(const std::list<GURL>& urls); | 82 void OnURLsReceived(const std::list<GURL>& urls); |
| 83 | 83 |
| 84 // The browser context that owns this PrecacheManager. | 84 // The browser context that owns this PrecacheManager. |
| 85 content::BrowserContext* browser_context_; | 85 content::BrowserContext* browser_context_; |
| 86 | 86 |
| 87 // The PrecacheFetcher used to precache resources. Should only be used on the | 87 // The PrecacheFetcher used to precache resources. Should only be used on the |
| 88 // UI thread. | 88 // UI thread. |
| 89 scoped_ptr<PrecacheFetcher> precache_fetcher_; | 89 scoped_ptr<PrecacheFetcher> precache_fetcher_; |
| 90 | 90 |
| 91 // The callback that will be run if precaching finishes without being | 91 // The callback that will be run if precaching finishes without being |
| 92 // canceled. | 92 // canceled. |
| 93 PrecacheCompletionCallback precache_completion_callback_; | 93 PrecacheCompletionCallback precache_completion_callback_; |
| 94 | 94 |
| 95 // The PrecacheDatabase for tracking precache metrics. Should only be used on | 95 // The PrecacheDatabase for tracking precache metrics. Should only be used on |
| 96 // the DB thread. | 96 // the DB thread. |
| 97 scoped_refptr<PrecacheDatabase> precache_database_; | 97 scoped_refptr<PrecacheDatabase> precache_database_; |
| 98 | 98 |
| 99 // Flag indicating whether or not precaching is currently in progress. | 99 // Flag indicating whether or not precaching is currently in progress. |
| 100 bool is_precaching_; | 100 bool is_precaching_; |
| 101 | 101 |
| 102 DISALLOW_COPY_AND_ASSIGN(PrecacheManager); | 102 DISALLOW_COPY_AND_ASSIGN(PrecacheManager); |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 } // namespace precache | 105 } // namespace precache |
| 106 | 106 |
| 107 #endif // COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_ | 107 #endif // COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_ |
| OLD | NEW |