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. 4 5 #ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_QUOTA_CLIENT_H_ 6 #define CONTENT_BROWSER_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 "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" 21 22 namespace content { 23 class AppCacheQuotaClientTest; 24 class AppCacheServiceImpl; 25 class AppCacheStorageImpl; 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 storage::QuotaClient { 33 public: 34 typedef std::deque<base::Closure> RequestQueue; 35 36 virtual ~AppCacheQuotaClient(); 37 38 // QuotaClient method overrides 39 virtual ID id() const OVERRIDE; 40 virtual void OnQuotaManagerDestroyed() OVERRIDE; 41 virtual void GetOriginUsage(const GURL& origin, 42 storage::StorageType type, 43 const GetUsageCallback& callback) OVERRIDE; 44 virtual void GetOriginsForType(storage::StorageType type, 45 const GetOriginsCallback& callback) OVERRIDE; 46 virtual void GetOriginsForHost(storage::StorageType type, 47 const std::string& host, 48 const GetOriginsCallback& callback) OVERRIDE; 49 virtual void DeleteOriginData(const GURL& origin, 50 storage::StorageType type, 51 const DeletionCallback& callback) OVERRIDE; 52 virtual bool DoesSupport(storage::StorageType type) const OVERRIDE; 53 54 private: 55 friend class content::AppCacheQuotaClientTest; 56 friend class AppCacheServiceImpl; // for NotifyAppCacheIsDestroyed 57 friend class AppCacheStorageImpl; // for NotifyAppCacheIsReady 58 59 CONTENT_EXPORT 60 explicit AppCacheQuotaClient(AppCacheServiceImpl* service); 61 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(); 70 71 // For use by appcache internals during initialization and shutdown. 72 CONTENT_EXPORT void NotifyAppCacheReady(); 73 CONTENT_EXPORT void NotifyAppCacheDestroyed(); 74 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_; 79 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_; 84 85 AppCacheServiceImpl* service_; 86 bool appcache_is_ready_; 87 bool quota_manager_is_destroyed_; 88 89 DISALLOW_COPY_AND_ASSIGN(AppCacheQuotaClient); 90 }; 91 92 } // namespace content 93 94 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_QUOTA_CLIENT_H_ 95