1 // Copyright 2015 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_CACHE_STORAGE_HELPER_H_
6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_CACHE_STORAGE_HELPER_H_
11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/time/time.h"
14 #include "content/public/browser/cache_storage_context.h"
15 #include "content/public/browser/cache_storage_usage_info.h"
18 // BrowsingDataCacheStorageHelper is an interface for classes dealing with
19 // aggregating and deleting browsing data stored for Cache Storage.
20 // A client of this class need to call StartFetching from the UI thread to
21 // initiate the flow, and it'll be notified by the callback in its UI thread at
23 class BrowsingDataCacheStorageHelper
24 : public base::RefCountedThreadSafe
<BrowsingDataCacheStorageHelper
> {
27 base::Callback
<void(const std::list
<content::CacheStorageUsageInfo
>&)>;
29 // Create a BrowsingDataCacheStorageHelper instance for the Cache Storage
30 // stored in |context|'s associated profile's user data directory.
31 explicit BrowsingDataCacheStorageHelper(
32 content::CacheStorageContext
* context
);
34 // Starts the fetching process, which will notify its completion via
35 // |callback|. This must be called only in the UI thread.
36 virtual void StartFetching(const FetchCallback
& callback
);
37 // Requests the Cache Storage data for an origin be deleted.
38 virtual void DeleteCacheStorage(const GURL
& origin
);
41 virtual ~BrowsingDataCacheStorageHelper();
43 // Owned by the profile.
44 content::CacheStorageContext
* cache_storage_context_
;
47 friend class base::RefCountedThreadSafe
<BrowsingDataCacheStorageHelper
>;
49 // Deletes Cache Storages for an origin the IO thread.
50 void DeleteCacheStorageOnIOThread(const GURL
& origin
);
52 // Enumerates all Cache Storage instances on the IO thread.
53 void FetchCacheStorageUsageInfoOnIOThread(const FetchCallback
& callback
);
55 DISALLOW_COPY_AND_ASSIGN(BrowsingDataCacheStorageHelper
);
58 // This class is an implementation of BrowsingDataCacheStorageHelper that does
59 // not fetch its information from the Cache Storage context, but is passed the
60 // info as a parameter.
61 class CannedBrowsingDataCacheStorageHelper
62 : public BrowsingDataCacheStorageHelper
{
64 // Contains information about a Cache Storage.
65 struct PendingCacheStorageUsageInfo
{
66 PendingCacheStorageUsageInfo(const GURL
& origin
,
67 int64 total_size_bytes
,
68 const base::Time
& last_modified
);
69 ~PendingCacheStorageUsageInfo();
71 bool operator<(const PendingCacheStorageUsageInfo
& other
) const;
74 int64 total_size_bytes
;
75 base::Time last_modified
;
78 explicit CannedBrowsingDataCacheStorageHelper(
79 content::CacheStorageContext
* context
);
81 // Add a Cache Storage to the set of canned Cache Storages that is
82 // returned by this helper.
83 void AddCacheStorage(const GURL
& origin
);
85 // Clear the list of canned Cache Storages.
88 // True if no Cache Storages are currently stored.
91 // Returns the number of currently stored Cache Storages.
92 size_t GetCacheStorageCount() const;
94 // Returns the current list of Cache Storages.
96 CannedBrowsingDataCacheStorageHelper::PendingCacheStorageUsageInfo
>&
97 GetCacheStorageUsageInfo() const;
99 // BrowsingDataCacheStorageHelper methods.
100 void StartFetching(const base::Callback
<
101 void(const std::list
<content::CacheStorageUsageInfo
>&)>&
103 void DeleteCacheStorage(const GURL
& origin
) override
;
106 ~CannedBrowsingDataCacheStorageHelper() override
;
108 std::set
<PendingCacheStorageUsageInfo
> pending_cache_storage_info_
;
110 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataCacheStorageHelper
);
113 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_CACHE_STORAGE_HELPER_H_