| 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..829a5768a61a4763d5c7807307dfbce66d67da10
|
| --- /dev/null
|
| +++ b/chrome/browser/browsing_data/browsing_data_cache_storage_helper.h
|
| @@ -0,0 +1,119 @@
|
| +// 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 <vector>
|
| +
|
| +#include "base/callback.h"
|
| +#include "base/memory/ref_counted.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"
|
| +
|
| +// 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:
|
| + using FetchCallback =
|
| + base::Callback<void(const std::list<content::CacheStorageUsageInfo>&)>;
|
| +
|
| + // 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 FetchCallback& 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_;
|
| +
|
| + private:
|
| + friend class base::RefCountedThreadSafe<BrowsingDataCacheStorageHelper>;
|
| +
|
| + // Deletes Cache Storages for an origin the IO thread.
|
| + void DeleteCacheStorageOnIOThread(const GURL& origin);
|
| +
|
| + // Enumerates all Cache Storage instances on the IO thread.
|
| + void FetchCacheStorageUsageInfoOnIOThread(const FetchCallback& callback);
|
| +
|
| + // Callback from CacheStorageContext::GetAllOriginsInfo()
|
| + void GetAllOriginsInfoCallback(
|
| + const FetchCallback& callback,
|
| + 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_
|
|
|