Chromium Code Reviews| Index: chrome/browser/browsing_data/browsing_data_cache_storage_helper.h |
| diff --git a/chrome/browser/browsing_data/browsing_data_cache_storage_helper.h b/chrome/browser/browsing_data/browsing_data_cache_storage_helper.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..91c8c749c04c43c02f4729b25cf5484e7a74a22d |
| --- /dev/null |
| +++ b/chrome/browser/browsing_data/browsing_data_cache_storage_helper.h |
| @@ -0,0 +1,144 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_CACHE_STORAGE_HELPER_H_ |
| +#define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_CACHE_STORAGE_HELPER_H_ |
| + |
| +#include <list> |
| +#include <set> |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/callback.h" |
| +#include "base/compiler_specific.h" |
| +#include "base/files/file_path.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/synchronization/lock.h" |
| +#include "base/time/time.h" |
| +#include "content/public/browser/cache_storage_context.h" |
| +#include "content/public/browser/cache_storage_usage_info.h" |
| +#include "url/gurl.h" |
| + |
| +class Profile; |
| + |
| +// BrowsingDataCacheStorageHelper is an interface for classes dealing with |
| +// aggregating and deleting browsing data stored for Cache Storage. |
| +// A client of this class need to call StartFetching from the UI thread to |
| +// initiate the flow, and it'll be notified by the callback in its UI thread at |
| +// some later point. |
| +class BrowsingDataCacheStorageHelper |
| + : public base::RefCountedThreadSafe<BrowsingDataCacheStorageHelper> { |
| + public: |
| + // Create a BrowsingDataCacheStorageHelper instance for the Cache Storage |
| + // stored in |context|'s associated profile's user data directory. |
| + explicit BrowsingDataCacheStorageHelper( |
| + content::CacheStorageContext* context); |
| + |
| + // Starts the fetching process, which will notify its completion via |
| + // |callback|. This must be called only in the UI thread. |
| + virtual void StartFetching( |
| + const base::Callback< |
| + void(const std::list<content::CacheStorageUsageInfo>&)>& callback); |
| + // Requests the Cache Storage data for an origin be deleted. |
| + virtual void DeleteCacheStorage(const GURL& origin); |
| + |
| + protected: |
| + virtual ~BrowsingDataCacheStorageHelper(); |
| + |
| + // Owned by the profile. |
| + content::CacheStorageContext* cache_storage_context_; |
| + |
| + // Access to |cache_storage_info_| is triggered indirectly via the UI |
| + // thread and guarded by |is_fetching_|. This means |cache_storage_info_| |
| + // is only accessed while |is_fetching_| is true. The flag |is_fetching_| is |
| + // only accessed on the UI thread. |
| + // In the context of this class |cache_storage_info_| is only accessed on the |
| + // context's CacheStorage thread. |
| + std::list<content::CacheStorageUsageInfo> cache_storage_info_; |
| + |
| + // This member is only mutated on the UI thread. |
| + base::Callback<void(const std::list<content::CacheStorageUsageInfo>&)> |
| + completion_callback_; |
| + |
| + // Indicates whether or not we're currently fetching information: |
| + // it's true when StartFetching() is called in the UI thread, and it's reset |
| + // after we notified the callback in the UI thread. |
| + // This member is only mutated on the UI thread. |
| + bool is_fetching_ = false; |
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<BrowsingDataCacheStorageHelper>; |
| + |
| + // Enumerates all Cache Storage instances on the IO thread. |
| + void FetchCacheStorageUsageInfoOnIOThread(); |
| + |
| + // Notifies the completion callback in the UI thread. |
| + void NotifyOnUIThread(); |
| + |
| + // Deletes Cache Storages for an origin the IO thread. |
|
michaeln
2015/08/18 22:25:51
origin -on- the IO thread
but consider removing t
|
| + void DeleteCacheStorageOnIOThread(const GURL& origin); |
| + |
| + // Callback from CacheStorageContext::GetAllOriginsInfo() |
| + void GetAllOriginsInfoCallback( |
| + const std::vector<content::CacheStorageUsageInfo>& origins); |
| + |
| + DISALLOW_COPY_AND_ASSIGN(BrowsingDataCacheStorageHelper); |
| +}; |
| + |
| +// This class is an implementation of BrowsingDataCacheStorageHelper that does |
| +// not fetch its information from the Cache Storage context, but is passed the |
| +// info as a parameter. |
| +class CannedBrowsingDataCacheStorageHelper |
| + : public BrowsingDataCacheStorageHelper { |
| + public: |
| + // Contains information about a Cache Storage. |
| + struct PendingCacheStorageUsageInfo { |
| + PendingCacheStorageUsageInfo(const GURL& origin, |
| + int64 total_size_bytes, |
| + const base::Time& last_modified); |
| + ~PendingCacheStorageUsageInfo(); |
| + |
| + bool operator<(const PendingCacheStorageUsageInfo& other) const; |
| + |
| + GURL origin; |
| + int64 total_size_bytes; |
| + base::Time last_modified; |
| + }; |
| + |
| + explicit CannedBrowsingDataCacheStorageHelper( |
| + content::CacheStorageContext* context); |
| + |
| + // Add a Cache Storage to the set of canned Cache Storages that is |
| + // returned by this helper. |
| + void AddCacheStorage(const GURL& origin); |
| + |
| + // Clear the list of canned Cache Storages. |
| + void Reset(); |
| + |
| + // True if no Cache Storages are currently stored. |
| + bool empty() const; |
| + |
| + // Returns the number of currently stored Cache Storages. |
| + size_t GetCacheStorageCount() const; |
| + |
| + // Returns the current list of Cache Storages. |
| + const std::set< |
| + CannedBrowsingDataCacheStorageHelper::PendingCacheStorageUsageInfo>& |
| + GetCacheStorageUsageInfo() const; |
| + |
| + // BrowsingDataCacheStorageHelper methods. |
| + void StartFetching(const base::Callback< |
| + void(const std::list<content::CacheStorageUsageInfo>&)>& |
| + callback) override; |
| + void DeleteCacheStorage(const GURL& origin) override; |
| + |
| + private: |
| + ~CannedBrowsingDataCacheStorageHelper() override; |
| + |
| + std::set<PendingCacheStorageUsageInfo> pending_cache_storage_info_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataCacheStorageHelper); |
| +}; |
| + |
| +#endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_CACHE_STORAGE_HELPER_H_ |