Update V8 to version 4.7.21.
[chromium-blink-merge.git] / chrome / browser / browsing_data / browsing_data_quota_helper_impl.h
blob3bb9ff13599ee1c3c67bc8241090a20a086b1943
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_
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <utility>
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"
19 class GURL;
21 namespace storage {
22 class QuotaManager;
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 {
29 public:
30 void StartFetching(const FetchResultCallback& callback) override;
31 void RevokeHostQuota(const std::string& host) override;
33 private:
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,
58 int64 usage);
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_