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.
5 #ifndef CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_APPCACHE_HELPER_H_
6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_APPCACHE_HELPER_H_
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"
19 class AppCacheService;
22 // This class fetches appcache information on behalf of a caller
24 class BrowsingDataAppCacheHelper
25 : public base::RefCountedThreadSafe<BrowsingDataAppCacheHelper> {
27 typedef std::map<GURL, content::AppCacheInfoVector> OriginAppCacheInfoMap;
29 explicit BrowsingDataAppCacheHelper(Profile* profile);
31 virtual void StartFetching(const base::Closure& completion_callback);
32 virtual void DeleteAppCacheGroup(const GURL& manifest_url);
34 content::AppCacheInfoCollection* info_collection() const {
35 DCHECK(!is_fetching_);
36 return info_collection_.get();
40 friend class base::RefCountedThreadSafe<BrowsingDataAppCacheHelper>;
41 virtual ~BrowsingDataAppCacheHelper();
43 base::Closure completion_callback_;
44 scoped_refptr<content::AppCacheInfoCollection> info_collection_;
47 void OnFetchComplete(int rv);
50 content::AppCacheService* appcache_service_;
51 net::CancelableCompletionCallback appcache_info_callback_;
53 DISALLOW_COPY_AND_ASSIGN(BrowsingDataAppCacheHelper);
56 // This class is a thin wrapper around BrowsingDataAppCacheHelper that does not
57 // fetch its information from the appcache service, but gets them passed as
58 // a parameter during construction.
59 class CannedBrowsingDataAppCacheHelper : public BrowsingDataAppCacheHelper {
61 explicit CannedBrowsingDataAppCacheHelper(Profile* profile);
63 // Return a copy of the appcache helper. Only one consumer can use the
64 // StartFetching method at a time, so we need to create a copy of the helper
65 // every time we instantiate a cookies tree model for it.
66 CannedBrowsingDataAppCacheHelper* Clone();
68 // Add an appcache to the set of canned caches that is returned by this
70 void AddAppCache(const GURL& manifest_url);
72 // Clears the list of canned caches.
75 // True if no appcaches are currently stored.
78 // Returns the number of app cache resources.
79 size_t GetAppCacheCount() const;
81 // Returns a current map with the |AppCacheInfoVector|s per origin.
82 const OriginAppCacheInfoMap& GetOriginAppCacheInfoMap() const;
84 // BrowsingDataAppCacheHelper methods.
85 virtual void StartFetching(const base::Closure& completion_callback) OVERRIDE;
86 virtual void DeleteAppCacheGroup(const GURL& manifest_url) OVERRIDE;
89 virtual ~CannedBrowsingDataAppCacheHelper();
93 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataAppCacheHelper);
96 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_APPCACHE_HELPER_H_