Home | History | Annotate | Download | only in browsing_data
      1 // Copyright (c) 2012 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 CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_APPCACHE_HELPER_H_
      6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_APPCACHE_HELPER_H_
      7 
      8 #include <map>
      9 
     10 #include "base/callback.h"
     11 #include "base/memory/ref_counted.h"
     12 #include "content/public/browser/appcache_service.h"
     13 #include "net/base/completion_callback.h"
     14 #include "url/gurl.h"
     15 
     16 namespace content {
     17 class BrowserContext;
     18 }
     19 
     20 // This class fetches appcache information on behalf of a caller
     21 // on the UI thread.
     22 class BrowsingDataAppCacheHelper
     23     : public base::RefCountedThreadSafe<BrowsingDataAppCacheHelper> {
     24  public:
     25   typedef std::map<GURL, content::AppCacheInfoVector> OriginAppCacheInfoMap;
     26 
     27   explicit BrowsingDataAppCacheHelper(content::BrowserContext* browser_context);
     28 
     29   virtual void StartFetching(const base::Closure& completion_callback);
     30   virtual void DeleteAppCacheGroup(const GURL& manifest_url);
     31 
     32   content::AppCacheInfoCollection* info_collection() const {
     33     DCHECK(!is_fetching_);
     34     return info_collection_.get();
     35   }
     36 
     37  protected:
     38   friend class base::RefCountedThreadSafe<BrowsingDataAppCacheHelper>;
     39   virtual ~BrowsingDataAppCacheHelper();
     40 
     41   base::Closure completion_callback_;
     42   scoped_refptr<content::AppCacheInfoCollection> info_collection_;
     43 
     44  private:
     45   void OnFetchComplete(int rv);
     46 
     47   bool is_fetching_;
     48   content::AppCacheService* appcache_service_;
     49   net::CancelableCompletionCallback appcache_info_callback_;
     50 
     51   DISALLOW_COPY_AND_ASSIGN(BrowsingDataAppCacheHelper);
     52 };
     53 
     54 // This class is a thin wrapper around BrowsingDataAppCacheHelper that does not
     55 // fetch its information from the appcache service, but gets them passed as
     56 // a parameter during construction.
     57 class CannedBrowsingDataAppCacheHelper : public BrowsingDataAppCacheHelper {
     58  public:
     59   explicit CannedBrowsingDataAppCacheHelper(
     60       content::BrowserContext* browser_context);
     61 
     62   // Add an appcache to the set of canned caches that is returned by this
     63   // helper.
     64   void AddAppCache(const GURL& manifest_url);
     65 
     66   // Clears the list of canned caches.
     67   void Reset();
     68 
     69   // True if no appcaches are currently stored.
     70   bool empty() const;
     71 
     72   // Returns the number of app cache resources.
     73   size_t GetAppCacheCount() const;
     74 
     75   // Returns a current map with the |AppCacheInfoVector|s per origin.
     76   const OriginAppCacheInfoMap& GetOriginAppCacheInfoMap() const;
     77 
     78   // BrowsingDataAppCacheHelper methods.
     79   virtual void StartFetching(const base::Closure& completion_callback) OVERRIDE;
     80   virtual void DeleteAppCacheGroup(const GURL& manifest_url) OVERRIDE;
     81 
     82  private:
     83   virtual ~CannedBrowsingDataAppCacheHelper();
     84 
     85   DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataAppCacheHelper);
     86 };
     87 
     88 #endif  // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_APPCACHE_HELPER_H_
     89