OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_CACHE_STORAGE_HELPER_H_ |
| 6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_CACHE_STORAGE_HELPER_H_ |
| 7 |
| 8 #include <list> |
| 9 #include <set> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/callback.h" |
| 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/time/time.h" |
| 15 #include "content/public/browser/cache_storage_context.h" |
| 16 #include "content/public/browser/cache_storage_usage_info.h" |
| 17 #include "url/gurl.h" |
| 18 |
| 19 // BrowsingDataCacheStorageHelper is an interface for classes dealing with |
| 20 // aggregating and deleting browsing data stored for Cache Storage. |
| 21 // A client of this class need to call StartFetching from the UI thread to |
| 22 // initiate the flow, and it'll be notified by the callback in its UI thread at |
| 23 // some later point. |
| 24 class BrowsingDataCacheStorageHelper |
| 25 : public base::RefCountedThreadSafe<BrowsingDataCacheStorageHelper> { |
| 26 public: |
| 27 using FetchCallback = |
| 28 base::Callback<void(const std::list<content::CacheStorageUsageInfo>&)>; |
| 29 |
| 30 // Create a BrowsingDataCacheStorageHelper instance for the Cache Storage |
| 31 // stored in |context|'s associated profile's user data directory. |
| 32 explicit BrowsingDataCacheStorageHelper( |
| 33 content::CacheStorageContext* context); |
| 34 |
| 35 // Starts the fetching process, which will notify its completion via |
| 36 // |callback|. This must be called only in the UI thread. |
| 37 virtual void StartFetching(const FetchCallback& callback); |
| 38 // Requests the Cache Storage data for an origin be deleted. |
| 39 virtual void DeleteCacheStorage(const GURL& origin); |
| 40 |
| 41 protected: |
| 42 virtual ~BrowsingDataCacheStorageHelper(); |
| 43 |
| 44 // Owned by the profile. |
| 45 content::CacheStorageContext* cache_storage_context_; |
| 46 |
| 47 private: |
| 48 friend class base::RefCountedThreadSafe<BrowsingDataCacheStorageHelper>; |
| 49 |
| 50 // Deletes Cache Storages for an origin the IO thread. |
| 51 void DeleteCacheStorageOnIOThread(const GURL& origin); |
| 52 |
| 53 // Enumerates all Cache Storage instances on the IO thread. |
| 54 void FetchCacheStorageUsageInfoOnIOThread(const FetchCallback& callback); |
| 55 |
| 56 // Callback from CacheStorageContext::GetAllOriginsInfo() |
| 57 void GetAllOriginsInfoCallback( |
| 58 const FetchCallback& callback, |
| 59 const std::vector<content::CacheStorageUsageInfo>& origins); |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(BrowsingDataCacheStorageHelper); |
| 62 }; |
| 63 |
| 64 // This class is an implementation of BrowsingDataCacheStorageHelper that does |
| 65 // not fetch its information from the Cache Storage context, but is passed the |
| 66 // info as a parameter. |
| 67 class CannedBrowsingDataCacheStorageHelper |
| 68 : public BrowsingDataCacheStorageHelper { |
| 69 public: |
| 70 // Contains information about a Cache Storage. |
| 71 struct PendingCacheStorageUsageInfo { |
| 72 PendingCacheStorageUsageInfo(const GURL& origin, |
| 73 int64 total_size_bytes, |
| 74 const base::Time& last_modified); |
| 75 ~PendingCacheStorageUsageInfo(); |
| 76 |
| 77 bool operator<(const PendingCacheStorageUsageInfo& other) const; |
| 78 |
| 79 GURL origin; |
| 80 int64 total_size_bytes; |
| 81 base::Time last_modified; |
| 82 }; |
| 83 |
| 84 explicit CannedBrowsingDataCacheStorageHelper( |
| 85 content::CacheStorageContext* context); |
| 86 |
| 87 // Add a Cache Storage to the set of canned Cache Storages that is |
| 88 // returned by this helper. |
| 89 void AddCacheStorage(const GURL& origin); |
| 90 |
| 91 // Clear the list of canned Cache Storages. |
| 92 void Reset(); |
| 93 |
| 94 // True if no Cache Storages are currently stored. |
| 95 bool empty() const; |
| 96 |
| 97 // Returns the number of currently stored Cache Storages. |
| 98 size_t GetCacheStorageCount() const; |
| 99 |
| 100 // Returns the current list of Cache Storages. |
| 101 const std::set< |
| 102 CannedBrowsingDataCacheStorageHelper::PendingCacheStorageUsageInfo>& |
| 103 GetCacheStorageUsageInfo() const; |
| 104 |
| 105 // BrowsingDataCacheStorageHelper methods. |
| 106 void StartFetching(const base::Callback< |
| 107 void(const std::list<content::CacheStorageUsageInfo>&)>& |
| 108 callback) override; |
| 109 void DeleteCacheStorage(const GURL& origin) override; |
| 110 |
| 111 private: |
| 112 ~CannedBrowsingDataCacheStorageHelper() override; |
| 113 |
| 114 std::set<PendingCacheStorageUsageInfo> pending_cache_storage_info_; |
| 115 |
| 116 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataCacheStorageHelper); |
| 117 }; |
| 118 |
| 119 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_CACHE_STORAGE_HELPER_H_ |
OLD | NEW |