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_IMPL_H_
6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_QUOTA_HELPER_IMPL_H_
13 #include "base/callback_forward.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/weak_ptr.h"
16 #include "chrome/browser/browsing_data/browsing_data_quota_helper.h"
17 #include "storage/common/quota/quota_types.h"
25 // Implementation of BrowsingDataQuotaHelper. Since a client of
26 // BrowsingDataQuotaHelper should live in UI thread and QuotaManager lives in
27 // IO thread, we have to communicate over thread using PostTask.
28 class BrowsingDataQuotaHelperImpl
: public BrowsingDataQuotaHelper
{
30 void StartFetching(const FetchResultCallback
& callback
) override
;
31 void RevokeHostQuota(const std::string
& host
) override
;
34 using PendingHosts
= std::set
<std::pair
<std::string
, storage::StorageType
>>;
35 using QuotaInfoMap
= std::map
<std::string
, QuotaInfo
>;
37 explicit BrowsingDataQuotaHelperImpl(storage::QuotaManager
* quota_manager
);
38 ~BrowsingDataQuotaHelperImpl() override
;
40 // Calls QuotaManager::GetOriginModifiedSince for each storage type.
41 void FetchQuotaInfoOnIOThread(const FetchResultCallback
& callback
);
43 // Callback function for QuotaManager::GetOriginModifiedSince.
44 void GotOrigins(PendingHosts
* pending_hosts
,
45 const base::Closure
& completion
,
46 const std::set
<GURL
>& origins
,
47 storage::StorageType type
);
49 // Calls QuotaManager::GetHostUsage for each (origin, type) pair.
50 void OnGetOriginsComplete(const FetchResultCallback
& callback
,
51 PendingHosts
* pending_hosts
);
53 // Callback function for QuotaManager::GetHostUsage.
54 void GotHostUsage(QuotaInfoMap
* quota_info
,
55 const base::Closure
& completion
,
56 const std::string
& host
,
57 storage::StorageType type
,
60 // Called when all QuotaManager::GetHostUsage requests are complete.
61 void OnGetHostsUsageComplete(const FetchResultCallback
& callback
,
62 QuotaInfoMap
* quota_info
);
64 void RevokeHostQuotaOnIOThread(const std::string
& host
);
65 void DidRevokeHostQuota(storage::QuotaStatusCode status
, int64 quota
);
67 scoped_refptr
<storage::QuotaManager
> quota_manager_
;
69 base::WeakPtrFactory
<BrowsingDataQuotaHelperImpl
> weak_factory_
;
71 friend class BrowsingDataQuotaHelper
;
72 friend class BrowsingDataQuotaHelperTest
;
74 DISALLOW_COPY_AND_ASSIGN(BrowsingDataQuotaHelperImpl
);
77 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_QUOTA_HELPER_IMPL_H_