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 CONTENT_BROWSER_APPCACHE_APPCACHE_QUOTA_CLIENT_H_
6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_QUOTA_CLIENT_H_
12 #include "base/gtest_prod_util.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "content/browser/appcache/appcache_storage.h"
16 #include "content/common/content_export.h"
17 #include "net/base/completion_callback.h"
18 #include "storage/browser/quota/quota_client.h"
19 #include "storage/browser/quota/quota_task.h"
20 #include "storage/common/quota/quota_types.h"
23 class AppCacheQuotaClientTest
;
24 class AppCacheServiceImpl
;
25 class AppCacheStorageImpl
;
27 // A QuotaClient implementation to integrate the appcache service
28 // with the quota management system. The QuotaClient interface is
29 // used on the IO thread by the quota manager. This class deletes
30 // itself when both the quota manager and the appcache service have
32 class AppCacheQuotaClient
: public storage::QuotaClient
{
34 typedef std::deque
<base::Closure
> RequestQueue
;
36 ~AppCacheQuotaClient() override
;
38 // QuotaClient method overrides
39 ID
id() const override
;
40 void OnQuotaManagerDestroyed() override
;
41 void GetOriginUsage(const GURL
& origin
,
42 storage::StorageType type
,
43 const GetUsageCallback
& callback
) override
;
44 void GetOriginsForType(storage::StorageType type
,
45 const GetOriginsCallback
& callback
) override
;
46 void GetOriginsForHost(storage::StorageType type
,
47 const std::string
& host
,
48 const GetOriginsCallback
& callback
) override
;
49 void DeleteOriginData(const GURL
& origin
,
50 storage::StorageType type
,
51 const DeletionCallback
& callback
) override
;
52 bool DoesSupport(storage::StorageType type
) const override
;
55 friend class content::AppCacheQuotaClientTest
;
56 friend class AppCacheServiceImpl
; // for NotifyAppCacheIsDestroyed
57 friend class AppCacheStorageImpl
; // for NotifyAppCacheIsReady
60 explicit AppCacheQuotaClient(AppCacheServiceImpl
* service
);
62 void DidDeleteAppCachesForOrigin(int rv
);
63 void GetOriginsHelper(storage::StorageType type
,
64 const std::string
& opt_host
,
65 const GetOriginsCallback
& callback
);
66 void ProcessPendingRequests();
67 void DeletePendingRequests();
68 const AppCacheStorage::UsageMap
* GetUsageMap();
69 net::CancelableCompletionCallback
* GetServiceDeleteCallback();
71 // For use by appcache internals during initialization and shutdown.
72 CONTENT_EXPORT
void NotifyAppCacheReady();
73 CONTENT_EXPORT
void NotifyAppCacheDestroyed();
75 // Prior to appcache service being ready, we have to queue
76 // up reqeusts and defer acting on them until we're ready.
77 RequestQueue pending_batch_requests_
;
78 RequestQueue pending_serial_requests_
;
80 // And once it's ready, we can only handle one delete request at a time,
81 // so we queue up additional requests while one is in already in progress.
82 DeletionCallback current_delete_request_callback_
;
83 scoped_ptr
<net::CancelableCompletionCallback
> service_delete_callback_
;
85 AppCacheServiceImpl
* service_
;
86 bool appcache_is_ready_
;
87 bool quota_manager_is_destroyed_
;
89 DISALLOW_COPY_AND_ASSIGN(AppCacheQuotaClient
);
92 } // namespace content
94 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_QUOTA_CLIENT_H_