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_
8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "net/base/completion_callback.h"
12 #include "webkit/browser/appcache/appcache_service.h"
17 class AppCacheService
;
20 // This class fetches appcache information on behalf of a caller
22 class BrowsingDataAppCacheHelper
23 : public base::RefCountedThreadSafe
<BrowsingDataAppCacheHelper
> {
25 typedef std::map
<GURL
, appcache::AppCacheInfoVector
> OriginAppCacheInfoMap
;
27 explicit BrowsingDataAppCacheHelper(Profile
* profile
);
29 virtual void StartFetching(const base::Closure
& completion_callback
);
30 virtual void DeleteAppCacheGroup(const GURL
& manifest_url
);
32 appcache::AppCacheInfoCollection
* info_collection() const {
33 DCHECK(!is_fetching_
);
34 return info_collection_
.get();
38 friend class base::RefCountedThreadSafe
<BrowsingDataAppCacheHelper
>;
39 virtual ~BrowsingDataAppCacheHelper();
41 base::Closure completion_callback_
;
42 scoped_refptr
<appcache::AppCacheInfoCollection
> info_collection_
;
45 void OnFetchComplete(int rv
);
48 appcache::AppCacheService
* appcache_service_
;
49 net::CancelableCompletionCallback appcache_info_callback_
;
51 DISALLOW_COPY_AND_ASSIGN(BrowsingDataAppCacheHelper
);
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
{
59 explicit CannedBrowsingDataAppCacheHelper(Profile
* profile
);
61 // Return a copy of the appcache helper. Only one consumer can use the
62 // StartFetching method at a time, so we need to create a copy of the helper
63 // every time we instantiate a cookies tree model for it.
64 CannedBrowsingDataAppCacheHelper
* Clone();
66 // Add an appcache to the set of canned caches that is returned by this
68 void AddAppCache(const GURL
& manifest_url
);
70 // Clears the list of canned caches.
73 // True if no appcaches are currently stored.
76 // Returns the number of app cache resources.
77 size_t GetAppCacheCount() const;
79 // Returns a current map with the |AppCacheInfoVector|s per origin.
80 const OriginAppCacheInfoMap
& GetOriginAppCacheInfoMap() const;
82 // BrowsingDataAppCacheHelper methods.
83 virtual void StartFetching(const base::Closure
& completion_callback
) OVERRIDE
;
86 virtual ~CannedBrowsingDataAppCacheHelper();
90 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataAppCacheHelper
);
93 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_APPCACHE_HELPER_H_