1 // Copyright (c) 2011 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_QUOTA_HELPER_IMPL_H_
6 #define CHROME_BROWSER_BROWSING_DATA_QUOTA_HELPER_IMPL_H_
14 #include "base/callback_old.h"
15 #include "base/compiler_specific.h"
16 #include "base/memory/ref_counted.h"
17 #include "base/memory/scoped_callback_factory.h"
18 #include "base/memory/scoped_ptr.h"
19 #include "base/time.h"
20 #include "chrome/browser/browsing_data_quota_helper.h"
21 #include "content/public/browser/browser_thread.h"
22 #include "webkit/quota/quota_types.h"
28 // Implementation of BrowsingDataQuotaHelper. Since a client of
29 // BrowsingDataQuotaHelper should live in UI thread and QuotaManager lives in
30 // IO thread, we have to communicate over thread using PostTask.
31 class BrowsingDataQuotaHelperImpl
: public BrowsingDataQuotaHelper
{
33 virtual void StartFetching(const FetchResultCallback
& callback
) OVERRIDE
;
34 virtual void CancelNotification() OVERRIDE
;
35 virtual void RevokeHostQuota(const std::string
& host
) OVERRIDE
;
38 BrowsingDataQuotaHelperImpl(base::MessageLoopProxy
* ui_thread
,
39 base::MessageLoopProxy
* io_thread
,
40 quota::QuotaManager
* quota_manager
);
41 virtual ~BrowsingDataQuotaHelperImpl();
43 void FetchQuotaInfo();
45 // Callback function for GetOriginModifiedSince.
46 void GotOrigins(const std::set
<GURL
>& origins
, quota::StorageType type
);
48 void ProcessPendingHosts();
49 void GetHostUsage(const std::string
& host
, quota::StorageType type
);
51 // Callback function for GetHostUsage.
52 void GotHostUsage(const std::string
& host
,
53 quota::StorageType type
,
57 void DidRevokeHostQuota(quota::QuotaStatusCode status
,
58 const std::string
& host
,
59 quota::StorageType type
,
62 scoped_refptr
<quota::QuotaManager
> quota_manager_
;
63 FetchResultCallback callback_
;
65 typedef std::set
<std::pair
<std::string
, quota::StorageType
> > PendingHosts
;
66 PendingHosts pending_hosts_
;
67 std::map
<std::string
, QuotaInfo
> quota_info_
;
71 scoped_refptr
<base::MessageLoopProxy
> ui_thread_
;
72 scoped_refptr
<base::MessageLoopProxy
> io_thread_
;
73 base::WeakPtrFactory
<BrowsingDataQuotaHelperImpl
> weak_factory_
;
75 friend class BrowsingDataQuotaHelper
;
76 friend class BrowsingDataQuotaHelperTest
;
78 DISALLOW_COPY_AND_ASSIGN(BrowsingDataQuotaHelperImpl
);
81 #endif // CHROME_BROWSER_BROWSING_DATA_QUOTA_HELPER_IMPL_H_