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_QUOTA_HELPER_H_
6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_QUOTA_HELPER_H_
11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/sequenced_task_runner_helpers.h"
14 #include "storage/common/quota/quota_types.h"
18 class SingleThreadTaskRunner
;
21 class BrowsingDataQuotaHelper
;
24 struct BrowsingDataQuotaHelperDeleter
{
25 static void Destruct(const BrowsingDataQuotaHelper
* helper
);
28 // This class is an interface class to bridge between Cookies Tree and Unified
29 // Quota System. This class provides a way to get usage and quota information
30 // through the instance.
32 // Call Create to create an instance for a profile and call StartFetching with
33 // a callback to fetch information asynchronously.
35 // Parallel fetching is not allowed, a fetching task should start after end of
36 // previous task. All method of this class should called from UI thread.
37 class BrowsingDataQuotaHelper
38 : public base::RefCountedThreadSafe
<BrowsingDataQuotaHelper
,
39 BrowsingDataQuotaHelperDeleter
> {
41 // QuotaInfo contains host-based quota and usage information for persistent
42 // and temporary storage.
45 explicit QuotaInfo(const std::string
& host
);
46 QuotaInfo(const std::string
& host
,
47 int64 temporary_usage
,
48 int64 persistent_usage
,
49 int64 syncable_usage
);
52 // Certain versions of MSVC 2008 have bad implementations of ADL for nested
53 // classes so they require these operators to be declared here instead of in
54 // the global namespace.
55 bool operator <(const QuotaInfo
& rhs
) const;
56 bool operator ==(const QuotaInfo
& rhs
) const;
59 int64 temporary_usage
;
60 int64 persistent_usage
;
64 typedef std::list
<QuotaInfo
> QuotaInfoArray
;
65 typedef base::Callback
<void(const QuotaInfoArray
&)> FetchResultCallback
;
67 static BrowsingDataQuotaHelper
* Create(Profile
* profile
);
69 virtual void StartFetching(const FetchResultCallback
& callback
) = 0;
71 virtual void RevokeHostQuota(const std::string
& host
) = 0;
74 explicit BrowsingDataQuotaHelper(base::SingleThreadTaskRunner
* io_thread_
);
75 virtual ~BrowsingDataQuotaHelper();
78 friend class base::DeleteHelper
<BrowsingDataQuotaHelper
>;
79 friend struct BrowsingDataQuotaHelperDeleter
;
80 scoped_refptr
<base::SingleThreadTaskRunner
> io_thread_
;
82 DISALLOW_COPY_AND_ASSIGN(BrowsingDataQuotaHelper
);
85 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_QUOTA_HELPER_H_