| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 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 | 
|  | 3 // found in the LICENSE file. | 
|  | 4 | 
|  | 5 #ifndef COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_ | 
|  | 6 #define COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_ | 
|  | 7 | 
|  | 8 #include <list> | 
|  | 9 | 
|  | 10 #include "base/memory/ref_counted.h" | 
|  | 11 #include "base/memory/scoped_ptr.h" | 
|  | 12 #include "base/synchronization/lock.h" | 
|  | 13 #include "components/browser_context_keyed_service/browser_context_keyed_service
    .h" | 
|  | 14 #include "components/precache/core/precache_fetcher.h" | 
|  | 15 #include "url/gurl.h" | 
|  | 16 | 
|  | 17 namespace content { | 
|  | 18 class BrowserContext; | 
|  | 19 } | 
|  | 20 | 
|  | 21 namespace precache { | 
|  | 22 | 
|  | 23 class PrecacheDatabase; | 
|  | 24 class URLListProvider; | 
|  | 25 | 
|  | 26 // Class that manages all precaching-related activities. Owned by the | 
|  | 27 // BrowserContext that it is constructed for. Use | 
|  | 28 // PrecacheManagerFactory::GetForBrowserContext to get an instance of this | 
|  | 29 // class. | 
|  | 30 // TODO(sclittle): Delete precache history when browsing history is deleted. | 
|  | 31 class PrecacheManager : public BrowserContextKeyedService, | 
|  | 32                         PrecacheFetcher::PrecacheDelegate { | 
|  | 33  public: | 
|  | 34   explicit PrecacheManager(content::BrowserContext* browser_context); | 
|  | 35   virtual ~PrecacheManager(); | 
|  | 36 | 
|  | 37   // Returns true if precaching is enabled by either Finch or the command line | 
|  | 38   // flag. | 
|  | 39   static bool IsPrecachingEnabled(); | 
|  | 40 | 
|  | 41   // From BrowserContextKeyedService. | 
|  | 42   virtual void Shutdown() OVERRIDE; | 
|  | 43 | 
|  | 44   // From PrecacheFetcher::PrecacheDelegate. | 
|  | 45   virtual void OnDone() OVERRIDE; | 
|  | 46 | 
|  | 47   // Starts precaching resources that the user is predicted to fetch in the | 
|  | 48   // future. If precaching is already currently in progress, then this method | 
|  | 49   // does nothing. Must be called on the UI thread. | 
|  | 50   void StartPrecaching(URLListProvider* url_list_provider); | 
|  | 51 | 
|  | 52   // Cancels precaching if it is in progress. Must be called on the UI thread. | 
|  | 53   void CancelPrecaching(); | 
|  | 54 | 
|  | 55   // Returns true if precaching is currently in progress, or false otherwise. | 
|  | 56   // May be called from any thread. | 
|  | 57   bool IsPrecaching(); | 
|  | 58 | 
|  | 59   // Returns the PrecacheDatabase used for tracking precache metrics. This | 
|  | 60   // method can be called on any thread, but methods on the PrecacheDatabase | 
|  | 61   // should only be used on the DB thread. | 
|  | 62   scoped_refptr<PrecacheDatabase> precache_database(); | 
|  | 63 | 
|  | 64  private: | 
|  | 65   void OnURLsReceived(const std::list<GURL>& urls); | 
|  | 66 | 
|  | 67   // The browser context that owns this PrecacheManager. | 
|  | 68   content::BrowserContext* browser_context_; | 
|  | 69 | 
|  | 70   // The PrecacheFetcher used to precache resources. Should only be used on the | 
|  | 71   // UI thread. | 
|  | 72   scoped_ptr<PrecacheFetcher> precache_fetcher_; | 
|  | 73 | 
|  | 74   // The PrecacheDatabase for tracking precache metrics. Should only be used on | 
|  | 75   // the DB thread. | 
|  | 76   scoped_refptr<PrecacheDatabase> precache_database_; | 
|  | 77 | 
|  | 78   // Flag indicating whether or not precaching is currently in progress. | 
|  | 79   bool is_precaching_; | 
|  | 80 | 
|  | 81   // Lock for |is_precaching_|. | 
|  | 82   base::Lock lock_; | 
|  | 83 | 
|  | 84   DISALLOW_COPY_AND_ASSIGN(PrecacheManager); | 
|  | 85 }; | 
|  | 86 | 
|  | 87 }  // namespace precache | 
|  | 88 | 
|  | 89 #endif  // COMPONENTS_PRECACHE_CONTENT_PRECACHE_MANAGER_H_ | 
| OLD | NEW | 
|---|