OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef WEBKIT_APPCACHE_APPCACHE_QUOTA_CLIENT_H_ |
| 6 #define WEBKIT_APPCACHE_APPCACHE_QUOTA_CLIENT_H_ |
| 7 |
| 8 #include <deque> |
| 9 #include <map> |
| 10 #include <string> |
| 11 |
| 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "net/base/completion_callback.h" |
| 16 #include "webkit/appcache/appcache_storage.h" |
| 17 #include "webkit/quota/quota_client.h" |
| 18 #include "webkit/quota/quota_task.h" |
| 19 #include "webkit/quota/quota_types.h" |
| 20 |
| 21 namespace appcache { |
| 22 |
| 23 class AppCacheService; |
| 24 class AppCacheStorageImpl; |
| 25 class AppCacheQuotaClientTest; |
| 26 |
| 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 |
| 31 // been destroyed. |
| 32 class AppCacheQuotaClient : public quota::QuotaClient { |
| 33 public: |
| 34 virtual ~AppCacheQuotaClient(); |
| 35 |
| 36 // QuotaClient method overrides |
| 37 virtual ID id() const OVERRIDE; |
| 38 virtual void OnQuotaManagerDestroyed(); |
| 39 virtual void GetOriginUsage(const GURL& origin, |
| 40 quota::StorageType type, |
| 41 GetUsageCallback* callback) OVERRIDE; |
| 42 virtual void GetOriginsForType(quota::StorageType type, |
| 43 GetOriginsCallback* callback) OVERRIDE; |
| 44 virtual void GetOriginsForHost(quota::StorageType type, |
| 45 const std::string& host, |
| 46 GetOriginsCallback* callback) OVERRIDE; |
| 47 virtual void DeleteOriginData(const GURL& origin, |
| 48 quota::StorageType type, |
| 49 DeletionCallback* callback) OVERRIDE; |
| 50 |
| 51 private: |
| 52 friend class AppCacheService; // for NotifyAppCacheIsDestroyed |
| 53 friend class AppCacheStorageImpl; // for NotifyAppCacheIsReady |
| 54 friend class AppCacheQuotaClientTest; |
| 55 |
| 56 struct UsageRequest { |
| 57 GURL origin; |
| 58 quota::StorageType type; |
| 59 GetUsageCallback* callback; |
| 60 }; |
| 61 struct OriginsRequest { |
| 62 quota::StorageType type; |
| 63 std::string opt_host; |
| 64 GetOriginsCallback* callback; |
| 65 }; |
| 66 struct DeleteRequest { |
| 67 GURL origin; |
| 68 quota::StorageType type; |
| 69 DeletionCallback* callback; |
| 70 }; |
| 71 typedef std::deque<UsageRequest> UsageRequestQueue; |
| 72 typedef std::deque<OriginsRequest> OriginsRequestQueue; |
| 73 typedef std::deque<DeleteRequest> DeleteRequestQueue; |
| 74 |
| 75 explicit AppCacheQuotaClient(AppCacheService* service); |
| 76 |
| 77 void DidDeleteAppCachesForOrigin(int rv); |
| 78 void GetOriginsHelper(quota::StorageType type, |
| 79 const std::string& opt_host, |
| 80 GetOriginsCallback* callback_ptr); |
| 81 void ProcessPendingRequests(); |
| 82 void AbortPendingRequests(); |
| 83 void DeletePendingRequests(); |
| 84 const AppCacheStorage::UsageMap* GetUsageMap(); |
| 85 |
| 86 // For use by appcache internals during initialization and shutdown. |
| 87 void NotifyAppCacheReady(); |
| 88 void NotifyAppCacheDestroyed(); |
| 89 |
| 90 // Prior to appcache service being ready, we have to queue |
| 91 // up reqeusts and defer acting on them until we're ready. |
| 92 UsageRequestQueue pending_usage_requests_; |
| 93 OriginsRequestQueue pending_origins_requests_; |
| 94 DeleteRequestQueue pending_delete_requests_; |
| 95 |
| 96 // And once it's ready, we can only handle one delete request at a time, |
| 97 // so we queue up additional requests while one is in already in progress. |
| 98 scoped_ptr<DeletionCallback> current_delete_request_callback_; |
| 99 scoped_refptr<net::CancelableCompletionCallback<AppCacheQuotaClient> > |
| 100 service_delete_callback_; |
| 101 |
| 102 AppCacheService* service_; |
| 103 bool appcache_is_ready_; |
| 104 bool quota_manager_is_destroyed_; |
| 105 |
| 106 DISALLOW_COPY_AND_ASSIGN(AppCacheQuotaClient); |
| 107 }; |
| 108 |
| 109 } // namespace appcache |
| 110 |
| 111 #endif // WEBKIT_APPCACHE_APPCACHE_QUOTA_CLIENT_H_ |
OLD | NEW |