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