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