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/compiler_specific.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 BrowsingDataQuotaHelperImpl(base::SingleThreadTaskRunner
* ui_thread
,
35 base::SingleThreadTaskRunner
* io_thread
,
36 storage::QuotaManager
* quota_manager
);
37 ~BrowsingDataQuotaHelperImpl() override
;
39 void FetchQuotaInfo();
41 // Callback function for GetOriginModifiedSince.
42 void GotOrigins(const std::set
<GURL
>& origins
, storage::StorageType type
);
44 void ProcessPendingHosts();
45 void GetHostUsage(const std::string
& host
, storage::StorageType type
);
47 // Callback function for GetHostUsage.
48 void GotHostUsage(const std::string
& host
,
49 storage::StorageType type
,
53 void DidRevokeHostQuota(storage::QuotaStatusCode status
, int64 quota
);
55 scoped_refptr
<storage::QuotaManager
> quota_manager_
;
56 FetchResultCallback callback_
;
58 typedef std::set
<std::pair
<std::string
, storage::StorageType
> > PendingHosts
;
59 PendingHosts pending_hosts_
;
60 std::map
<std::string
, QuotaInfo
> quota_info_
;
62 bool is_fetching_
= false;
64 scoped_refptr
<base::SingleThreadTaskRunner
> ui_thread_
;
65 scoped_refptr
<base::SingleThreadTaskRunner
> io_thread_
;
66 base::WeakPtrFactory
<BrowsingDataQuotaHelperImpl
> weak_factory_
;
68 friend class BrowsingDataQuotaHelper
;
69 friend class BrowsingDataQuotaHelperTest
;
71 DISALLOW_COPY_AND_ASSIGN(BrowsingDataQuotaHelperImpl
);
74 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_QUOTA_HELPER_IMPL_H_